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
32 df -T $mountpoint | tail -n 1 | cut -wf 2
38 atf_set "descr" "Verify that setting ownership recursively via -R doesn't " \
39 "affect symlinks specified via the arguments when -H " \
41 atf_set "require.user" "root"
45 atf_check mkdir -p A/B
47 atf_check chown -h 42:42 A/C
48 atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C
49 atf_check chown -RH 84:84 A
50 atf_check -o inline:'84:84\n84:84\n84:84\n' stat -f '%u:%g' A A/B A/C
51 atf_check chown -RH 126:126 A/C
52 atf_check -o inline:'84:84\n126:126\n84:84\n' stat -f '%u:%g' A A/B A/C
58 atf_set "descr" "Verify that setting ownership recursively via -R doesn't " \
59 "affect symlinks specified via the arguments when -L " \
61 atf_set "require.user" "root"
65 atf_check mkdir -p A/B
67 atf_check chown -h 42:42 A/C
68 atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C
69 atf_check chown -RL 84:84 A
70 atf_check -o inline:'84:84\n84:84\n42:42\n' stat -f '%u:%g' A A/B A/C
71 atf_check chown -RL 126:126 A/C
72 atf_check -o inline:'84:84\n126:126\n42:42\n' stat -f '%u:%g' A A/B A/C
78 atf_set "descr" "Verify that setting ownership recursively via -R " \
79 "doesn't affect symlinks specified via the arguments " \
80 "when -P is specified"
81 atf_set "require.user" "root"
85 atf_check mkdir -p A/B
87 atf_check chown -h 42:42 A/C
88 atf_check -o inline:'0:0\n0:0\n42:42\n' stat -f '%u:%g' A A/B A/C
89 atf_check chown -RP 84:84 A
90 atf_check -o inline:'84:84\n84:84\n84:84\n' stat -f '%u:%g' A A/B A/C
91 atf_check chown -RP 126:126 A/C
92 atf_check -o inline:'84:84\n84:84\n126:126\n' stat -f '%u:%g' A A/B A/C
95 atf_test_case f_flag cleanup
98 atf_set "descr" "Verify that setting a mode for a file with -f " \
99 "doesn't emit an error message/exit with a non-zero " \
101 atf_set "require.user" "root"
106 atf_check truncate -s 0 foo bar
107 atf_check chown 0:0 foo bar
108 case "$(get_filesystem .)" in
110 atf_expect_fail "ZFS does not support UF_IMMUTABLE; returns EPERM"
113 atf_check chflags uchg foo
114 atf_check -e not-empty -s not-exit:0 chown 42:42 foo bar
115 atf_check -o inline:'0:0\n42:42\n' stat -f '%u:%g' foo bar
116 atf_check -s exit:0 chown -f 84:84 foo bar
117 atf_check -o inline:'0:0\n84:84\n' stat -f '%u:%g' foo bar
128 atf_set "descr" "Verify that setting a mode for a file with -f " \
129 "doesn't emit an error message/exit with a non-zero " \
131 atf_set "require.user" "root"
136 atf_check truncate -s 0 foo
137 atf_check -o inline:'0:0\n' stat -f '%u:%g' foo
138 atf_check ln -s foo bar
139 atf_check -o inline:'0:0\n0:0\n' stat -f '%u:%g' foo bar
140 atf_check chown -h 42:42 bar
141 atf_check -o inline:'0:0\n42:42\n' stat -f '%u:%g' foo bar
142 atf_check chown 84:84 bar
143 atf_check -o inline:'84:84\n42:42\n' stat -f '%u:%g' foo bar
149 atf_set "descr" "Verify that setting ownership with -v emits the " \
150 "file doesn't emit an error message/exit with a " \
152 atf_set "require.user" "root"
156 atf_check truncate -s 0 foo bar
157 atf_check chown 0:0 foo
158 atf_check chown 42:42 bar
159 atf_check -o 'inline:bar\n' chown -v 0:0 foo bar
160 atf_check chown -v 0:0 foo bar
162 echo "$f: 0:0 -> 84:84";
164 atf_check -o file:output.txt chown -vv 84:84 foo bar
165 atf_check chown -vv 84:84 foo bar
169 atf_test_case x_flag cleanup
172 atf_set "descr" "Verify that setting a mode with -x doesn't set " \
173 "ownership across mountpoints"
174 atf_set "require.user" "root"
178 atf_check -o save:$md_file mdconfig -a -t malloc -s 20m
179 if ! md_device=$(cat $md_file); then
180 atf_fail "cat $md_file failed"
182 atf_check -o not-empty newfs /dev/$md_device
184 atf_check mount /dev/$md_device mnt
185 atf_check truncate -s 0 foo bar mnt/bazbaz
186 atf_check ln -s bar mnt/barbaz
187 atf_check ln -s ../foo mnt/foobaz
189 test_files="../foo ../bar barbaz bazbaz foobaz"
190 atf_check -o inline:'0:0\n0:0\n0:0\n0:0\n0:0\n' \
191 stat -f '%u:%g' $test_files
192 atf_check chown -Rx 42:42 .
193 atf_check -o inline:'0:0\n0:0\n42:42\n42:42\n42:42\n' \
194 stat -f '%u:%g' $test_files
195 atf_check chown -R 84:84 .
196 atf_check -o inline:'0:0\n0:0\n84:84\n84:84\n84:84\n' \
197 stat -f '%u:%g' $test_files
201 if ! md_device=$(cat $md_file) || [ -z "$md_device" ]; then
202 echo "Couldn't get device from $md_file"
206 mdconfig -d -u $md_device
209 atf_init_test_cases()
211 atf_add_test_case RH_flag
212 atf_add_test_case RL_flag
213 atf_add_test_case RP_flag
214 atf_add_test_case f_flag
215 atf_add_test_case h_flag
216 atf_add_test_case v_flag
217 atf_add_test_case x_flag