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 modes recursively via -R doesn't " \
32 "affect symlinks specified via the arguments when -H " \
37 atf_check mkdir -m 0777 -p A/B
39 atf_check chmod -h 0777 A/C
40 atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C
41 atf_check chmod -RH 0700 A
42 atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C
43 atf_check chmod -RH 0600 A/C
44 atf_check -o inline:'40700\n40600\n120700\n' stat -f '%p' A A/B A/C
50 atf_set "descr" "Verify that setting modes recursively via -R doesn't " \
51 "affect symlinks specified via the arguments when -L " \
56 atf_check mkdir -m 0777 -p A/B
58 atf_check chmod -h 0777 A/C
59 atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C
60 atf_check chmod -RL 0700 A
61 atf_check -o inline:'40700\n40700\n120777\n' stat -f '%p' A A/B A/C
62 atf_check chmod -RL 0600 A/C
63 atf_check -o inline:'40700\n40600\n120777\n' stat -f '%p' A A/B A/C
69 atf_set "descr" "Verify that setting modes recursively via -R doesn't " \
70 "affect symlinks specified via the arguments when -P " \
75 atf_check mkdir -m 0777 -p A/B
77 atf_check chmod -h 0777 A/C
78 atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C
79 atf_check chmod -RP 0700 A
80 atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C
81 atf_check chmod -RP 0600 A/C
82 atf_check -o inline:'40700\n40700\n120600\n' stat -f '%p' A A/B A/C
85 atf_test_case f_flag cleanup
88 atf_set "descr" "Verify that setting a mode for a file with -f " \
89 "doesn't emit an error message/exit with a non-zero " \
95 atf_check truncate -s 0 foo bar
96 atf_check chmod 0750 foo bar
97 atf_check chflags uchg foo
98 atf_check -e not-empty -s not-exit:0 chmod 0700 foo bar
99 atf_check -o inline:'100750\n100700\n' stat -f '%p' foo bar
100 atf_check -s exit:0 chmod -f 0600 foo bar
101 atf_check -o inline:'100750\n100600\n' stat -f '%p' foo bar
106 atf_check chflags 0 foo
112 atf_set "descr" "Verify that setting a mode for a file with -f " \
113 "doesn't emit an error message/exit with a non-zero " \
119 atf_check truncate -s 0 foo
120 atf_check chmod 0600 foo
121 atf_check -o inline:'100600\n' stat -f '%p' foo
123 atf_check ln -s foo bar
124 atf_check -o inline:'100600\n120700\n' stat -f '%p' foo bar
125 atf_check chmod -h 0500 bar
126 atf_check -o inline:'100600\n120500\n' stat -f '%p' foo bar
127 atf_check chmod 0660 bar
128 atf_check -o inline:'100660\n120500\n' stat -f '%p' foo bar
134 atf_set "descr" "Verify that setting a mode with -v emits the file when " \
135 "doesn't emit an error message/exit with a non-zero " \
140 atf_check truncate -s 0 foo bar
141 atf_check chmod 0600 foo
142 atf_check chmod 0750 bar
143 atf_check -o 'inline:bar\n' chmod -v 0600 foo bar
144 atf_check chmod -v 0600 foo bar
146 echo "$f: 0100600 [-rw------- ] -> 0100700 [-rwx------ ]";
148 atf_check -o file:output.txt chmod -vv 0700 foo bar
149 atf_check chmod -vv 0700 foo bar
152 atf_init_test_cases()
154 atf_add_test_case RH_flag
155 atf_add_test_case RL_flag
156 atf_add_test_case RP_flag
157 atf_add_test_case f_flag
158 atf_add_test_case h_flag
159 atf_add_test_case v_flag