upload tizen1.0 source
[framework/security/smack.git] / smack-def
1 #! /bin/bash
2 #
3 # Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
4 # Copyright (C) 2011 Nokia 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, version 2.
9 #
10 #      This program is distributed in the hope that it will be useful, but
11 #      WITHOUT ANY WARRANTY; without even the implied warranty of
12 #      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 #      General Public License for more details.
14 #
15 #      You should have received a copy of the GNU General Public
16 #      License along with this program; if not, write to the Free Software
17 #      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 #      02110-1301 USA
19 #
20 # Authors:
21 #      Casey Schaufler <casey@schaufler-ca.com>
22 #
23 # chkconfig: 2345 08 08
24 # description: Initialize Smack configuration
25 ### BEGIN INIT INFO
26 # Provides: smack
27 # Required-Start: $local_fs
28 # Required-Stop:
29 # Default-Start: 2 3 4 5
30 # Default-Stop: 0 1 6
31 # Short-Description: Set up Smack configuration
32 # Description: Smack is an implementation of Mandatory Access Control. \
33 #              The access control rules are loaded using the smackfs \
34 #              pseudo-filesystem.
35 ### END INIT INFO
36
37 #
38 # Make sure that /smack is mounted
39 # Ensure that the mount point is a directory
40 #
41 mount_smack() {
42         if [ ! -e /smack ] ; then
43                 /bin/mkdir /smack
44         fi
45
46         if [ ! -d /smack ] ; then
47                 if [ -e /smack ] ; then
48                         /bin/rm -f /smack
49                 fi
50                 /bin/mkdir /smack
51         fi
52
53         /bin/mount smackfs -t smackfs /smack >& /dev/null
54 }
55
56 #
57 # Load any Smack access rules
58 #
59 load_rules() {
60         if [ -f /etc/smack/accesses ] ; then
61                 /sbin/smackload < /etc/smack/accesses
62         fi
63 }
64
65 #
66 # Unload any Smack access rules
67 #
68 unload_rules() {
69         /sbin/smackload -c < /smack/load
70 }
71
72 #
73 # Load any Smack CIPSO mappings
74 #
75 load_cipso() {
76         if [ -f /etc/smack/cipso ] ; then
77                 /sbin/smackcipso < /etc/smack/cipso
78         fi
79 }
80
81 case "$1" in
82    start)
83         mount_smack
84         load_rules
85         load_cipso
86         ;;
87    status)
88         if [ ! -e /smack/load ] ; then
89                 exit 4
90         fi
91         ;;
92    reload|force-reload|restart|try-restart)
93         unload_rules
94         load_rules
95         load_cipso
96         ;;
97    stop)
98         unload_rules
99         ;;
100    *)
101         ;;
102 esac
103
104 exit 0