struct task_struct 成员?
我已经编写了在 /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’
我认为 task_struct 中还有其他成员指向 user id 。我对解决方案以及用于的 task_struct 成员字段的描述感兴趣。
问候 卡兰
i have written module which reads and write on /proc file and is working fine but want to use permissions with it when i make the function for permissions shown below its gives me error (basically i want every one could read the file but only root could write in it).
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,
};
but its giving me error as follow:
/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’
I think there is other member in task_struct which points to user id . I am interested in solution as well as description of task_struct members field used for.
regards
karan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 include/linux/cred.h:
因此 current_euid() 依赖于 current_cred():
因此,对于您的问题,要进行有效的 UID 比较,请查看 /fs/exec.c:
与您的程序对比:
这意味着即使用户不是以UID=0登录的,也会被有效地视为UID==0?听起来很危险
See include/linux/cred.h:
and so current_euid() falls back on current_cred():
So for you problem, to do effective UID comparison, take a look at /fs/exec.c:
contrast with your program:
which means even if the user is not logined with UID=0, it will be treated effecively as UID==0? Sounds dangerous
current->euid
吗?也许你是想比较。current
在哪里定义的?我假设它是一个 struct task_struct ,但如果是这样,那么 euid 是一个指针吗?或者current
是指向struct task_struct
的指针?如果euid
和current
都不是指针,只需将->
替换为。
有点偏离主题,但是:
这种事情会让维护你代码的程序员想在你睡梦中杀死你。使用
typedef
提高可读性。不要声明全局变量;如果这样做,请不要在函数之后声明它们。当声明具有部分赋值的结构时,在声明之后执行它更具可读性。我知道它是一个测试,或者是不完整的代码,或者是没有人需要维护的东西。但您可能想在几年后阅读本文,当您这样做时,您将花费两倍的时间来尝试找到您正在寻找的解决方案。你把这个贴在SO上,那里有一些纳粹风格的人,比如我自己,在看到这样的声明后今晚将难以入睡。
current->euid
? Maybe you meant to compare.current
defined? I'm assuming its astruct task_struct
but if so, iseuid
a pointer? or iscurrent
a pointer to astruct task_struct
? If neithereuid
norcurrent
are pointers just replace->
with.
Kind of out of topic, but:
Is the kind of thing that would make a programmer maintaining your code want to kill you in your sleep. Use
typedef
for readability. Don't declare global variables; if you do, don't declare them after a function. When declaring a struct with partial assignments its more readable to do it after the declaration.I know its a test, or an incomplete code, or something no one will need to maintain. But you might want to read this in a couple of years, and when you do you'll spend twice as much trying to find the solution you are looking for. And you are posting this on SO where there are some style nazis, like myself, that will have problems to sleep this night after seeing a declaration like that.