2012-02-02 69 views
3

我写了一个内核模块,它读取和写入/proc文件,它工作正常。现在我想使用它的权限,但是当我为下面显示的权限编写函数时,它给我一个错误。目标是让每个人都能够读取文件,但只有root可以写入。get_current()在这个内核模块中返回什么?

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' 

我知道current已经#defined到get_current()。这是为什么发生?是否有从get_current()返回的结构成员列表?

回答

6

struct task_struct在内核源代码树中的include/linux/sched.h中定义,您可以查看其中的成员。当前凭据将是get_current()->cred,有效用户ID是get_current()->cred->euid

这不是安全的直接访问这些成员,必须而调用current_euid()include/linux/cred.h

http://www.kernel.org/doc/Documentation/security/credentials.txt可能是你的兴趣以及