doc: mention cksum error fix with cpu feature checks changes
[coreutils.git] / tests / misc / chcon.sh
blob7028a95e1c0ee884bba385ac3e3f4cde24e61b31
1 #!/bin/sh
2 # exercise chcon
4 # Copyright (C) 2007-2023 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ chcon
21 require_root_
22 require_selinux_
23 skip_if_mcstransd_is_running_
24 mls_enabled_ || skip_ 'MLS is disabled'
26 mkdir -p d/sub/s2 || framework_failure_
27 touch f g d/sub/1 d/sub/2 || framework_failure_
30 # Set to a specified context.
31 # Use root:object_r:tmp_t:s0. It is special in that
32 # it works even when mcstransd isn't running.
33 u1=root
34 r1=object_r
35 t1=tmp_t
36 range=s0
37 ctx=$u1:$r1:$t1:$range
38 chcon $ctx f || skip_ "Failed to set context: $ctx"
39 stat --printf='f|%C\n' f > out || fail=1
41 # Use --reference.
42 chcon --ref=f g || fail=1
43 stat --printf='g|%C\n' g >> out || fail=1
45 # Change the individual parts of the context, one by one.
46 u2=user_u
47 r2=object_r
48 t2=unlabeled_t
49 for i in --user=$u2 --role=$r2 --type=$t2 --range=$range; do
50 chcon $i f || fail=1
51 stat --printf="f|$i|"'%C\n' f >> out || fail=1
52 done
54 # Same, but change back using the short-named options.
55 for i in -u$u1 -r$r1 -t$t1; do
56 chcon $i f || fail=1
57 stat --printf="f|$i|"'%C\n' f >> out || fail=1
58 done
60 cat <<EOF > exp || framework_failure_
61 f|$ctx
62 g|$ctx
63 f|--user=$u2|$u2:$r1:$t1:$range
64 f|--role=$r2|$u2:$r2:$t1:$range
65 f|--type=$t2|$u2:$r2:$t2:$range
66 f|--range=$range|$u2:$r2:$t2:$range
67 f|-uroot|root:object_r:$t2:$range
68 f|-robject_r|root:object_r:$t2:$range
69 f|-ttmp_t|root:object_r:tmp_t:$range
70 EOF
72 compare exp out || fail=1
74 chcon --verbose -u$u1 f > out || fail=1
75 echo "changing security context of 'f'" > exp || framework_failure_
76 compare exp out || fail=1
78 Exit $fail