1 # $NetBSD: t_setattr.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
29 # Verifies that the setattr vnode operation works, using several commands
30 # that require this function.
35 atf_set
"descr" "Tests that the file owner can be changed"
36 atf_set
"require.user" "root"
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
45 [ ${st_uid} -eq 1234 ] || atf_fail
"uid was not set"
46 [ ${st_gid} -eq ${ost_gid} ] || atf_fail
"gid was modified"
51 atf_test_case chown_kqueue
53 atf_set
"descr" "Tests that changing the file owner raises" \
55 atf_set
"require.user" "root"
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
69 atf_set
"descr" "Tests that the file group can be changed"
70 atf_set
"require.user" "root"
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
79 [ ${st_uid} -eq ${ost_uid} ] || atf_fail
"uid was modified"
80 [ ${st_gid} -eq 5678 ] || atf_fail
"gid was not set"
85 atf_test_case chgrp_kqueue
87 atf_set
"descr" "Tests that changing the file group raises" \
89 atf_set
"require.user" "root"
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
101 atf_test_case chowngrp
103 atf_set
"descr" "Tests that the file owner and group can be" \
105 atf_set
"require.user" "root"
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"
119 atf_test_case chowngrp_kqueue
120 chowngrp_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"
125 chowngrp_kqueue_body
() {
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
137 atf_set
"descr" "Tests that the file mode can be changed"
138 atf_set
"require.user" "root"
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
146 [ ${st_mode} -eq 40000 ] || af_fail
"mode was not set"
151 atf_test_case chmod_kqueue
152 chmod_kqueue_head
() {
153 atf_set
"descr" "Tests that changing the file mode raises" \
155 atf_set
"require.user" "root"
157 chmod_kqueue_body
() {
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
167 atf_test_case chtimes
169 atf_set
"descr" "Tests that file times can be changed"
170 atf_set
"require.user" "root"
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"
186 atf_test_case chtimes_kqueue
187 chtimes_kqueue_head
() {
188 atf_set
"descr" "Tests that changing the file times raises" \
190 atf_set
"require.user" "root"
192 chtimes_kqueue_body
() {
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
202 atf_init_test_cases
() {
203 . $
(atf_get_srcdir
)/..
/h_funcs.subr
204 . $
(atf_get_srcdir
)/h_funcs.subr
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