PageRenderTime 117ms CodeModel.GetById 30ms RepoModel.GetById 6ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 415 lines | 197 code | 70 blank | 148 comment | 47 complexity | 90575f7ed4db3bfbc75b6f43fffcf490 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 2008 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)zfs_acl_chmod_inherit_002_pos.ksh 1.3 08/02/27 SMI"
  28. #
  29. . $STF_SUITE/tests/acl/acl_common.kshlib
  30. . $STF_SUITE/tests/acl/cifs/cifs.kshlib
  31. #################################################################################
  32. #
  33. # __stc_assertion_start
  34. #
  35. # ID: zfs_acl_chmod_inherit_002_pos
  36. #
  37. # DESCRIPTION:
  38. # Verify chmod have correct behaviour to directory and file when
  39. # filesystem has the different aclinherit setting
  40. #
  41. # STRATEGY:
  42. # 1. Loop super user and non-super user to run the test case.
  43. # 2. Create basedir and a set of subdirectores and files within it.
  44. # 3. Separately chmod basedir with different inherite options,
  45. # combine with the variable setting of aclinherit:
  46. # "discard", "noallow", "secure" or "passthrough".
  47. # 4. Then create nested directories and files like the following.
  48. #
  49. # ofile
  50. # odir
  51. # chmod --> basedir -|
  52. # |_ nfile1
  53. # |_ ndir1 _
  54. # |_ nfile2
  55. # |_ ndir2 _
  56. # |_ nfile3
  57. # |_ ndir3
  58. #
  59. # 5. Verify each directories and files have the correct access control
  60. # capability.
  61. #
  62. # TESTABILITY: explicit
  63. #
  64. # TEST_AUTOMATION_LEVEL: automated
  65. #
  66. # CODING_STATUS: COMPLETED (2006-03-02)
  67. #
  68. # __stc_assertion_end
  69. #
  70. ################################################################################
  71. verify_runnable "both"
  72. function cleanup
  73. {
  74. typeset dir
  75. # Cleanup basedir, compared file and dir.
  76. if [[ -f $ofile ]]; then
  77. log_must $RM -f $ofile
  78. fi
  79. for dir in $odir $basedir ; do
  80. if [[ -d $dir ]]; then
  81. log_must $RM -rf $dir
  82. fi
  83. done
  84. }
  85. log_assert "Verify chmod have correct behaviour to directory and file when " \
  86. "filesystem has the different aclinherit setting."
  87. log_onexit cleanup
  88. # Define inherit flag
  89. set -A aclinherit_flag discard noallow secure passthrough
  90. set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit
  91. set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate
  92. typeset ace_prefix1="user:$ZFS_ACL_OTHER1"
  93. typeset ace_prefix2="user:$ZFS_ACL_OTHER2"
  94. typeset ace_discard ace_noallow ace_secure ace_passthrough
  95. typeset ace_secure_new
  96. # Defile the based directory and file
  97. basedir=$TESTDIR/basedir; ofile=$TESTDIR/ofile; odir=$TESTDIR/odir
  98. test_requires ZFS_ACL
  99. # Define the files and directories will be created after chmod
  100. ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
  101. nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
  102. # Verify all the node have expected correct access control
  103. allnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
  104. typeset cifs=""
  105. if cifs_supported ; then
  106. cifs="true"
  107. fi
  108. #
  109. # According to inherited flag, verify subdirectories and files within it has
  110. # correct inherited access control.
  111. #
  112. function verify_inherit #<aclinherit> <object> [strategy]
  113. {
  114. # Define the nodes which will be affected by inherit.
  115. typeset inherit_nodes
  116. typeset inherit=$1
  117. typeset obj=$2
  118. typeset str=$3
  119. # count: the ACE item to fetch
  120. # pass: to mark if the current ACE should apply to the target
  121. # maxnumber: predefine as 4
  122. # passcnt: counter, if it achieves to maxnumber,
  123. # then no additional ACE should apply.
  124. # isinherit: indicate if the current target is in the inherit list.
  125. # step: indicate if the ACE be split during inherit.
  126. typeset -i count=0 pass=0 passcnt=0 isinherit=0 maxnumber=4 step=0
  127. log_must usr_exec $MKDIR -p $ndir3
  128. log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
  129. # Get the files which inherited ACE.
  130. if [[ $obj == *"file_inherit"* ]]; then
  131. inherit_nodes="$inherit_nodes $nfile1"
  132. if [[ $str != *"no_propagate"* ]]; then
  133. inherit_nodes="$inherit_nodes $nfile2 $nfile3"
  134. fi
  135. fi
  136. # Get the directores which inherited ACE.
  137. if [[ $obj == *"dir_inherit"* ]]; then
  138. inherit_nodes="$inherit_nodes $ndir1"
  139. if [[ $str != *"no_propagate"* ]]; then
  140. inherit_nodes="$inherit_nodes $ndir2 $ndir3"
  141. fi
  142. fi
  143. for node in $allnodes; do
  144. step=0
  145. if [[ " $inherit_nodes " == *" $node "* ]]; then
  146. isinherit=1
  147. if [[ -d $node ]] ; then
  148. step=1
  149. fi
  150. else
  151. isinherit=0
  152. fi
  153. i=0
  154. count=0
  155. passcnt=0
  156. while (( i < maxnumber )); do
  157. pass=0
  158. eval expect1=\$acl$i
  159. expect2=$expect1
  160. #
  161. # aclinherit=passthrough,
  162. # inherit all inheritable ACL entries without any
  163. # modifications made to the ACL entries when they
  164. # are inherited.
  165. #
  166. # aclinherit=secure,
  167. # any inheritable ACL entries will remove
  168. # write_acl and write_owner permissions when the ACL entry is
  169. # inherited.
  170. #
  171. # aclinherit=noallow,
  172. # only inherit inheritable ACE that specify "deny" permissions
  173. #
  174. # aclinherit=discard
  175. # will not inherit any ACL entries
  176. #
  177. case $inherit in
  178. passthrough)
  179. ;;
  180. secure)
  181. if [[ $expect1 == *":allow" ]] ; then
  182. eval expect2=\$acls$i
  183. fi
  184. ;;
  185. noallow)
  186. if [[ $expect1 == *":allow" ]] ; then
  187. pass=1
  188. (( passcnt = passcnt + 1 ))
  189. fi
  190. ;;
  191. discard)
  192. passcnt=maxnumber
  193. break
  194. ;;
  195. esac
  196. if (( pass == 0 )) ; then
  197. acltemp=${expect2%:*}
  198. acltemp=${acltemp%:*}
  199. aclaction=${expect2##*:}
  200. if [[ -n $cifs ]]; then
  201. expect2=${acltemp}:inherited:${aclaction}
  202. else
  203. expect2=${acltemp}:${aclaction}
  204. fi
  205. acltemp=${expect1%:*}
  206. if [[ -d $node ]]; then
  207. if [[ $expect1 == *"no_propagate"* ]] ; then
  208. #
  209. # if no_propagate is set,
  210. # then clear all inherit flags,
  211. # only one ACE should left.
  212. #
  213. step=0
  214. expect1=""
  215. elif [[ $expect1 != *"inherit_only"* ]]; then
  216. #
  217. # directory should append
  218. # "inherit_only" if not have
  219. #
  220. if [[ -n $cifs ]]; then
  221. expect1=${acltemp}/inherit_only/inherited:${aclaction}
  222. else
  223. expect1=${acltemp}/inherit_only:${aclaction}
  224. fi
  225. elif [[ -n $cifs ]]; then
  226. expect1=${acltemp}/inherited:${aclaction}
  227. fi
  228. #
  229. # cleanup the first ACE if the directory
  230. # not in inherit list
  231. #
  232. if (( isinherit == 0 )); then
  233. expect1=""
  234. fi
  235. elif [[ -f $node ]] ; then
  236. expect1=""
  237. fi
  238. # Get the first ACE to do comparison
  239. aclcur=$(get_ACE $node $count)
  240. aclcur=${aclcur#$count:}
  241. if [[ -n $expect1 && $expect1 != $aclcur ]]; then
  242. $LS -vd $basedir
  243. $LS -vd $node
  244. log_fail "$inherit $i #$count " \
  245. "ACE: $aclcur, expect to be " \
  246. "$expect1"
  247. fi
  248. # Get the second ACE (if should have) to do comparison
  249. if (( step > 0 )); then
  250. (( count = count + step ))
  251. aclcur=$(get_ACE $node $count)
  252. aclcur=${aclcur#$count:}
  253. if [[ -n $expect2 && \
  254. $expect2 != $aclcur ]]; then
  255. $LS -vd $basedir
  256. $LS -vd $node
  257. log_fail "$inherit $i #$count " \
  258. "ACE: $aclcur, expect to be " \
  259. "$expect2"
  260. fi
  261. fi
  262. (( count = count + 1 ))
  263. fi
  264. (( i = i + 1 ))
  265. done
  266. #
  267. # If there's no any ACE be checked, it should be identify as
  268. # an normal file/dir, verify it.
  269. #
  270. if (( passcnt == maxnumber )); then
  271. if [[ -d $node ]]; then
  272. compare_acls $node $odir
  273. elif [[ -f $node ]]; then
  274. compare_acls $node $ofile
  275. fi
  276. if [[ $? -ne 0 ]]; then
  277. $LS -vd $basedir
  278. $LS -vd $node
  279. log_fail "Unexpect acl: $node, $inherit ($str)"
  280. fi
  281. fi
  282. done
  283. }
  284. typeset -i i=0
  285. typeset acl0 acl1 acl2 acl3
  286. typeset acls0 acls1 acls2 acls3
  287. #
  288. # Set aclmode=passthrough to make sure
  289. # the acl will not change during chmod.
  290. # A general testing should verify the combination of
  291. # aclmode/aclinherit works well,
  292. # here we just simple test them separately.
  293. #
  294. log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
  295. for inherit in "${aclinherit_flag[@]}"; do
  296. #
  297. # Set different value of aclinherit
  298. #
  299. log_must $ZFS set aclinherit=$inherit $TESTPOOL/$TESTFS
  300. for user in root $ZFS_ACL_STAFF1; do
  301. log_must set_cur_usr $user
  302. for obj in "${object_flag[@]}"; do
  303. for str in "${strategy_flag[@]}"; do
  304. typeset inh_opt=$obj
  305. (( ${#str} != 0 )) && inh_opt=$inh_opt/$str
  306. #
  307. # Prepare 4 ACES, which should include :
  308. # deny -> to verify "noallow"
  309. # write_acl/write_owner -> to verify "secure"
  310. #
  311. acl0="$ace_prefix1:read_xattr/write_acl/write_owner:$inh_opt:deny"
  312. acl1="$ace_prefix2:read_xattr/write_acl/write_owner:$inh_opt:allow"
  313. acl2="$ace_prefix1:read_xattr:$inh_opt:deny"
  314. acl3="$ace_prefix2:read_xattr:$inh_opt:allow"
  315. #
  316. # The ACE filtered by write_acl/write_owner
  317. #
  318. acls0="$ace_prefix1:read_xattr:$inh_opt:deny"
  319. acls1="$ace_prefix2:read_xattr:$inh_opt:allow"
  320. acls2=$acl2
  321. acls3=$acl3
  322. #
  323. # Create basedir and tmp dir/file
  324. # for comparison.
  325. #
  326. log_note "$user: $CHMOD $acl $basedir"
  327. log_must usr_exec $MKDIR $basedir
  328. log_must usr_exec $MKDIR $odir
  329. log_must usr_exec $TOUCH $ofile
  330. i=3
  331. while (( i >= 0 )); do
  332. eval acl=\$acl$i
  333. #
  334. # Place on a directory should succeed.
  335. #
  336. log_must usr_exec $CHMOD A+$acl $basedir
  337. (( i = i - 1 ))
  338. done
  339. verify_inherit $inherit $obj $str
  340. log_must usr_exec $RM -rf $ofile $odir $basedir
  341. done
  342. done
  343. done
  344. done
  345. log_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed."