misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 369
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 369
6 #
7 # RichACL delete test
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
27 # remove previous $seqres.full before test
28 rm -f $seqres.full
29
30 # real QA test starts here
31
32 _supported_fs generic
33
34 _require_scratch
35 _require_scratch_richacl
36 _require_richacl_prog
37 _require_runas
38
39 _scratch_mkfs_richacl >> $seqres.full
40 _scratch_mount
41
42 cd $SCRATCH_MNT
43
44 r()
45 {
46         echo "--- runas -u 99 -g 99 $*"
47         _runas -u 99 -g 99 -- "$@"
48 }
49
50 umask 022
51
52 chmod go+w .
53 mkdir d1 d2 d3 d4 d5 d6 d7
54 touch d1/f d1/g d2/f d3/f d4/f d5/f d6/f d7/f d7/g d7/h
55 chmod o+w d1/g
56 chown 99 d2
57 chgrp 99 d3
58 chmod g+w d3
59 $SETRICHACL_PROG --set 'u:99:wx::allow' d4
60 $SETRICHACL_PROG --set 'u:99:d::allow' d5
61 $SETRICHACL_PROG --set 'u:99:xd::allow' d6
62 $SETRICHACL_PROG --set 'u:99:D::allow' d7/f d7/g d7/h
63 chmod 664 d7/g
64
65 mkdir s2 s3 s4 s5 s6 s7
66 chmod +t s2 s3 s4 s5 s6 s7
67 touch s2/f s3/f s4/f s5/f s6/f s7/f s7/g s7/h
68 chown 99 s2
69 chgrp 99 s3
70 chmod g+w s3
71 $SETRICHACL_PROG --set 'u:99:wx::allow' s4
72 $SETRICHACL_PROG --set 'u:99:d::allow' s5
73 $SETRICHACL_PROG --set 'u:99:xd::allow' s6
74 $SETRICHACL_PROG --set 'u:99:D::allow' s7/f s7/g s7/h
75 chmod 664 s7/g
76
77 # Cannot delete files with no or only with write permissions on the directory
78 r rm -f d1/f d1/g
79
80 # Can delete files in directories we own
81 r rm -f d2/f s2/f
82
83 # Can delete files in non-sticky directories we have write access to
84 r rm -f d3/f s3/f
85
86 # "Write_data/execute" access does not include delete_child access, so deleting
87 # is not allowed:
88 r rm -f d4/f s4/f
89
90 # "Delete_child" access alone also is not sufficient
91 r rm -f d5/f s5/f
92
93 # "Execute/delete_child" access is sufficient for non-sticky directories
94 r rm -f d6/f s6/f
95
96 # "Delete" access on the child is sufficient, even in sticky directories.
97 r rm -f d7/f s7/f
98
99 # Regression: Delete access must not override add_file / add_subdirectory
100 # access.
101 r touch h
102 r mv -f h d7/
103 r mv -f h s7/
104
105 # A chmod turns off the "delete" permission
106 r rm -f d7/g s7/g
107
108 # success, all done
109 status=0
110 exit