1 # Process this file with autom4te to create testsuite. -*- Autotest -*-
3 # Test suite for GNU tar.
4 # Copyright 2012-2014 Free Software Foundation, Inc.
6 # This file is part of GNU tar.
8 # GNU tar is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU tar is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # This is basic test for selinux support (store & restore).
25 AT_SETUP([selinux: basic store/restore])
26 AT_KEYWORDS([xattrs selinux selnx01])
29 AT_XATTRS_UTILS_PREREQ
33 genfile --file dir/file
36 getfattr -h -d -msecurity.selinux dir dir/file dir/link > start
39 chcon -h --user=system_u dir
40 chcon -h --user=unconfined_u dir/file
41 chcon -h --user=system_u dir/link
43 # archive whole directory including selinux contexts
44 tar --selinux -cf archive.tar dir
49 # ================================================
50 # check if selinux contexts are correctly restored
52 tar --selinux -xf archive.tar
54 # archive for later debugging
55 cp archive.tar archive_origin.tar
57 # check if selinux contexts were restored
58 getfattr -h -d dir dir/file dir/link -msecurity.selinux | \
59 grep -v -e '^#' -e ^$ | cut -d: -f1
61 # ===========================================================================
62 # check if selinux contexts are not restored when --selinux option is missing
64 getfattr -h -d -msecurity.selinux dir dir/file dir/link > with_selinux
67 getfattr -h -d -msecurity.selinux dir dir/file dir/link > without_selinux
69 diff with_selinux without_selinux > diff_with_without
70 if test "$?" -eq "0"; then
71 echo "selinux contexts probably restored while --selinux is off"
74 # =================================================================
75 # check if selinux is not archived when --selinux option is missing
77 tar -cf archive.tar dir
82 # restore (with --selinux)
83 tar --selinux -xf archive.tar dir
85 getfattr -h -d -msecurity.selinux dir dir/file dir/link > final
86 diff start final > final_diff
87 if test "$?" -ne "0"; then
93 [security.selinux="system_u
94 security.selinux="unconfined_u
95 security.selinux="system_u