PageRenderTime 45ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 193 lines | 75 code | 27 blank | 91 comment | 18 complexity | fe40f7c6fb42b62c2ad327531cd30b21 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_inherit_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_inherit_001_pos
  35. #
  36. # DESCRIPTION:
  37. # Verify chmod have correct behaviour to directory and file when setting
  38. # different inherit strategy to them.
  39. #
  40. # STRATEGY:
  41. # 1. Loop super user and non-super user to run the test case.
  42. # 2. Create basedir and a set of subdirectores and files within it.
  43. # 3. Separately chmod basedir with different inherite options.
  44. # 4. Then create nested directories and files like the following.
  45. #
  46. # _ odir4
  47. # |_ ofile4
  48. # _ odir3 _|
  49. # |_ ofile3
  50. # _ odir1 _|
  51. # |_ ofile2
  52. # basefile |
  53. # chmod --> basedir -|
  54. # |_ nfile1
  55. # |_ ndir1 _
  56. # |_ nfile2
  57. # |_ ndir2 _
  58. # |_ nfile3
  59. # |_ ndir3
  60. #
  61. # 5. Verify each directories and files have the correct access control
  62. # capability.
  63. #
  64. # TESTABILITY: explicit
  65. #
  66. # TEST_AUTOMATION_LEVEL: automated
  67. #
  68. # CODING_STATUS: COMPLETED (2005-11-15)
  69. #
  70. # __stc_assertion_end
  71. #
  72. ################################################################################
  73. verify_runnable "both"
  74. function cleanup
  75. {
  76. if [[ -f $basefile ]]; then
  77. log_must $RM -f $basefile
  78. fi
  79. if [[ -d $basedir ]]; then
  80. log_must $RM -rf $basedir
  81. fi
  82. }
  83. log_assert "Verify chmod have correct behaviour to directory and file when " \
  84. "setting different inherit strategies to them."
  85. log_onexit cleanup
  86. # Define inherit flag
  87. set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit
  88. set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate
  89. # Defile the based directory and file
  90. basedir=$TESTDIR/basedir; basefile=$TESTDIR/basefile
  91. test_requires ZFS_ACL
  92. # Define the existed files and directories before chmod
  93. odir1=$basedir/odir1; odir2=$odir1/odir2; odir3=$odir2/odir3
  94. ofile1=$basedir/ofile1; ofile2=$odir1/ofile2; ofile3=$odir2/ofile3
  95. # Define the files and directories will be created after chmod
  96. ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
  97. nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
  98. # Verify all the node have expected correct access control
  99. allnodes="$basedir $ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
  100. allnodes="$allnodes $odir1 $odir2 $odir3 $ofile1 $ofile2 $ofile3"
  101. #
  102. # According to inherited flag, verify subdirectories and files within it has
  103. # correct inherited access control.
  104. #
  105. function verify_inherit #<object> [strategy]
  106. {
  107. # Define the nodes which will be affected by inherit.
  108. typeset inherit_nodes
  109. typeset obj=$1
  110. typeset str=$2
  111. log_must usr_exec $MKDIR -p $ndir3
  112. log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
  113. # Except for inherit_only, the basedir was affected always.
  114. if [[ $str != *"inherit_only"* ]]; then
  115. inherit_nodes="$inherit_nodes $basedir"
  116. fi
  117. # Get the files which inherited ACE.
  118. if [[ $obj == *"file_inherit"* ]]; then
  119. inherit_nodes="$inherit_nodes $nfile1"
  120. if [[ $str != *"no_propagate"* ]]; then
  121. inherit_nodes="$inherit_nodes $nfile2 $nfile3"
  122. fi
  123. fi
  124. # Get the directores which inherited ACE.
  125. if [[ $obj == *"dir_inherit"* ]]; then
  126. inherit_nodes="$inherit_nodes $ndir1"
  127. if [[ $str != *"no_propagate"* ]]; then
  128. inherit_nodes="$inherit_nodes $ndir2 $ndir3"
  129. fi
  130. fi
  131. for node in $allnodes; do
  132. if [[ " $inherit_nodes " == *" $node "* ]]; then
  133. log_mustnot chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \
  134. > /dev/null 2>&1
  135. else
  136. log_must chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \
  137. > /dev/null 2>&1
  138. fi
  139. done
  140. }
  141. for user in root $ZFS_ACL_STAFF1; do
  142. log_must set_cur_usr $user
  143. for obj in "${object_flag[@]}"; do
  144. for str in "${strategy_flag[@]}"; do
  145. typeset inh_opt=$obj
  146. (( ${#str} != 0 )) && inh_opt=$inh_opt/$str
  147. aclspec="A+user:$ZFS_ACL_OTHER1:read_acl:$inh_opt:deny"
  148. log_must usr_exec $MKDIR $basedir
  149. log_must usr_exec $TOUCH $basefile
  150. log_must usr_exec $MKDIR -p $odir3
  151. log_must usr_exec $TOUCH $ofile1 $ofile2 $ofile3
  152. #
  153. # Inherit flag can only be placed on a directory,
  154. # otherwise it will fail.
  155. #
  156. log_must usr_exec $CHMOD $aclspec $basefile
  157. #
  158. # Place on a directory should succeed.
  159. #
  160. log_must usr_exec $CHMOD $aclspec $basedir
  161. verify_inherit $obj $str
  162. log_must usr_exec $RM -rf $basefile $basedir
  163. done
  164. done
  165. done
  166. log_pass "Verify chmod inherit behaviour passed."