fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 318
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2013 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 318
6 #
7 # Check get/set ACLs to/from disk with a user namespace. A new file
8 # will be created and ACLs set on it from both inside a userns and
9 # from init_user_ns. We check that the ACL is is correct from both
10 # inside the userns and also from init_user_ns. We will then unmount
11 # and remount the file system and check the ACL from both inside the
12 # userns and from init_user_ns to show that the correct uid/gid in
13 # the ACL was flushed and brought back from disk.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22
23 _cleanup()
24 {
25     cd /
26     _scratch_unmount >/dev/null 2>&1
27 }
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/attr
34
35 nsexec=$here/src/nsexec
36 file=$SCRATCH_MNT/file1
37
38 # real QA test starts here
39 _supported_fs generic
40 # only Linux supports user namespace
41 _supported_os Linux
42
43 rm -f $seqres.full
44
45 _require_scratch
46 _acl_setup_ids
47 _require_acls
48 _require_ugid_map
49 _require_userns
50 ns_acl1=0
51 ns_acl2=`expr $acl2 - $acl1`
52 ns_acl3=`expr $acl3 - $acl1`
53
54 _getfacl_filter_nsid()
55 {
56     sed \
57        -e "s/user:$ns_acl1/user:nsid1/" \
58        -e "s/user:$ns_acl2/user:nsid2/" \
59        -e "s/user:$ns_acl3/user:nsid3/" \
60        -e "s/group:$ns_acl1/group:nsid1/" \
61        -e "s/group:$ns_acl2/group:nsid2/" \
62        -e "s/group:$ns_acl3/group:nsid3/" \
63        -e "s/: $ns_acl1/: nsid1/" \
64        -e "s/: $ns_acl2/: nsid2/" \
65        -e "s/: $ns_acl3/: nsid3/"
66 }
67
68 _print_getfacls()
69 {
70     echo "From init_user_ns"
71     getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_id
72
73     echo "From user_ns"
74     $nsexec -U -M "0 $acl1 1000" -G "0 $acl1 1000" getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_nsid
75 }
76
77 _scratch_unmount >/dev/null 2>&1
78 echo "*** MKFS ***" >>$seqres.full
79 echo ""             >>$seqres.full
80 _scratch_mkfs       >>$seqres.full 2>&1 || _fail "mkfs failed"
81 _scratch_mount
82
83 touch $file
84 chown $acl1.$acl1 $file
85
86 # set acls from init_user_ns, to be checked from inside the userns
87 setfacl -n -m u:$acl2:rw,g:$acl2:r $file
88 # set acls from inside userns, to be checked from init_user_ns
89 $nsexec -s -U -M "0 $acl1 1000" -G "0 $acl1 1000" setfacl -n -m u:root:rx,g:$ns_acl2:x $file
90
91 _print_getfacls
92
93 echo "*** Remounting ***"
94 echo ""
95 sync
96 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
97
98 _print_getfacls
99
100 _scratch_unmount >/dev/null 2>&1
101 status=0
102 exit