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