build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / chcon.sh
1 #!/bin/sh
2 # exercise chcon
3
4 # Copyright (C) 2007-2013 Free Software Foundation, Inc.
5
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.
10
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.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
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
25 mkdir -p d/sub/s2 || framework_failure_
26 touch f g d/sub/1 d/sub/2 || framework_failure_
27
28
29 # Set to a specified context.
30 # Use root:object_r:tmp_t:s0.  It is special in that
31 # it works even when mcstransd isn't running.
32 u1=root
33 r1=object_r
34 t1=tmp_t
35 range=s0
36 ctx=$u1:$r1:$t1:$range
37 chcon $ctx f || fail=1
38 stat --printf='f|%C\n' f > out || fail=1
39
40 # Use --reference.
41 chcon --ref=f g || fail=1
42 stat --printf='g|%C\n' g >> out || fail=1
43
44 # Change the individual parts of the context, one by one.
45 u2=user_u
46 r2=object_r
47 t2=file_t
48 for i in --user=$u2 --role=$r2 --type=$t2 --range=$range; do
49   chcon $i f || fail=1
50   stat --printf="f|$i|"'%C\n' f >> out || fail=1
51 done
52
53 # Same, but change back using the short-named options.
54 for i in -u$u1 -r$r1 -t$t1; do
55   chcon $i f || fail=1
56   stat --printf="f|$i|"'%C\n' f >> out || fail=1
57 done
58
59 cat <<EOF > exp || fail=1
60 f|$ctx
61 g|$ctx
62 f|--user=$u2|$u2:$r1:$t1:$range
63 f|--role=$r2|$u2:$r2:$t1:$range
64 f|--type=$t2|$u2:$r2:$t2:$range
65 f|--range=$range|$u2:$r2:$t2:$range
66 f|-uroot|root:object_r:file_t:$range
67 f|-robject_r|root:object_r:file_t:$range
68 f|-ttmp_t|root:object_r:tmp_t:$range
69 EOF
70
71 compare exp out || fail=1
72
73 chcon --verbose -u$u1 f > out || fail=1
74 echo "changing security context of 'f'" > exp
75 compare exp out || fail=1
76
77 Exit $fail