📄 permissions.test
字号:
This script tests if file permissions are properly checked with andwithout ACLs. The script must be run as root to allow switching users.The following users are required. They must be a member in the groupslisted in parentheses. bin (bin) daemon (bin, daemon)Cry immediately if we are not running as root. $ id -u > 0First, set up a temporary directory and create a regular file withdefined permissions. $ mkdir d $ cd d $ umask 027 $ touch f $ ls -l f | awk -- '{ print $1, $3, $4 }' > -rw-r----- root rootMake sure root has access to the file. Verify that user daemon does nothave access to the file owned by root. $ echo root > f $ su daemon $ echo daemon >> f > f: Permission denied $ suNow, change the ownership of the file to bin:bin and verify that thisgives user bin write access. $ chown bin:bin f $ ls -l f | awk -- '{ print $1, $3, $4 }' > -rw-r----- bin bin $ su bin $ echo bin >> fUser daemon is a member in the owning group, which has only read access.Verify this. $ su daemon $ cat f > root > bin $ echo daemon >> f > f: Permission deniedNow, add an ACL entry for user daemon that grants him rw- access. Fileowners and users capable of CAP_FOWNER are allowed to change ACLs. $ su bin $ setfacl -m u:daemon:rw f $ getfacl --omit-header f > user::rw- > user:daemon:rw- > group::r-- > mask::rw- > other::--- >Verify that the additional ACL entry grants user daemon write access. $ su daemon $ echo daemon >> f $ cat f > root > bin > daemonRemove write access from the group class permission bits, andverify that this masks daemon's write permission. $ su bin $ chmod g-w f $ getfacl --omit-header f > user::rw- > user:daemon:rw- #effective:r-- > group::r-- > mask::r-- > other::--- > $ su daemon $ echo daemon >> f > f: Permission deniedAdd an entry for group daemon with rw- access, and change thepermissions for user daemon to r--. Also change the others permissions trw-. The user entry should take precedence, so daemon should be deniedaccess. $ su bin $ setfacl -m u:daemon:r,g:daemon:rw-,o::rw- f $ su daemon $ echo daemon >> f > f: Permission deniedRemove the entry for user daemon. The group daemon permissions shouldnow give user daemon rw- access. $ su bin $ setfacl -x u:daemon f $ su daemon $ echo daemon2 >> f $ cat f > root > bin > daemon > daemon2Set the group daemon permissions to r-- and verify that after than, userdaemon does not have write access anymore. $ su bin $ setfacl -m g:daemon:r f $ su daemon $ echo daemon3 >> f > f: Permission deniedNow, remove the group daemon entry. Because user daemon is a member inthe owning group, he should still have no write access. $ su bin $ setfacl -x g:daemon f $ su daemon $ echo daemon4 >> f > f: Permission deniedChange the owning group. The other permissions should now grant userdaemon write access. $ su $ chgrp root f $ su daemon $ echo daemon5 >> f $ cat f > root > bin > daemon > daemon2 > daemon5Verify that permissions in separate matching ACL entries do notaccumulate. $ su $ setfacl -m g:bin:r,g:daemon:w f $ su daemon $ : < f # open for reading $ : > f # open for writing $ : <> f # open for read-write > f: Permission deniedTest if directories can have ACLs. We assume that only one access checkalgorithm is used for all file types the file system, so these testsonly need to verify that ACL permissions make a difference. $ su $ mkdir -m 750 e $ touch e/h $ su bin $ shopt -s nullglob ; echo e/* > $ echo i > e/i > e/i: Permission denied $ su $ setfacl -m u:bin:rx e $ su bin $ echo e/* > e/hfollowing 2 lines seems not valid, which also failed on ext3 in FC3 enviroment,although it pass in FC2. commented out by CFS (agreed with HP)# $ echo i > e/i# > e/i: Permission denied $ su $ setfacl -m u:bin:rwx e $ su bin $ echo i > e/iTest if symlinks are properly followed. $ su $ touch g $ ln -s g l $ setfacl -m u:bin:rw l $ ls -l g | awk -- '{ print $1, $3, $4 }' > -rw-rw----+ root rootTest if ACLs are effective for block and character special files, fifos,sockets. This is done by creating special files locally. The devices donot need to exist: The access check is earlier in the code path than thetest if the device exists. $ mknod -m 0660 hdt b 91 64 # /dev/hdt $ mknod -m 0660 null c 1 3 # /dev/null $ mkfifo -m 0660 fifo $ su bin $ : < hdt > hdt: Permission denied $ : < null > null: Permission denied $ : < fifo > fifo: Permission denied $ su $ setfacl -m u:bin:rw hdt null fifo $ su bin $ : < hdt > hdt: No such device or address $ : < null $ ( echo blah > fifo & ) ; cat fifo > blahTest if CAP_FOWNER is properly honored for directories. This addresses aspecific bug in XFS 1.2, which does not grant root access to files indirectories if the file has an ACL and only CAP_FOWNER would grant them. $ su $ mkdir -m 600 x $ chown daemon:daemon x $ echo j > x/j $ ls -l x/j | awk -- '{ print $1, $3, $4 }' > -rw-r----- root root $ setfacl -m u:daemon:r x $ ls -l x/j | awk -- '{ print $1, $3, $4 }' > -rw-r----- root root (With the bug this gives: `ls: x/j: Permission denied'.) $ echo k > x/k (With the bug this gives: `x/k: Permission denied'.) $ chmod 750 xClean up. $ su $ cd .. $ rm -rf d
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -