c – seteuidgeteuid:程序始终具有root id

c – seteuidgeteuid:程序始终具有root id,第1张

概述我目前正试图弄清楚SUID位和相应的函数seteuid和geteuid是如何工作的.所以我写了这个小程序: #include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>int main(int argc, char **argv) { printf("oldid %d\n", geteuid 我目前正试图弄清楚SUID位和相应的函数seteuID和geteuID是如何工作的.所以我写了这个小程序:

#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>int main(int argc,char **argv) {    printf("oldID %d\n",geteuID());    if(seteuID(0) == -1)        perror("seteuID faIEd");    printf("newID %d\n",geteuID());    return 0;}

编译它,将其所有者更改为root,并将文件所有者的s位更改为:

[chris@myhost Test]$ls -l test-rwsr-xr-x 1 root root 4830 Apr  5 07:56 test

但是产生的输出看起来像这样:

[chris@myhost Test]$./testoldID 0newID 0

这是我不明白的事情.根据我的发现,geteuID的第一次调用实际上应该返回该程序的调用者的用户ID(即chris – 我的ID将是1000),但程序将root显示为有效用户ID.任何人都可以解释为什么会这样吗?

解决方法 从我Mac上的geteuID()的手册页(OS X 10.6.7):

The real user ID is that of the user who has invoked the program. As the effective user ID gives the process additional permissions during execution of “set-user-ID” mode processes,getuID() is used to determine the real-user-ID of the calling process.

由于您已设置suID位,因此程序的有效用户ID是从执行开始的文件所有者(root).

总结

以上是内存溢出为你收集整理的c – seteuid / geteuid:程序始终具有root id全部内容,希望文章能够帮你解决c – seteuid / geteuid:程序始终具有root id所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1213536.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存