1# $NetBSD: t_setattr.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $ 2# 3# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28# 29# Verifies that the setattr vnode operation works, using several commands 30# that require this function. 31# 32 33atf_test_case chown 34chown_head() { 35 atf_set "descr" "Tests that the file owner can be changed" 36 atf_set "require.user" "root" 37} 38chown_body() { 39 test_mount 40 41 atf_check -s eq:0 -o empty -e empty mkdir own 42 eval $(stat -s own | sed -e 's|st_|ost_|g') 43 atf_check -s eq:0 -o empty -e empty chown 1234 own 44 eval $(stat -s own) 45 [ ${st_uid} -eq 1234 ] || atf_fail "uid was not set" 46 [ ${st_gid} -eq ${ost_gid} ] || atf_fail "gid was modified" 47 48 test_unmount 49} 50 51atf_test_case chown_kqueue 52chown_kqueue_head() { 53 atf_set "descr" "Tests that changing the file owner raises" \ 54 "NOTE_ATTRIB on it" 55 atf_set "require.user" "root" 56} 57chown_kqueue_body() { 58 test_mount 59 60 atf_check -s eq:0 -o empty -e empty mkdir ownq 61 echo 'chown 1234 ownq' | kqueue_monitor 1 ownq 62 kqueue_check ownq NOTE_ATTRIB 63 64 test_unmount 65} 66 67atf_test_case chgrp 68chgrp_head() { 69 atf_set "descr" "Tests that the file group can be changed" 70 atf_set "require.user" "root" 71} 72chgrp_body() { 73 test_mount 74 75 atf_check -s eq:0 -o empty -e empty mkdir grp 76 eval $(stat -s grp | sed -e 's|st_|ost_|g') 77 atf_check -s eq:0 -o empty -e empty chgrp 5678 grp 78 eval $(stat -s grp) 79 [ ${st_uid} -eq ${ost_uid} ] || atf_fail "uid was modified" 80 [ ${st_gid} -eq 5678 ] || atf_fail "gid was not set" 81 82 test_unmount 83} 84 85atf_test_case chgrp_kqueue 86chgrp_kqueue_head() { 87 atf_set "descr" "Tests that changing the file group raises" \ 88 "NOTE_ATTRIB on it" 89 atf_set "require.user" "root" 90} 91chgrp_kqueue_body() { 92 test_mount 93 94 atf_check -s eq:0 -o empty -e empty mkdir grpq 95 echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq 96 kqueue_check grpq NOTE_ATTRIB 97 98 test_unmount 99} 100 101atf_test_case chowngrp 102chowngrp_head() { 103 atf_set "descr" "Tests that the file owner and group can be" \ 104 "changed at once" 105 atf_set "require.user" "root" 106} 107chowngrp_body() { 108 test_mount 109 110 atf_check -s eq:0 -o empty -e empty mkdir owngrp 111 atf_check -s eq:0 -o empty -e empty chown 1234:5678 owngrp 112 eval $(stat -s owngrp) 113 [ ${st_uid} -eq 1234 ] || atf_fail "uid was not modified" 114 [ ${st_gid} -eq 5678 ] || atf_fail "gid was not modified" 115 116 test_unmount 117} 118 119atf_test_case chowngrp_kqueue 120chowngrp_kqueue_head() { 121 atf_set "descr" "Tests that changing the file owner and group" \ 122 "raises NOTE_ATTRIB on it" 123 atf_set "require.user" "root" 124} 125chowngrp_kqueue_body() { 126 test_mount 127 128 atf_check -s eq:0 -o empty -e empty mkdir owngrpp 129 echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp 130 kqueue_check owngrpp NOTE_ATTRIB 131 132 test_unmount 133} 134 135atf_test_case chmod 136chmod_head() { 137 atf_set "descr" "Tests that the file mode can be changed" 138 atf_set "require.user" "root" 139} 140chmod_body() { 141 test_mount 142 143 atf_check -s eq:0 -o empty -e empty mkdir mode 144 atf_check -s eq:0 -o empty -e empty chmod 0000 mode 145 eval $(stat -s mode) 146 [ ${st_mode} -eq 40000 ] || af_fail "mode was not set" 147 148 test_unmount 149} 150 151atf_test_case chmod_kqueue 152chmod_kqueue_head() { 153 atf_set "descr" "Tests that changing the file mode raises" \ 154 "NOTE_ATTRIB on it" 155 atf_set "require.user" "root" 156} 157chmod_kqueue_body() { 158 test_mount 159 160 atf_check -s eq:0 -o empty -e empty mkdir modeq 161 echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq 162 kqueue_check modeq NOTE_ATTRIB 163 164 test_unmount 165} 166 167atf_test_case chtimes 168chtimes_head() { 169 atf_set "descr" "Tests that file times can be changed" 170 atf_set "require.user" "root" 171} 172chtimes_body() { 173 test_mount 174 175 atf_check -s eq:0 -o empty -e empty mkdir times 176 atf_check -s eq:0 -o empty -e empty \ 177 -x 'TZ=GMT touch -t 200501010101 times' 178 eval $(stat -s times) 179 [ ${st_atime} = ${st_mtime} ] || \ 180 atf_fail "atime does not match mtime" 181 [ ${st_atime} = 1104541260 ] || atf_fail "atime does not match" 182 183 test_unmount 184} 185 186atf_test_case chtimes_kqueue 187chtimes_kqueue_head() { 188 atf_set "descr" "Tests that changing the file times raises" \ 189 "NOTE_ATTRIB on it" 190 atf_set "require.user" "root" 191} 192chtimes_kqueue_body() { 193 test_mount 194 195 atf_check -s eq:0 -o empty -e empty mkdir timesq 196 echo 'touch timesq' | kqueue_monitor 1 timesq 197 kqueue_check timesq NOTE_ATTRIB 198 199 test_unmount 200} 201 202atf_init_test_cases() { 203 . $(atf_get_srcdir)/../h_funcs.subr 204 . $(atf_get_srcdir)/h_funcs.subr 205 206 atf_add_test_case chown 207 atf_add_test_case chown_kqueue 208 atf_add_test_case chgrp 209 atf_add_test_case chgrp_kqueue 210 atf_add_test_case chowngrp 211 atf_add_test_case chowngrp_kqueue 212 atf_add_test_case chmod 213 atf_add_test_case chmod_kqueue 214 atf_add_test_case chtimes 215 atf_add_test_case chtimes_kqueue 216} 217