source code open - smack
[framework/security/smack.git] / init / smack.rc
1 #!/bin/sh
2 #
3 # Copyright (c) 2012 Intel Corporation
4 #
5 #      This program is free software; you can redistribute it and/or modify
6 #      it under the terms of the GNU General Public License as published by
7 #      the Free Software Foundation, version 2.
8 #
9 #      This program is distributed in the hope that it will be useful, but
10 #      WITHOUT ANY WARRANTY; without even the implied warranty of
11 #      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 #      General Public License for more details.
13 #
14 #      You should have received a copy of the GNU General Public
15 #      License along with this program; if not, write to the Free Software
16 #      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 #      02110-1301 USA
18 #
19 # Authors:
20 #      Brian McGillion <brian.mcgillion@intel.com>
21 #
22 # Description: Initialize Smack policy
23 #
24 ### BEGIN INIT INFO
25 # Provides:          smack-utils
26 # Required-Start:    $remote_fs $local_fs
27 # Required-Stop:     $remote_fs $local_fs
28 # Default-Start:     2 3 4 5
29 # Default-Stop:      0 1 6
30 # Short-Description: Utility to set up SMACK policy
31 # Description:       SMACK is a simplified mandatory access control \
32 #                    framework using an the LSM interface of the kernel. \
33 #                    The access control rules are loaded using smackfs \
34 #                    pseudo-filesystem.
35 ### END INIT INFO
36
37 PATH=/sbin:/usr/sbin:/bin:/usr/bin
38
39 PROG=smack-utils
40 DESC="Simplified MAC Kernel (SMACK)"
41 SMACKCTL=/usr/bin/smackctl
42
43 # Check kernel whether smack is supported
44 [ `grep -c smack /proc/filesystems` -eq 1 ] || exit 0
45
46 #
47 # Mount smackfs in /smack
48 #
49 mount_smack() {
50     if [ ! -d /smack ] ; then
51       test -e /smack && rm -f /smack
52       mkdir /smack
53     fi
54     if ! grep -E -qs smackfs /etc/mtab; then
55         mount -t smackfs smackfs /smack > /dev/null 2>&1
56     fi
57 }
58
59 case "$1" in
60    start)
61         echo -n "Starting $DESC ..."
62         mount_smack
63         /usr/bin/smackctl apply
64         echo " done."
65         ;;
66    status)
67         if [ ! -e /smack/load2 ] ; then
68                 exit -1
69         fi
70         ;;
71    reload|force-reload|restart|try-restart)
72         echo -n "Reloading $DESC ..."
73         /usr/bin/smackctl clear
74         /usr/bin/smackctl apply
75         echo " done."
76         ;;
77    stop)
78         echo -n "Stopping $DESC ..."
79         /usr/bin/smackctl clear
80         echo " done."
81         ;;
82    *)
83         echo $"Usage: $0 {start|stop|reload|force-reload|restart|try-restart|status}"
84         exit 3
85         ;;
86 esac
87
88 exit 0