关于setuid的一点疑问

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
jiandan23
帖子: 94
注册时间: 2010-12-17 22:31
系统: Mint 19.2

关于setuid的一点疑问

#1

帖子 jiandan23 » 2014-10-25 10:24

按照道理,如果某个可执行程序设置了setuid的话,那么任何用户在执行它的时候,都自动的变成文件拥有者的身份。
但是大家请看下面的这个例子:
捕获.JPG
为什么普通用户在执行ping命令时,所产生的进程的real user和effective user还是它自己?不知道是不是我的理解有误
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 关于setuid的一点疑问

#2

帖子 poloshiao » 2014-10-25 14:21

为什么普通用户在执行ping命令时,所产生的进程的real user和effective user还是它自己?
參閱
http://manpages.ubuntu.com/manpages/uto ... uid.2.html
If the effective UID of the caller is root, the real UID and saved set-user-ID are also set.
头像
astolia
论坛版主
帖子: 6703
注册时间: 2008-09-18 13:11

Re: 关于setuid的一点疑问

#3

帖子 astolia » 2014-10-25 17:51

这有什么想不明白的,程序自己用setuid重置了呗,用ltrace或strace看就知道了
或者直接看代码也行 http://sourceforge.net/p/iputils/code/c ... g_common.c 第114行
MacOS上的ping的源代码注释更明白 http://www.opensource.apple.com/source/ ... roj/ping.c
/*
* Do the stuff that we need root priv's for *first*, and
* then drop our setuid bit. Save error reporting for
* after arg parsing.
*/
回复