Add SELinux context store/restore/list support.
[tar.git] / tests / selnx01.at
blob13a208a9fcd569d4df8011be75cd54ad890dffa9
1 # Process this file with autom4te to create testsuite. -*- Autotest -*-
3 # Test suite for GNU tar.
4 # Copyright (C) 2012 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, or (at your option)
9 # 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 <http://www.gnu.org/licenses/>.
19 # Test description:
21 # This is basic test for selinux support (store & restore).
23 AT_SETUP([selinux: basic store/restore])
24 AT_KEYWORDS([xattrs selinux selnx01])
26 AT_TAR_CHECK([
27 AT_XATTRS_UTILS_PREREQ
28 AT_SELINUX_PREREQ
30 mkdir dir
31 genfile --file dir/file
32 ln -s file dir/link
34 getfattr -h -d -msecurity.selinux dir dir/file dir/link > start
36 chcon -h --user=system_u     dir
37 chcon -h --user=unconfined_u dir/file
38 chcon -h --user=system_u     dir/link
40 # archive whole directory including selinux contexts
41 tar --selinux -cf archive.tar dir
43 # clear the directory
44 rm -rf dir
46 # ================================================
47 # check if selinux contexts are correctly restored
49 tar --selinux -xf archive.tar
51 # archive for later debugging
52 cp archive.tar archive_origin.tar
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
58 # ===========================================================================
59 # check if selinux contexts are not restored when --selinux option is missing
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
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"
71 # =================================================================
72 # check if selinux is not archived when --selinux option is missing
74 tar -cf archive.tar dir
76 # clear the directory
77 rm -rf dir
79 # restore (with --selinux)
80 tar --selinux -xf archive.tar dir
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"
89 [0],
90 [security.selinux="system_u
91 security.selinux="unconfined_u
92 security.selinux="system_u
95 AT_CLEANUP