23,217
社区成员




#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
int main() {
struct passwd *pwd, *rpwd;
rpwd = getpwuid(getuid());
pwd = getpwuid(geteuid());
printf("real UID:[%s]\n", rpwd->pw_name);
printf("effective UID:[%s]\n", pwd->pw_name);
system("touch /tmp/foo.txt;ls -l /tmp/foo.txt; rm -rf /tmp/foo.txt;");
printf("\nset EUID to 'skin'..\n");
pwd = getpwnam("skin");
seteuid(pwd->pw_uid);
rpwd = getpwuid(getuid());
printf("real UID:[%s]\n", rpwd->pw_name);
pwd = getpwuid(geteuid());
printf("effective UID:[%s]\n", pwd->pw_name);
system("touch /tmp/foo.txt;ls -l /tmp/foo.txt; rm -rf /tmp/foo.txt;");
printf("\nset EUID to 'root'\n");
seteuid(0);
rpwd = getpwuid(getuid());
printf("real UID:[%s]\n", rpwd->pw_name);
pwd = getpwuid(geteuid());
printf("effective UID:[%s]\n", pwd->pw_name);
system("touch /tmp/foo.txt;ls -l /tmp/foo.txt; rm -rf /tmp/foo.txt;");
return 0;
}