xref: /freebsd/contrib/pjdfstest/tests/chmod/11.t (revision bc96366c864c07ef352edb92017357917c75b36c)
1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/11.t 211352 2010-08-15 21:24:17Z pjd $
3
4desc="chmod returns EFTYPE if the effective user ID is not the super-user, the mode includes the sticky bit (S_ISVTX), and path does not refer to a directory"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9if supported lchmod; then
10	echo "1..173"
11else
12	echo "1..109"
13fi
14
15n0=`namegen`
16n1=`namegen`
17n2=`namegen`
18
19expect 0 mkdir ${n0} 0755
20cdir=`pwd`
21cd ${n0}
22
23for type in regular dir fifo block char socket symlink; do
24	if [ "${type}" != "symlink" ]; then
25		create_file ${type} ${n1}
26		expect 0 chmod ${n1} 01621
27		expect 01621 stat ${n1} mode
28		expect 0 symlink ${n1} ${n2}
29		expect 0 chmod ${n2} 01700
30		expect 01700 stat ${n1} mode
31		expect 0 unlink ${n2}
32		if [ "${type}" = "dir" ]; then
33			expect 0 rmdir ${n1}
34		else
35			expect 0 unlink ${n1}
36		fi
37	fi
38
39	if supported lchmod; then
40		create_file ${type} ${n1}
41		expect 0 lchmod ${n1} 01621
42		expect 01621 lstat ${n1} mode
43		if [ "${type}" = "dir" ]; then
44			expect 0 rmdir ${n1}
45		else
46			expect 0 unlink ${n1}
47		fi
48	fi
49done
50
51expect 0 mkdir ${n1} 0755
52expect 0 chown ${n1} 65534 65534
53expect 0 -u 65534 -g 65534 chmod ${n1} 01755
54expect 01755 stat ${n1} mode
55expect 0 symlink ${n1} ${n2}
56expect 0 chmod ${n2} 01700
57expect 01700 stat ${n1} mode
58expect 0 unlink ${n2}
59expect 0 rmdir ${n1}
60
61for type in regular fifo block char socket symlink; do
62	if [ "${type}" != "symlink" ]; then
63		create_file ${type} ${n1} 0640 65534 65534
64		expect 0 symlink ${n1} ${n2}
65		case "${os}" in
66		FreeBSD)
67			expect EFTYPE -u 65534 -g 65534 chmod ${n1} 01644
68			expect 0640 stat ${n1} mode
69			expect EFTYPE -u 65534 -g 65534 chmod ${n2} 01644
70			expect 0640 stat ${n1} mode
71			;;
72		SunOS)
73			expect 0 -u 65534 -g 65534 chmod ${n1} 01644
74			expect 0644 stat ${n1} mode
75			expect 0 -u 65534 -g 65534 chmod ${n2} 01640
76			expect 0640 stat ${n1} mode
77			;;
78		Linux)
79			expect 0 -u 65534 -g 65534 chmod ${n1} 01644
80			expect 01644 stat ${n1} mode
81			expect 0 -u 65534 -g 65534 chmod ${n2} 01640
82			expect 01640 stat ${n1} mode
83			;;
84		esac
85		expect 0 unlink ${n2}
86		if [ "${type}" = "dir" ]; then
87			expect 0 rmdir ${n1}
88		else
89			expect 0 unlink ${n1}
90		fi
91	fi
92
93	if supported lchmod; then
94		create_file ${type} ${n1} 0640 65534 65534
95		case "${os}" in
96		FreeBSD)
97			expect EFTYPE -u 65534 -g 65534 lchmod ${n1} 01644
98			expect 0640 lstat ${n1} mode
99			;;
100		SunOS)
101			expect 0 -u 65534 -g 65534 lchmod ${n1} 01644
102			expect 0644 lstat ${n1} mode
103			;;
104		Linux)
105			expect 0 -u 65534 -g 65534 lchmod ${n1} 01644
106			expect 01644 lstat ${n1} mode
107			;;
108		esac
109		if [ "${type}" = "dir" ]; then
110			expect 0 rmdir ${n1}
111		else
112			expect 0 unlink ${n1}
113		fi
114	fi
115done
116
117cd ${cdir}
118expect 0 rmdir ${n0}
119