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