• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2################################################################################
3##                                                                            ##
4## Copyright (C) 2009 IBM Corporation                                         ##
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 2 of the License, or          ##
9## (at your option) any later version.                                        ##
10##                                                                            ##
11## This program is distributed in the hope that it will be useful, but        ##
12## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
14## for more details.                                                          ##
15##                                                                            ##
16## You should have received a copy of the GNU General Public License          ##
17## along with this program;  if not, write to the Free Software Foundation,   ##
18## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
19##                                                                            ##
20################################################################################
21#
22# File :        ima_setup.sh
23#
24# Description:  setup/cleanup routines for the integrity tests.
25#
26# Author:       Mimi Zohar, zohar@ibm.vnet.ibm.com
27################################################################################
28. test.sh
29mount_sysfs()
30{
31	SYSFS=$(mount 2>/dev/null | awk '$5 == "sysfs" { print $3 }')
32	if [ "x$SYSFS" = x ] ; then
33
34		SYSFS=/sys
35
36		test -d $SYSFS || mkdir -p $SYSFS 2>/dev/null
37		if [ $? -ne 0 ] ; then
38			tst_brkm TBROK "Failed to mkdir $SYSFS"
39		fi
40		if ! mount -t sysfs sysfs $SYSFS 2>/dev/null ; then
41			tst_brkm TBROK "Failed to mount $SYSFS"
42		fi
43
44	fi
45}
46
47mount_securityfs()
48{
49	SECURITYFS=$(mount 2>/dev/null | awk '$5 == "securityfs" { print $3 }')
50	if [ "x$SECURITYFS" = x ] ; then
51
52		SECURITYFS="$SYSFS/kernel/security"
53
54		test -d $SECURITYFS || mkdir -p $SECURITYFS 2>/dev/null
55		if [ $? -ne 0 ] ; then
56			tst_brkm TBROK "Failed to mkdir $SECURITYFS"
57		fi
58		if ! mount -t securityfs securityfs $SECURITYFS 2>/dev/null ; then
59			tst_brkm TBROK "Failed to mount $SECURITYFS"
60		fi
61
62	fi
63}
64
65setup()
66{
67	tst_require_root
68
69	tst_tmpdir
70
71	mount_sysfs
72
73	# mount securityfs if it is not already mounted
74	mount_securityfs
75
76	# IMA must be configured in the kernel
77	IMA_DIR=$SECURITYFS/ima
78	if [ ! -d "$IMA_DIR" ]; then
79		tst_brkm TCONF "IMA not enabled in kernel"
80	fi
81}
82
83cleanup()
84{
85	tst_rmdir
86}
87