161dd0429967a22169bfdb873eb17b03548bb356
[xfstests-dev.git] / tests / generic / 355
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat Inc.,  All Rights Reserved.
4 #
5 # FS QA Test 355
6 #
7 # Test clear of suid/sgid on direct write.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 rm -f $seqres.full
29
30 # real QA test starts here
31 _supported_fs generic
32 _require_test
33 _require_user
34 _require_odirect
35
36 testfile=$TEST_DIR/$seq.test
37 rm -f $testfile
38
39 do_io()
40 {
41         su $qa_user -c "$XFS_IO_PROG -d -c 'pwrite 0 4k' $testfile" \
42                 >>$seqres.full
43 }
44
45 echo "Check that suid/sgid bits are cleared after direct write"
46
47 # create testfile and set base ownership & permission
48 echo "this is a test" >> $testfile
49 chmod 644 $testfile
50 chown $qa_user:$qa_user $testfile
51
52 echo "== with no exec perm"
53 chmod ug+s $testfile
54 echo -n "before: "; stat -c '%A' $testfile
55 do_io
56 echo -n "after:  "; stat -c '%A' $testfile
57
58 echo "== with user exec perm"
59 chmod ug+s $testfile
60 chmod u+x $testfile
61 echo -n "before: "; stat -c '%A' $testfile
62 do_io
63 echo -n "after:  "; stat -c '%A' $testfile
64
65 echo "== with group exec perm"
66 chmod ug+s $testfile
67 chmod g+x $testfile
68 chmod u-x $testfile
69 echo -n "before: "; stat -c '%A' $testfile
70 do_io
71 echo -n "after:  "; stat -c '%A' $testfile
72
73 echo "== with user+group exec perm"
74 chmod ug+s $testfile
75 chmod u+x $testfile
76 echo -n "before: "; stat -c '%A' $testfile
77 do_io
78 echo -n "after:  "; stat -c '%A' $testfile
79
80 # success, all done
81 status=0
82 exit