PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_002_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 261 lines | 138 code | 39 blank | 84 comment | 31 complexity | 5182005504a85c4e32c85941dcc85114 MD5 | raw file
  1. #!/usr/local/bin/ksh93 -p
  2. #
  3. # CDDL HEADER START
  4. #
  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.
  8. #
  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.
  13. #
  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]
  19. #
  20. # CDDL HEADER END
  21. #
  22. # $FreeBSD$
  23. #
  24. # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)zfs_acl_chmod_rwx_002_pos.ksh 1.5 09/01/13 SMI"
  28. #
  29. . $STF_SUITE/tests/acl/acl_common.kshlib
  30. #################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: zfs_acl_chmod_rwx_002_pos
  35. #
  36. # DESCRIPTION:
  37. # chmod A{+|-|=} read_data|write_data|execute for owner@ group@ or everyone@
  38. # correctly alters mode bits .
  39. #
  40. # STRATEGY:
  41. # 1. Loop root and non-root user.
  42. # 2. Get the random initial map.
  43. # 3. Get the random ACL string.
  44. # 4. Separately chmod +|-|= read_data|write_data|execute
  45. # 5. Check map bits
  46. #
  47. # TESTABILITY: explicit
  48. #
  49. # TEST_AUTOMATION_LEVEL: automated
  50. #
  51. # CODING_STATUS: COMPLETED (2005-10-05)
  52. #
  53. # __stc_assertion_end
  54. #
  55. ################################################################################
  56. verify_runnable "both"
  57. log_assert "chmod A{+|-|=} read_data|write_data|execute for owner@, group@ " \
  58. "or everyone@ correctly alters mode bits."
  59. log_onexit cleanup
  60. set -A bits 0 1 2 3 4 5 6 7
  61. set -A a_flag owner group everyone
  62. set -A a_access read_data write_data execute
  63. set -A a_type allow deny
  64. #
  65. # Get a random item from an array.
  66. #
  67. # $1 the base set
  68. #
  69. function random_select #array_name
  70. {
  71. typeset arr_name=$1
  72. typeset -i ind
  73. eval typeset -i cnt=\${#${arr_name}[@]}
  74. (( ind = $RANDOM % cnt ))
  75. eval print \${${arr_name}[$ind]}
  76. }
  77. #
  78. # Create a random string according to array name, the item number and
  79. # separated tag.
  80. #
  81. # $1 array name where the function get the elements
  82. # $2 the items number which you want to form the random string
  83. # $3 the separated tag
  84. #
  85. function form_random_str #<array_name> <count> <sep>
  86. {
  87. typeset arr_name=$1
  88. typeset -i count=${2:-1}
  89. typeset sep=${3:-""}
  90. typeset str=""
  91. while (( count > 0 )); do
  92. str="${str}$(random_select $arr_name)${sep}"
  93. (( count -= 1 ))
  94. done
  95. print $str
  96. }
  97. #
  98. # According to the original bits, the input ACE access and ACE type, return the
  99. # expect bits after 'chmod A0{+|=}'.
  100. #
  101. # $1 bits which was make up of three bit 'rwx'
  102. # $2 ACE access which is read_data, write_data or execute
  103. # $3 ACE type which is allow or deny
  104. #
  105. function cal_bits #bits acl_access acl_type
  106. {
  107. typeset bits=$1
  108. typeset acl_access=$2
  109. typeset acl_type=$3
  110. set -A bit r w x
  111. typeset tmpbits=""
  112. typeset -i i=0 j
  113. while (( i < 3 )); do
  114. if [[ $acl_access == *"${a_access[i]}"* ]]; then
  115. if [[ $acl_type == "allow" ]]; then
  116. tmpbits="$tmpbits${bit[i]}"
  117. elif [[ $acl_type == "deny" ]]; then
  118. tmpbits="${tmpbits}-"
  119. fi
  120. else
  121. (( j = i + 1 ))
  122. tmpbits="$tmpbits$(get_substr $bits $j 1)"
  123. fi
  124. (( i += 1 ))
  125. done
  126. print "$tmpbits"
  127. }
  128. #
  129. # Based on the initial node map before chmod and the ace-spec, check if chmod
  130. # has the correct behaven to map bits.
  131. #
  132. function check_test_result #init_mode node acl_flag acl_access a_type
  133. {
  134. typeset init_mode=$1
  135. typeset node=$2
  136. typeset acl_flag=$3
  137. typeset acl_access=$4
  138. typeset acl_type=$5
  139. typeset -3L u_bits=$init_mode
  140. typeset g_bits=$(get_substr $init_mode 4 3)
  141. typeset -3R o_bits=$init_mode
  142. if [[ $acl_flag == "owner" || $acl_flag == "everyone" ]]; then
  143. u_bits=$(cal_bits $u_bits $acl_access $acl_type)
  144. fi
  145. if [[ $acl_flag == "group" || $acl_flag == "everyone" ]]; then
  146. g_bits=$(cal_bits $g_bits $acl_access $acl_type)
  147. fi
  148. if [[ $acl_flag == "everyone" ]]; then
  149. o_bits=$(cal_bits $o_bits $acl_access $acl_type)
  150. fi
  151. typeset cur_mode=$(get_mode $node)
  152. cur_mode=$(get_substr $cur_mode 2 9)
  153. if [[ $cur_mode == $u_bits$g_bits$o_bits ]]; then
  154. log_note "SUCCESS: Current map($cur_mode) ==" \
  155. "expected map($u_bits$g_bits$o_bits)"
  156. else
  157. log_fail "FAIL: Current map($cur_mode) != " \
  158. "expected map($u_bits$g_bits$o_bits)"
  159. fi
  160. }
  161. function test_chmod_map #<node>
  162. {
  163. typeset node=$1
  164. typeset init_mask acl_flag acl_access acl_type
  165. typeset -i cnt
  166. if (( ${#node} == 0 )); then
  167. log_fail "FAIL: file name or directroy name is not defined."
  168. fi
  169. # Get the initial map
  170. init_mask=$(form_random_str bits 3)
  171. # Get ACL flag, access & type
  172. acl_flag=$(form_random_str a_flag)
  173. (( cnt = ($RANDOM % ${#a_access[@]}) + 1 ))
  174. acl_access=$(form_random_str a_access $cnt '/')
  175. acl_access=${acl_access%/}
  176. acl_type=$(form_random_str a_type)
  177. typeset acl_spec=${acl_flag}@:${acl_access}:${acl_type}
  178. # Set the initial map and back the initial ACEs
  179. typeset orig_ace=$TMPDIR/orig_ace.${TESTCASE_ID}
  180. typeset cur_ace=$TMPDIR/cur_ace.${TESTCASE_ID}
  181. for operator in "A0+" "A0="; do
  182. log_must usr_exec $CHMOD $init_mask $node
  183. init_mode=$(get_mode $node)
  184. init_mode=$(get_substr $init_mode 2 9)
  185. log_must usr_exec eval "$LS -vd $node > $orig_ace"
  186. # To "A=", firstly add one ACE which can't modify map
  187. if [[ $operator == "A0=" ]]; then
  188. log_must $CHMOD A0+user:$ZFS_ACL_OTHER1:execute:deny \
  189. $node
  190. fi
  191. log_must usr_exec $CHMOD $operator$acl_spec $node
  192. check_test_result \
  193. $init_mode $node $acl_flag $acl_access $acl_type
  194. # Check "chmod A-"
  195. log_must usr_exec $CHMOD A0- $node
  196. log_must usr_exec eval "$LS -vd $node > $cur_ace"
  197. if $DIFF $orig_ace $cur_ace; then
  198. log_note "SUCCESS: original ACEs equivalence the " \
  199. "current ACEs. 'chmod A-' succeeded."
  200. else
  201. log_fail "FAIL: 'chmod A-' failed."
  202. fi
  203. done
  204. [[ -f $orig_ace ]] && log_must usr_exec $RM -f $orig_ace
  205. [[ -f $cur_ace ]] && log_must usr_exec $RM -f $cur_ace
  206. }
  207. test_requires ZFS_ACL
  208. for user in root $ZFS_ACL_STAFF1; do
  209. set_cur_usr $user
  210. typeset -i loop_cnt=20
  211. while (( loop_cnt > 0 )); do
  212. log_must usr_exec $TOUCH $testfile
  213. test_chmod_map $testfile
  214. log_must $RM -f $testfile
  215. log_must usr_exec $MKDIR $testdir
  216. test_chmod_map $testdir
  217. log_must $RM -rf $testdir
  218. (( loop_cnt -= 1 ))
  219. done
  220. done
  221. log_pass "chmod A{+|-|=} read_data|write_data|execute for owner@, group@ " \
  222. "oreveryone@ correctly alters mode bits passed."