4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 . $STF_SUITE/tests/functional/acl/acl.cfg
28 . $STF_SUITE/include/libtest.shlib
31 # Get the given file/directory access mode
33 # $1 object -- file or directroy
35 function get_mode #<obj>
38 if (( ${#obj} == 0 )); then
42 $LS -ld $obj | $AWK '{print $1}'
46 # Get the given file/directory ACL
48 # $1 object -- file or directroy
50 function get_acl #<obj>
53 if (( ${#obj} == 0 )); then
57 $LS -vd $obj | $NAWK '(NR != 1) {print $0}'
61 # Get the given file/directory ACL
63 # $1 object -- file or directroy
65 function get_compact_acl #<obj>
68 if (( ${#obj} == 0 )); then
72 $LS -Vd $obj | $NAWK '(NR != 1) {print $0}'
76 # Check the given two files/directories have the same ACLs
78 # Return 0, if source object acl is equal to target object acl.
83 function compare_acls #<src> <tgt>
88 (( ${#src} == 0 || ${#tgt} == 0 )) && return 1
89 [[ $src == $tgt ]] && return 0
91 typeset tmpsrc=/tmp/compare_acls.src.$$
92 typeset tmptgt=/tmp/compare_acls.tgt.$$
94 get_acl $src > $tmpsrc
95 get_acl $tgt > $tmptgt
97 $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
99 $RM -f $tmpsrc $tmptgt
101 if (( ret != 0 )); then
105 get_compact_acl $src > $tmpsrc
106 get_compact_acl $tgt > $tmptgt
107 $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
109 $RM -f $tmpsrc $tmptgt
115 # Check that the given two objects have the same modes.
116 # Return 0, if their modes are equal with each other. Otherwise, return 1.
121 function compare_modes #<src> <tgt>
128 (( ${#src} == 0 || ${#tgt} == 0 )) && return 1
129 [[ $src == $tgt ]] && return 0
134 mode[i]=$(get_mode $obj)
139 [[ ${mode[0]} != ${mode[1]} ]] && return 1
145 # Check that the given two objects have the same xattrs.
146 # Return 0, if their xattrs are equal with each other. Otherwise, return 1.
151 function compare_xattrs #<src> <tgt>
156 (( ${#src} == 0 || ${#tgt} == 0 )) && return 1
157 [[ $src == $tgt ]] && return 0
159 typeset tmpsrc=/tmp/compare_xattrs.src.$$
160 typeset tmptgt=/tmp/compare_xattrs.tgt.$$
162 get_xattr $src > $tmpsrc
163 get_xattr $tgt > $tmptgt
165 $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
167 $RM -f $tmpsrc $tmptgt
173 # Check '+' is set for a given file/directory with 'ls [-l]' command
175 # $1 object -- file or directory.
177 function plus_sign_check_l #<obj>
180 if (( ${#obj} == 0 )); then
184 $LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null
190 # Check '+' is set for a given file/directory with 'ls [-v]' command
192 # $1 object -- file or directory.
194 function plus_sign_check_v #<obj>
197 if (( ${#obj} == 0 )); then
201 $LS -vd $obj | $NAWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null
207 # A wrapper function of c program
209 # $1 legal login name
210 # $2-n commands and options
212 function chgusr_exec #<login_name> <commands> [...]
219 # Export the current user for the following usr_exec operating.
221 # $1 legal login name
223 function set_cur_usr #<login_name>
225 export ZFS_ACL_CUR_USER=$1
229 # Run commands by $ZFS_ACL_CUR_USER
231 # $1-n commands and options
233 function usr_exec #<commands> [...]
235 $CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@
240 # Count how many ACEs for the speficied file or directory.
242 # $1 file or directroy name
244 function count_ACE #<file or dir name>
246 if [[ ! -e $1 ]]; then
247 log_note "Need input file or directroy name."
251 $LS -vd $1 | $NAWK 'BEGIN {count=0}
252 (NR != 1)&&(/[0-9]:/) {count++}
259 # Get specified number ACE content of specified file or directory.
261 # $1 file or directory name
262 # $2 specified number
264 function get_ACE #<file or dir name> <specified number> <verbose|compact>
266 if [[ ! -e $1 || $2 -ge $(count_ACE $1) ]]; then
272 typeset format=${3:-verbose}
273 typeset -i next_num=-1
275 typeset tmpfile=/tmp/tmp_get_ACE.$$
284 *) log_fail "Invalid parameter as ($format), " \
285 "only verbose|compact is supported."
289 $LS $args $file > $tmpfile
290 (( $? != 0 )) && log_fail "FAIL: $LS $args $file > $tmpfile"
292 [[ -z $line ]] && continue
293 if [[ $args == -vd ]]; then
294 if [[ $line == "$num":* ]]; then
295 (( next_num = num + 1 ))
297 if [[ $line == "$next_num":* ]]; then
300 if (( next_num != -1 )); then
304 if (( next_num == num )); then
312 (( $? != 0 )) && log_fail "FAIL: $RM -f $tmpfile"
316 # Cleanup exist user/group.
318 function cleanup_user_group
320 del_user $ZFS_ACL_ADMIN
322 del_user $ZFS_ACL_STAFF1
323 del_user $ZFS_ACL_STAFF2
324 del_group $ZFS_ACL_STAFF_GROUP
326 del_user $ZFS_ACL_OTHER1
327 del_user $ZFS_ACL_OTHER2
328 del_group $ZFS_ACL_OTHER_GROUP
334 # Clean up testfile and test directory
338 if [[ -d $TESTDIR ]]; then
345 # According to specified access or acl_spec, do relevant operating by using the
350 # $3 acl_spec or access
352 function rwx_node #user node acl_spec|access
358 if [[ $user == "" || $node == "" || $acl_spec == "" ]]; then
359 log_note "node or acl_spec are not defined."
363 if [[ -d $node ]]; then
365 *:read_data:*|read_data)
366 chgusr_exec $user $LS -l $node > /dev/null 2>&1
368 *:write_data:*|write_data)
369 if [[ -f ${node}/tmpfile ]]; then
370 log_must $RM -f ${node}/tmpfile
372 chgusr_exec $user $TOUCH ${node}/tmpfile > \
375 *"execute:"*|execute)
376 chgusr_exec $user $FIND $node > /dev/null 2>&1
381 *:read_data:*|read_data)
382 chgusr_exec $user $CAT $node > /dev/null 2>&1
384 *:write_data:*|write_data)
385 chgusr_exec $user $DD if=/usr/bin/ls of=$node > \
388 *"execute:"*|execute)
389 ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
396 # Get the given file/directory xattr
398 # $1 object -- file or directroy
400 function get_xattr #<obj>
404 if (( ${#obj} == 0 )); then
408 for xattr in `$RUNAT $obj $LS | \
409 /usr/xpg4/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do
410 $RUNAT $obj $SUM $xattr
415 # Get the owner of a file/directory
417 function get_owner #node
422 if [[ -z $node ]]; then
423 log_fail "node are not defined."
426 if [[ -d $node ]]; then
427 value=$($LS -dl $node | $AWK '{print $3}')
428 elif [[ -e $node ]]; then
429 value=$($LS -l $node | $AWK '{print $3}')
436 # Get the group of a file/directory
438 function get_group #node
443 if [[ -z $node ]]; then
444 log_fail "node are not defined."
447 if [[ -d $node ]]; then
448 value=$($LS -dl $node | $AWK '{print $4}')
449 elif [[ -e $node ]]; then
450 value=$($LS -l $node | $AWK '{print $4}')
458 # Get the group name that a UID belongs to
460 function get_user_group #uid
465 if [[ -z $uid ]]; then
466 log_fail "UID not defined."
471 if [[ $? -eq 0 ]]; then
476 log_fail "Invalid UID (uid)."
481 # Get the specified item of the specified string
483 # $1: Item number, count from 0.
496 # This function calculate the specified directory files checksum and write
497 # to the specified array.
499 # $1 directory in which the files will be cksum.
500 # $2 file array name which was used to store file cksum information.
501 # $3 attribute array name which was used to store attribute information.
503 function cksum_files #<dir> <file_array_name> <attribute_array_name>
509 [[ ! -d $dir ]] && return
512 typeset files=$($LS file*)
516 while (( i < NUM_FILE )); do
517 typeset f=$(getitem $i $files)
518 eval $farr_name[$i]=\$\(\$CKSUM $f\)
521 while (( j < NUM_ATTR )); do
522 eval $aarr_name[$n]=\$\(\$RUNAT \$f \$CKSUM \
536 # This function compare two cksum results array.
538 # $1 The array name which stored the cksum before operation.
539 # $2 The array name which stored the cksum after operation.
541 function compare_cksum #<array1> <array2>
545 eval typeset -i count=\${#$before[@]}
548 while (( i < count )); do
549 eval typeset var1=\${$before[$i]}
550 eval typeset var2=\${$after[$i]}
552 if [[ $var1 != $var2 ]]; then
563 # This function calculate all the files cksum information in current directory
564 # and output them to the specified file.
566 # $1 directory from which the files will be cksum.
567 # $2 cksum output file
569 function record_cksum #<outfile>
574 [[ ! -d ${outfile%/*} ]] && usr_exec $MKDIR -p ${outfile%/*}
576 usr_exec cd $dir ; $FIND . -depth -type f -exec cksum {} \\\; | \
578 usr_exec cd $dir ; $FIND . -depth -type f -xattr -exec runat {} \
579 cksum attribute* \\\; | $SORT >> $outfile
583 # The function create_files creates the directories and files that the script
584 # will operate on to test extended attribute functionality.
586 # $1 The base directory in which to create directories and files.
588 function create_files #<directory>
592 [[ ! -d $basedir ]] && usr_exec $MKDIR -m 777 $basedir
593 [[ ! -d $RES_DIR ]] && usr_exec $MKDIR -m 777 $RES_DIR
594 [[ ! -d $INI_DIR ]] && usr_exec $MKDIR -m 777 $INI_DIR
595 [[ ! -d $TST_DIR ]] && usr_exec $MKDIR -m 777 $TST_DIR
596 [[ ! -d $TMP_DIR ]] && usr_exec $MKDIR -m 777 $TMP_DIR
599 # Create the original file and its attribute files.
601 [[ ! -a $RES_DIR/file ]] && \
602 usr_exec $FILE_WRITE -o create -f $RES_DIR/file \
604 [[ ! -a $RES_DIR/attribute ]] && \
605 usr_exec $CP $RES_DIR/file $RES_DIR/attribute
611 while (( i < NUM_FILE )); do
612 typeset dstfile=$INI_DIR/file.$$.$i
613 usr_exec $CP $RES_DIR/file $dstfile
616 while (( j < NUM_ATTR )); do
617 usr_exec $RUNAT $dstfile \
618 $CP $RES_DIR/attribute ./attribute.$j