7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / acl / trivial / zfs_acl_chmod_001_pos.ksh
blobc1eb631b4ece64e854bbff200ca3a56e7980ccaa
1 #!/bin/ksh -p
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/acl/acl_common.kshlib
35 # DESCRIPTION:
36 # Verify chmod permission settings on files and directories, as both root
37 # and non-root users.
39 # STRATEGY:
40 # 1. Loop root and $ZFS_ACL_STAFF1 as root and non-root users.
41 # 2. Create test file and directory in zfs filesystem.
42 # 3. Execute 'chmod' with specified options.
43 # 4. Check 'ls -l' output and compare with expect results.
45 # NOTE:
46 # The test does not work for default "discard" aclmode property.
47 # The test is modified to run with "passthrough" aclmode property.
49 verify_runnable "both"
51 function cleanup
53 # reset aclmode=discard
54 log_must zfs set aclmode=discard $TESTPOOL/$TESTFS
57 # "init_map" "options" "expect_map"
58 set -A argv \
59 "000" "a+rw" "rw-rw-rw-" "000" "a+rwx" "rwxrwxrwx" \
60 "000" "u+xr" "r-x------" "000" "gu-xw" "---------" \
61 "644" "a-r" "-w-------" "644" "augo-x" "rw-r--r--" \
62 "644" "=x" "--x--x--x" "644" "u-rw" "---r--r--" \
63 "644" "uo+x" "rwxr--r-x" "644" "ga-wr" "---------" \
64 "777" "augo+x" "rwxrwxrwx" "777" "go-xr" "rwx-w--w-" \
65 "777" "o-wx" "rwxrwxr--" "777" "ou-rx" "-w-rwx-w-" \
66 "777" "a+rwx" "rwxrwxrwx" "777" "u=rw" "rw-rwxrwx" \
67 "000" "123" "--x-w--wx" "000" "412" "r----x-w-" \
68 "231" "562" "r-xrw--w-" "712" "000" "---------" \
69 "777" "121" "--x-w---x" "123" "775" "rwxrwxr-x"
71 log_assert " Verify chmod permission settings on files and directories"
72 log_onexit cleanup
75 # Verify file or directory have correct map after chmod
77 # $1 file or directory
79 function test_chmod_mapping #<file-dir>
81 typeset node=$1
82 typeset -i i=0
84 while ((i < ${#argv[@]})); do
85 usr_exec chmod ${argv[i]} $node
86 if (($? != 0)); then
87 log_note "usr_exec chmod ${argv[i]} $node"
88 return 1
90 usr_exec chmod ${argv[((i + 1))]} $node
91 if (($? != 0)); then
92 log_note "usr_exec chmod ${argv[((i + 1))]} $node"
93 return 1
96 typeset mode
97 mode=$(get_mode ${node})
99 if [[ $mode != "-${argv[((i + 2))]}"* && \
100 $mode != "d${argv[((i + 2))]}"* ]]
101 then
102 log_fail "FAIL: '${argv[i]}' '${argv[((i + 1))]}' \
103 '${argv[((i + 2))]}'"
106 ((i += 3))
107 done
109 return 0
112 # set aclmode=passthrough
113 log_must zfs set aclmode=passthrough $TESTPOOL/$TESTFS
115 for user in root $ZFS_ACL_STAFF1; do
116 log_must set_cur_usr $user
118 # Test file
119 log_must usr_exec touch $testfile
120 log_must test_chmod_mapping $testfile
121 log_must usr_exec chmod A+user:$ZFS_ACL_STAFF2:write_acl:allow $testfile
123 # Test directory
124 log_must usr_exec mkdir $testdir
125 log_must test_chmod_mapping $testdir
126 log_must usr_exec chmod A+user:$ZFS_ACL_STAFF2:write_acl:allow $testdir
128 # Grant privileges of write_acl and retest the chmod commands.
130 log_must set_cur_usr $ZFS_ACL_STAFF2
131 log_must test_chmod_mapping $testfile
132 log_must test_chmod_mapping $testdir
134 log_must set_cur_usr $user
136 log_must usr_exec rm $testfile
137 log_must usr_exec rm -rf $testdir
138 done
140 log_pass "Setting permissions using 'chmod' completed successfully."