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