2 # Copyright (c) 2017 Dell EMC
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 atf_set "descr" "Verify that setting ownership recursively via -R doesn't " \
32 "affect symlinks specified via the arguments when -H " \
34 atf_set "require.user" "root"
38 atf_check mkdir -p A/B
40 atf_check chown -h 42:42 A/C
41 atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C
42 atf_check chown -RH 84:84 A
43 atf_check -o inline:'84:84\n84:84\n84:84\n' stat -f '%u:%g' A A/B A/C
44 atf_check chown -RH 126:126 A/C
45 atf_check -o inline:'84:84\n126:126\n84:84\n' stat -f '%u:%g' A A/B A/C
51 atf_set "descr" "Verify that setting ownership recursively via -R doesn't " \
52 "affect symlinks specified via the arguments when -L " \
54 atf_set "require.user" "root"
58 atf_check mkdir -p A/B
60 atf_check chown -h 42:42 A/C
61 atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C
62 atf_check chown -RL 84:84 A
63 atf_check -o inline:'84:84\n84:84\n42:42\n' stat -f '%u:%g' A A/B A/C
64 atf_check chown -RL 126:126 A/C
65 atf_check -o inline:'84:84\n126:126\n42:42\n' stat -f '%u:%g' A A/B A/C
71 atf_set "descr" "Verify that setting ownership recursively via -R " \
72 "doesn't affect symlinks specified via the arguments " \
73 "when -P is specified"
74 atf_set "require.user" "root"
78 atf_check mkdir -p A/B
80 atf_check chown -h 42:42 A/C
81 atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C
82 atf_check chown -RP 84:84 A
83 atf_check -o inline:'84:84\n84:84\n84:84\n' stat -f '%u:%g' A A/B A/C
84 atf_check chown -RP 126:126 A/C
85 atf_check -o inline:'84:84\n84:84\n126:126\n' stat -f '%u:%g' A A/B A/C
88 atf_test_case f_flag cleanup
91 atf_set "descr" "Verify that setting a mode for a file with -f " \
92 "doesn't emit an error message/exit with a non-zero " \
94 atf_set "require.user" "root"
99 atf_check truncate -s 0 foo bar
100 atf_check chown 0:0 foo bar
101 atf_check chflags uchg foo
102 atf_check -e not-empty -s not-exit:0 chown 42:42 foo bar
103 atf_check -o inline:'0:0\n42:42\n' stat -f '%u:%g' foo bar
104 atf_check -s exit:0 chown -f 84:84 foo bar
105 atf_check -o inline:'0:0\n84:84\n' stat -f '%u:%g' foo bar
110 atf_check chflags 0 foo
116 atf_set "descr" "Verify that setting a mode for a file with -f " \
117 "doesn't emit an error message/exit with a non-zero " \
119 atf_set "require.user" "root"
124 atf_check truncate -s 0 foo
125 atf_check -o inline:'0:0\n' stat -f '%u:%g' foo
126 atf_check ln -s foo bar
127 atf_check -o inline:'0:0\n0:0\n' stat -f '%u:%g' foo bar
128 atf_check chown -h 42:42 bar
129 atf_check -o inline:'0:0\n42:42\n' stat -f '%u:%g' foo bar
130 atf_check chown 84:84 bar
131 atf_check -o inline:'84:84\n42:42\n' stat -f '%u:%g' foo bar
137 atf_set "descr" "Verify that setting ownership with -v emits the " \
138 "file doesn't emit an error message/exit with a " \
140 atf_set "require.user" "root"
144 atf_check truncate -s 0 foo bar
145 atf_check chown 0:0 foo
146 atf_check chown 42:42 bar
147 atf_check -o 'inline:bar\n' chown -v 0:0 foo bar
148 atf_check chown -v 0:0 foo bar
150 echo "$f: 0:0 -> 84:84";
152 atf_check -o file:output.txt chown -vv 84:84 foo bar
153 atf_check chown -vv 84:84 foo bar
157 atf_test_case x_flag cleanup
160 atf_set "descr" "Verify that setting a mode with -x doesn't set " \
161 "ownership across mountpoints"
162 atf_set "require.user" "root"
166 atf_check -o save:$md_file mdconfig -a -t malloc -s 20m
167 if ! md_device=$(cat $md_file); then
168 atf_fail "cat $md_file failed"
170 atf_check -o not-empty newfs /dev/$md_device
172 atf_check mount /dev/$md_device mnt
173 atf_check truncate -s 0 foo bar mnt/bazbaz
174 atf_check ln -s bar mnt/barbaz
175 atf_check ln -s ../foo mnt/foobaz
177 test_files="../foo ../bar barbaz bazbaz foobaz"
178 atf_check -o inline:'0:0\n0:0\n0:0\n0:0\n0:0\n' \
179 stat -f '%u:%g' $test_files
180 atf_check chown -Rx 42:42 .
181 atf_check -o inline:'0:0\n0:0\n42:42\n42:42\n42:42\n' \
182 stat -f '%u:%g' $test_files
183 atf_check chown -R 84:84 .
184 atf_check -o inline:'0:0\n0:0\n84:84\n84:84\n84:84\n' \
185 stat -f '%u:%g' $test_files
189 if ! md_device=$(cat $md_file) || [ -z "$md_device" ]; then
190 echo "Couldn't get device from $md_file"
194 mdconfig -d -u $md_device
197 atf_init_test_cases()
199 atf_add_test_case RH_flag
200 atf_add_test_case RL_flag
201 atf_add_test_case RP_flag
202 atf_add_test_case f_flag
203 atf_add_test_case h_flag
204 atf_add_test_case v_flag
205 atf_add_test_case x_flag