xref: /freebsd/contrib/pjdfstest/tests/chflags/11.t (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/11.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="chflags returns EPERM if a user tries to set or remove the SF_SNAPSHOT flag"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags_SF_SNAPSHOT
11
12echo "1..145"
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 EPERM -u 65534 -g 65534 chflags ${n1} SF_SNAPSHOT
26		expect none stat ${n1} flags
27		expect EPERM chflags ${n1} SF_SNAPSHOT
28		expect none stat ${n1} flags
29		expect 0 chown ${n1} 65534 65534
30		expect EPERM -u 65534 -g 65534 chflags ${n1} SF_SNAPSHOT
31		expect none stat ${n1} flags
32		expect EPERM chflags ${n1} SF_SNAPSHOT
33		expect none stat ${n1} flags
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 EPERM -u 65534 -g 65534 lchflags ${n1} SF_SNAPSHOT
43	expect none lstat ${n1} flags
44	expect EPERM lchflags ${n1} SF_SNAPSHOT
45	expect none lstat ${n1} flags
46	expect 0 lchown ${n1} 65534 65534
47	expect EPERM -u 65534 -g 65534 lchflags ${n1} SF_SNAPSHOT
48	expect none lstat ${n1} flags
49	expect EPERM lchflags ${n1} SF_SNAPSHOT
50	expect none lstat ${n1} flags
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