2008-04-22

ruid-euid-suid

折腾于ruid(real user ID),euid(effective user ID)和suid(saved user ID)之中。从一知半解到似乎理解,手册读起来比较困惑。终于写出一个测试程序taccess.c,开始为root,然后切换到普通用户,最后再变回root。不过有一个地方还是比较困惑:
$ ls -l /tmp/foo.txt
-rw-r----- 1 root root 0 2008-04-22 23:26 /tmp/foo.txt
$ sudo ./taccess /tmp/foo.txt
--------------------
uid: 0 euid: 0
gid: 0 egid: 0
/tmp/foo.txt: Success
--------------------
uid: 1000 euid: 1000
gid: 1000 egid: 1000
/tmp/foo.txt: Success
--------------------
uid: 0 euid: 0
gid: 0 egid: 0
/tmp/foo.txt: Success
$ cat /tmp/foo.txt
cat: /tmp/foo.txt: Permission denied

不明白为何第二次以普通用户访问文件时仍然得到success。

2 Comments:

At 09:06, Blogger YY© said...

The problem is if Linux check "real user ID" while check process permission.
BTW: I can't see your taccess.c.

 
At 09:53, Blogger David Lee said...

For access(), the check is done with the process's real UID and GID, rather than with the effective IDs.

 

发表评论

<< Home