简体   繁体   English

setuid和seteuid函数

[英]setuid and seteuid function

I tried to find the difference between setuid and seteuid function. 我试图找到setuid和seteuid函数之间的区别。 At that time, many of them says the following is the difference. 当时,许多人说以下是区别。 It is showed in the man page of setuid. 它显示在setuid的手册页中。

Thus, a set-user-ID-root program wishing to temporarily drop root privileges, assume the identity of an unprivileged user, and then regain root privileges afterward cannot use setuid() . 因此,希望暂时放弃root特权,假定未特权用户的身份,然后再获取root特权的set-user-ID-root程序不能使用setuid() You can accomplish this with seteuid(2) . 您可以使用seteuid(2)完成此seteuid(2)

I have a doubt in the above man page reference. 我对上面的手册页参考有疑问。 Using setuid we can set the effective user id of the process. 使用setuid,我们可以设置进程的有效用户ID。 For Ex: 例如:

setuid(getuid());

After this statement is executed, the effective userid of the process is changed to current user. 执行此语句后,该进程的有效用户标识将更改为当前用户。 So, to regain the root permission, I simply use, 因此,为了获得root权限,我只需使用,

setuid(0);

But why the man page reference shows 但是为什么手册页参考显示

afterward cannot use setuid(). You can accomplish this with seteuid(2)

  • The setuid() function sets (on success) all three process UIDs to the one specified in the function argument. setuid()函数将(成功)将所有三个进程UID设置为在函数参数中指定的一个。 Root permissions can be gained back only from the saved-uid process field, that has been just overwritten by the setuid call. 只能从setuid调用已覆盖的save-uid进程字段中获取根权限。 So, on the systems with defined _POSIX_SAVED_IDS in the unistd.h file, there is no way to get back to be root after the setuid() was called. 因此,在unistd.h文件中定义了_POSIX_SAVED_IDS的系统上,在调用setuid()之后无法回到根目录。 The setuid() is a one way ticket. setuid()是单程票。
  • The seteuid() function does not overwrite the saved-uid field, therefore root permissions can be re-gained after the function has called. seteuid()函数不会覆盖save-uid字段,因此可以在调用该函数后重新获得root权限。
  • I'm not sure the setuid(0) mentioned in your question does actual work (or perhaps the _POSIX_SAVED_IDS is not defined on your system). 我不确定您的问题中提到的setuid(0)是否可以实际工作(或者您的系统上未定义_POSIX_SAVED_IDS)。

请注意手册页的措辞:它用于set-user-id-root程序(因此,可执行文件由用户root拥有,并且suid位置1)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM