1166065Spjd#!/bin/sh
2166065Spjd# $FreeBSD$
3166065Spjd
4166065Spjddesc="chflags returns EPERM if a user tries to set or remove the SF_SNAPSHOT flag"
5166065Spjd
6166065Spjddir=`dirname $0`
7166065Spjd. ${dir}/../misc.sh
8166065Spjd
9185173Spjdrequire chflags_SF_SNAPSHOT
10166065Spjd
11211186Spjdecho "1..145"
12166065Spjd
13166065Spjdn0=`namegen`
14166065Spjdn1=`namegen`
15166065Spjdn2=`namegen`
16166065Spjd
17166065Spjdexpect 0 mkdir ${n0} 0755
18166065Spjdcdir=`pwd`
19166065Spjdcd ${n0}
20166065Spjd
21211180Spjdfor type in regular dir fifo block char socket symlink; do
22211180Spjd	if [ "${type}" != "symlink" ]; then
23211186Spjd		create_file ${type} ${n1}
24211180Spjd		expect EPERM -u 65534 -g 65534 chflags ${n1} SF_SNAPSHOT
25211180Spjd		expect none stat ${n1} flags
26211180Spjd		expect EPERM chflags ${n1} SF_SNAPSHOT
27211180Spjd		expect none stat ${n1} flags
28211180Spjd		expect 0 chown ${n1} 65534 65534
29211180Spjd		expect EPERM -u 65534 -g 65534 chflags ${n1} SF_SNAPSHOT
30211180Spjd		expect none stat ${n1} flags
31211180Spjd		expect EPERM chflags ${n1} SF_SNAPSHOT
32211180Spjd		expect none stat ${n1} flags
33211180Spjd		if [ "${type}" = "dir" ]; then
34211180Spjd			expect 0 rmdir ${n1}
35211180Spjd		else
36211180Spjd			expect 0 unlink ${n1}
37211180Spjd		fi
38211180Spjd	fi
39166065Spjd
40211186Spjd	create_file ${type} ${n1}
41211180Spjd	expect EPERM -u 65534 -g 65534 lchflags ${n1} SF_SNAPSHOT
42211180Spjd	expect none lstat ${n1} flags
43211180Spjd	expect EPERM lchflags ${n1} SF_SNAPSHOT
44211180Spjd	expect none lstat ${n1} flags
45211180Spjd	expect 0 lchown ${n1} 65534 65534
46211180Spjd	expect EPERM -u 65534 -g 65534 lchflags ${n1} SF_SNAPSHOT
47211180Spjd	expect none lstat ${n1} flags
48211180Spjd	expect EPERM lchflags ${n1} SF_SNAPSHOT
49211180Spjd	expect none lstat ${n1} flags
50211180Spjd	if [ "${type}" = "dir" ]; then
51211180Spjd		expect 0 rmdir ${n1}
52211180Spjd	else
53211180Spjd		expect 0 unlink ${n1}
54211180Spjd	fi
55211180Spjddone
56166065Spjd
57166065Spjdcd ${cdir}
58166065Spjdexpect 0 rmdir ${n0}
59