]> Dogcows Code - chaz/tar/blob - tests/selnx01.at
Add SELinux context store/restore/list support.
[chaz/tar] / tests / selnx01.at
1 # Process this file with autom4te to create testsuite. -*- Autotest -*-
2 #
3 # Test suite for GNU tar.
4 # Copyright (C) 2012 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, or (at your option)
9 # 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 # Test description:
20 #
21 # This is basic test for selinux support (store & restore).
22
23 AT_SETUP([selinux: basic store/restore])
24 AT_KEYWORDS([xattrs selinux selnx01])
25
26 AT_TAR_CHECK([
27 AT_XATTRS_UTILS_PREREQ
28 AT_SELINUX_PREREQ
29
30 mkdir dir
31 genfile --file dir/file
32 ln -s file dir/link
33
34 getfattr -h -d -msecurity.selinux dir dir/file dir/link > start
35
36 chcon -h --user=system_u dir
37 chcon -h --user=unconfined_u dir/file
38 chcon -h --user=system_u dir/link
39
40 # archive whole directory including selinux contexts
41 tar --selinux -cf archive.tar dir
42
43 # clear the directory
44 rm -rf dir
45
46 # ================================================
47 # check if selinux contexts are correctly restored
48
49 tar --selinux -xf archive.tar
50
51 # archive for later debugging
52 cp archive.tar archive_origin.tar
53
54 # check if selinux contexts were restored
55 getfattr -h -d dir dir/file dir/link -msecurity.selinux | \
56 grep -v -e '^#' -e ^$ | cut -d: -f1
57
58 # ===========================================================================
59 # check if selinux contexts are not restored when --selinux option is missing
60
61 getfattr -h -d -msecurity.selinux dir dir/file dir/link > with_selinux
62 rm -rf dir
63 tar -xf archive.tar
64 getfattr -h -d -msecurity.selinux dir dir/file dir/link > without_selinux
65
66 diff with_selinux without_selinux > diff_with_without
67 if test "$?" -eq "0"; then
68 echo "selinux contexts probably restored while --selinux is off"
69 fi
70
71 # =================================================================
72 # check if selinux is not archived when --selinux option is missing
73
74 tar -cf archive.tar dir
75
76 # clear the directory
77 rm -rf dir
78
79 # restore (with --selinux)
80 tar --selinux -xf archive.tar dir
81
82 getfattr -h -d -msecurity.selinux dir dir/file dir/link > final
83 diff start final > final_diff
84 if test "$?" -ne "0"; then
85 echo "bad result"
86 fi
87
88 ],
89 [0],
90 [security.selinux="system_u
91 security.selinux="unconfined_u
92 security.selinux="system_u
93 ])
94
95 AT_CLEANUP
This page took 0.043071 seconds and 5 git commands to generate.