1#!/bin/sh 2# vim: filetype=sh noexpandtab ts=8 sw=8 3# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/00.t 211352 2010-08-15 21:24:17Z pjd $ 4 5desc="chmod changes permission" 6 7dir=`dirname $0` 8. ${dir}/../misc.sh 9 10if supported lchmod; then 11 echo "1..203" 12else 13 echo "1..119" 14fi 15 16n0=`namegen` 17n1=`namegen` 18n2=`namegen` 19 20expect 0 mkdir ${n2} 0755 21cdir=`pwd` 22cd ${n2} 23 24for type in regular dir fifo block char socket symlink; do 25 if [ "${type}" != "symlink" ]; then 26 create_file ${type} ${n0} 27 expect 0 chmod ${n0} 0111 28 expect 0111 stat ${n0} mode 29 30 expect 0 symlink ${n0} ${n1} 31 mode=`${fstest} lstat ${n1} mode` 32 expect 0 chmod ${n1} 0222 33 expect 0222 stat ${n1} mode 34 expect 0222 stat ${n0} mode 35 expect ${mode} lstat ${n1} mode 36 expect 0 unlink ${n1} 37 38 if [ "${type}" = "dir" ]; then 39 expect 0 rmdir ${n0} 40 else 41 expect 0 unlink ${n0} 42 fi 43 fi 44 45 if supported lchmod; then 46 create_file ${type} ${n0} 47 expect 0 lchmod ${n0} 0111 48 expect 0111 lstat ${n0} mode 49 if [ "${type}" = "dir" ]; then 50 expect 0 rmdir ${n0} 51 else 52 expect 0 unlink ${n0} 53 fi 54 fi 55done 56 57# successful chmod(2) updates ctime. 58for type in regular dir fifo block char socket symlink; do 59 if [ "${type}" != "symlink" ]; then 60 create_file ${type} ${n0} 61 ctime1=`${fstest} stat ${n0} ctime` 62 sleep 1 63 expect 0 chmod ${n0} 0111 64 ctime2=`${fstest} stat ${n0} ctime` 65 test_check $ctime1 -lt $ctime2 66 if [ "${type}" = "dir" ]; then 67 expect 0 rmdir ${n0} 68 else 69 expect 0 unlink ${n0} 70 fi 71 fi 72 73 if supported lchmod; then 74 create_file ${type} ${n0} 75 ctime1=`${fstest} lstat ${n0} ctime` 76 sleep 1 77 expect 0 lchmod ${n0} 0111 78 ctime2=`${fstest} lstat ${n0} ctime` 79 test_check $ctime1 -lt $ctime2 80 if [ "${type}" = "dir" ]; then 81 expect 0 rmdir ${n0} 82 else 83 expect 0 unlink ${n0} 84 fi 85 fi 86done 87 88# unsuccessful chmod(2) does not update ctime. 89for type in regular dir fifo block char socket symlink; do 90 if [ "${type}" != "symlink" ]; then 91 create_file ${type} ${n0} 92 ctime1=`${fstest} stat ${n0} ctime` 93 sleep 1 94 expect EPERM -u 65534 chmod ${n0} 0111 95 ctime2=`${fstest} stat ${n0} ctime` 96 test_check $ctime1 -eq $ctime2 97 if [ "${type}" = "dir" ]; then 98 expect 0 rmdir ${n0} 99 else 100 expect 0 unlink ${n0} 101 fi 102 fi 103 104 if supported lchmod; then 105 create_file ${type} ${n0} 106 ctime1=`${fstest} lstat ${n0} ctime` 107 sleep 1 108 expect EPERM -u 65534 lchmod ${n0} 0321 109 ctime2=`${fstest} lstat ${n0} ctime` 110 test_check $ctime1 -eq $ctime2 111 if [ "${type}" = "dir" ]; then 112 expect 0 rmdir ${n0} 113 else 114 expect 0 unlink ${n0} 115 fi 116 fi 117done 118 119# POSIX: If the calling process does not have appropriate privileges, and if 120# the group ID of the file does not match the effective group ID or one of the 121# supplementary group IDs and if the file is a regular file, bit S_ISGID 122# (set-group-ID on execution) in the file's mode shall be cleared upon 123# successful return from chmod(). 124 125expect 0 create ${n0} 0755 126expect 0 chown ${n0} 65535 65535 127expect 0 -u 65535 -g 65535 chmod ${n0} 02755 128expect 02755 stat ${n0} mode 129expect 0 -u 65535 -g 65535 chmod ${n0} 0755 130expect 0755 stat ${n0} mode 131 132todo FreeBSD "S_ISGID should be removed and chmod(2) should success and FreeBSD returns EPERM." 133expect 0 -u 65535 -g 65534 chmod ${n0} 02755 134expect 0755 stat ${n0} mode 135 136expect 0 unlink ${n0} 137 138cd ${cdir} 139expect 0 rmdir ${n2} 140