xref: /freebsd/contrib/pjdfstest/tests/chown/07.t (revision fed1ca4b719c56c930f2259d80663cd34be812bb)
1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/07.t 211410 2010-08-17 06:08:09Z pjd $
3
4desc="chown returns EPERM if the operation would change the ownership, but the effective user ID is not the super-user and the process is not an owner of the file"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9echo "1..132"
10
11n0=`namegen`
12n1=`namegen`
13n2=`namegen`
14n3=`namegen`
15
16expect 0 mkdir ${n0} 0755
17cdir=`pwd`
18cd ${n0}
19expect 0 mkdir ${n1} 0755
20expect 0 chown ${n1} 65534 65534
21for type in regular dir fifo block char socket symlink; do
22	if [ "${type}" != "symlink" ]; then
23		create_file ${type} ${n1}/${n2} 65534 65534
24		expect EPERM -u 65534 -g 65534 chown ${n1}/${n2} 65533 65533
25		expect EPERM -u 65533 -g 65533 chown ${n1}/${n2} 65534 65534
26		expect EPERM -u 65533 -g 65533 chown ${n1}/${n2} 65533 65533
27		expect EPERM -u 65534 -g 65534 -- chown ${n1}/${n2} -1 65533
28		expect 0 -u 65534 -g 65534 symlink ${n2} ${n1}/${n3}
29		expect EPERM -u 65534 -g 65534 chown ${n1}/${n3} 65533 65533
30		expect EPERM -u 65533 -g 65533 chown ${n1}/${n3} 65534 65534
31		expect EPERM -u 65533 -g 65533 chown ${n1}/${n3} 65533 65533
32		expect EPERM -u 65534 -g 65534 -- chown ${n1}/${n3} -1 65533
33		expect 0 unlink ${n1}/${n3}
34		if [ "${type}" = "dir" ]; then
35			expect 0 rmdir ${n1}/${n2}
36		else
37			expect 0 unlink ${n1}/${n2}
38		fi
39	fi
40	create_file ${type} ${n1}/${n2} 65534 65534
41	expect EPERM -u 65534 -g 65534 lchown ${n1}/${n2} 65533 65533
42	expect EPERM -u 65533 -g 65533 lchown ${n1}/${n2} 65534 65534
43	expect EPERM -u 65533 -g 65533 lchown ${n1}/${n2} 65533 65533
44	expect EPERM -u 65534 -g 65534 -- lchown ${n1}/${n2} -1 65533
45	if [ "${type}" = "dir" ]; then
46		expect 0 rmdir ${n1}/${n2}
47	else
48		expect 0 unlink ${n1}/${n2}
49	fi
50done
51expect 0 rmdir ${n1}
52cd ${cdir}
53expect 0 rmdir ${n0}
54