Imported Upstream version 20081130
[ltp-debian.git] / testcases / audit-test / trustedprograms / tests / test_mount_context_ext3.bash
blob0d45cb60757f680eab14a188acecac831de689b0
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 overide the context on ext3
21 source tp_mount_functions.bash || exit 2
23 # create a loopback ext3 filesystem.
24 # separate losetup from mount so that context= only applies to the mount.
25 dd if=/dev/zero of=$tmp1 count=0 bs=1 seek=100M || exit_error "dd failed"
26 mkfs.ext3 -F $tmp1 || exit_error "mkfs.ext3 failed"
27 unset loop
28 prepend_cleanup 'losetup -d $loop'
29 loop=$(losetup -f) || exit_error "losetup -f failed"
30 losetup $loop $tmp1
32 # mount ext3fs on a temporary directory location.
33 # collect the context of the root inode of this filesystem.
34 prepend_cleanup 'umount -l $mnt'
35 mount $loop $mnt || exit_error "mount $loop failed"
36 context1=$(get_fsobj_context $mnt/.)
37 umount $mnt
39 # mount ext2fs using -o context= to force a context.
40 # collect the context of the root inode of this filesystem.
41 mount -o context=staff_u:object_r:lspp_harness_tmpfs_t:s1:c1 \
42 $loop $mnt || exit_error "mount $loop failed"
43 context2=$(get_fsobj_context $mnt/.)
44 umount $mnt
46 # make sure context2 at least contains something that looks like a context
47 [[ $context2 == *:* ]] || exit_error "context2=$context2"
49 # the two contexts should differ; quote RHS to guard against globs
50 [[ $context1 != "$context2" ]] || exit_fail "both contexts are $context1"
52 exit_pass