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
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.
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
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.
49 for i
in --user=$u2 --role=$r2 --type=$t2 --range=$range; do
51 stat
--printf="f|$i|"'%C\n' f
>> out || fail
=1
54 # Same, but change back using the short-named options.
55 for i
in -u$u1 -r$r1 -t$t1; do
57 stat
--printf="f|$i|"'%C\n' f
>> out || fail
=1
60 cat <<EOF > exp || framework_failure_
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
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