1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _PRIV_PRIVATE_H 27 #define _PRIV_PRIVATE_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/types.h> 32 #include <sys/priv.h> 33 #include <limits.h> 34 35 /* 36 * Libc private privilege data. 37 */ 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #define LOADPRIVDATA(d) if ((d = privdata) == NULL) d = __priv_getdata() 44 #define GETPRIVDATA() (privdata == NULL ? __priv_getdata() : privdata) 45 #define LOCKPRIVDATA() { \ 46 /* Data already allocated */ \ 47 (void) lock_data(); \ 48 (void) refresh_data(); \ 49 } 50 #define UNLOCKPRIVDATA() unlock_data() 51 #define WITHPRIVLOCKED(t, b, x) { \ 52 t __result; \ 53 if (lock_data() != 0) \ 54 return (b); \ 55 __result = (x); \ 56 if (__result == (b) && refresh_data()) \ 57 __result = (x); \ 58 unlock_data(); \ 59 return (__result); \ 60 } 61 62 /* 63 * Privilege mask macros. 64 */ 65 #define __NBWRD (CHAR_BIT * sizeof (priv_chunk_t)) 66 #define privmask(n) (1 << ((__NBWRD - 1) - ((n) % __NBWRD))) 67 #define privword(n) ((n)/__NBWRD) 68 69 /* 70 * Same as the functions, but for numeric privileges. 71 */ 72 #define PRIV_ADDSET(a, p) ((priv_chunk_t *)(a))[privword(p)] |= \ 73 privmask(p) 74 #define PRIV_DELSET(a, p) ((priv_chunk_t *)(a))[privword(p)] &= \ 75 ~privmask(p) 76 #define PRIV_ISMEMBER(a, p) ((((priv_chunk_t *)(a))[privword(p)] & \ 77 privmask(p)) != 0) 78 79 /* 80 * The structure is static except for the setsort, privnames and nprivs 81 * field. The pinfo structure initially has sufficient room and the kernel 82 * guarantees no offset changes so we can copy a new structure on top of it. 83 * The locking stratgegy is this: we lock it when we need to reference any 84 * of the volatile fields. 85 */ 86 typedef struct priv_data { 87 size_t pd_setsize; /* In bytes */ 88 int pd_nsets, pd_nprivs; 89 uint32_t pd_ucredsize; 90 char **pd_setnames; 91 char **pd_privnames; 92 int *pd_setsort; 93 priv_impl_info_t *pd_pinfo; 94 priv_set_t *pd_basicset; 95 priv_set_t *pd_zoneset; 96 } priv_data_t; 97 98 extern priv_data_t *__priv_getdata(void); 99 extern priv_data_t *__priv_parse_info(priv_impl_info_t *); 100 extern void __priv_free_info(priv_data_t *); 101 extern priv_data_t *privdata; 102 103 extern int lock_data(void); 104 extern boolean_t refresh_data(void); 105 extern void unlock_data(void); 106 107 extern boolean_t __priv_isemptyset(priv_data_t *, const priv_set_t *); 108 extern boolean_t __priv_isfullset(priv_data_t *, const priv_set_t *); 109 extern boolean_t __priv_issubset(priv_data_t *, const priv_set_t *, 110 const priv_set_t *); 111 extern const char *__priv_getbynum(const priv_data_t *, int); 112 113 extern int getprivinfo(priv_impl_info_t *, size_t); 114 115 extern priv_set_t *priv_basic(void); 116 117 #ifdef __cplusplus 118 } 119 #endif 120 121 #endif /* _PRIV_PRIVATE_H */ 122