Imported Upstream version 20080930
[ltp-debian.git] / testcases / audit-test / trustedprograms / tests / test_mount_context_tmpfs.bash
blobd90511879acff96164130671b2ca6675f0ce8c1a
1 #!/bin/bash
2 ###############################################################################
3 # (c) Copyright Hewlett-Packard Development Company, L.P., 2005
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of version 2 the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ###############################################################################
18 # PURPOSE:
19 # Verify that mount -o context=foo can override the context on tmpfs
21 source tp_mount_functions.bash || exit 2
23 # mount tmpfs on a temporary directory location.
24 # collect the context of the root inode of this filesystem.
25 prepend_cleanup 'umount -l $mnt'
26 mount -t tmpfs none $mnt || exit_error "mount tmpfs failed"
27 context1=$(get_fsobj_context $mnt/.)
28 umount $mnt
30 # mount tmpfs using -o context= to force a context.
31 # collect the context of the root inode of this filesystem.
32 mount -t tmpfs -o context=staff_u:object_r:lspp_harness_tmpfs_t:s1:c1 \
33 none $mnt || exit_error "mount tmpfs -o context failed"
34 context2=$(get_fsobj_context $mnt/.)
35 umount $mnt
37 # make sure context2 at least contains something that looks like a context
38 [[ $context2 == *:* ]] || exit_error "context2=$context2"
40 # the two contexts should differ; quote RHS to guard against globs
41 [[ $context1 != "$context2" ]] || exit_fail "both contexts are $context1"
43 exit_pass