1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/08.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="chflags returns EPERM when one of SF_IMMUTABLE, SF_APPEND, or SF_NOUNLINK is set and the user is not the super-user"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12echo "1..249"
13
14n0=`namegen`
15n1=`namegen`
16n2=`namegen`
17
18expect 0 mkdir ${n0} 0755
19cdir=`pwd`
20cd ${n0}
21
22for type in regular dir fifo block char socket symlink; do
23	if [ "${type}" != "symlink" ]; then
24		create_file ${type} ${n1}
25		expect 0 chown ${n1} 65534 65534
26		for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do
27			expect 0 chflags ${n1} ${flag}
28			expect EPERM -u 65533 -g 65533 chflags ${n1} UF_NODUMP
29			expect ${flag} stat ${n1} flags
30			expect EPERM -u 65534 -g 65534 chflags ${n1} UF_NODUMP
31			expect ${flag} stat ${n1} flags
32		done
33		expect 0 chflags ${n1} none
34		if [ "${type}" = "dir" ]; then
35			expect 0 rmdir ${n1}
36		else
37			expect 0 unlink ${n1}
38		fi
39	fi
40
41	create_file ${type} ${n1}
42	expect 0 lchown ${n1} 65534 65534
43	for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do
44		expect 0 lchflags ${n1} ${flag}
45		expect EPERM -u 65533 -g 65533 lchflags ${n1} UF_NODUMP
46		expect ${flag} lstat ${n1} flags
47		expect EPERM -u 65534 -g 65534 lchflags ${n1} UF_NODUMP
48		expect ${flag} lstat ${n1} flags
49	done
50	expect 0 lchflags ${n1} none
51	if [ "${type}" = "dir" ]; then
52		expect 0 rmdir ${n1}
53	else
54		expect 0 unlink ${n1}
55	fi
56done
57
58cd ${cdir}
59expect 0 rmdir ${n0}
60