xref: /illumos-gate/usr/src/lib/libc/inc/priv_private.h (revision e3895e32)
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
5*e3895e32Scasper  * Common Development and Distribution License (the "License").
6*e3895e32Scasper  * 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  */
217c478bd9Sstevel@tonic-gate /*
22*e3895e32Scasper  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _PRIV_PRIVATE_H
277c478bd9Sstevel@tonic-gate #define	_PRIV_PRIVATE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/priv.h>
337c478bd9Sstevel@tonic-gate #include <limits.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Libc private privilege data.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef __cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	LOADPRIVDATA(d)		if ((d = privdata) == NULL) d = __priv_getdata()
447c478bd9Sstevel@tonic-gate #define	GETPRIVDATA()		(privdata == NULL ? __priv_getdata() : privdata)
457c478bd9Sstevel@tonic-gate #define	LOCKPRIVDATA()		{ \
46*e3895e32Scasper 					/* Data already allocated */ \
47*e3895e32Scasper 					(void) lock_data(); \
487c478bd9Sstevel@tonic-gate 					(void) refresh_data(); \
497c478bd9Sstevel@tonic-gate 				}
507c478bd9Sstevel@tonic-gate #define	UNLOCKPRIVDATA()	unlock_data()
517c478bd9Sstevel@tonic-gate #define	WITHPRIVLOCKED(t, b, x)	{ \
527c478bd9Sstevel@tonic-gate 					t __result; \
53*e3895e32Scasper 					if (lock_data() != 0) \
54*e3895e32Scasper 						return (b); \
557c478bd9Sstevel@tonic-gate 					__result = (x); \
567c478bd9Sstevel@tonic-gate 					if (__result == (b) && refresh_data()) \
577c478bd9Sstevel@tonic-gate 						__result = (x); \
587c478bd9Sstevel@tonic-gate 					unlock_data(); \
597c478bd9Sstevel@tonic-gate 					return (__result); \
607c478bd9Sstevel@tonic-gate 				}
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Privilege mask macros.
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate #define	__NBWRD		(CHAR_BIT * sizeof (priv_chunk_t))
667c478bd9Sstevel@tonic-gate #define	privmask(n)	(1 << ((__NBWRD - 1) - ((n) % __NBWRD)))
677c478bd9Sstevel@tonic-gate #define	privword(n)	((n)/__NBWRD)
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Same as the functions, but for numeric privileges.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	PRIV_ADDSET(a, p)	((priv_chunk_t *)(a))[privword(p)] |= \
737c478bd9Sstevel@tonic-gate 							privmask(p)
747c478bd9Sstevel@tonic-gate #define	PRIV_DELSET(a, p)	((priv_chunk_t *)(a))[privword(p)] &= \
757c478bd9Sstevel@tonic-gate 							~privmask(p)
767c478bd9Sstevel@tonic-gate #define	PRIV_ISMEMBER(a, p)	((((priv_chunk_t *)(a))[privword(p)] & \
777c478bd9Sstevel@tonic-gate 							privmask(p)) != 0)
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * The structure is static except for the setsort, privnames and nprivs
817c478bd9Sstevel@tonic-gate  * field.  The pinfo structure initially has sufficient room and the kernel
827c478bd9Sstevel@tonic-gate  * guarantees no offset changes so we can copy a new structure on top of it.
837c478bd9Sstevel@tonic-gate  * The locking stratgegy is this: we lock it when we need to reference any
847c478bd9Sstevel@tonic-gate  * of the volatile fields.
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate typedef struct priv_data {
877c478bd9Sstevel@tonic-gate 	size_t			pd_setsize;		/* In bytes */
887c478bd9Sstevel@tonic-gate 	int			pd_nsets, pd_nprivs;
897c478bd9Sstevel@tonic-gate 	uint32_t		pd_ucredsize;
907c478bd9Sstevel@tonic-gate 	char  			**pd_setnames;
917c478bd9Sstevel@tonic-gate 	char			**pd_privnames;
927c478bd9Sstevel@tonic-gate 	int			*pd_setsort;
937c478bd9Sstevel@tonic-gate 	priv_impl_info_t 	*pd_pinfo;
947c478bd9Sstevel@tonic-gate 	priv_set_t		*pd_basicset;
957c478bd9Sstevel@tonic-gate 	priv_set_t		*pd_zoneset;
967c478bd9Sstevel@tonic-gate } priv_data_t;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate extern priv_data_t *__priv_getdata(void);
997c478bd9Sstevel@tonic-gate extern priv_data_t *__priv_parse_info(priv_impl_info_t *);
1007c478bd9Sstevel@tonic-gate extern void __priv_free_info(priv_data_t *);
1017c478bd9Sstevel@tonic-gate extern priv_data_t *privdata;
1027c478bd9Sstevel@tonic-gate 
103*e3895e32Scasper extern int lock_data(void);
1047c478bd9Sstevel@tonic-gate extern boolean_t refresh_data(void);
1057c478bd9Sstevel@tonic-gate extern void unlock_data(void);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate extern boolean_t __priv_isemptyset(priv_data_t *, const priv_set_t *);
1087c478bd9Sstevel@tonic-gate extern boolean_t __priv_isfullset(priv_data_t *, const priv_set_t *);
1097c478bd9Sstevel@tonic-gate extern boolean_t __priv_issubset(priv_data_t *, const priv_set_t *,
1107c478bd9Sstevel@tonic-gate 				const priv_set_t *);
1117c478bd9Sstevel@tonic-gate extern const char *__priv_getbynum(const priv_data_t *, int);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate extern int getprivinfo(priv_impl_info_t *, size_t);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate extern priv_set_t *priv_basic(void);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate #endif
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #endif /* _PRIV_PRIVATE_H */
122