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