[英]Using the setuid bit in Linux
I have this C
file: 我有这个C
文件:
#include <stdio.h>
#include <unistd.h>
int main(void)
{
printf("%s\n", getlogin());
printf("%i\n", getuid());
}
I compile it, set the UID and GID both to root
and set the setuid bit, so that it looks like this: 我编译它,将UID和GID都设置为root
并设置setuid位,使其看起来像这样:
-rwsrwsr-x 1 root root 8735 Apr 8 19:51 a.out
However when I call $ ./a.out
I still get: 但是,当我打电话给$ ./a.out
我仍然得到:
user
1000
What am I doing wrong? 我究竟做错了什么?
The real user ID is still the user that called the program, but the effective user ID is root. 实际用户ID仍然是调用程序的用户,但是有效用户ID是root。 In a setuid program, they are not the same. 在setuid程序中,它们是不同的。
To get the effective user ID, call geteuid()
. 要获取有效的用户ID,请调用geteuid()
。 You can also use cuserid()
to get the name associated with the effective user ID. 您还可以使用cuserid()
获取与有效用户ID关联的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.