xref: /netbsd-src/sys/secmodel/bsd44/secmodel_bsd44.c (revision ba65fde2d7fefa7d39838fa5fa855e62bd606b5e)
1 /* $NetBSD: secmodel_bsd44.c,v 1.15 2011/12/04 19:25:00 jym 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.15 2011/12/04 19:25:00 jym 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 #include <secmodel/extensions/extensions.h>
45 
46 MODULE(MODULE_CLASS_SECMODEL, secmodel_bsd44, "suser,securelevel,extensions");
47 
48 static secmodel_t bsd44_sm;
49 static struct sysctllog *sysctl_bsd44_log;
50 
51 void
52 sysctl_security_bsd44_setup(struct sysctllog **clog)
53 {
54 	const struct sysctlnode *rnode;
55 
56 	sysctl_createv(clog, 0, NULL, &rnode,
57 		       CTLFLAG_PERMANENT,
58 		       CTLTYPE_NODE, "security", NULL,
59 		       NULL, 0, NULL, 0,
60 		       CTL_SECURITY, CTL_EOL);
61 
62 	sysctl_createv(clog, 0, &rnode, &rnode,
63 		       CTLFLAG_PERMANENT,
64 		       CTLTYPE_NODE, "models", NULL,
65 		       NULL, 0, NULL, 0,
66 		       CTL_CREATE, CTL_EOL);
67 
68 	sysctl_createv(clog, 0, &rnode, &rnode,
69 		       CTLFLAG_PERMANENT,
70 		       CTLTYPE_NODE, "bsd44", NULL,
71 		       NULL, 0, NULL, 0,
72 		       CTL_CREATE, CTL_EOL);
73 
74 	sysctl_createv(clog, 0, &rnode, NULL,
75 		       CTLFLAG_PERMANENT,
76 		       CTLTYPE_STRING, "name", NULL,
77 		       NULL, 0,
78 		       __UNCONST(SECMODEL_BSD44_NAME), 0,
79 		       CTL_CREATE, CTL_EOL);
80 }
81 
82 void
83 secmodel_bsd44_init(void)
84 {
85 
86 }
87 
88 void
89 secmodel_bsd44_start(void)
90 {
91 
92 }
93 
94 void
95 secmodel_bsd44_stop(void)
96 {
97 
98 }
99 
100 static int
101 secmodel_bsd44_modcmd(modcmd_t cmd, void *arg)
102 {
103 	int error = 0;
104 
105 	switch (cmd) {
106 	case MODULE_CMD_INIT:
107 
108 		error = secmodel_register(&bsd44_sm,
109 		    SECMODEL_BSD44_ID, SECMODEL_BSD44_NAME,
110 		    NULL, NULL, NULL);
111 		if (error != 0)
112 			printf("secmodel_bsd44_modcmd::init: "
113 			    "secmodel_register returned %d\n", error);
114 
115 		secmodel_bsd44_init();
116 		secmodel_bsd44_start();
117 		sysctl_security_bsd44_setup(&sysctl_bsd44_log);
118 		break;
119 
120 	case MODULE_CMD_FINI:
121 		sysctl_teardown(&sysctl_bsd44_log);
122 		secmodel_bsd44_stop();
123 
124 		error = secmodel_deregister(bsd44_sm);
125 		if (error != 0)
126 			printf("secmodel_bsd44_modcmd::fini: "
127 			    "secmodel_deregister returned %d\n", error);
128 		break;
129 
130 	default:
131 		error = ENOTTY;
132 		break;
133 	}
134 
135 	return error;
136 }
137 
138