1166065Spjd#!/bin/sh 2166065Spjd# $FreeBSD: releng/10.3/tools/regression/pjdfstest/tests/chmod/00.t 211336 2010-08-15 14:44:48Z pjd $ 3166065Spjd 4166065Spjddesc="chmod changes permission" 5166065Spjd 6166065Spjddir=`dirname $0` 7166065Spjd. ${dir}/../misc.sh 8166065Spjd 9166065Spjdif supported lchmod; then 10211336Spjd echo "1..203" 11166065Spjdelse 12211336Spjd echo "1..119" 13166065Spjdfi 14166065Spjd 15166065Spjdn0=`namegen` 16166065Spjdn1=`namegen` 17166065Spjdn2=`namegen` 18166065Spjd 19166065Spjdexpect 0 mkdir ${n2} 0755 20166065Spjdcdir=`pwd` 21166065Spjdcd ${n2} 22166065Spjd 23211336Spjdfor type in regular dir fifo block char socket symlink; do 24211336Spjd if [ "${type}" != "symlink" ]; then 25211336Spjd create_file ${type} ${n0} 26211336Spjd expect 0 chmod ${n0} 0111 27211336Spjd expect 0111 stat ${n0} mode 28166065Spjd 29211336Spjd expect 0 symlink ${n0} ${n1} 30211336Spjd mode=`${fstest} lstat ${n1} mode` 31211336Spjd expect 0 chmod ${n1} 0222 32211336Spjd expect 0222 stat ${n1} mode 33211336Spjd expect 0222 stat ${n0} mode 34211336Spjd expect ${mode} lstat ${n1} mode 35211336Spjd expect 0 unlink ${n1} 36166065Spjd 37211336Spjd if [ "${type}" = "dir" ]; then 38211336Spjd expect 0 rmdir ${n0} 39211336Spjd else 40211336Spjd expect 0 unlink ${n0} 41211336Spjd fi 42211336Spjd fi 43166065Spjd 44211336Spjd if supported lchmod; then 45211336Spjd create_file ${type} ${n0} 46211336Spjd expect 0 lchmod ${n0} 0111 47211336Spjd expect 0111 lstat ${n0} mode 48211336Spjd if [ "${type}" = "dir" ]; then 49211336Spjd expect 0 rmdir ${n0} 50211336Spjd else 51211336Spjd expect 0 unlink ${n0} 52211336Spjd fi 53211336Spjd fi 54211336Spjddone 55166065Spjd 56166065Spjd# successful chmod(2) updates ctime. 57211336Spjdfor type in regular dir fifo block char socket symlink; do 58211336Spjd if [ "${type}" != "symlink" ]; then 59211336Spjd create_file ${type} ${n0} 60211336Spjd ctime1=`${fstest} stat ${n0} ctime` 61211336Spjd sleep 1 62211336Spjd expect 0 chmod ${n0} 0111 63211336Spjd ctime2=`${fstest} stat ${n0} ctime` 64211336Spjd test_check $ctime1 -lt $ctime2 65211336Spjd if [ "${type}" = "dir" ]; then 66211336Spjd expect 0 rmdir ${n0} 67211336Spjd else 68211336Spjd expect 0 unlink ${n0} 69211336Spjd fi 70211336Spjd fi 71166065Spjd 72211336Spjd if supported lchmod; then 73211336Spjd create_file ${type} ${n0} 74211336Spjd ctime1=`${fstest} lstat ${n0} ctime` 75211336Spjd sleep 1 76211336Spjd expect 0 lchmod ${n0} 0111 77211336Spjd ctime2=`${fstest} lstat ${n0} ctime` 78211336Spjd test_check $ctime1 -lt $ctime2 79211336Spjd if [ "${type}" = "dir" ]; then 80211336Spjd expect 0 rmdir ${n0} 81211336Spjd else 82211336Spjd expect 0 unlink ${n0} 83211336Spjd fi 84211336Spjd fi 85211336Spjddone 86166065Spjd 87166065Spjd# unsuccessful chmod(2) does not update ctime. 88211336Spjdfor type in regular dir fifo block char socket symlink; do 89211336Spjd if [ "${type}" != "symlink" ]; then 90211336Spjd create_file ${type} ${n0} 91211336Spjd ctime1=`${fstest} stat ${n0} ctime` 92211336Spjd sleep 1 93211336Spjd expect EPERM -u 65534 chmod ${n0} 0111 94211336Spjd ctime2=`${fstest} stat ${n0} ctime` 95211336Spjd test_check $ctime1 -eq $ctime2 96211336Spjd if [ "${type}" = "dir" ]; then 97211336Spjd expect 0 rmdir ${n0} 98211336Spjd else 99211336Spjd expect 0 unlink ${n0} 100211336Spjd fi 101211336Spjd fi 102166065Spjd 103211336Spjd if supported lchmod; then 104211336Spjd create_file ${type} ${n0} 105211336Spjd ctime1=`${fstest} lstat ${n0} ctime` 106211336Spjd sleep 1 107211336Spjd expect EPERM -u 65534 lchmod ${n0} 0321 108211336Spjd ctime2=`${fstest} lstat ${n0} ctime` 109211336Spjd test_check $ctime1 -eq $ctime2 110211336Spjd if [ "${type}" = "dir" ]; then 111211336Spjd expect 0 rmdir ${n0} 112211336Spjd else 113211336Spjd expect 0 unlink ${n0} 114211336Spjd fi 115211336Spjd fi 116211336Spjddone 117166065Spjd 118166065Spjd# POSIX: If the calling process does not have appropriate privileges, and if 119166065Spjd# the group ID of the file does not match the effective group ID or one of the 120166065Spjd# supplementary group IDs and if the file is a regular file, bit S_ISGID 121166065Spjd# (set-group-ID on execution) in the file's mode shall be cleared upon 122166065Spjd# successful return from chmod(). 123166065Spjd 124166065Spjdexpect 0 create ${n0} 0755 125166065Spjdexpect 0 chown ${n0} 65535 65535 126166065Spjdexpect 0 -u 65535 -g 65535 chmod ${n0} 02755 127166065Spjdexpect 02755 stat ${n0} mode 128166065Spjdexpect 0 -u 65535 -g 65535 chmod ${n0} 0755 129166065Spjdexpect 0755 stat ${n0} mode 130166065Spjd 131211336Spjdtodo FreeBSD "S_ISGID should be removed and chmod(2) should success and FreeBSD returns EPERM." 132211336Spjdexpect 0 -u 65535 -g 65534 chmod ${n0} 02755 133211336Spjdexpect 0755 stat ${n0} mode 134211336Spjd 135166065Spjdexpect 0 unlink ${n0} 136166065Spjd 137166065Spjdcd ${cdir} 138166065Spjdexpect 0 rmdir ${n2} 139