1# $NetBSD: t_setattr.sh,v 1.4 2010/06/04 08:39:40 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 atf_set "use.fs" "true" 38} 39chown_body() { 40 test_mount 41 42 atf_check -s eq:0 -o empty -e empty mkdir own 43 eval $(stat -s own | sed -e 's|st_|ost_|g') 44 atf_check -s eq:0 -o empty -e empty chown 1234 own 45 eval $(stat -s own) 46 [ ${st_uid} -eq 1234 ] || atf_fail "uid was not set" 47 [ ${st_gid} -eq ${ost_gid} ] || atf_fail "gid was modified" 48 49 test_unmount 50} 51 52atf_test_case chown_kqueue 53chown_kqueue_head() { 54 atf_set "descr" "Tests that changing the file owner raises" \ 55 "NOTE_ATTRIB on it" 56 atf_set "require.user" "root" 57 atf_set "use.fs" "true" 58} 59chown_kqueue_body() { 60 test_mount 61 62 atf_check -s eq:0 -o empty -e empty mkdir ownq 63 echo 'chown 1234 ownq' | kqueue_monitor 1 ownq 64 kqueue_check ownq NOTE_ATTRIB 65 66 test_unmount 67} 68 69atf_test_case chgrp 70chgrp_head() { 71 atf_set "descr" "Tests that the file group can be changed" 72 atf_set "require.user" "root" 73 atf_set "use.fs" "true" 74} 75chgrp_body() { 76 test_mount 77 78 atf_check -s eq:0 -o empty -e empty mkdir grp 79 eval $(stat -s grp | sed -e 's|st_|ost_|g') 80 atf_check -s eq:0 -o empty -e empty chgrp 5678 grp 81 eval $(stat -s grp) 82 [ ${st_uid} -eq ${ost_uid} ] || atf_fail "uid was modified" 83 [ ${st_gid} -eq 5678 ] || atf_fail "gid was not set" 84 85 test_unmount 86} 87 88atf_test_case chgrp_kqueue 89chgrp_kqueue_head() { 90 atf_set "descr" "Tests that changing the file group raises" \ 91 "NOTE_ATTRIB on it" 92 atf_set "require.user" "root" 93 atf_set "use.fs" "true" 94} 95chgrp_kqueue_body() { 96 test_mount 97 98 atf_check -s eq:0 -o empty -e empty mkdir grpq 99 echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq 100 kqueue_check grpq NOTE_ATTRIB 101 102 test_unmount 103} 104 105atf_test_case chowngrp 106chowngrp_head() { 107 atf_set "descr" "Tests that the file owner and group can be" \ 108 "changed at once" 109 atf_set "require.user" "root" 110 atf_set "use.fs" "true" 111} 112chowngrp_body() { 113 test_mount 114 115 atf_check -s eq:0 -o empty -e empty mkdir owngrp 116 atf_check -s eq:0 -o empty -e empty chown 1234:5678 owngrp 117 eval $(stat -s owngrp) 118 [ ${st_uid} -eq 1234 ] || atf_fail "uid was not modified" 119 [ ${st_gid} -eq 5678 ] || atf_fail "gid was not modified" 120 121 test_unmount 122} 123 124atf_test_case chowngrp_kqueue 125chowngrp_kqueue_head() { 126 atf_set "descr" "Tests that changing the file owner and group" \ 127 "raises NOTE_ATTRIB on it" 128 atf_set "require.user" "root" 129 atf_set "use.fs" "true" 130} 131chowngrp_kqueue_body() { 132 test_mount 133 134 atf_check -s eq:0 -o empty -e empty mkdir owngrpp 135 echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp 136 kqueue_check owngrpp NOTE_ATTRIB 137 138 test_unmount 139} 140 141atf_test_case chmod 142chmod_head() { 143 atf_set "descr" "Tests that the file mode can be changed" 144 atf_set "require.user" "root" 145 atf_set "use.fs" "true" 146} 147chmod_body() { 148 test_mount 149 150 atf_check -s eq:0 -o empty -e empty mkdir mode 151 atf_check -s eq:0 -o empty -e empty chmod 0000 mode 152 eval $(stat -s mode) 153 [ ${st_mode} -eq 40000 ] || af_fail "mode was not set" 154 155 test_unmount 156} 157 158atf_test_case chmod_kqueue 159chmod_kqueue_head() { 160 atf_set "descr" "Tests that changing the file mode raises" \ 161 "NOTE_ATTRIB on it" 162 atf_set "require.user" "root" 163 atf_set "use.fs" "true" 164} 165chmod_kqueue_body() { 166 test_mount 167 168 atf_check -s eq:0 -o empty -e empty mkdir modeq 169 echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq 170 kqueue_check modeq NOTE_ATTRIB 171 172 test_unmount 173} 174 175atf_test_case chtimes 176chtimes_head() { 177 atf_set "descr" "Tests that file times can be changed" 178 atf_set "require.user" "root" 179 atf_set "use.fs" "true" 180} 181chtimes_body() { 182 test_mount 183 184 atf_check -s eq:0 -o empty -e empty mkdir times 185 atf_check -s eq:0 -o empty -e empty \ 186 -x 'TZ=GMT touch -t 200501010101 times' 187 eval $(stat -s times) 188 [ ${st_atime} = ${st_mtime} ] || \ 189 atf_fail "atime does not match mtime" 190 [ ${st_atime} = 1104541260 ] || atf_fail "atime does not match" 191 192 test_unmount 193} 194 195atf_test_case chtimes_kqueue 196chtimes_kqueue_head() { 197 atf_set "descr" "Tests that changing the file times raises" \ 198 "NOTE_ATTRIB on it" 199 atf_set "require.user" "root" 200 atf_set "use.fs" "true" 201} 202chtimes_kqueue_body() { 203 test_mount 204 205 atf_check -s eq:0 -o empty -e empty mkdir timesq 206 echo 'touch timesq' | kqueue_monitor 1 timesq 207 kqueue_check timesq NOTE_ATTRIB 208 209 test_unmount 210} 211 212atf_init_test_cases() { 213 . $(atf_get_srcdir)/../h_funcs.subr 214 . $(atf_get_srcdir)/h_funcs.subr 215 216 atf_add_test_case chown 217 atf_add_test_case chown_kqueue 218 atf_add_test_case chgrp 219 atf_add_test_case chgrp_kqueue 220 atf_add_test_case chowngrp 221 atf_add_test_case chowngrp_kqueue 222 atf_add_test_case chmod 223 atf_add_test_case chmod_kqueue 224 atf_add_test_case chtimes 225 atf_add_test_case chtimes_kqueue 226} 227