我已经编写了一个读写/proc文件的内核模块,它工作得很好。现在我想对它使用权限,但当我为下面显示的权限编写函数时,它给了我一个错误。目标是让每个人都能够读取该文件,但只有root用户可以对其进行写入。
int my_permission(struct inode *inode, int op)
{
if(op == 4||(op == 2 && current->euid = 0)) //euid is not a member of task_struct
return 0;
return -EACCES;
}
const struct inode_operations my_iops = {
.permission = my_permission,
};我得到的错误是:
/home/karan/practice/procf/testproc1.c: In function ‘my_permission’:
/home/karan/practice/procf/testproc1.c:50:32: error: ‘struct task_struct’ has no member named ‘euid'我知道在get_current()中#定义了current。为什么会发生这种情况?是否有从get_current()返回的结构的成员列表
发布于 2012-02-03 05:50:12
struct task_struct是在内核源代码树的include/linux/sched.h中定义的,您可以在那里查看成员。当前凭据的格式为get_current()->cred,有效的用户id为get_current()->cred->euid
直接访问这些成员是不安全的,您必须从include/linux/cred.h调用current_euid()
您可能也会对http://www.kernel.org/doc/Documentation/security/credentials.txt感兴趣
https://stackoverflow.com/questions/9120323
复制相似问题