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

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 321 lines | 194 code | 48 blank | 79 comment | 43 complexity | 017796a7b7a04f7b33fd01250b50df97 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_delete_001_pos.ksh 1.6 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_delete_001_pos
  35. #
  36. # DESCRIPTION:
  37. # Verify that the combined delete_child/delete permission for
  38. # owner/group/everyone are correct.
  39. #
  40. # -------------------------------------------------------
  41. # | Parent Dir | Target Object Permissions |
  42. # | permissions | |
  43. # -------------------------------------------------------
  44. # | | ACL Allows | ACL Denies| Delete |
  45. # | | Delete | Delete | unspecified|
  46. # -------------------------------------------------------
  47. # | ACL Allows | Permit | Permit | Permit |
  48. # | DELETE_CHILD | |
  49. # -------------------------------------------------------
  50. # | ACL Denies | Permit | Deny | Deny |
  51. # | DELETE_CHILD | | | |
  52. # -------------------------------------------------------
  53. # | ACL specifies | | | |
  54. # | only allows | Permit | Permit | Permit |
  55. # | write and | | | |
  56. # | execute | | | |
  57. # -------------------------------------------------------
  58. # | ACL denies | | | |
  59. # | write and | Permit | Deny | Deny |
  60. # | execute | | | |
  61. # -------------------------------------------------------
  62. #
  63. # STRATEGY:
  64. # 1. Create file and directory in zfs filesystem
  65. # 2. Set special ACE combination to the file and directory
  66. # 3. Try to remove the file
  67. # 4. Verify that combined permissions for owner/group/everyone are correct.
  68. #
  69. # TESTABILITY: explicit
  70. #
  71. # TEST_AUTOMATION_LEVEL: automated
  72. #
  73. # CODING_STATUS: COMPLETED (2005-10-24)
  74. #
  75. # __stc_assertion_end
  76. #
  77. ################################################################################
  78. verify_runnable "both"
  79. function cleanup
  80. {
  81. [[ ! -e $TESTDIR/$ARCHIVEFILE ]] && return 0
  82. if [[ ! -e $target ]]; then
  83. log_must $TAR xpf $TESTDIR/$ARCHIVEFILE
  84. fi
  85. (( ${#cwd} != 0 )) && cd $cwd
  86. cleanup_test_files $TESTDIR/basedir
  87. log_must $RM -f $TESTDIR/$ARCHIVEFILE
  88. return 0
  89. }
  90. #owner@ group group_users other_users
  91. set -A users \
  92. "root" "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \
  93. "$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1"
  94. set -A access_parent \
  95. "delete_child:allow" \
  96. "delete_child:deny" \
  97. "write_data:allow" \
  98. "write_data:deny" \
  99. "delete_child:deny write_data:allow" \
  100. "delete_child:allow write_data:deny"
  101. set -A access_target \
  102. "delete:allow" \
  103. "delete:deny" \
  104. ""
  105. set -A a_flag "owner@" "group@" "everyone@" "user:$ZFS_ACL_STAFF1"
  106. log_assert "Verify that the combined delete_child/delete permission for" \
  107. "owner/group/everyone are correct."
  108. log_onexit cleanup
  109. function operate_node #user node
  110. {
  111. typeset user=$1
  112. typeset node=$2
  113. typeset ret
  114. if [[ $user == "" || $node == "" ]]; then
  115. log_fail "user, node are not defined."
  116. fi
  117. if [[ -d $node ]]; then
  118. chgusr_exec $user $RM -rf $node ; ret=$?
  119. else
  120. chgusr_exec $user $RM -f $node ; ret=$?
  121. fi
  122. if [[ -e $node ]]; then
  123. if [[ $ret -eq 0 ]]; then
  124. log_note "$node not removed, but return code is 0."
  125. return 1
  126. fi
  127. else
  128. log_must $TAR xpf $TESTDIR/$ARCHIVEFILE
  129. if [[ $ret -ne 0 ]]; then
  130. log_note "$node removed, but return code is $ret."
  131. return 1
  132. fi
  133. fi
  134. return $ret
  135. }
  136. function logname #acl_parent acl_target user
  137. {
  138. typeset acl_parent=$1
  139. typeset acl_target=$2
  140. typeset user=$3
  141. # To super user, read and write deny permission was override.
  142. if [[ $user == root || $acl_target == *:allow ]]; then
  143. print "log_must"
  144. elif [[ $acl_parent == *"delete_child"* ]]; then
  145. if [[ $acl_parent == *"delete_child:allow"* ]]; then
  146. print "log_must"
  147. else
  148. print "log_mustnot"
  149. fi
  150. elif [[ $acl_parent == *"write_data"* ]]; then
  151. if [[ $acl_parent == *"write_data:allow"* ]]; then
  152. print "log_must"
  153. else
  154. print "log_mustnot"
  155. fi
  156. else
  157. print "log_mustnot"
  158. fi
  159. }
  160. function check_chmod_results #node flag acl_parent acl_target g_usr o_usr
  161. {
  162. typeset node=$1
  163. typeset flag=$2
  164. typeset acl_parent=$3
  165. typeset acl_target=$2:$4
  166. typeset g_usr=$5
  167. typeset o_usr=$6
  168. typeset log acl_tmp
  169. for acl in $acl_parent ; do
  170. acl_tmp="$2:$acl $acl_tmp"
  171. done
  172. acl_parent=$acl_tmp
  173. if [[ $flag == "owner@" || $flag == "everyone@" ]]; then
  174. log=$(logname "$acl_parent" $acl_target $ZFS_ACL_CUR_USER)
  175. $log operate_node $ZFS_ACL_CUR_USER $node
  176. fi
  177. if [[ $flag == "group@" || $flag == "everyone@" ]]; then
  178. log=$(logname "$acl_parent" $acl_target $g_usr)
  179. $log operate_node $g_usr $node
  180. fi
  181. if [[ $flag == "everyone@" ]]; then
  182. log=$(logname "$acl_parent" $acl_target $o_usr)
  183. $log operate_node $o_usr $node
  184. fi
  185. if [[ $flag == "user:"* ]]; then
  186. typeset user=${flag#user:}
  187. log=$(logname "$acl_parent" $acl_target $user)
  188. $log operate_node $user $node
  189. fi
  190. }
  191. function test_chmod_basic_access #node g_usr o_usr
  192. {
  193. typeset node=${1%/}
  194. typeset g_usr=$2
  195. typeset o_usr=$3
  196. typeset flag acl_p acl_t parent
  197. typeset -i i=0
  198. parent=${node%/*}
  199. for flag in ${a_flag[@]}; do
  200. for acl_p in "${access_parent[@]}"; do
  201. i=0
  202. for acl in $acl_p ; do
  203. log_must usr_exec $CHMOD A+$flag:$acl $parent
  204. (( i = i + 1))
  205. done
  206. for acl_t in "${access_target[@]}"; do
  207. [[ -n $acl_t ]] && \
  208. log_must usr_exec $CHMOD A+$flag:$acl_t $node
  209. log_must $TAR cpf $TESTDIR/$ARCHIVEFILE basedir
  210. check_chmod_results "$node" "$flag" \
  211. "$acl_p" "$acl_t" "$g_usr" "$o_usr"
  212. [[ -n $acl_t ]] && \
  213. log_must usr_exec $CHMOD A0- $node
  214. done
  215. while (( i > 0 )); do
  216. log_must usr_exec $CHMOD A0- $parent
  217. (( i = i - 1 ))
  218. done
  219. done
  220. done
  221. }
  222. function setup_test_files #base_node user group
  223. {
  224. typeset base_node=$1
  225. typeset user=$2
  226. typeset group=$3
  227. cleanup_test_files $base_node
  228. log_must $MKDIR -p $base_node
  229. log_must $CHOWN $user:$group $base_node
  230. log_must set_cur_usr $user
  231. # Prepare all files/sub-dirs for testing.
  232. file0=$base_node/testfile_rm
  233. dir0=$base_node/testdir_rm
  234. log_must usr_exec $TOUCH $file0
  235. log_must usr_exec $CHMOD 444 $file0
  236. log_must usr_exec $MKDIR -p $dir0
  237. log_must usr_exec $CHMOD 444 $dir0
  238. log_must usr_exec $CHMOD 555 $base_node
  239. return 0
  240. }
  241. function cleanup_test_files #base_node
  242. {
  243. typeset base_node=$1
  244. if [[ -d $base_node ]]; then
  245. log_must $RM -rf $base_node
  246. elif [[ -e $base_node ]]; then
  247. log_must $RM -f $base_node
  248. fi
  249. return 0
  250. }
  251. typeset cwd=$PWD
  252. typeset ARCHIVEFILE=archive.tar
  253. test_requires ZFS_ACL
  254. typeset -i i=0
  255. typeset -i j=0
  256. typeset target
  257. cd $TESTDIR
  258. while (( i < ${#users[@]} )); do
  259. setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]}
  260. j=0
  261. while (( j < 1 )); do
  262. eval target=\$file$j
  263. test_chmod_basic_access $target \
  264. "${users[((i+2))]}" "${users[((i+3))]}"
  265. eval target=\$dir$j
  266. test_chmod_basic_access $target \
  267. "${users[((i+2))]}" "${users[((i+3))]}"
  268. (( j = j + 1 ))
  269. done
  270. (( i += 4 ))
  271. done
  272. log_pass "Verify that the combined delete_child/delete permission for" \
  273. "owner/group/everyone are correct."