1271294Sngie#!/bin/sh 2271294Sngie# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/00.t 211352 2010-08-15 21:24:17Z pjd $ 3271294Sngie 4271294Sngiedesc="chmod changes permission" 5271294Sngie 6271294Sngiedir=`dirname $0` 7271294Sngie. ${dir}/../misc.sh 8271294Sngie 9271294Sngieif supported lchmod; then 10271294Sngie echo "1..203" 11271294Sngieelse 12271294Sngie echo "1..119" 13271294Sngiefi 14271294Sngie 15271294Sngien0=`namegen` 16271294Sngien1=`namegen` 17271294Sngien2=`namegen` 18271294Sngie 19271294Sngieexpect 0 mkdir ${n2} 0755 20271294Sngiecdir=`pwd` 21271294Sngiecd ${n2} 22271294Sngie 23271294Sngiefor type in regular dir fifo block char socket symlink; do 24271294Sngie if [ "${type}" != "symlink" ]; then 25271294Sngie create_file ${type} ${n0} 26271294Sngie expect 0 chmod ${n0} 0111 27271294Sngie expect 0111 stat ${n0} mode 28271294Sngie 29271294Sngie expect 0 symlink ${n0} ${n1} 30271294Sngie mode=`${fstest} lstat ${n1} mode` 31271294Sngie expect 0 chmod ${n1} 0222 32271294Sngie expect 0222 stat ${n1} mode 33271294Sngie expect 0222 stat ${n0} mode 34271294Sngie expect ${mode} lstat ${n1} mode 35271294Sngie expect 0 unlink ${n1} 36271294Sngie 37271294Sngie if [ "${type}" = "dir" ]; then 38271294Sngie expect 0 rmdir ${n0} 39271294Sngie else 40271294Sngie expect 0 unlink ${n0} 41271294Sngie fi 42271294Sngie fi 43271294Sngie 44271294Sngie if supported lchmod; then 45271294Sngie create_file ${type} ${n0} 46271294Sngie expect 0 lchmod ${n0} 0111 47271294Sngie expect 0111 lstat ${n0} mode 48271294Sngie if [ "${type}" = "dir" ]; then 49271294Sngie expect 0 rmdir ${n0} 50271294Sngie else 51271294Sngie expect 0 unlink ${n0} 52271294Sngie fi 53271294Sngie fi 54271294Sngiedone 55271294Sngie 56271294Sngie# successful chmod(2) updates ctime. 57271294Sngiefor type in regular dir fifo block char socket symlink; do 58271294Sngie if [ "${type}" != "symlink" ]; then 59271294Sngie create_file ${type} ${n0} 60271294Sngie ctime1=`${fstest} stat ${n0} ctime` 61271294Sngie sleep 1 62271294Sngie expect 0 chmod ${n0} 0111 63271294Sngie ctime2=`${fstest} stat ${n0} ctime` 64271294Sngie test_check $ctime1 -lt $ctime2 65271294Sngie if [ "${type}" = "dir" ]; then 66271294Sngie expect 0 rmdir ${n0} 67271294Sngie else 68271294Sngie expect 0 unlink ${n0} 69271294Sngie fi 70271294Sngie fi 71271294Sngie 72271294Sngie if supported lchmod; then 73271294Sngie create_file ${type} ${n0} 74271294Sngie ctime1=`${fstest} lstat ${n0} ctime` 75271294Sngie sleep 1 76271294Sngie expect 0 lchmod ${n0} 0111 77271294Sngie ctime2=`${fstest} lstat ${n0} ctime` 78271294Sngie test_check $ctime1 -lt $ctime2 79271294Sngie if [ "${type}" = "dir" ]; then 80271294Sngie expect 0 rmdir ${n0} 81271294Sngie else 82271294Sngie expect 0 unlink ${n0} 83271294Sngie fi 84271294Sngie fi 85271294Sngiedone 86271294Sngie 87271294Sngie# unsuccessful chmod(2) does not update ctime. 88271294Sngiefor type in regular dir fifo block char socket symlink; do 89271294Sngie if [ "${type}" != "symlink" ]; then 90271294Sngie create_file ${type} ${n0} 91271294Sngie ctime1=`${fstest} stat ${n0} ctime` 92271294Sngie sleep 1 93271294Sngie expect EPERM -u 65534 chmod ${n0} 0111 94271294Sngie ctime2=`${fstest} stat ${n0} ctime` 95271294Sngie test_check $ctime1 -eq $ctime2 96271294Sngie if [ "${type}" = "dir" ]; then 97271294Sngie expect 0 rmdir ${n0} 98271294Sngie else 99271294Sngie expect 0 unlink ${n0} 100271294Sngie fi 101271294Sngie fi 102271294Sngie 103271294Sngie if supported lchmod; then 104271294Sngie create_file ${type} ${n0} 105271294Sngie ctime1=`${fstest} lstat ${n0} ctime` 106271294Sngie sleep 1 107271294Sngie expect EPERM -u 65534 lchmod ${n0} 0321 108271294Sngie ctime2=`${fstest} lstat ${n0} ctime` 109271294Sngie test_check $ctime1 -eq $ctime2 110271294Sngie if [ "${type}" = "dir" ]; then 111271294Sngie expect 0 rmdir ${n0} 112271294Sngie else 113271294Sngie expect 0 unlink ${n0} 114271294Sngie fi 115271294Sngie fi 116271294Sngiedone 117271294Sngie 118271294Sngie# POSIX: If the calling process does not have appropriate privileges, and if 119271294Sngie# the group ID of the file does not match the effective group ID or one of the 120271294Sngie# supplementary group IDs and if the file is a regular file, bit S_ISGID 121271294Sngie# (set-group-ID on execution) in the file's mode shall be cleared upon 122271294Sngie# successful return from chmod(). 123271294Sngie 124271294Sngieexpect 0 create ${n0} 0755 125271294Sngieexpect 0 chown ${n0} 65535 65535 126271294Sngieexpect 0 -u 65535 -g 65535 chmod ${n0} 02755 127271294Sngieexpect 02755 stat ${n0} mode 128271294Sngieexpect 0 -u 65535 -g 65535 chmod ${n0} 0755 129271294Sngieexpect 0755 stat ${n0} mode 130271294Sngie 131271294Sngietodo FreeBSD "S_ISGID should be removed and chmod(2) should success and FreeBSD returns EPERM." 132271294Sngieexpect 0 -u 65535 -g 65534 chmod ${n0} 02755 133271294Sngieexpect 0755 stat ${n0} mode 134271294Sngie 135271294Sngieexpect 0 unlink ${n0} 136271294Sngie 137271294Sngiecd ${cdir} 138271294Sngieexpect 0 rmdir ${n2} 139