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