xref: /freebsd/contrib/pjdfstest/tests/chmod/07.t (revision b2d48be1bc7df45ddd13b143a160d0acb5a383c5)
1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/07.t 211352 2010-08-15 21:24:17Z pjd $
3
4desc="chmod returns EPERM if the operation would change the ownership, but the effective user ID is not the super-user"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9if supported lchmod; then
10	echo "1..34"
11else
12	echo "1..25"
13fi
14
15n0=`namegen`
16n1=`namegen`
17n2=`namegen`
18n3=`namegen`
19
20expect 0 mkdir ${n0} 0755
21cdir=`pwd`
22cd ${n0}
23expect 0 mkdir ${n1} 0755
24expect 0 chown ${n1} 65534 65534
25
26expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644
27expect 0 -u 65534 -g 65534 chmod ${n1}/${n2} 0642
28expect 0642 stat ${n1}/${n2} mode
29expect EPERM -u 65533 -g 65533 chmod ${n1}/${n2} 0641
30expect 0642 stat ${n1}/${n2} mode
31expect 0 chown ${n1}/${n2} 0 0
32expect EPERM -u 65534 -g 65534 chmod ${n1}/${n2} 0641
33expect 0642 stat ${n1}/${n2} mode
34expect 0 unlink ${n1}/${n2}
35
36expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644
37expect 0 -u 65534 -g 65534 symlink ${n2} ${n1}/${n3}
38expect 0 -u 65534 -g 65534 chmod ${n1}/${n3} 0642
39expect 0642,65534,65534 stat ${n1}/${n2} mode,uid,gid
40expect EPERM -u 65533 -g 65533 chmod ${n1}/${n3} 0641
41expect 0642,65534,65534 stat ${n1}/${n2} mode,uid,gid
42expect 0 chown ${n1}/${n3} 0 0
43expect EPERM -u 65534 -g 65534 chmod ${n1}/${n3} 0641
44expect 0642,0,0 stat ${n1}/${n2} mode,uid,gid
45expect 0 unlink ${n1}/${n2}
46expect 0 unlink ${n1}/${n3}
47
48if supported lchmod; then
49	expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644
50	expect 0 -u 65534 -g 65534 lchmod ${n1}/${n2} 0642
51	expect 0642 stat ${n1}/${n2} mode
52	expect EPERM -u 65533 -g 65533 lchmod ${n1}/${n2} 0641
53	expect 0642 stat ${n1}/${n2} mode
54	expect 0 chown ${n1}/${n2} 0 0
55	expect EPERM -u 65534 -g 65534 lchmod ${n1}/${n2} 0641
56	expect 0642 stat ${n1}/${n2} mode
57	expect 0 unlink ${n1}/${n2}
58fi
59
60expect 0 rmdir ${n1}
61cd ${cdir}
62expect 0 rmdir ${n0}
63