PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 262 lines | 151 code | 48 blank | 63 comment | 24 complexity | 5a8612a1bfe1b84222c9c04c0c468ca0 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_rwacl_001_pos.ksh 1.5 09/05/19 SMI"
  28. #
  29. . $STF_SUITE/tests/acl/acl_common.kshlib
  30. #################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: zfs_acl_chmod_rwacl_001_pos
  35. #
  36. # DESCRIPTION:
  37. # Verify assigned read_acl/write_acl to owner@/group@/everyone@,
  38. # specificied user and group. File have the correct access permission.
  39. #
  40. # STRATEGY:
  41. # 1. Separatedly verify file and directory was assigned read_acl/write_acl
  42. # by root and non-root user.
  43. # 2. Verify owner always can read and write acl, even deny.
  44. # 3. Verify group access permission, when group was assigned
  45. # read_acl/write_acl.
  46. # 4. Verify access permission, after everyone was assigned read_acl/write.
  47. # 5. Verify everyone@ was deny except specificied user, this user can read
  48. # and write acl.
  49. # 6. Verify the group was deny except specified user, this user can read
  50. # and write acl
  51. #
  52. # TESTABILITY: explicit
  53. #
  54. # TEST_AUTOMATION_LEVEL: automated
  55. #
  56. # CODING_STATUS: COMPLETED (2005-10-19)
  57. #
  58. # __stc_assertion_end
  59. #
  60. ################################################################################
  61. verify_runnable "both"
  62. log_assert "Verify chmod A[number]{+|-|=} read_acl/write_acl have correct " \
  63. "behaviour to access permission."
  64. log_onexit cleanup
  65. function read_ACL #<node> <user1> <user2> ...
  66. {
  67. typeset node=$1
  68. typeset user
  69. typeset -i ret
  70. shift
  71. for user in $@; do
  72. chgusr_exec $user $LS -vd $node > /dev/null 2>&1
  73. ret=$?
  74. (( ret != 0 )) && return $ret
  75. shift
  76. done
  77. return 0
  78. }
  79. function write_ACL #<node> <user1> <user2> ...
  80. {
  81. typeset node=$1
  82. typeset user
  83. typeset -i ret before_cnt after_cnt
  84. shift
  85. for user in "$@"; do
  86. before_cnt=$(count_ACE $node)
  87. ret=$?;
  88. (( ret != 0 )) && return $ret
  89. chgusr_exec $user $CHMOD A0+owner@:read_data:allow $node
  90. ret=$?
  91. (( ret != 0 )) && return $ret
  92. after_cnt=$(count_ACE $node)
  93. ret=$?
  94. (( ret != 0 )) && return $ret
  95. chgusr_exec $user $CHMOD A0- $node
  96. ret=$?
  97. (( ret != 0 )) && return $ret
  98. if (( after_cnt - before_cnt != 1 )); then
  99. return 1
  100. fi
  101. shift
  102. done
  103. return 0
  104. }
  105. function check_owner #<node>
  106. {
  107. typeset node=$1
  108. for acc in allow deny; do
  109. log_must usr_exec \
  110. $CHMOD A0+owner@:read_acl/write_acl:$acc $node
  111. log_must read_ACL $node $ZFS_ACL_CUR_USER
  112. log_must write_ACL $node $ZFS_ACL_CUR_USER
  113. log_must usr_exec $CHMOD A0- $node
  114. done
  115. }
  116. function check_group #<node>
  117. {
  118. typeset node=$1
  119. typeset grp_usr=""
  120. if [[ $ZFS_ACL_CUR_USER == root ]]; then
  121. grp_usr=$ZFS_ACL_ADMIN
  122. elif [[ $ZFS_ACL_CUR_USER == $ZFS_ACL_STAFF1 ]]; then
  123. grp_usr=$ZFS_ACL_STAFF2
  124. fi
  125. log_must usr_exec $CHMOD A0+group@:read_acl/write_acl:allow $node
  126. log_must read_ACL $node $grp_usr
  127. log_must write_ACL $node $grp_usr
  128. log_must usr_exec $CHMOD A0- $node
  129. log_must usr_exec $CHMOD A0+group@:read_acl/write_acl:deny $node
  130. log_mustnot read_ACL $node $grp_usr
  131. log_mustnot write_ACL $node $grp_usr
  132. log_must usr_exec $CHMOD A0- $node
  133. }
  134. function check_everyone #<node>
  135. {
  136. typeset node=$1
  137. typeset flag
  138. for flag in allow deny; do
  139. if [[ $flag == allow ]]; then
  140. log=log_must
  141. else
  142. log=log_mustnot
  143. fi
  144. log_must usr_exec \
  145. $CHMOD A0+everyone@:read_acl/write_acl:$flag $node
  146. $log read_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
  147. $log write_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
  148. log_must usr_exec $CHMOD A0- $node
  149. done
  150. }
  151. function check_spec_user #<node>
  152. {
  153. typeset node=$1
  154. log_must usr_exec $CHMOD A0+everyone@:read_acl/write_acl:deny $node
  155. log_must usr_exec \
  156. $CHMOD A0+user:$ZFS_ACL_OTHER1:read_acl/write_acl:allow $node
  157. # The specified user can read and write acl
  158. log_must read_ACL $node $ZFS_ACL_OTHER1
  159. log_must write_ACL $node $ZFS_ACL_OTHER1
  160. # All the other user can't read and write acl
  161. log_mustnot \
  162. read_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER2
  163. log_mustnot \
  164. write_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER2
  165. log_must usr_exec $CHMOD A0- $node
  166. log_must usr_exec $CHMOD A0- $node
  167. }
  168. function check_spec_group #<node>
  169. {
  170. typeset node=$1
  171. log_must usr_exec $CHMOD A0+everyone@:read_acl/write_acl:deny $node
  172. log_must usr_exec $CHMOD \
  173. A0+group:$ZFS_ACL_OTHER_GROUP:read_acl/write_acl:allow $node
  174. # The specified group can read and write acl
  175. log_must read_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
  176. log_must write_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
  177. # All the other user can't read and write acl
  178. log_mustnot read_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2
  179. log_mustnot write_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2
  180. }
  181. function check_user_in_group #<node>
  182. {
  183. typeset node=$1
  184. log_must usr_exec $CHMOD \
  185. A0+group:$ZFS_ACL_OTHER_GROUP:read_acl/write_acl:deny $node
  186. log_must usr_exec $CHMOD \
  187. A0+user:$ZFS_ACL_OTHER1:read_acl/write_acl:allow $node
  188. log_must read_ACL $node $ZFS_ACL_OTHER1
  189. log_must write_ACL $node $ZFS_ACL_OTHER1
  190. log_mustnot read_ACL $node $ZFS_ACL_OTHER2
  191. log_mustnot write_ACL $node $ZFS_ACL_OTHER2
  192. log_must usr_exec $CHMOD A0- $node
  193. log_must usr_exec $CHMOD A0- $node
  194. }
  195. set -A func_name check_owner \
  196. check_group \
  197. check_everyone \
  198. check_spec_user \
  199. check_spec_group \
  200. check_user_in_group
  201. test_requires ZFS_ACL
  202. for user in root $ZFS_ACL_STAFF1; do
  203. log_must set_cur_usr $user
  204. log_must usr_exec $TOUCH $testfile
  205. log_must usr_exec $MKDIR $testdir
  206. typeset func node
  207. for func in ${func_name[@]}; do
  208. for node in $testfile $testdir; do
  209. eval $func \$node
  210. done
  211. done
  212. log_must usr_exec $RM -rf $testfile $testdir
  213. done
  214. log_pass "Verify chmod A[number]{+|-|=} read_acl/write_acl passed."