【发布时间】:2014-11-15 03:10:18
【问题描述】:
我想将当前进程的有效 uid 设置为其他用户的 uid(或任意值)。
struct passwd* pwHost = getpwnam(hostName);//hostName is another user's name
struct passwd* pwGuest = getpwnam(guestName);//guestName is the current log-in user's name
if(pwHost==NULL||pwGuest==NULL)
{
printf("User cannot be found\n");
exit(0);
}
//setresuid(pwGuest->pw_uid, pwHost->pw_uid, pwGuest->pw_uid);//change the effective uid of current process to the host uid
setresuid(1000, 1000, 1000);//change current process's uid to a arbitrary value
printf("Host uid: %u\n", pwHost->pw_uid);
printf("Guest uid: %u\n", pwGuest->pw_uid);
static uid_t euid, ruid, suid;
getresuid(&euid, &ruid, &suid);
printf("euid: %u\n", euid);
printf("ruid: %u\n", ruid);
printf("suid: %u\n", suid);
printf("Set permission complete\n");
结果:
Host uid: 35917
Guest uid: 35917
euid: 35917
ruid: 35917
suid: 35917
但是,它们似乎都没有改变。我查阅了手册,其中解释了用户需要特权或我不太明白的东西。谁能给我一些关于如何实现目标的提示?非常感谢。
【问题讨论】: