xref: /freebsd/contrib/pjdfstest/tests/chmod/11.t (revision 531c2d7af3cd2e64eec94aa1b19c4b2f16fce515)
140a8ac8fSEnji Cooper#!/bin/sh
2*3416500aSEnji Cooper# vim: filetype=sh noexpandtab ts=8 sw=8
340a8ac8fSEnji Cooper# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/11.t 211352 2010-08-15 21:24:17Z pjd $
440a8ac8fSEnji Cooper
540a8ac8fSEnji Cooperdesc="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"
640a8ac8fSEnji Cooper
740a8ac8fSEnji Cooperdir=`dirname $0`
840a8ac8fSEnji Cooper. ${dir}/../misc.sh
940a8ac8fSEnji Cooper
1040a8ac8fSEnji Cooperif supported lchmod; then
1140a8ac8fSEnji Cooper	echo "1..173"
1240a8ac8fSEnji Cooperelse
1340a8ac8fSEnji Cooper	echo "1..109"
1440a8ac8fSEnji Cooperfi
1540a8ac8fSEnji Cooper
1640a8ac8fSEnji Coopern0=`namegen`
1740a8ac8fSEnji Coopern1=`namegen`
1840a8ac8fSEnji Coopern2=`namegen`
1940a8ac8fSEnji Cooper
2040a8ac8fSEnji Cooperexpect 0 mkdir ${n0} 0755
2140a8ac8fSEnji Coopercdir=`pwd`
2240a8ac8fSEnji Coopercd ${n0}
2340a8ac8fSEnji Cooper
2440a8ac8fSEnji Cooperfor type in regular dir fifo block char socket symlink; do
2540a8ac8fSEnji Cooper	if [ "${type}" != "symlink" ]; then
2640a8ac8fSEnji Cooper		create_file ${type} ${n1}
2740a8ac8fSEnji Cooper		expect 0 chmod ${n1} 01621
2840a8ac8fSEnji Cooper		expect 01621 stat ${n1} mode
2940a8ac8fSEnji Cooper		expect 0 symlink ${n1} ${n2}
3040a8ac8fSEnji Cooper		expect 0 chmod ${n2} 01700
3140a8ac8fSEnji Cooper		expect 01700 stat ${n1} mode
3240a8ac8fSEnji Cooper		expect 0 unlink ${n2}
3340a8ac8fSEnji Cooper		if [ "${type}" = "dir" ]; then
3440a8ac8fSEnji Cooper			expect 0 rmdir ${n1}
3540a8ac8fSEnji Cooper		else
3640a8ac8fSEnji Cooper			expect 0 unlink ${n1}
3740a8ac8fSEnji Cooper		fi
3840a8ac8fSEnji Cooper	fi
3940a8ac8fSEnji Cooper
4040a8ac8fSEnji Cooper	if supported lchmod; then
4140a8ac8fSEnji Cooper		create_file ${type} ${n1}
4240a8ac8fSEnji Cooper		expect 0 lchmod ${n1} 01621
4340a8ac8fSEnji Cooper		expect 01621 lstat ${n1} mode
4440a8ac8fSEnji Cooper		if [ "${type}" = "dir" ]; then
4540a8ac8fSEnji Cooper			expect 0 rmdir ${n1}
4640a8ac8fSEnji Cooper		else
4740a8ac8fSEnji Cooper			expect 0 unlink ${n1}
4840a8ac8fSEnji Cooper		fi
4940a8ac8fSEnji Cooper	fi
5040a8ac8fSEnji Cooperdone
5140a8ac8fSEnji Cooper
5240a8ac8fSEnji Cooperexpect 0 mkdir ${n1} 0755
5340a8ac8fSEnji Cooperexpect 0 chown ${n1} 65534 65534
5440a8ac8fSEnji Cooperexpect 0 -u 65534 -g 65534 chmod ${n1} 01755
5540a8ac8fSEnji Cooperexpect 01755 stat ${n1} mode
5640a8ac8fSEnji Cooperexpect 0 symlink ${n1} ${n2}
5740a8ac8fSEnji Cooperexpect 0 chmod ${n2} 01700
5840a8ac8fSEnji Cooperexpect 01700 stat ${n1} mode
5940a8ac8fSEnji Cooperexpect 0 unlink ${n2}
6040a8ac8fSEnji Cooperexpect 0 rmdir ${n1}
6140a8ac8fSEnji Cooper
6240a8ac8fSEnji Cooperfor type in regular fifo block char socket symlink; do
6340a8ac8fSEnji Cooper	if [ "${type}" != "symlink" ]; then
6440a8ac8fSEnji Cooper		create_file ${type} ${n1} 0640 65534 65534
6540a8ac8fSEnji Cooper		expect 0 symlink ${n1} ${n2}
6640a8ac8fSEnji Cooper		case "${os}" in
67*3416500aSEnji Cooper		Darwin)
68*3416500aSEnji Cooper			expect 0 -u 65534 -g 65534 chmod ${n1} 01644
69*3416500aSEnji Cooper			expect 01644 stat ${n1} mode
70*3416500aSEnji Cooper			expect 0 -u 65534 -g 65534 chmod ${n2} 01640
71*3416500aSEnji Cooper			expect 01640 stat ${n1} mode
72*3416500aSEnji Cooper			;;
7340a8ac8fSEnji Cooper		FreeBSD)
7440a8ac8fSEnji Cooper			expect EFTYPE -u 65534 -g 65534 chmod ${n1} 01644
7540a8ac8fSEnji Cooper			expect 0640 stat ${n1} mode
7640a8ac8fSEnji Cooper			expect EFTYPE -u 65534 -g 65534 chmod ${n2} 01644
7740a8ac8fSEnji Cooper			expect 0640 stat ${n1} mode
7840a8ac8fSEnji Cooper			;;
7940a8ac8fSEnji Cooper		SunOS)
8040a8ac8fSEnji Cooper			expect 0 -u 65534 -g 65534 chmod ${n1} 01644
8140a8ac8fSEnji Cooper			expect 0644 stat ${n1} mode
8240a8ac8fSEnji Cooper			expect 0 -u 65534 -g 65534 chmod ${n2} 01640
8340a8ac8fSEnji Cooper			expect 0640 stat ${n1} mode
8440a8ac8fSEnji Cooper			;;
8540a8ac8fSEnji Cooper		Linux)
8640a8ac8fSEnji Cooper			expect 0 -u 65534 -g 65534 chmod ${n1} 01644
8740a8ac8fSEnji Cooper			expect 01644 stat ${n1} mode
8840a8ac8fSEnji Cooper			expect 0 -u 65534 -g 65534 chmod ${n2} 01640
8940a8ac8fSEnji Cooper			expect 01640 stat ${n1} mode
9040a8ac8fSEnji Cooper			;;
9140a8ac8fSEnji Cooper		esac
9240a8ac8fSEnji Cooper		expect 0 unlink ${n2}
9340a8ac8fSEnji Cooper		if [ "${type}" = "dir" ]; then
9440a8ac8fSEnji Cooper			expect 0 rmdir ${n1}
9540a8ac8fSEnji Cooper		else
9640a8ac8fSEnji Cooper			expect 0 unlink ${n1}
9740a8ac8fSEnji Cooper		fi
9840a8ac8fSEnji Cooper	fi
9940a8ac8fSEnji Cooper
10040a8ac8fSEnji Cooper	if supported lchmod; then
10140a8ac8fSEnji Cooper		create_file ${type} ${n1} 0640 65534 65534
10240a8ac8fSEnji Cooper		case "${os}" in
103*3416500aSEnji Cooper		Darwin)
104*3416500aSEnji Cooper			expect 0 -u 65534 -g 65534 lchmod ${n1} 01644
105*3416500aSEnji Cooper			expect 01644 lstat ${n1} mode
106*3416500aSEnji Cooper			;;
10740a8ac8fSEnji Cooper		FreeBSD)
10840a8ac8fSEnji Cooper			expect EFTYPE -u 65534 -g 65534 lchmod ${n1} 01644
10940a8ac8fSEnji Cooper			expect 0640 lstat ${n1} mode
11040a8ac8fSEnji Cooper			;;
11140a8ac8fSEnji Cooper		SunOS)
11240a8ac8fSEnji Cooper			expect 0 -u 65534 -g 65534 lchmod ${n1} 01644
11340a8ac8fSEnji Cooper			expect 0644 lstat ${n1} mode
11440a8ac8fSEnji Cooper			;;
11540a8ac8fSEnji Cooper		Linux)
11640a8ac8fSEnji Cooper			expect 0 -u 65534 -g 65534 lchmod ${n1} 01644
11740a8ac8fSEnji Cooper			expect 01644 lstat ${n1} mode
11840a8ac8fSEnji Cooper			;;
11940a8ac8fSEnji Cooper		esac
12040a8ac8fSEnji Cooper		if [ "${type}" = "dir" ]; then
12140a8ac8fSEnji Cooper			expect 0 rmdir ${n1}
12240a8ac8fSEnji Cooper		else
12340a8ac8fSEnji Cooper			expect 0 unlink ${n1}
12440a8ac8fSEnji Cooper		fi
12540a8ac8fSEnji Cooper	fi
12640a8ac8fSEnji Cooperdone
12740a8ac8fSEnji Cooper
12840a8ac8fSEnji Coopercd ${cdir}
12940a8ac8fSEnji Cooperexpect 0 rmdir ${n0}
130