xref: /freebsd/contrib/pjdfstest/tests/chown/07.t (revision f4f33ea0c752ff0f9bfad34991d5bbb54e71133d)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/07.t 211410 2010-08-17 06:08:09Z pjd $
4
5desc="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"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10echo "1..132"
11
12n0=`namegen`
13n1=`namegen`
14n2=`namegen`
15n3=`namegen`
16
17expect 0 mkdir ${n0} 0755
18cdir=`pwd`
19cd ${n0}
20expect 0 mkdir ${n1} 0755
21expect 0 chown ${n1} 65534 65534
22for type in regular dir fifo block char socket symlink; do
23	if [ "${type}" != "symlink" ]; then
24		create_file ${type} ${n1}/${n2} 65534 65534
25		expect EPERM -u 65534 -g 65534 chown ${n1}/${n2} 65533 65533
26		expect EPERM -u 65533 -g 65533 chown ${n1}/${n2} 65534 65534
27		expect EPERM -u 65533 -g 65533 chown ${n1}/${n2} 65533 65533
28		expect EPERM -u 65534 -g 65534 -- chown ${n1}/${n2} -1 65533
29		expect 0 -u 65534 -g 65534 symlink ${n2} ${n1}/${n3}
30		expect EPERM -u 65534 -g 65534 chown ${n1}/${n3} 65533 65533
31		expect EPERM -u 65533 -g 65533 chown ${n1}/${n3} 65534 65534
32		expect EPERM -u 65533 -g 65533 chown ${n1}/${n3} 65533 65533
33		expect EPERM -u 65534 -g 65534 -- chown ${n1}/${n3} -1 65533
34		expect 0 unlink ${n1}/${n3}
35		if [ "${type}" = "dir" ]; then
36			expect 0 rmdir ${n1}/${n2}
37		else
38			expect 0 unlink ${n1}/${n2}
39		fi
40	fi
41	create_file ${type} ${n1}/${n2} 65534 65534
42	expect EPERM -u 65534 -g 65534 lchown ${n1}/${n2} 65533 65533
43	expect EPERM -u 65533 -g 65533 lchown ${n1}/${n2} 65534 65534
44	expect EPERM -u 65533 -g 65533 lchown ${n1}/${n2} 65533 65533
45	expect EPERM -u 65534 -g 65534 -- lchown ${n1}/${n2} -1 65533
46	if [ "${type}" = "dir" ]; then
47		expect 0 rmdir ${n1}/${n2}
48	else
49		expect 0 unlink ${n1}/${n2}
50	fi
51done
52expect 0 rmdir ${n1}
53cd ${cdir}
54expect 0 rmdir ${n0}
55