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 modes recursively via -R doesn't " \
39 "affect symlinks specified via the arguments when -H " \
44 atf_check mkdir -m 0777 -p A/B
46 atf_check chmod -h 0777 A/C
47 atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C
48 atf_check chmod -RH 0700 A
49 atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C
50 atf_check chmod -RH 0600 A/C
51 atf_check -o inline:'40700\n40600\n120700\n' stat -f '%p' A A/B A/C
57 atf_set "descr" "Verify that setting modes recursively via -R doesn't " \
58 "affect symlinks specified via the arguments when -L " \
63 atf_check mkdir -m 0777 -p A/B
65 atf_check chmod -h 0777 A/C
66 atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C
67 atf_check chmod -RL 0700 A
68 atf_check -o inline:'40700\n40700\n120777\n' stat -f '%p' A A/B A/C
69 atf_check chmod -RL 0600 A/C
70 atf_check -o inline:'40700\n40600\n120777\n' stat -f '%p' A A/B A/C
76 atf_set "descr" "Verify that setting modes recursively via -R doesn't " \
77 "affect symlinks specified via the arguments when -P " \
82 atf_check mkdir -m 0777 -p A/B
84 atf_check chmod -h 0777 A/C
85 atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C
86 atf_check chmod -RP 0700 A
87 atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C
88 atf_check chmod -RP 0600 A/C
89 atf_check -o inline:'40700\n40700\n120600\n' stat -f '%p' A A/B A/C
92 atf_test_case f_flag cleanup
95 atf_set "descr" "Verify that setting a mode for a file with -f " \
96 "doesn't emit an error message/exit with a non-zero " \
102 atf_check truncate -s 0 foo bar
103 atf_check chmod 0750 foo bar
104 case "$(get_filesystem .)" in
106 atf_expect_fail "ZFS doesn't support UF_IMMUTABLE; returns EPERM - bug 221189"
109 atf_check chflags uchg foo
110 atf_check -e not-empty -s not-exit:0 chmod 0700 foo bar
111 atf_check -o inline:'100750\n100700\n' stat -f '%p' foo bar
112 atf_check -s exit:0 chmod -f 0600 foo bar
113 atf_check -o inline:'100750\n100600\n' stat -f '%p' foo bar
124 atf_set "descr" "Verify that setting a mode for a file with -f " \
125 "doesn't emit an error message/exit with a non-zero " \
131 atf_check truncate -s 0 foo
132 atf_check chmod 0600 foo
133 atf_check -o inline:'100600\n' stat -f '%p' foo
135 atf_check ln -s foo bar
136 atf_check -o inline:'100600\n120700\n' stat -f '%p' foo bar
137 atf_check chmod -h 0500 bar
138 atf_check -o inline:'100600\n120500\n' stat -f '%p' foo bar
139 atf_check chmod 0660 bar
140 atf_check -o inline:'100660\n120500\n' stat -f '%p' foo bar
146 atf_set "descr" "Verify that setting a mode with -v emits the file when " \
147 "doesn't emit an error message/exit with a non-zero " \
152 atf_check truncate -s 0 foo bar
153 atf_check chmod 0600 foo
154 atf_check chmod 0750 bar
155 case "$(get_filesystem .)" in
157 atf_expect_fail "ZFS updates mode for foo unnecessarily - bug 221188"
160 atf_check -o 'inline:bar\n' chmod -v 0600 foo bar
161 atf_check chmod -v 0600 foo bar
163 echo "$f: 0100600 [-rw------- ] -> 0100700 [-rwx------ ]";
165 atf_check -o file:output.txt chmod -vv 0700 foo bar
166 atf_check chmod -vv 0700 foo bar
169 atf_init_test_cases()
171 atf_add_test_case RH_flag
172 atf_add_test_case RL_flag
173 atf_add_test_case RP_flag
174 atf_add_test_case f_flag
175 atf_add_test_case h_flag
176 atf_add_test_case v_flag