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