1*245e210cSEnji Cooper# 2*245e210cSEnji Cooper# Copyright (c) 2017 Dell EMC 3*245e210cSEnji Cooper# All rights reserved. 4*245e210cSEnji Cooper# 5*245e210cSEnji Cooper# Redistribution and use in source and binary forms, with or without 6*245e210cSEnji Cooper# modification, are permitted provided that the following conditions 7*245e210cSEnji Cooper# are met: 8*245e210cSEnji Cooper# 1. Redistributions of source code must retain the above copyright 9*245e210cSEnji Cooper# notice, this list of conditions and the following disclaimer. 10*245e210cSEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright 11*245e210cSEnji Cooper# notice, this list of conditions and the following disclaimer in the 12*245e210cSEnji Cooper# documentation and/or other materials provided with the distribution. 13*245e210cSEnji Cooper# 14*245e210cSEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*245e210cSEnji Cooper# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*245e210cSEnji Cooper# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*245e210cSEnji Cooper# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*245e210cSEnji Cooper# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*245e210cSEnji Cooper# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*245e210cSEnji Cooper# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*245e210cSEnji Cooper# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*245e210cSEnji Cooper# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*245e210cSEnji Cooper# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*245e210cSEnji Cooper# SUCH DAMAGE. 25*245e210cSEnji Cooper# 26*245e210cSEnji Cooper# $FreeBSD$ 27*245e210cSEnji Cooper 28*245e210cSEnji Cooperatf_test_case RH_flag 29*245e210cSEnji CooperRH_flag_head() 30*245e210cSEnji Cooper{ 31*245e210cSEnji Cooper atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ 32*245e210cSEnji Cooper "affect symlinks specified via the arguments when -H " \ 33*245e210cSEnji Cooper "is specified" 34*245e210cSEnji Cooper} 35*245e210cSEnji CooperRH_flag_body() 36*245e210cSEnji Cooper{ 37*245e210cSEnji Cooper atf_check mkdir -m 0777 -p A/B 38*245e210cSEnji Cooper atf_check ln -s B A/C 39*245e210cSEnji Cooper atf_check chmod -h 0777 A/C 40*245e210cSEnji Cooper atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C 41*245e210cSEnji Cooper atf_check chmod -RH 0700 A 42*245e210cSEnji Cooper atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C 43*245e210cSEnji Cooper atf_check chmod -RH 0600 A/C 44*245e210cSEnji Cooper atf_check -o inline:'40700\n40600\n120700\n' stat -f '%p' A A/B A/C 45*245e210cSEnji Cooper} 46*245e210cSEnji Cooper 47*245e210cSEnji Cooperatf_test_case RL_flag 48*245e210cSEnji CooperRL_flag_head() 49*245e210cSEnji Cooper{ 50*245e210cSEnji Cooper atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ 51*245e210cSEnji Cooper "affect symlinks specified via the arguments when -L " \ 52*245e210cSEnji Cooper "is specified" 53*245e210cSEnji Cooper} 54*245e210cSEnji CooperRL_flag_body() 55*245e210cSEnji Cooper{ 56*245e210cSEnji Cooper atf_check mkdir -m 0777 -p A/B 57*245e210cSEnji Cooper atf_check ln -s B A/C 58*245e210cSEnji Cooper atf_check chmod -h 0777 A/C 59*245e210cSEnji Cooper atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C 60*245e210cSEnji Cooper atf_check chmod -RL 0700 A 61*245e210cSEnji Cooper atf_check -o inline:'40700\n40700\n120777\n' stat -f '%p' A A/B A/C 62*245e210cSEnji Cooper atf_check chmod -RL 0600 A/C 63*245e210cSEnji Cooper atf_check -o inline:'40700\n40600\n120777\n' stat -f '%p' A A/B A/C 64*245e210cSEnji Cooper} 65*245e210cSEnji Cooper 66*245e210cSEnji Cooperatf_test_case RP_flag 67*245e210cSEnji CooperRP_flag_head() 68*245e210cSEnji Cooper{ 69*245e210cSEnji Cooper atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ 70*245e210cSEnji Cooper "affect symlinks specified via the arguments when -P " \ 71*245e210cSEnji Cooper "is specified" 72*245e210cSEnji Cooper} 73*245e210cSEnji CooperRP_flag_body() 74*245e210cSEnji Cooper{ 75*245e210cSEnji Cooper atf_check mkdir -m 0777 -p A/B 76*245e210cSEnji Cooper atf_check ln -s B A/C 77*245e210cSEnji Cooper atf_check chmod -h 0777 A/C 78*245e210cSEnji Cooper atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C 79*245e210cSEnji Cooper atf_check chmod -RP 0700 A 80*245e210cSEnji Cooper atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C 81*245e210cSEnji Cooper atf_check chmod -RP 0600 A/C 82*245e210cSEnji Cooper atf_check -o inline:'40700\n40700\n120600\n' stat -f '%p' A A/B A/C 83*245e210cSEnji Cooper} 84*245e210cSEnji Cooper 85*245e210cSEnji Cooperatf_test_case f_flag cleanup 86*245e210cSEnji Cooperf_flag_head() 87*245e210cSEnji Cooper{ 88*245e210cSEnji Cooper atf_set "descr" "Verify that setting a mode for a file with -f " \ 89*245e210cSEnji Cooper "doesn't emit an error message/exit with a non-zero " \ 90*245e210cSEnji Cooper "code" 91*245e210cSEnji Cooper} 92*245e210cSEnji Cooper 93*245e210cSEnji Cooperf_flag_body() 94*245e210cSEnji Cooper{ 95*245e210cSEnji Cooper atf_check truncate -s 0 foo bar 96*245e210cSEnji Cooper atf_check chmod 0750 foo bar 97*245e210cSEnji Cooper atf_check chflags uchg foo 98*245e210cSEnji Cooper atf_check -e not-empty -s not-exit:0 chmod 0700 foo bar 99*245e210cSEnji Cooper atf_check -o inline:'100750\n100700\n' stat -f '%p' foo bar 100*245e210cSEnji Cooper atf_check -s exit:0 chmod -f 0600 foo bar 101*245e210cSEnji Cooper atf_check -o inline:'100750\n100600\n' stat -f '%p' foo bar 102*245e210cSEnji Cooper} 103*245e210cSEnji Cooper 104*245e210cSEnji Cooperf_flag_cleanup() 105*245e210cSEnji Cooper{ 106*245e210cSEnji Cooper atf_check chflags 0 foo 107*245e210cSEnji Cooper} 108*245e210cSEnji Cooper 109*245e210cSEnji Cooperatf_test_case h_flag 110*245e210cSEnji Cooperh_flag_head() 111*245e210cSEnji Cooper{ 112*245e210cSEnji Cooper atf_set "descr" "Verify that setting a mode for a file with -f " \ 113*245e210cSEnji Cooper "doesn't emit an error message/exit with a non-zero " \ 114*245e210cSEnji Cooper "code" 115*245e210cSEnji Cooper} 116*245e210cSEnji Cooper 117*245e210cSEnji Cooperh_flag_body() 118*245e210cSEnji Cooper{ 119*245e210cSEnji Cooper atf_check truncate -s 0 foo 120*245e210cSEnji Cooper atf_check chmod 0600 foo 121*245e210cSEnji Cooper atf_check -o inline:'100600\n' stat -f '%p' foo 122*245e210cSEnji Cooper umask 0077 123*245e210cSEnji Cooper atf_check ln -s foo bar 124*245e210cSEnji Cooper atf_check -o inline:'100600\n120700\n' stat -f '%p' foo bar 125*245e210cSEnji Cooper atf_check chmod -h 0500 bar 126*245e210cSEnji Cooper atf_check -o inline:'100600\n120500\n' stat -f '%p' foo bar 127*245e210cSEnji Cooper atf_check chmod 0660 bar 128*245e210cSEnji Cooper atf_check -o inline:'100660\n120500\n' stat -f '%p' foo bar 129*245e210cSEnji Cooper} 130*245e210cSEnji Cooper 131*245e210cSEnji Cooperatf_test_case v_flag 132*245e210cSEnji Cooperv_flag_head() 133*245e210cSEnji Cooper{ 134*245e210cSEnji Cooper atf_set "descr" "Verify that setting a mode with -v emits the file when " \ 135*245e210cSEnji Cooper "doesn't emit an error message/exit with a non-zero " \ 136*245e210cSEnji Cooper "code" 137*245e210cSEnji Cooper} 138*245e210cSEnji Cooperv_flag_body() 139*245e210cSEnji Cooper{ 140*245e210cSEnji Cooper atf_check truncate -s 0 foo bar 141*245e210cSEnji Cooper atf_check chmod 0600 foo 142*245e210cSEnji Cooper atf_check chmod 0750 bar 143*245e210cSEnji Cooper atf_check -o 'inline:bar\n' chmod -v 0600 foo bar 144*245e210cSEnji Cooper atf_check chmod -v 0600 foo bar 145*245e210cSEnji Cooper for f in foo bar; do 146*245e210cSEnji Cooper echo "$f: 0100600 [-rw------- ] -> 0100700 [-rwx------ ]"; 147*245e210cSEnji Cooper done > output.txt 148*245e210cSEnji Cooper atf_check -o file:output.txt chmod -vv 0700 foo bar 149*245e210cSEnji Cooper atf_check chmod -vv 0700 foo bar 150*245e210cSEnji Cooper} 151*245e210cSEnji Cooper 152*245e210cSEnji Cooperatf_init_test_cases() 153*245e210cSEnji Cooper{ 154*245e210cSEnji Cooper atf_add_test_case RH_flag 155*245e210cSEnji Cooper atf_add_test_case RL_flag 156*245e210cSEnji Cooper atf_add_test_case RP_flag 157*245e210cSEnji Cooper atf_add_test_case f_flag 158*245e210cSEnji Cooper atf_add_test_case h_flag 159*245e210cSEnji Cooper atf_add_test_case v_flag 160*245e210cSEnji Cooper} 161