00.t revision 271295
1193323Sed#!/bin/sh 2193323Sed# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/00.t 211352 2010-08-15 21:24:17Z pjd $ 3193323Sed 4193323Seddesc="chmod changes permission" 5193323Sed 6193323Seddir=`dirname $0` 7193323Sed. ${dir}/../misc.sh 8193323Sed 9193323Sedif supported lchmod; then 10193323Sed echo "1..203" 11193323Sedelse 12193323Sed echo "1..119" 13193323Sedfi 14193323Sed 15193323Sedn0=`namegen` 16193323Sedn1=`namegen` 17193323Sedn2=`namegen` 18193323Sed 19193323Sedexpect 0 mkdir ${n2} 0755 20198090Srdivackycdir=`pwd` 21198090Srdivackycd ${n2} 22198090Srdivacky 23198090Srdivackyfor type in regular dir fifo block char socket symlink; do 24198090Srdivacky if [ "${type}" != "symlink" ]; then 25198090Srdivacky create_file ${type} ${n0} 26249423Sdim expect 0 chmod ${n0} 0111 27249423Sdim expect 0111 stat ${n0} mode 28249423Sdim 29249423Sdim expect 0 symlink ${n0} ${n1} 30249423Sdim mode=`${fstest} lstat ${n1} mode` 31249423Sdim expect 0 chmod ${n1} 0222 32249423Sdim expect 0222 stat ${n1} mode 33249423Sdim expect 0222 stat ${n0} mode 34198090Srdivacky expect ${mode} lstat ${n1} mode 35193323Sed expect 0 unlink ${n1} 36251662Sdim 37193323Sed if [ "${type}" = "dir" ]; then 38193323Sed expect 0 rmdir ${n0} 39193323Sed else 40193323Sed expect 0 unlink ${n0} 41193323Sed fi 42193323Sed fi 43199989Srdivacky 44193323Sed if supported lchmod; then 45193323Sed create_file ${type} ${n0} 46193323Sed expect 0 lchmod ${n0} 0111 47193323Sed expect 0111 lstat ${n0} mode 48226633Sdim if [ "${type}" = "dir" ]; then 49193323Sed expect 0 rmdir ${n0} 50193323Sed else 51193323Sed expect 0 unlink ${n0} 52193323Sed fi 53193323Sed fi 54193323Seddone 55193323Sed 56193323Sed# successful chmod(2) updates ctime. 57193323Sedfor type in regular dir fifo block char socket symlink; do 58193323Sed if [ "${type}" != "symlink" ]; then 59199989Srdivacky create_file ${type} ${n0} 60193323Sed ctime1=`${fstest} stat ${n0} ctime` 61234353Sdim sleep 1 62234353Sdim expect 0 chmod ${n0} 0111 63234353Sdim ctime2=`${fstest} stat ${n0} ctime` 64193323Sed test_check $ctime1 -lt $ctime2 65193323Sed if [ "${type}" = "dir" ]; then 66193323Sed expect 0 rmdir ${n0} 67193323Sed else 68193323Sed expect 0 unlink ${n0} 69193323Sed fi 70226633Sdim fi 71193323Sed 72193323Sed if supported lchmod; then 73193323Sed create_file ${type} ${n0} 74193323Sed ctime1=`${fstest} lstat ${n0} ctime` 75193323Sed sleep 1 76193323Sed expect 0 lchmod ${n0} 0111 77193323Sed ctime2=`${fstest} lstat ${n0} ctime` 78193323Sed test_check $ctime1 -lt $ctime2 79193323Sed if [ "${type}" = "dir" ]; then 80193323Sed expect 0 rmdir ${n0} 81193323Sed else 82193323Sed expect 0 unlink ${n0} 83193323Sed fi 84193323Sed fi 85193323Seddone 86193323Sed 87193323Sed# unsuccessful chmod(2) does not update ctime. 88193323Sedfor type in regular dir fifo block char socket symlink; do 89193323Sed if [ "${type}" != "symlink" ]; then 90193323Sed create_file ${type} ${n0} 91193323Sed ctime1=`${fstest} stat ${n0} ctime` 92193323Sed sleep 1 93193323Sed expect EPERM -u 65534 chmod ${n0} 0111 94193323Sed ctime2=`${fstest} stat ${n0} ctime` 95193323Sed test_check $ctime1 -eq $ctime2 96193323Sed if [ "${type}" = "dir" ]; then 97193323Sed expect 0 rmdir ${n0} 98193323Sed else 99193323Sed expect 0 unlink ${n0} 100193323Sed fi 101193323Sed fi 102193323Sed 103193323Sed if supported lchmod; then 104193323Sed create_file ${type} ${n0} 105193323Sed ctime1=`${fstest} lstat ${n0} ctime` 106193323Sed sleep 1 107193323Sed expect EPERM -u 65534 lchmod ${n0} 0321 108193323Sed ctime2=`${fstest} lstat ${n0} ctime` 109193323Sed test_check $ctime1 -eq $ctime2 110251662Sdim if [ "${type}" = "dir" ]; then 111251662Sdim expect 0 rmdir ${n0} 112251662Sdim else 113193323Sed expect 0 unlink ${n0} 114251662Sdim fi 115251662Sdim fi 116251662Sdimdone 117251662Sdim 118251662Sdim# POSIX: If the calling process does not have appropriate privileges, and if 119251662Sdim# the group ID of the file does not match the effective group ID or one of the 120251662Sdim# supplementary group IDs and if the file is a regular file, bit S_ISGID 121251662Sdim# (set-group-ID on execution) in the file's mode shall be cleared upon 122193323Sed# successful return from chmod(). 123193323Sed 124193323Sedexpect 0 create ${n0} 0755 125193323Sedexpect 0 chown ${n0} 65535 65535 126193323Sedexpect 0 -u 65535 -g 65535 chmod ${n0} 02755 127193323Sedexpect 02755 stat ${n0} mode 128198090Srdivackyexpect 0 -u 65535 -g 65535 chmod ${n0} 0755 129198090Srdivackyexpect 0755 stat ${n0} mode 130198090Srdivacky 131198090Srdivackytodo FreeBSD "S_ISGID should be removed and chmod(2) should success and FreeBSD returns EPERM." 132193323Sedexpect 0 -u 65535 -g 65534 chmod ${n0} 02755 133193323Sedexpect 0755 stat ${n0} mode 134193323Sed 135193323Sedexpect 0 unlink ${n0} 136193323Sed 137193323Sedcd ${cdir} 138193323Sedexpect 0 rmdir ${n2} 139193323Sed