我以 root 身份运行 php-cli 7.3.19(在 Debian 10 Buster、linux 内核 4.19.0-8-amd64 上),在使用 posix_seteuid() 更改我的 euid 后,子进程应该继承我的 euid ?
我以为答案是肯定的,但是测试了一下,
root@devdb:/srv/http/easyad_branches# whoami
root
root@devdb:/srv/http/easyad_branches# id
uid=0(root) gid=0(root) groups=0(root)
root@devdb:/srv/http/easyad_branches# php -r ' \
var_dump(posix_seteuid(posix_getpwnam("www-data")["uid"])); \
var_dump(shell_exec("whoami;id")); \
posix_seteuid(0); \
var_dump(posix_setuid(posix_getpwnam("www-data")["uid"])); \
var_dump(shell_exec("whoami;id"));'
bool(true)
string(44) "root
uid=0(root) gid=0(root) groups=0(root)
"
bool(true)
string(53) "www-data
uid=33(www-data) gid=0(root) groups=0(root)
"
看起来 whoami 继承了我的uid因为它是euid,而不是继承我的euid因为它是euid,这是预期的行为吗?
换句话说,我得到了bool(true) root bool(true) www-data,但我预料到了bool(true) www-data bool(true) www-data,是我的期望错了,还是有其他事情发生?
qq_笑_17