xref: /freebsd/contrib/pjdfstest/tests/chflags/10.t (revision 8657387683946d0c03e09fe77029edfe309eeb20)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/10.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="chflags returns EPERM if non-super-user tries to set one of SF_IMMUTABLE, SF_APPEND, or SF_NOUNLINK"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12echo "1..197"
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 EPERM -u 65533 -g 65533 chflags ${n1} ${flag}
28			expect none stat ${n1} flags
29			expect EPERM -u 65534 -g 65534 chflags ${n1} ${flag}
30			expect none stat ${n1} flags
31		done
32		if [ "${type}" = "dir" ]; then
33			expect 0 rmdir ${n1}
34		else
35			expect 0 unlink ${n1}
36		fi
37	fi
38
39	create_file ${type} ${n1}
40	expect 0 lchown ${n1} 65534 65534
41	for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do
42		expect EPERM -u 65533 -g 65533 lchflags ${n1} ${flag}
43		expect none lstat ${n1} flags
44		expect EPERM -u 65534 -g 65534 lchflags ${n1} ${flag}
45		expect none lstat ${n1} flags
46	done
47	if [ "${type}" = "dir" ]; then
48		expect 0 rmdir ${n1}
49	else
50		expect 0 unlink ${n1}
51	fi
52done
53
54cd ${cdir}
55expect 0 rmdir ${n0}
56