turns printfs back on
[freebsd-src/fkvm-freebsd.git] / tools / regression / fstest / tests / chmod / 00.t
blobe6349e8cc9ed45a6316c63472006f3e3b2a73e41
1 #!/bin/sh
2 # $FreeBSD$
4 desc="chmod changes permission"
6 dir=`dirname $0`
7 . ${dir}/../misc.sh
9 if supported lchmod; then
10 echo "1..77"
11 else
12 echo "1..58"
15 n0=`namegen`
16 n1=`namegen`
17 n2=`namegen`
19 expect 0 mkdir ${n2} 0755
20 cdir=`pwd`
21 cd ${n2}
23 expect 0 create ${n0} 0644
24 expect 0644 stat ${n0} mode
25 expect 0 chmod ${n0} 0111
26 expect 0111 stat ${n0} mode
27 expect 0 unlink ${n0}
29 expect 0 mkdir ${n0} 0755
30 expect 0755 stat ${n0} mode
31 expect 0 chmod ${n0} 0753
32 expect 0753 stat ${n0} mode
33 expect 0 rmdir ${n0}
35 expect 0 mkfifo ${n0} 0644
36 expect 0644 stat ${n0} mode
37 expect 0 chmod ${n0} 0310
38 expect 0310 stat ${n0} mode
39 expect 0 unlink ${n0}
41 expect 0 create ${n0} 0644
42 expect 0 symlink ${n0} ${n1}
43 expect 0644 stat ${n1} mode
44 expect 0 chmod ${n1} 0321
45 expect 0321 stat ${n1} mode
46 expect 0321 lstat ${n0} mode
47 expect 0 unlink ${n0}
48 expect 0 unlink ${n1}
50 if supported lchmod; then
51 expect 0 create ${n0} 0644
52 expect 0 symlink ${n0} ${n1}
53 expect 0644 stat ${n1} mode
54 expect 0 lchmod ${n1} 0321
55 expect 0321 lstat ${n1} mode
56 expect 0 lchmod ${n1} 0531
57 expect 0531 lstat ${n1} mode
58 expect 0644 stat ${n0} mode
59 expect 0644 stat ${n1} mode
60 expect 0 unlink ${n0}
61 expect 0 unlink ${n1}
64 # successful chmod(2) updates ctime.
65 expect 0 create ${n0} 0644
66 ctime1=`${fstest} stat ${n0} ctime`
67 sleep 1
68 expect 0 chmod ${n0} 0111
69 ctime2=`${fstest} stat ${n0} ctime`
70 test_check $ctime1 -lt $ctime2
71 expect 0 unlink ${n0}
73 expect 0 mkdir ${n0} 0755
74 ctime1=`${fstest} stat ${n0} ctime`
75 sleep 1
76 expect 0 chmod ${n0} 0753
77 ctime2=`${fstest} stat ${n0} ctime`
78 test_check $ctime1 -lt $ctime2
79 expect 0 rmdir ${n0}
81 expect 0 mkfifo ${n0} 0644
82 ctime1=`${fstest} stat ${n0} ctime`
83 sleep 1
84 expect 0 chmod ${n0} 0310
85 ctime2=`${fstest} stat ${n0} ctime`
86 test_check $ctime1 -lt $ctime2
87 expect 0 unlink ${n0}
89 if supported lchmod; then
90 expect 0 symlink ${n1} ${n0}
91 ctime1=`${fstest} lstat ${n0} ctime`
92 sleep 1
93 expect 0 lchmod ${n0} 0321
94 ctime2=`${fstest} lstat ${n0} ctime`
95 test_check $ctime1 -lt $ctime2
96 expect 0 unlink ${n0}
99 # unsuccessful chmod(2) does not update ctime.
100 expect 0 create ${n0} 0644
101 ctime1=`${fstest} stat ${n0} ctime`
102 sleep 1
103 expect EPERM -u 65534 chmod ${n0} 0111
104 ctime2=`${fstest} stat ${n0} ctime`
105 test_check $ctime1 -eq $ctime2
106 expect 0 unlink ${n0}
108 expect 0 mkdir ${n0} 0755
109 ctime1=`${fstest} stat ${n0} ctime`
110 sleep 1
111 expect EPERM -u 65534 chmod ${n0} 0753
112 ctime2=`${fstest} stat ${n0} ctime`
113 test_check $ctime1 -eq $ctime2
114 expect 0 rmdir ${n0}
116 expect 0 mkfifo ${n0} 0644
117 ctime1=`${fstest} stat ${n0} ctime`
118 sleep 1
119 expect EPERM -u 65534 chmod ${n0} 0310
120 ctime2=`${fstest} stat ${n0} ctime`
121 test_check $ctime1 -eq $ctime2
122 expect 0 unlink ${n0}
124 if supported lchmod; then
125 expect 0 symlink ${n1} ${n0}
126 ctime1=`${fstest} lstat ${n0} ctime`
127 sleep 1
128 expect EPERM -u 65534 lchmod ${n0} 0321
129 ctime2=`${fstest} lstat ${n0} ctime`
130 test_check $ctime1 -eq $ctime2
131 expect 0 unlink ${n0}
134 # POSIX: If the calling process does not have appropriate privileges, and if
135 # the group ID of the file does not match the effective group ID or one of the
136 # supplementary group IDs and if the file is a regular file, bit S_ISGID
137 # (set-group-ID on execution) in the file's mode shall be cleared upon
138 # successful return from chmod().
140 expect 0 create ${n0} 0755
141 expect 0 chown ${n0} 65535 65535
142 expect 0 -u 65535 -g 65535 chmod ${n0} 02755
143 expect 02755 stat ${n0} mode
144 expect 0 -u 65535 -g 65535 chmod ${n0} 0755
145 expect 0755 stat ${n0} mode
147 # Unfortunately FreeBSD doesn't clear set-gid bit, but returns EPERM instead.
148 case "${os}" in
149 FreeBSD)
150 expect EPERM -u 65535 -g 65534 chmod ${n0} 02755
151 expect 0755 stat ${n0} mode
154 expect 0 -u 65535 -g 65534 chmod ${n0} 02755
155 expect 0755 stat ${n0} mode
157 esac
158 expect 0 unlink ${n0}
160 cd ${cdir}
161 expect 0 rmdir ${n2}