diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index d494eda5533f..6d1a452adc98 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -41,7 +41,7 @@ # PATH may have been modified by sudo's secure_path behavior. # if [ -n "$STF_PATH" ]; then - PATH="$STF_PATH" + export PATH="$STF_PATH" fi # @@ -2766,10 +2766,6 @@ function add_user # ;; esac - echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.profile - echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.bash_profile - echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.login - return 0 } @@ -3391,10 +3387,18 @@ function get_cpu_freq function user_run { typeset user=$1 + typeset out=$TEST_BASE_DIR/out + typeset err=$TEST_BASE_DIR/err shift - log_note "user:$user $@" - eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err + log_note "user: $user" + log_note "cmd: $*" + log_note "user env: `sudo -Eu $user env`" + sudo -Eu $user $(which ksh) <<<"$*" >$out 2>$err + typeset res=$? + log_note "out: $(<$out)" + log_note "err: $(<$err)" + return $res } # diff --git a/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib b/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib index e39b015b21b8..3196a1e850f6 100644 --- a/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib +++ b/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib @@ -388,7 +388,7 @@ function verify_send typeset bak_user=$TEST_BASE_DIR/bak.$user.$stamp typeset bak_root=$TEST_BASE_DIR/bak.root.$stamp - user_run $user eval "zfs send $snap > $bak_user" + user_run $user "zfs send $snap > $bak_user" log_must eval "zfs send $snap > $bak_root" if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then @@ -430,27 +430,27 @@ function verify_fs_receive log_must eval "zfs send $dtstsnap > $bak_root" log_must_busy zfs destroy -rf $dtst - user_run $user eval "zfs receive $dtst < $bak_root" + user_run $user "zfs receive $dtst < $bak_root" if datasetexists $dtstsnap ; then return 1 fi log_must zfs allow $user create $fs - user_run $user eval "zfs receive $dtst < $bak_root" + user_run $user "zfs receive $dtst < $bak_root" log_must zfs unallow $user create $fs if datasetexists $dtstsnap ; then return 1 fi log_must zfs allow $user mount $fs - user_run $user eval "zfs receive $dtst < $bak_root" + user_run $user "zfs receive $dtst < $bak_root" log_must zfs unallow $user mount $fs if datasetexists $dtstsnap ; then return 1 fi log_must zfs allow $user mount,create $fs - user_run $user eval "zfs receive $dtst < $bak_root" + user_run $user "zfs receive $dtst < $bak_root" log_must zfs unallow $user mount,create $fs if ! datasetexists $dtstsnap ; then return 1 diff --git a/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh b/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh index fbfc141be3e3..de90b9c20991 100755 --- a/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh +++ b/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh @@ -126,14 +126,14 @@ log_must zfs set filesystem_limit=0 "$DATASET_TEST" log_must zfs create "$DATASET_UTIL/send" log_must zfs snapshot "$DATASET_UTIL/send@snap1" log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM" -log_mustnot user_run $STAFF1 eval "zfs receive $DATASET_TEST/received < $ZSTREAM" +log_mustnot user_run $STAFF1 "zfs receive $DATASET_TEST/received < $ZSTREAM" log_mustnot datasetexists "$DATASET_TEST/received" log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0" # Verify filesystem_limit is *not* enforced for users allowed to change it log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM" log_must zfs destroy -r "$DATASET_TEST/received" log_must zfs allow -l $STAFF1 'filesystem_limit' "$DATASET_TEST" -log_must user_run $STAFF1 eval "zfs receive $DATASET_TEST/received < $ZSTREAM" +log_must user_run $STAFF1 "zfs receive $DATASET_TEST/received < $ZSTREAM" log_must datasetexists "$DATASET_TEST/received" log_pass "'filesystem_limit' property is enforced" diff --git a/tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh b/tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh index 62f14466e693..6edd7d2f371b 100755 --- a/tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh +++ b/tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh @@ -142,16 +142,16 @@ log_must zfs create "$DATASET_UTIL/send" log_must zfs snapshot "$DATASET_UTIL/send@snap1" log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM" log_mustnot user_run $STAFF1 \ - eval "zfs receive $DATASET_TEST/received < $ZSTREAM" + "zfs receive $DATASET_TEST/received < $ZSTREAM" log_mustnot datasetexists "$DATASET_TEST/received" log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "0" log_must zfs set snapshot_limit=1 "$DATASET_TEST" log_must user_run $STAFF1 \ - eval "zfs receive $DATASET_TEST/received < $ZSTREAM" + "zfs receive $DATASET_TEST/received < $ZSTREAM" log_must zfs snapshot "$DATASET_UTIL/send@snap2" log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM" log_mustnot user_run $STAFF1 \ - eval "zfs receive $DATASET_TEST/received < $ZSTREAM" + "zfs receive $DATASET_TEST/received < $ZSTREAM" log_mustnot datasetexists "$DATASET_TEST/received@snap2" log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1" # Verify snapshot_limit is *not* enforced for users allowed to change it @@ -160,7 +160,7 @@ log_must zfs snapshot "$DATASET_UTIL/send@snap3" log_must eval "zfs send -i @snap2 $DATASET_UTIL/send@snap3 > $ZSTREAM" log_must zfs allow -l $STAFF1 'snapshot_limit' "$DATASET_TEST" log_must user_run $STAFF1 \ - eval "zfs receive $DATASET_TEST/received < $ZSTREAM" + "zfs receive $DATASET_TEST/received < $ZSTREAM" log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "3" log_pass "'snapshot_limit' property is enforced" diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh index a3b25ff66266..ba27d043b7fe 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh @@ -43,34 +43,40 @@ # 4. Check that we're unable to write an xattr as a non-root user # -function cleanup { - - log_must rm $TESTDIR/myfile.$$ - +function cleanup +{ + rm -f $testfile $tempfile } log_assert "read/write xattr on a file with no permissions fails" log_onexit cleanup -log_must touch $TESTDIR/myfile.$$ -create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd +typeset testfile=$TESTDIR/testfile.$$ +typeset tempfile=/tmp/tempfile.$$ + +log_must touch $testfile +create_xattr $testfile passwd /etc/passwd -log_must chmod 000 $TESTDIR/myfile.$$ +log_must chmod 000 $testfile if is_illumos; then - log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cat passwd" - log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cp /etc/passwd ." + log_mustnot su $ZFS_USER -c "runat $testfile cat passwd" + log_mustnot su $ZFS_USER -c "runat $testfile cp /etc/passwd ." else - user_run $ZFS_USER eval \ - "get_xattr passwd $TESTDIR/myfile.$$ >/tmp/passwd.$$" - log_mustnot diff /etc/passwd /tmp/passwd.$$ - log_must rm /tmp/passwd.$$ + log_mustnot user_run $ZFS_USER " +. $STF_SUITE/include/libtest.shlib +get_xattr passwd $testfile >$tempfile +" + log_mustnot diff -q /etc/passwd $tempfile + log_must rm $tempfile - user_run $ZFS_USER eval \ - "set_xattr_stdin passwd $TESTDIR/myfile.$$ /tmp/passwd.$$ - log_must diff /etc/passwd /tmp/passwd.$$ - log_must rm /tmp/passwd.$$ + log_mustnot user_run $ZFS_USER " +. $STF_SUITE/include/libtest.shlib +set_xattr_stdin passwd $testfile $tempfile + log_must diff -q /etc/passwd $tempfile + log_must rm $tempfile fi log_pass "read/write xattr on a file with no permissions fails"