Skip to content

Commit 4d1a093

Browse files
Ryan MoellerRyan Moeller
authored andcommitted
ZTS: Fix incorrect use of libtest in user_run by xattr_003_neg
You can't use user_run to eval ksh functions defined in libtest unless you include libtest in the user shell. Simplify user_run to retain the current environment, eliminate eval, and feed the command string into ksh. Enhance the logging for user_run so we can see out and err. Fix xattr_003_neg by: * running ksh as the user * feeding it the commands to include libtest *then* run get_xattr * assert this fails * use variables for filenames so they don't change in the user's shell * don't log the contents of /etc/passwd * cleanup all byproducts Signed-off-by: Ryan Moeller <[email protected]>
1 parent 801723f commit 4d1a093

File tree

5 files changed

+43
-32
lines changed

5 files changed

+43
-32
lines changed

tests/zfs-tests/include/libtest.shlib

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,8 +3393,13 @@ function user_run
33933393
typeset user=$1
33943394
shift
33953395

3396-
log_note "user:$user $@"
3397-
eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err
3396+
log_note "user: $user"
3397+
log_note "cmd: $*"
3398+
sudo -Eu $user ksh <<<"$*" >$TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err
3399+
typeset res=$?
3400+
log_note "out: `<$TEST_BASE_DIR/out`"
3401+
log_note "err: `<$TEST_BASE_DIR/err`"
3402+
return $res
33983403
}
33993404

34003405
#

tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ function verify_send
388388
typeset bak_user=$TEST_BASE_DIR/bak.$user.$stamp
389389
typeset bak_root=$TEST_BASE_DIR/bak.root.$stamp
390390

391-
user_run $user eval "zfs send $snap > $bak_user"
391+
user_run $user "zfs send $snap > $bak_user"
392392
log_must eval "zfs send $snap > $bak_root"
393393

394394
if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then
@@ -430,27 +430,27 @@ function verify_fs_receive
430430
log_must eval "zfs send $dtstsnap > $bak_root"
431431
log_must_busy zfs destroy -rf $dtst
432432

433-
user_run $user eval "zfs receive $dtst < $bak_root"
433+
user_run $user "zfs receive $dtst < $bak_root"
434434
if datasetexists $dtstsnap ; then
435435
return 1
436436
fi
437437

438438
log_must zfs allow $user create $fs
439-
user_run $user eval "zfs receive $dtst < $bak_root"
439+
user_run $user "zfs receive $dtst < $bak_root"
440440
log_must zfs unallow $user create $fs
441441
if datasetexists $dtstsnap ; then
442442
return 1
443443
fi
444444

445445
log_must zfs allow $user mount $fs
446-
user_run $user eval "zfs receive $dtst < $bak_root"
446+
user_run $user "zfs receive $dtst < $bak_root"
447447
log_must zfs unallow $user mount $fs
448448
if datasetexists $dtstsnap ; then
449449
return 1
450450
fi
451451

452452
log_must zfs allow $user mount,create $fs
453-
user_run $user eval "zfs receive $dtst < $bak_root"
453+
user_run $user "zfs receive $dtst < $bak_root"
454454
log_must zfs unallow $user mount,create $fs
455455
if ! datasetexists $dtstsnap ; then
456456
return 1

tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ log_must zfs set filesystem_limit=0 "$DATASET_TEST"
126126
log_must zfs create "$DATASET_UTIL/send"
127127
log_must zfs snapshot "$DATASET_UTIL/send@snap1"
128128
log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
129-
log_mustnot user_run $STAFF1 eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
129+
log_mustnot user_run $STAFF1 "zfs receive $DATASET_TEST/received < $ZSTREAM"
130130
log_mustnot datasetexists "$DATASET_TEST/received"
131131
log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
132132
# Verify filesystem_limit is *not* enforced for users allowed to change it
133133
log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
134134
log_must zfs destroy -r "$DATASET_TEST/received"
135135
log_must zfs allow -l $STAFF1 'filesystem_limit' "$DATASET_TEST"
136-
log_must user_run $STAFF1 eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
136+
log_must user_run $STAFF1 "zfs receive $DATASET_TEST/received < $ZSTREAM"
137137
log_must datasetexists "$DATASET_TEST/received"
138138

139139
log_pass "'filesystem_limit' property is enforced"

tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,16 @@ log_must zfs create "$DATASET_UTIL/send"
142142
log_must zfs snapshot "$DATASET_UTIL/send@snap1"
143143
log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
144144
log_mustnot user_run $STAFF1 \
145-
eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
145+
"zfs receive $DATASET_TEST/received < $ZSTREAM"
146146
log_mustnot datasetexists "$DATASET_TEST/received"
147147
log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "0"
148148
log_must zfs set snapshot_limit=1 "$DATASET_TEST"
149149
log_must user_run $STAFF1 \
150-
eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
150+
"zfs receive $DATASET_TEST/received < $ZSTREAM"
151151
log_must zfs snapshot "$DATASET_UTIL/send@snap2"
152152
log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM"
153153
log_mustnot user_run $STAFF1 \
154-
eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
154+
"zfs receive $DATASET_TEST/received < $ZSTREAM"
155155
log_mustnot datasetexists "$DATASET_TEST/received@snap2"
156156
log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1"
157157
# Verify snapshot_limit is *not* enforced for users allowed to change it
@@ -160,7 +160,7 @@ log_must zfs snapshot "$DATASET_UTIL/send@snap3"
160160
log_must eval "zfs send -i @snap2 $DATASET_UTIL/send@snap3 > $ZSTREAM"
161161
log_must zfs allow -l $STAFF1 'snapshot_limit' "$DATASET_TEST"
162162
log_must user_run $STAFF1 \
163-
eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
163+
"zfs receive $DATASET_TEST/received < $ZSTREAM"
164164
log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "3"
165165

166166
log_pass "'snapshot_limit' property is enforced"

tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,40 @@
4343
# 4. Check that we're unable to write an xattr as a non-root user
4444
#
4545

46-
function cleanup {
47-
48-
log_must rm $TESTDIR/myfile.$$
49-
46+
function cleanup
47+
{
48+
rm -f $testfile $tempfile
5049
}
5150

5251
log_assert "read/write xattr on a file with no permissions fails"
5352
log_onexit cleanup
5453

55-
log_must touch $TESTDIR/myfile.$$
56-
create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
54+
typeset testfile=$TESTDIR/testfile.$$
55+
typeset tempfile=/tmp/tempfile.$$
56+
57+
log_must touch $testfile
58+
create_xattr $testfile passwd /etc/passwd
5759

58-
log_must chmod 000 $TESTDIR/myfile.$$
60+
log_must chmod 000 $testfile
5961
if is_illumos; then
60-
log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cat passwd"
61-
log_mustnot su $ZFS_USER -c "runat $TESTDIR/myfile.$$ cp /etc/passwd ."
62+
log_mustnot su $ZFS_USER -c "runat $testfile cat passwd"
63+
log_mustnot su $ZFS_USER -c "runat $testfile cp /etc/passwd ."
6264
else
63-
user_run $ZFS_USER eval \
64-
"get_xattr passwd $TESTDIR/myfile.$$ >/tmp/passwd.$$"
65-
log_mustnot diff /etc/passwd /tmp/passwd.$$
66-
log_must rm /tmp/passwd.$$
65+
log_mustnot user_run $ZFS_USER "
66+
. $STF_SUITE/include/libtest.shlib
67+
get_xattr passwd $testfile >$tempfile
68+
"
69+
log_mustnot diff -q /etc/passwd $tempfile
70+
log_must rm $tempfile
6771

68-
user_run $ZFS_USER eval \
69-
"set_xattr_stdin passwd $TESTDIR/myfile.$$ </etc/group"
70-
log_must chmod 644 $TESTDIR/myfile.$$
71-
get_xattr passwd $TESTDIR/myfile.$$ >/tmp/passwd.$$
72-
log_must diff /etc/passwd /tmp/passwd.$$
73-
log_must rm /tmp/passwd.$$
72+
log_mustnot user_run $ZFS_USER "
73+
. $STF_SUITE/include/libtest.shlib
74+
set_xattr_stdin passwd $testfile </etc/group
75+
"
76+
log_must chmod 644 $testfile
77+
get_xattr passwd $testfile >$tempfile
78+
log_must diff -q /etc/passwd $tempfile
79+
log_must rm $tempfile
7480
fi
7581

7682
log_pass "read/write xattr on a file with no permissions fails"

0 commit comments

Comments
 (0)