generic: test for creating duplicate filenames in encrypted dir
[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
42 rm -f $seqres.full
43
44 _require_scratch
45 _acl_setup_ids
46 _require_acls
47 _require_ugid_map
48 _require_userns
49 ns_acl1=0
50 ns_acl2=`expr $acl2 - $acl1`
51 ns_acl3=`expr $acl3 - $acl1`
52
53 _getfacl_filter_nsid()
54 {
55     sed \
56        -e "s/user:$ns_acl1/user:nsid1/" \
57        -e "s/user:$ns_acl2/user:nsid2/" \
58        -e "s/user:$ns_acl3/user:nsid3/" \
59        -e "s/group:$ns_acl1/group:nsid1/" \
60        -e "s/group:$ns_acl2/group:nsid2/" \
61        -e "s/group:$ns_acl3/group:nsid3/" \
62        -e "s/: $ns_acl1/: nsid1/" \
63        -e "s/: $ns_acl2/: nsid2/" \
64        -e "s/: $ns_acl3/: nsid3/"
65 }
66
67 _print_getfacls()
68 {
69     echo "From init_user_ns"
70     getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_id
71
72     echo "From user_ns"
73     $nsexec -U -M "0 $acl1 1000" -G "0 $acl1 1000" getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_nsid
74 }
75
76 _scratch_unmount >/dev/null 2>&1
77 echo "*** MKFS ***" >>$seqres.full
78 echo ""             >>$seqres.full
79 _scratch_mkfs       >>$seqres.full 2>&1 || _fail "mkfs failed"
80 _scratch_mount
81
82 touch $file
83 chown $acl1.$acl1 $file
84
85 # set acls from init_user_ns, to be checked from inside the userns
86 setfacl -n -m u:$acl2:rw,g:$acl2:r $file
87 # set acls from inside userns, to be checked from init_user_ns
88 $nsexec -s -U -M "0 $acl1 1000" -G "0 $acl1 1000" setfacl -n -m u:root:rx,g:$ns_acl2:x $file
89
90 _print_getfacls
91
92 echo "*** Remounting ***"
93 echo ""
94 sync
95 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
96
97 _print_getfacls
98
99 _scratch_unmount >/dev/null 2>&1
100 status=0
101 exit