xref: /netbsd/sys/secmodel/bsd44/secmodel_bsd44.c (revision 6550d01e)
1 /* $NetBSD: secmodel_bsd44.c,v 1.13 2009/10/02 18:50:13 elad Exp $ */
2 /*-
3  * Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: secmodel_bsd44.c,v 1.13 2009/10/02 18:50:13 elad Exp $");
31 
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/kauth.h>
35 
36 #include <sys/sysctl.h>
37 #include <sys/mount.h>
38 
39 #include <sys/module.h>
40 
41 #include <secmodel/bsd44/bsd44.h>
42 #include <secmodel/suser/suser.h>
43 #include <secmodel/securelevel/securelevel.h>
44 
45 MODULE(MODULE_CLASS_SECMODEL, secmodel_bsd44, "suser,securelevel");
46 
47 static struct sysctllog *sysctl_bsd44_log;
48 
49 void
50 sysctl_security_bsd44_setup(struct sysctllog **clog)
51 {
52 	const struct sysctlnode *rnode;
53 
54 	sysctl_createv(clog, 0, NULL, &rnode,
55 		       CTLFLAG_PERMANENT,
56 		       CTLTYPE_NODE, "security", NULL,
57 		       NULL, 0, NULL, 0,
58 		       CTL_SECURITY, CTL_EOL);
59 
60 	sysctl_createv(clog, 0, &rnode, &rnode,
61 		       CTLFLAG_PERMANENT,
62 		       CTLTYPE_NODE, "models", NULL,
63 		       NULL, 0, NULL, 0,
64 		       CTL_CREATE, CTL_EOL);
65 
66 	sysctl_createv(clog, 0, &rnode, &rnode,
67 		       CTLFLAG_PERMANENT,
68 		       CTLTYPE_NODE, "bsd44", NULL,
69 		       NULL, 0, NULL, 0,
70 		       CTL_CREATE, CTL_EOL);
71 
72 	sysctl_createv(clog, 0, &rnode, NULL,
73 		       CTLFLAG_PERMANENT,
74 		       CTLTYPE_STRING, "name", NULL,
75 		       NULL, 0, __UNCONST("Traditional NetBSD (derived from 4.4BSD)"), 0,
76 		       CTL_CREATE, CTL_EOL);
77 }
78 
79 void
80 secmodel_bsd44_init(void)
81 {
82 	secmodel_suser_init();
83 	secmodel_securelevel_init();
84 }
85 
86 void
87 secmodel_bsd44_start(void)
88 {
89 	secmodel_suser_start();
90 	secmodel_securelevel_start();
91 
92 	/* secmodel_register(); */
93 }
94 
95 void
96 secmodel_bsd44_stop(void)
97 {
98 	secmodel_suser_stop();
99 	secmodel_securelevel_stop();
100 
101 	/* secmodel_deregister(); */
102 }
103 
104 static int
105 secmodel_bsd44_modcmd(modcmd_t cmd, void *arg)
106 {
107 	int error = 0;
108 
109 	switch (cmd) {
110 	case MODULE_CMD_INIT:
111 		secmodel_bsd44_init();
112 		secmodel_bsd44_start();
113 		sysctl_security_bsd44_setup(&sysctl_bsd44_log);
114 		break;
115 
116 	case MODULE_CMD_FINI:
117 		sysctl_teardown(&sysctl_bsd44_log);
118 		secmodel_bsd44_stop();
119 		break;
120 
121 	default:
122 		error = ENOTTY;
123 		break;
124 	}
125 
126 	return error;
127 }
128 
129