Chinaunix首页 | 论坛 | 博客
  • 博客访问: 251543
  • 博文数量: 88
  • 博客积分: 1429
  • 博客等级:
  • 技术积分: 523
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-18 15:31
文章分类

全部博文(88)

文章存档

2017年(2)

2016年(24)

2013年(1)

2012年(24)

2011年(15)

2010年(22)

我的朋友

分类: LINUX

2012-12-16 13:02:16

 

  1. man setuid
  2. -----
  3. setuid() sets the effective user ID of the calling process. If the effective UID of the caller is root, the real UID and saved set-user-ID are also set.
  4. Under Linux, setuid() is implemented like the POSIX version with the _POSIX_SAVED_IDS feature. This allows a set-user-ID (other than root) program to drop all of its user privileges, do some un-privi-leged work, and then re-engage the original effective user ID in a secure manner.
  5. If the user is root or the program is set-user-ID-root, special care must be taken. The setuid() function checks the effective user ID of the caller and if it is the superuser, all process-related user ID's are set to uid. After this has occurred, it is impossible for the program to regain root privileges.
  6. Thus, a set-user-ID-root program wishing to temporarily drop root privileges, assume the identity of a non-root user, and then regain root privileges afterwards cannot use setuid(). You can accomplish this with the (non-POSIX, BSD) call seteuid(2).
  7. 在一个程序里调用setuid()要注意两点:
  8. 一个程序如果被root用户执行,或者程序本身是set-user-ID-root(属主是root,且设置了set-user-ID位),程序中如果调用了setuid(non-root-uid),那么该进程就变成了普通进程,再也无法获取到root的权限了。
  9. 如果一个set-user-ID-root程序仅仅想暂时地放弃root权限,那么可以调用seteuid(non-root-uid),这样之后如果想重新获取到root权限,调用seteuid(0)即可!!!这是因为,seteuid()只会改变进程的effective user ID。当调用seteuid(non-root-uid),这时effective user ID是变成了non-root-uid,但saved set-user-ID还是为0(即root),所以当再次调用seteuid(0)时,又能将effective user ID设置为root。
  10. man seteuid
  11. -----
  12. seteuid() sets the effective user ID of the calling process. Unprivileged user processes may only set the effective user ID to the real user ID, the effective user ID or the saved set-user-ID.

阅读(2094) | 评论(0) | 转发(0) |
0

上一篇:文件权限后的点

下一篇:交换分区(SWAP)

给主人留下些什么吧!~~