chown: fix ownership format string
[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 . ./common/preamble
16 _begin_fstest acl attr auto quick
17
18 # Override the default cleanup function.
19 _cleanup()
20 {
21     cd /
22     _scratch_unmount >/dev/null 2>&1
23 }
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/attr
28
29 nsexec=$here/src/nsexec
30 file=$SCRATCH_MNT/file1
31
32 # real QA test starts here
33 _supported_fs generic
34 # only Linux supports user namespace
35
36 _require_scratch
37 _acl_setup_ids
38 _require_acls
39 _require_ugid_map
40 _require_userns
41 ns_acl1=0
42 ns_acl2=`expr $acl2 - $acl1`
43 ns_acl3=`expr $acl3 - $acl1`
44
45 _getfacl_filter_nsid()
46 {
47     sed \
48        -e "s/user:$ns_acl1/user:nsid1/" \
49        -e "s/user:$ns_acl2/user:nsid2/" \
50        -e "s/user:$ns_acl3/user:nsid3/" \
51        -e "s/group:$ns_acl1/group:nsid1/" \
52        -e "s/group:$ns_acl2/group:nsid2/" \
53        -e "s/group:$ns_acl3/group:nsid3/" \
54        -e "s/: $ns_acl1/: nsid1/" \
55        -e "s/: $ns_acl2/: nsid2/" \
56        -e "s/: $ns_acl3/: nsid3/"
57 }
58
59 _print_getfacls()
60 {
61     echo "From init_user_ns"
62     getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_id
63
64     echo "From user_ns"
65     $nsexec -U -M "0 $acl1 1000" -G "0 $acl1 1000" getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_nsid
66 }
67
68 _scratch_unmount >/dev/null 2>&1
69 echo "*** MKFS ***" >>$seqres.full
70 echo ""             >>$seqres.full
71 _scratch_mkfs       >>$seqres.full 2>&1 || _fail "mkfs failed"
72 _scratch_mount
73
74 touch $file
75 chown $acl1:$acl1 $file
76
77 # set acls from init_user_ns, to be checked from inside the userns
78 setfacl -n -m u:$acl2:rw,g:$acl2:r $file
79 # set acls from inside userns, to be checked from init_user_ns
80 $nsexec -s -U -M "0 $acl1 1000" -G "0 $acl1 1000" setfacl -n -m u:root:rx,g:$ns_acl2:x $file
81
82 _print_getfacls
83
84 echo "*** Remounting ***"
85 echo ""
86 sync
87 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
88
89 _print_getfacls
90
91 _scratch_unmount >/dev/null 2>&1
92 status=0
93 exit