xref: /illumos-gate/usr/src/lib/libc/inc/priv_private.h (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5e3895e32Scasper  * Common Development and Distribution License (the "License").
6e3895e32Scasper  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*cb620785Sraf 
227c478bd9Sstevel@tonic-gate /*
23*cb620785Sraf  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _PRIV_PRIVATE_H
287c478bd9Sstevel@tonic-gate #define	_PRIV_PRIVATE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/priv.h>
327c478bd9Sstevel@tonic-gate #include <limits.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Libc private privilege data.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef __cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
42*cb620785Sraf #define	LOADPRIVDATA(d)		d = __priv_getdata()
43*cb620785Sraf #define	GETPRIVDATA()		__priv_getdata()
447c478bd9Sstevel@tonic-gate #define	LOCKPRIVDATA()		{ \
45e3895e32Scasper 					/* Data already allocated */ \
46e3895e32Scasper 					(void) lock_data(); \
477c478bd9Sstevel@tonic-gate 					(void) refresh_data(); \
487c478bd9Sstevel@tonic-gate 				}
497c478bd9Sstevel@tonic-gate #define	UNLOCKPRIVDATA()	unlock_data()
507c478bd9Sstevel@tonic-gate #define	WITHPRIVLOCKED(t, b, x)	{ \
517c478bd9Sstevel@tonic-gate 					t __result; \
52e3895e32Scasper 					if (lock_data() != 0) \
53e3895e32Scasper 						return (b); \
547c478bd9Sstevel@tonic-gate 					__result = (x); \
557c478bd9Sstevel@tonic-gate 					if (__result == (b) && refresh_data()) \
567c478bd9Sstevel@tonic-gate 						__result = (x); \
577c478bd9Sstevel@tonic-gate 					unlock_data(); \
587c478bd9Sstevel@tonic-gate 					return (__result); \
597c478bd9Sstevel@tonic-gate 				}
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Privilege mask macros.
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate #define	__NBWRD		(CHAR_BIT * sizeof (priv_chunk_t))
657c478bd9Sstevel@tonic-gate #define	privmask(n)	(1 << ((__NBWRD - 1) - ((n) % __NBWRD)))
667c478bd9Sstevel@tonic-gate #define	privword(n)	((n)/__NBWRD)
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Same as the functions, but for numeric privileges.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate #define	PRIV_ADDSET(a, p)	((priv_chunk_t *)(a))[privword(p)] |= \
727c478bd9Sstevel@tonic-gate 							privmask(p)
737c478bd9Sstevel@tonic-gate #define	PRIV_DELSET(a, p)	((priv_chunk_t *)(a))[privword(p)] &= \
747c478bd9Sstevel@tonic-gate 							~privmask(p)
757c478bd9Sstevel@tonic-gate #define	PRIV_ISMEMBER(a, p)	((((priv_chunk_t *)(a))[privword(p)] & \
767c478bd9Sstevel@tonic-gate 							privmask(p)) != 0)
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * The structure is static except for the setsort, privnames and nprivs
807c478bd9Sstevel@tonic-gate  * field.  The pinfo structure initially has sufficient room and the kernel
817c478bd9Sstevel@tonic-gate  * guarantees no offset changes so we can copy a new structure on top of it.
827c478bd9Sstevel@tonic-gate  * The locking stratgegy is this: we lock it when we need to reference any
837c478bd9Sstevel@tonic-gate  * of the volatile fields.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate typedef struct priv_data {
867c478bd9Sstevel@tonic-gate 	size_t			pd_setsize;		/* In bytes */
877c478bd9Sstevel@tonic-gate 	int			pd_nsets, pd_nprivs;
887c478bd9Sstevel@tonic-gate 	uint32_t		pd_ucredsize;
897c478bd9Sstevel@tonic-gate 	char  			**pd_setnames;
907c478bd9Sstevel@tonic-gate 	char			**pd_privnames;
917c478bd9Sstevel@tonic-gate 	int			*pd_setsort;
927c478bd9Sstevel@tonic-gate 	priv_impl_info_t 	*pd_pinfo;
937c478bd9Sstevel@tonic-gate 	priv_set_t		*pd_basicset;
947c478bd9Sstevel@tonic-gate 	priv_set_t		*pd_zoneset;
957c478bd9Sstevel@tonic-gate } priv_data_t;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate extern priv_data_t *__priv_getdata(void);
987c478bd9Sstevel@tonic-gate extern priv_data_t *__priv_parse_info(priv_impl_info_t *);
997c478bd9Sstevel@tonic-gate extern void __priv_free_info(priv_data_t *);
1007c478bd9Sstevel@tonic-gate extern priv_data_t *privdata;
1017c478bd9Sstevel@tonic-gate 
102e3895e32Scasper extern int lock_data(void);
1037c478bd9Sstevel@tonic-gate extern boolean_t refresh_data(void);
1047c478bd9Sstevel@tonic-gate extern void unlock_data(void);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate extern boolean_t __priv_isemptyset(priv_data_t *, const priv_set_t *);
1077c478bd9Sstevel@tonic-gate extern boolean_t __priv_isfullset(priv_data_t *, const priv_set_t *);
1087c478bd9Sstevel@tonic-gate extern boolean_t __priv_issubset(priv_data_t *, const priv_set_t *,
1097c478bd9Sstevel@tonic-gate 				const priv_set_t *);
1107c478bd9Sstevel@tonic-gate extern const char *__priv_getbynum(const priv_data_t *, int);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate extern int getprivinfo(priv_impl_info_t *, size_t);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate extern priv_set_t *priv_basic(void);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate #endif
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #endif /* _PRIV_PRIVATE_H */
121