]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - tools/regression/pjdfstest/tests/chmod/00.t
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / tools / regression / pjdfstest / tests / chmod / 00.t
1 #!/bin/sh
2 # $FreeBSD$
3
4 desc="chmod changes permission"
5
6 dir=`dirname $0`
7 . ${dir}/../misc.sh
8
9 if supported lchmod; then
10         echo "1..203"
11 else
12         echo "1..119"
13 fi
14
15 n0=`namegen`
16 n1=`namegen`
17 n2=`namegen`
18
19 expect 0 mkdir ${n2} 0755
20 cdir=`pwd`
21 cd ${n2}
22
23 for type in regular dir fifo block char socket symlink; do
24         if [ "${type}" != "symlink" ]; then
25                 create_file ${type} ${n0}
26                 expect 0 chmod ${n0} 0111
27                 expect 0111 stat ${n0} mode
28
29                 expect 0 symlink ${n0} ${n1}
30                 mode=`${fstest} lstat ${n1} mode`
31                 expect 0 chmod ${n1} 0222
32                 expect 0222 stat ${n1} mode
33                 expect 0222 stat ${n0} mode
34                 expect ${mode} lstat ${n1} mode
35                 expect 0 unlink ${n1}
36
37                 if [ "${type}" = "dir" ]; then
38                         expect 0 rmdir ${n0}
39                 else
40                         expect 0 unlink ${n0}
41                 fi
42         fi
43
44         if supported lchmod; then
45                 create_file ${type} ${n0}
46                 expect 0 lchmod ${n0} 0111
47                 expect 0111 lstat ${n0} mode
48                 if [ "${type}" = "dir" ]; then
49                         expect 0 rmdir ${n0}
50                 else
51                         expect 0 unlink ${n0}
52                 fi
53         fi
54 done
55
56 # successful chmod(2) updates ctime.
57 for type in regular dir fifo block char socket symlink; do
58         if [ "${type}" != "symlink" ]; then
59                 create_file ${type} ${n0}
60                 ctime1=`${fstest} stat ${n0} ctime`
61                 sleep 1
62                 expect 0 chmod ${n0} 0111
63                 ctime2=`${fstest} stat ${n0} ctime`
64                 test_check $ctime1 -lt $ctime2
65                 if [ "${type}" = "dir" ]; then
66                         expect 0 rmdir ${n0}
67                 else
68                         expect 0 unlink ${n0}
69                 fi
70         fi
71
72         if supported lchmod; then
73                 create_file ${type} ${n0}
74                 ctime1=`${fstest} lstat ${n0} ctime`
75                 sleep 1
76                 expect 0 lchmod ${n0} 0111
77                 ctime2=`${fstest} lstat ${n0} ctime`
78                 test_check $ctime1 -lt $ctime2
79                 if [ "${type}" = "dir" ]; then
80                         expect 0 rmdir ${n0}
81                 else
82                         expect 0 unlink ${n0}
83                 fi
84         fi
85 done
86
87 # unsuccessful chmod(2) does not update ctime.
88 for type in regular dir fifo block char socket symlink; do
89         if [ "${type}" != "symlink" ]; then
90                 create_file ${type} ${n0}
91                 ctime1=`${fstest} stat ${n0} ctime`
92                 sleep 1
93                 expect EPERM -u 65534 chmod ${n0} 0111
94                 ctime2=`${fstest} stat ${n0} ctime`
95                 test_check $ctime1 -eq $ctime2
96                 if [ "${type}" = "dir" ]; then
97                         expect 0 rmdir ${n0}
98                 else
99                         expect 0 unlink ${n0}
100                 fi
101         fi
102
103         if supported lchmod; then
104                 create_file ${type} ${n0}
105                 ctime1=`${fstest} lstat ${n0} ctime`
106                 sleep 1
107                 expect EPERM -u 65534 lchmod ${n0} 0321
108                 ctime2=`${fstest} lstat ${n0} ctime`
109                 test_check $ctime1 -eq $ctime2
110                 if [ "${type}" = "dir" ]; then
111                         expect 0 rmdir ${n0}
112                 else
113                         expect 0 unlink ${n0}
114                 fi
115         fi
116 done
117
118 # POSIX: If the calling process does not have appropriate privileges, and if
119 # the group ID of the file does not match the effective group ID or one of the
120 # supplementary group IDs and if the file is a regular file, bit S_ISGID
121 # (set-group-ID on execution) in the file's mode shall be cleared upon
122 # successful return from chmod().
123
124 expect 0 create ${n0} 0755
125 expect 0 chown ${n0} 65535 65535
126 expect 0 -u 65535 -g 65535 chmod ${n0} 02755
127 expect 02755 stat ${n0} mode
128 expect 0 -u 65535 -g 65535 chmod ${n0} 0755
129 expect 0755 stat ${n0} mode
130
131 todo FreeBSD "S_ISGID should be removed and chmod(2) should success and FreeBSD returns EPERM."
132 expect 0 -u 65535 -g 65534 chmod ${n0} 02755
133 expect 0755 stat ${n0} mode
134
135 expect 0 unlink ${n0}
136
137 cd ${cdir}
138 expect 0 rmdir ${n2}