Skip to content

Commit b41d867

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. Fix xattr_003_neg by: * include libtest in the user shell * *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 6ba4d1b commit b41d867

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

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)