PageRenderTime 95ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_002_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 280 lines | 161 code | 29 blank | 90 comment | 35 complexity | df6d95fc4495d994aeab62ed0dcba7cf 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 "@(#)cifs_attr_002_pos.ksh 1.1 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: cifs_attr_002_pos
  36. #
  37. # DESCRIPTION:
  38. # Verify the user with PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR
  39. # could set/clear BSD'ish attributes.
  40. # (Immutable, nounlink, and appendonly)
  41. #
  42. # STRATEGY:
  43. # 1. Loop super user and non-super user to run the test case.
  44. # 2. Create basedir and a set of subdirectores and files within it.
  45. # 3. Grant user has PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR separately.
  46. # 4. Verify set/clear BSD'ish attributes should succeed.
  47. #
  48. # TESTABILITY: explicit
  49. #
  50. # TEST_AUTOMATION_LEVEL: automated
  51. #
  52. # CODING_STATUS: COMPLETED (2007-11-05)
  53. #
  54. # __stc_assertion_end
  55. #
  56. ################################################################################
  57. verify_runnable "global"
  58. if ! cifs_supported ; then
  59. log_unsupported "CIFS not supported on current system."
  60. fi
  61. test_requires ZFS_ACL ZFS_XATTR
  62. function cleanup
  63. {
  64. if [[ -n $gobject ]]; then
  65. destroy_object $gobject
  66. fi
  67. for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
  68. mtpt=$(get_prop mountpoint $fs)
  69. log_must $RM -rf $mtpt/file.* $mtpt/dir.*
  70. done
  71. }
  72. #
  73. # Set the special attribute to the given node
  74. #
  75. # $1: The given node (file/dir)
  76. # $2: The special attribute to be set
  77. # $3: Execute username
  78. #
  79. function set_attribute
  80. {
  81. typeset object=$1
  82. typeset attr=$2
  83. typeset user=$3
  84. typeset ret=0
  85. if [[ -z $object ]]; then
  86. log_fail "Object not defined."
  87. fi
  88. if [[ -z $attr ]]; then
  89. attr="uiadm"
  90. if [[ -f $object ]]; then
  91. attr="${attr}q"
  92. fi
  93. fi
  94. if [[ -n $user ]]; then
  95. $RUNWATTR -u $user -p =basic${priv_mod} \
  96. "$CHMOD S+c${attr} $object"
  97. ret=$?
  98. else
  99. $CHMOD S+c${attr} $object
  100. ret=$?
  101. fi
  102. return $ret
  103. }
  104. #
  105. # Clear the special attribute to the given node
  106. #
  107. # $1: The given node (file/dir)
  108. # $2: The special attribute to be cleared
  109. # $3: Execute username
  110. #
  111. function clear_attribute
  112. {
  113. typeset object=$1
  114. typeset attr=$2
  115. typeset user=$3
  116. typeset ret=0
  117. if [[ -z $object ]]; then
  118. log_fail "Object($object) not defined."
  119. fi
  120. if [[ -z $attr ]]; then
  121. attr="uiadm"
  122. if [[ -f $object ]]; then
  123. attr="${attr}q"
  124. fi
  125. fi
  126. if [[ -n $user ]]; then
  127. $RUNWATTR -u $user -p =basic${priv_mod} \
  128. "$CHMOD S-c${attr} $object"
  129. ret=$?
  130. else
  131. $CHMOD S-c${attr} $object
  132. ret=$?
  133. fi
  134. return $ret
  135. }
  136. #
  137. # Grant the privset to the given user
  138. #
  139. # $1: The given user
  140. # $2: The given privset
  141. #
  142. function grant_priv
  143. {
  144. typeset user=$1
  145. typeset priv=$2
  146. if [[ -z $user || -z $priv ]]; then
  147. log_fail "User($user), Priv($priv) not defined."
  148. fi
  149. priv_mod=",$priv"
  150. return $?
  151. }
  152. #
  153. # Revoke the all additional privset from the given user
  154. #
  155. # $1: The given user
  156. #
  157. function revoke_priv
  158. {
  159. typeset user=$1
  160. if [[ -z $user ]]; then
  161. log_fail "User not defined."
  162. fi
  163. priv_mod=
  164. return $?
  165. }
  166. #
  167. # Invoke the function and verify whether its return code as expected
  168. #
  169. # $1: Function be invoked
  170. # $2: The given node (file/dir)
  171. # $3: Execute user
  172. # $4: Option
  173. #
  174. function verify_op
  175. {
  176. typeset func=$1
  177. typeset object=$2
  178. typeset opt=$3
  179. typeset user=$4
  180. typeset expect="log_mustnot"
  181. if [[ -z $func || -z $object ]]; then
  182. log_fail "Func($func), Object($object) not defined."
  183. fi
  184. # If user has PRIV_FILE_FLAG_SET, it could permit to set_attribute,
  185. # And If has PRIV_FILE_FLAG_CLEAR, it could permit to clear_attribute,
  186. # otherwise log_mustnot.
  187. if [[ -z $user || $user == "root" ]] || \
  188. [[ $priv_mod == *"file_flag_set"* ]] || \
  189. [[ $priv_mod == *"all"* ]] ; then
  190. expect="log_must"
  191. fi
  192. if [[ -d $object ]] && \
  193. [[ $opt == *"q"* ]] ; then
  194. expect="log_mustnot"
  195. fi
  196. if [[ $func == clear_attribute ]]; then
  197. if [[ $expect == "log_mustnot" ]]; then
  198. expect="log_must"
  199. elif [[ -z $user || $user == "root" ]] || \
  200. [[ $priv_mod == *"all"* ]] ; then
  201. expect="log_must"
  202. else
  203. expect="log_mustnot"
  204. fi
  205. fi
  206. $expect $func $object $opt $user
  207. }
  208. log_assert "Verify set/clear BSD'ish attributes will succeed while user has " \
  209. "PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR privilege"
  210. log_onexit cleanup
  211. file="file.0"
  212. dir="dir.0"
  213. FLAGOPTIONS="u i a d q m"
  214. typeset gobject
  215. for fs in $TESTPOOL $TESTPOOL/$TESTFS ; do
  216. mtpt=$(get_prop mountpoint $fs)
  217. for owner in root $ZFS_ACL_STAFF1 ; do
  218. create_object "file" $mtpt/$file $owner
  219. create_object "dir" $mtpt/$dir $owner
  220. for object in $mtpt/$file $mtpt/$dir ; do
  221. gobject=$object
  222. for user in root $ZFS_ACL_STAFF2 ; do
  223. log_must grant_priv $user file_flag_set
  224. for opt in $FLAGOPTIONS ; do
  225. verify_op set_attribute \
  226. $object $opt $user
  227. verify_op clear_attribute \
  228. $object $opt $user
  229. done
  230. log_must revoke_priv $user
  231. log_must grant_priv $user all
  232. for opt in $FLAGOPTIONS ; do
  233. verify_op set_attribute \
  234. $object $opt $user
  235. verify_op clear_attribute \
  236. $object $opt $user
  237. done
  238. log_must revoke_priv $user
  239. done
  240. done
  241. destroy_object $mtpt/$file $mtpt/$dir
  242. done
  243. done
  244. log_pass "Set/Clear BSD'ish attributes succeed while user has " \
  245. "PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR privilege"