The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/security/mac_label.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2004 Networks Associates Technology, Inc.
    3  * Copyright (c) 2005 SPARTA, Inc.
    4  * All rights reserved.
    5  *
    6  * This software was developed for the FreeBSD Project in part by Network
    7  * Associates Laboratories, the Security Research Division of Network
    8  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
    9  * as part of the DARPA CHATS research program.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  */
   32 
   33 #include <kern/zalloc.h>
   34 #include <security/_label.h>
   35 #include <sys/param.h>
   36 #include <sys/queue.h>
   37 #include <sys/systm.h>
   38 #include <security/mac_internal.h>
   39 
   40 static zone_t zone_label;
   41 
   42 void
   43 mac_labelzone_init(void)
   44 {
   45 
   46         zone_label = zinit(sizeof(struct label),
   47             8192 * sizeof(struct label),
   48             sizeof(struct label), "MAC Labels");
   49         zone_change(zone_label, Z_EXPAND, TRUE);
   50         zone_change(zone_label, Z_EXHAUST, FALSE);
   51 }
   52 
   53 struct label *
   54 mac_labelzone_alloc(int flags)
   55 {
   56         struct label *l;
   57 
   58         if (flags & MAC_NOWAIT) 
   59                 l = (struct label *) zalloc_noblock(zone_label);
   60         else
   61                 l = (struct label *) zalloc(zone_label);
   62         if (l == NULL)
   63                 return (NULL);
   64 
   65         bzero(l, sizeof(struct label));
   66         l->l_flags = MAC_FLAG_INITIALIZED;
   67         return (l);
   68 }
   69 
   70 void
   71 mac_labelzone_free(struct label *l)
   72 {
   73 
   74         if (l == NULL)
   75                 panic("Free of NULL MAC label\n");
   76 
   77         if ((l->l_flags & MAC_FLAG_INITIALIZED) == 0)
   78                 panic("Free of uninitialized label\n");
   79         bzero(l, sizeof(struct label));
   80         zfree(zone_label, l);
   81 }
   82 
   83 /*
   84  * Functions used by policy modules to get and set label values.
   85  */
   86 intptr_t
   87 mac_label_get(struct label *l, int slot)
   88 {
   89         KASSERT(l != NULL, ("mac_label_get: NULL label"));
   90 
   91         return ((intptr_t) (l->l_perpolicy[slot].l_ptr));
   92 }
   93 
   94 void
   95 mac_label_set(struct label *l, int slot, intptr_t v)
   96 {
   97         KASSERT(l != NULL, ("mac_label_set: NULL label"));
   98 
   99         l->l_perpolicy[slot].l_ptr = (void *) v;
  100 }
  101 

Cache object: 422ae9a6bea1adb4825cf25d70e98e68


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.