3、root用户可以通过调用setxxuid 来改变权限用户。非root用户是无法改变和转让权限用户。
继续看一下s权限位对进程权限的影响
三、s 标志位影响的是 euid,suid,和 fuid
int main(int argc, char *argv[])
{
while(1)sleep(1);
}
$>g++ main.cpp
$>ll
-rwxr-xr-x. 1 test1 test 6780 Sep 16 18:18 a.out
$>chmod u+s a.out
$>ll
-rwsr-xr-x. 1 test1 test 6780 Sep 16 18:18 a.out
使用root用户执行,查看用户ID为
0 502 502 502 4133 a.out
s权限位使用最经典的案例是passwd命令
下面我们看看他们对文件权限的影响,构建一个ruid,euid,和fuid都不同,看看创建出来的文件所有者是哪个uid
四、影响用户文件权限的是 fuid,不是 euid,该 uid 是 linux 特有的属性,unix 系统是靠 euid 来判定用户权限。
int main(int argc, char *argv[])
{
if( setfsuid(503) < 0) perror ("setfsuid error");
FILE * fp = fopen("test.log", "a+");
if(fp == NULL)
{
perror ("fopen error");
}
else
{
fclose(fp);
}
while(1)sleep(1);
}
使用s权限位,文件所有者为root,执行者为test1,改变fuid为test2,这样就构造出3个uid各部相同,方便观察效果
$>ll
-rws---r-x. 1 root root 7397 Sep 16 18:53 a.out
运行查看状态,ruid为test1,euid为root,fuid为test2
502 0 0 503 4240 a.out
$>ll
-rws---r-x. 1 root root 7397 Sep 16 18:53 a.out
-rw-rw-r--. 1 test2 test 0 Sep 16 18:54 test.log
五、权限的继承,当使用 fork 子进程的时候,子进程全部继承父进程四个 uid,和父进程 uid 相同
当使用exec系列函数时候,会把suid置为euid。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!










