Print this page
7290 ZFS test suite needs to control what utilities it can run
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>

@@ -22,10 +22,14 @@
 #
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 
+#
+# Copyright (c) 2016 by Delphix. All rights reserved.
+#
+
 . $STF_SUITE/tests/functional/acl/acl.cfg
 . $STF_SUITE/include/libtest.shlib
 
 #
 # Get the given file/directory access mode

@@ -37,11 +41,11 @@
         typeset obj=$1
         if (( ${#obj} == 0 )); then
                 return 1
         fi
 
-        $LS -ld $obj | $AWK '{print $1}'
+        ls -ld $obj | awk '{print $1}'
 }
 
 #
 # Get the given file/directory ACL
 #

@@ -52,11 +56,11 @@
         typeset obj=$1
         if (( ${#obj} == 0 )); then
                 return 1
         fi
 
-        $LS -vd $obj | $NAWK '(NR != 1) {print $0}'
+        ls -vd $obj | nawk '(NR != 1) {print $0}'
 }
 
 #
 # Get the given file/directory ACL
 #

@@ -67,11 +71,11 @@
         typeset obj=$1
         if (( ${#obj} == 0 )); then
                 return 1
         fi
 
-        $LS -Vd $obj | $NAWK '(NR != 1) {print $0}'
+        ls -Vd $obj | nawk '(NR != 1) {print $0}'
 }
 
 #
 # Check the given two files/directories have the same ACLs
 #

@@ -92,23 +96,23 @@
         typeset tmptgt=/tmp/compare_acls.tgt.$$
 
         get_acl $src > $tmpsrc
         get_acl $tgt > $tmptgt
         typeset -i ret=0
-        $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
+        diff $tmpsrc $tmptgt > /dev/null 2>&1
         ret=$?
-        $RM -f $tmpsrc $tmptgt
+        rm -f $tmpsrc $tmptgt
 
         if (( ret != 0 )); then
                 return $ret
         fi
 
         get_compact_acl $src > $tmpsrc
         get_compact_acl $tgt > $tmptgt
-        $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
+        diff $tmpsrc $tmptgt > /dev/null 2>&1
         ret=$?
-        $RM -f $tmpsrc $tmptgt
+        rm -f $tmpsrc $tmptgt
 
         return $ret
 }
 
 #

@@ -160,13 +164,13 @@
         typeset tmptgt=/tmp/compare_xattrs.tgt.$$
 
         get_xattr $src > $tmpsrc
         get_xattr $tgt > $tmptgt
         typeset -i ret=0
-        $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
+        diff $tmpsrc $tmptgt > /dev/null 2>&1
         ret=$?
-        $RM -f $tmpsrc $tmptgt
+        rm -f $tmpsrc $tmptgt
 
         return $ret
 }
 
 #

@@ -179,11 +183,11 @@
         typeset obj=$1
         if (( ${#obj} == 0 )); then
                 return 1
         fi
 
-        $LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null
+        ls -ld $obj | awk '{print $1}' | grep "+\>" > /dev/null
 
         return $?
 }
 
 #

@@ -196,11 +200,11 @@
         typeset obj=$1
         if (( ${#obj} == 0 )); then
                 return 1
         fi
 
-        $LS -vd $obj | $NAWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null
+        ls -vd $obj | nawk '(NR == 1) {print $1}' | grep "+\>" > /dev/null
 
         return $?
 }
 
 #

@@ -209,11 +213,11 @@
 # $1 legal login name
 # $2-n commands and options
 #
 function chgusr_exec #<login_name> <commands> [...]
 {
-        $CHG_USR_EXEC $@
+        chg_usr_exec $@
         return $?
 }
 
 #
 # Export the current user for the following usr_exec operating.

@@ -230,11 +234,11 @@
 #
 # $1-n commands and options
 #
 function usr_exec #<commands> [...]
 {
-        $CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@
+        chg_usr_exec "$ZFS_ACL_CUR_USER" $@
         return $?
 }
 
 #
 # Count how many ACEs for the speficied file or directory.

@@ -246,11 +250,11 @@
         if [[ ! -e $1 ]]; then
                 log_note "Need input file or directroy name."
                 return 1
         fi
 
-        $LS -vd $1 | $NAWK 'BEGIN {count=0}
+        ls -vd $1 | nawk 'BEGIN {count=0}
                         (NR != 1)&&(/[0-9]:/) {count++}
                         END {print count}'
 
         return 0
 }

@@ -284,12 +288,12 @@
                 *) log_fail "Invalid parameter as ($format), " \
                         "only verbose|compact is supported."
                         ;;
         esac
 
-        $LS $args $file > $tmpfile
-        (( $? != 0 )) && log_fail "FAIL: $LS $args $file > $tmpfile"
+        ls $args $file > $tmpfile
+        (( $? != 0 )) && log_fail "FAIL: ls $args $file > $tmpfile"
         while read line; do
                 [[ -z $line ]] && continue
                 if [[ $args == -vd ]]; then
                         if [[ $line == "$num":* ]]; then
                                 (( next_num = num + 1 ))

@@ -306,12 +310,12 @@
                         fi
                         (( next_num += 1 ))
                 fi
         done < $tmpfile
 
-        $RM -f $tmpfile
-        (( $? != 0 )) && log_fail "FAIL: $RM -f $tmpfile"
+        rm -f $tmpfile
+        (( $? != 0 )) && log_fail "FAIL: rm -f $tmpfile"
 }
 
 #
 # Cleanup exist user/group.
 #

@@ -335,11 +339,11 @@
 #
 function cleanup
 {
         if [[ -d $TESTDIR ]]; then
                 cd $TESTDIR
-                $RM -rf $TESTDIR/*
+                rm -rf $TESTDIR/*
         fi
 }
 
 #
 # According to specified access or acl_spec, do relevant operating by using the

@@ -361,30 +365,30 @@
         fi
 
         if [[ -d $node ]]; then
                 case $acl_spec in
                 *:read_data:*|read_data)
-                        chgusr_exec $user $LS -l $node > /dev/null 2>&1
+                        chgusr_exec $user ls -l $node > /dev/null 2>&1
                         return $? ;;
                 *:write_data:*|write_data)
                         if [[ -f ${node}/tmpfile ]]; then
-                                log_must $RM -f ${node}/tmpfile
+                                log_must rm -f ${node}/tmpfile
                         fi
-                        chgusr_exec $user $TOUCH ${node}/tmpfile > \
+                        chgusr_exec $user touch ${node}/tmpfile > \
                                 /dev/null 2>&1
                         return $? ;;
                 *"execute:"*|execute)
-                        chgusr_exec $user $FIND $node > /dev/null 2>&1
+                        chgusr_exec $user find $node > /dev/null 2>&1
                         return $? ;;
                 esac
         else
                 case $acl_spec in
                 *:read_data:*|read_data)
-                        chgusr_exec $user $CAT $node > /dev/null 2>&1
+                        chgusr_exec $user cat $node > /dev/null 2>&1
                         return $? ;;
                 *:write_data:*|write_data)
-                        chgusr_exec $user $DD if=/usr/bin/ls of=$node > \
+                        chgusr_exec $user dd if=/usr/bin/ls of=$node > \
                                 /dev/null 2>&1
                         return $? ;;
                 *"execute:"*|execute)
                         ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
                         return $? ;;

@@ -403,13 +407,13 @@
         typeset xattr
         if (( ${#obj} == 0 )); then
                 return 1
         fi
 
-        for xattr in `$RUNAT $obj $LS | \
+        for xattr in `runat $obj ls | \
                 /usr/xpg4/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do
-                $RUNAT $obj $SUM $xattr
+                runat $obj sum $xattr
         done
 }
 
 #
 # Get the owner of a file/directory

@@ -422,16 +426,16 @@
         if [[ -z $node ]]; then
                 log_fail "node are not defined."
         fi
 
         if [[ -d $node ]]; then
-                value=$($LS -dl $node | $AWK '{print $3}')
+                value=$(ls -dl $node | awk '{print $3}')
         elif [[ -e $node ]]; then
-                value=$($LS -l $node | $AWK '{print $3}')
+                value=$(ls -l $node | awk '{print $3}')
         fi
 
-        $ECHO $value
+        echo $value
 }
 
 #
 # Get the group of a file/directory
 #

@@ -443,16 +447,16 @@
         if [[ -z $node ]]; then
                 log_fail "node are not defined."
         fi
 
         if [[ -d $node ]]; then
-                value=$($LS -dl $node | $AWK '{print $4}')
+                value=$(ls -dl $node | awk '{print $4}')
         elif [[ -e $node ]]; then
-                value=$($LS -l $node | $AWK '{print $4}')
+                value=$(ls -l $node | awk '{print $4}')
         fi
 
-        $ECHO $value
+        echo $value
 }
 
 
 #
 # Get the group name that a UID belongs to

@@ -469,11 +473,11 @@
         value=$(id $uid)
 
         if [[ $? -eq 0 ]]; then
                 value=${value##*\(}
                 value=${value%%\)*}
-                $ECHO $value
+                echo $value
         else
                 log_fail "Invalid UID (uid)."
         fi
 }
 

@@ -507,21 +511,21 @@
         typeset aarr_name=$3
 
         [[ ! -d $dir ]] && return
         typeset oldpwd=$PWD
         cd $dir
-        typeset files=$($LS file*)
+        typeset files=$(ls file*)
 
         typeset -i i=0
         typeset -i n=0
         while (( i < NUM_FILE )); do
                 typeset f=$(getitem $i $files)
-                eval $farr_name[$i]=\$\(\$CKSUM $f\)
+                eval $farr_name[$i]=\$\(\cksum $f\)
 
                 typeset -i j=0
                 while (( j < NUM_ATTR )); do
-                        eval $aarr_name[$n]=\$\(\$RUNAT \$f \$CKSUM \
+                        eval $aarr_name[$n]=\$\(\runat \$f \cksum \
                                 attribute.$j\)
 
                         (( j += 1 ))
                         (( n += 1 ))
                 done

@@ -569,16 +573,16 @@
 function record_cksum #<outfile>
 {
         typeset dir=$1
         typeset outfile=$2
 
-        [[ ! -d ${outfile%/*} ]] && usr_exec $MKDIR -p ${outfile%/*}
+        [[ ! -d ${outfile%/*} ]] && usr_exec mkdir -p ${outfile%/*}
 
-        usr_exec cd $dir ; $FIND . -depth -type f -exec cksum {} \\\; | \
-            $SORT > $outfile
-        usr_exec cd $dir ; $FIND . -depth -type f -xattr -exec runat {} \
-                cksum attribute* \\\; | $SORT >> $outfile
+        usr_exec cd $dir ; find . -depth -type f -exec cksum {} \\\; | \
+            sort > $outfile
+        usr_exec cd $dir ; find . -depth -type f -xattr -exec runat {} \
+                cksum attribute* \\\; | sort >> $outfile
 }
 
 #
 # The function create_files creates the directories and files that the script
 # will operate on to test extended attribute functionality.

@@ -587,37 +591,37 @@
 #
 function create_files #<directory>
 {
         typeset basedir=$1
 
-        [[ ! -d $basedir ]] && usr_exec $MKDIR -m 777 $basedir
-        [[ ! -d $RES_DIR  ]] && usr_exec $MKDIR -m 777 $RES_DIR
-        [[ ! -d $INI_DIR ]] && usr_exec $MKDIR -m 777 $INI_DIR
-        [[ ! -d $TST_DIR ]] && usr_exec $MKDIR -m 777 $TST_DIR
-        [[ ! -d $TMP_DIR  ]] && usr_exec $MKDIR -m 777 $TMP_DIR
+        [[ ! -d $basedir ]] && usr_exec mkdir -m 777 $basedir
+        [[ ! -d $RES_DIR  ]] && usr_exec mkdir -m 777 $RES_DIR
+        [[ ! -d $INI_DIR ]] && usr_exec mkdir -m 777 $INI_DIR
+        [[ ! -d $TST_DIR ]] && usr_exec mkdir -m 777 $TST_DIR
+        [[ ! -d $TMP_DIR  ]] && usr_exec mkdir -m 777 $TMP_DIR
 
         #
         # Create the original file and its attribute files.
         #
         [[ ! -a $RES_DIR/file ]] && \
-                usr_exec $FILE_WRITE -o create -f $RES_DIR/file \
+                usr_exec file_write -o create -f $RES_DIR/file \
                         -b 1024 -d 0 -c 1
         [[ ! -a $RES_DIR/attribute ]] && \
-                usr_exec $CP $RES_DIR/file $RES_DIR/attribute
+                usr_exec cp $RES_DIR/file $RES_DIR/attribute
 
         typeset oldpwd=$PWD
         cd $INI_DIR
 
         typeset -i i=0
         while (( i < NUM_FILE )); do
                 typeset dstfile=$INI_DIR/file.$$.$i
-                usr_exec $CP $RES_DIR/file $dstfile
+                usr_exec cp $RES_DIR/file $dstfile
 
                 typeset -i j=0
                 while (( j < NUM_ATTR )); do
-                        usr_exec $RUNAT $dstfile \
-                                $CP $RES_DIR/attribute ./attribute.$j
+                        usr_exec runat $dstfile \
+                                cp $RES_DIR/attribute ./attribute.$j
                         (( j += 1 ))
                 done
 
                 (( i += 1 ))
         done