- 論壇徽章:
- 0
|
在Linux下,進程可以把有效用戶id轉(zhuǎn)到真正id或真正用戶id轉(zhuǎn)到有效用戶id。但更通用的是,有效用戶id可以轉(zhuǎn)換到真正的用戶id。
以下是例程。
超級用戶運行的結(jié)果:
sun sody # ./a.out; ls -l r c
Real: 0; Effective: 0.
Real: 0; Effective: 1000.
Real: 0; Effective: 0.
-rw-r--r-- 1 sody root 0 Dec 9 21:43 c
-rw-r--r-- 1 root root 0 Dec 9 21:43 r
從結(jié)果看,是可以轉(zhuǎn)換的。也就是,root轉(zhuǎn)換到一般用戶之后,只要有一個id還沒丟掉,都還可以轉(zhuǎn)換回來。有效id轉(zhuǎn)換到一般用戶之后,所有的角色都是以一般用戶為中心。真正id轉(zhuǎn)到一般用戶,平時的動作還是有效id的角色基礎(chǔ)。
#include stdio.h>
#include sys/types.h>
#include unistd.h>
int main()
{
printf("Real: %d; Effective: %d.\n",getuid(), geteuid());
if(setreuid(-1,1000) == -1)
{
perror("Fail to set reuid");
return -1;
}
printf("Real: %d; Effective: %d.\n",getuid(), geteuid());
fopen("c","wr");
if(setreuid(-1, getuid()) == -1)
{
perror("Fail to set reuid");
return -1;
}
fopen("r","wr");
printf("Real: %d; Effective: %d.\n",getuid(), geteuid());
return 0;
}
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/18481/showart_1710985.html |
|