xref: /onnv-gate/usr/src/uts/common/sys/priv.h (revision 1676:37f4a3e2bd99)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1676Sjpk  * Common Development and Distribution License (the "License").
6*1676Sjpk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1676Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_PRIV_H
270Sstevel@tonic-gate #define	_SYS_PRIV_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* from TSOL 8 */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/cred.h>
330Sstevel@tonic-gate #include <sys/priv_names.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate typedef uint32_t priv_chunk_t;
400Sstevel@tonic-gate typedef struct priv_set priv_set_t;
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef _KERNEL
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * Kernel type definitions.
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate typedef int priv_ptype_t;
480Sstevel@tonic-gate typedef int priv_t;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #else /* _KERNEL */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * Userland type definitions.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #ifdef __STDC__
570Sstevel@tonic-gate typedef const char *priv_ptype_t;
580Sstevel@tonic-gate typedef const char *priv_t;
590Sstevel@tonic-gate #else
600Sstevel@tonic-gate typedef char *priv_ptype_t;
610Sstevel@tonic-gate typedef char *priv_t;
620Sstevel@tonic-gate #endif
630Sstevel@tonic-gate 
640Sstevel@tonic-gate #endif /* _KERNEL */
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * priv_op_t indicates a privilege operation type
680Sstevel@tonic-gate  */
690Sstevel@tonic-gate typedef enum priv_op {
700Sstevel@tonic-gate 	PRIV_ON,
710Sstevel@tonic-gate 	PRIV_OFF,
720Sstevel@tonic-gate 	PRIV_SET
730Sstevel@tonic-gate } priv_op_t;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /*
760Sstevel@tonic-gate  * Privilege system call subcodes.
770Sstevel@tonic-gate  */
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	PRIVSYS_SETPPRIV	0
800Sstevel@tonic-gate #define	PRIVSYS_GETPPRIV	1
810Sstevel@tonic-gate #define	PRIVSYS_GETIMPLINFO	2
820Sstevel@tonic-gate #define	PRIVSYS_SETPFLAGS	3
830Sstevel@tonic-gate #define	PRIVSYS_GETPFLAGS	4
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * Maximum length of a user defined privilege name.
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate #define	PRIVNAME_MAX		32
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * Privilege interface functions for those parts of the kernel that
920Sstevel@tonic-gate  * know nothing of the privilege internals.
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  * A privilege implementation can have a varying number of sets; sets
950Sstevel@tonic-gate  * consist of a number of priv_chunk_t's and the size is expressed as such.
960Sstevel@tonic-gate  * The privileges can be represented as
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  *		priv_chunk_t privs[info.priv_nsets][info.priv_setsize]
990Sstevel@tonic-gate  *		... priv_infosize of extra information ...
1000Sstevel@tonic-gate  *
1010Sstevel@tonic-gate  * Extra data contained in the privilege information consists of chunks
1020Sstevel@tonic-gate  * of data with specified size and type all headed by a priv_info_t header
1030Sstevel@tonic-gate  * which defines both the type of information as well as the size of the
1040Sstevel@tonic-gate  * information.  ((char*)&info)+info->priv_info_size should be rounded up
1050Sstevel@tonic-gate  * to point to the next piece of information.
1060Sstevel@tonic-gate  */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate typedef struct priv_impl_info {
1090Sstevel@tonic-gate 	uint32_t	priv_headersize;	/* sizeof (priv_impl_info) */
1100Sstevel@tonic-gate 	uint32_t	priv_flags;		/* additional flags */
1110Sstevel@tonic-gate 	uint32_t	priv_nsets;		/* number of priv sets */
1120Sstevel@tonic-gate 	uint32_t	priv_setsize;		/* size in priv_chunk_t */
1130Sstevel@tonic-gate 	uint32_t	priv_max;		/* highest actual valid priv */
1140Sstevel@tonic-gate 	uint32_t	priv_infosize;		/* Per proc. additional info */
1150Sstevel@tonic-gate 	uint32_t	priv_globalinfosize;	/* Per system info */
1160Sstevel@tonic-gate } priv_impl_info_t;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate #define	PRIV_IMPL_INFO_SIZE(p) \
1190Sstevel@tonic-gate 			((p)->priv_headersize + (p)->priv_globalinfosize)
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate #define	PRIV_PRPRIV_INFO_OFFSET(p) \
1220Sstevel@tonic-gate 		(sizeof (*(p)) + \
1230Sstevel@tonic-gate 		((p)->pr_nsets * (p)->pr_setsize - 1) * sizeof (priv_chunk_t))
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #define	PRIV_PRPRIV_SIZE(p) \
1260Sstevel@tonic-gate 		(PRIV_PRPRIV_INFO_OFFSET(p) + (p)->pr_infosize)
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /*
1290Sstevel@tonic-gate  * Per credential flags.
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate #define	PRIV_DEBUG			0x0001		/* User debugging */
1320Sstevel@tonic-gate #define	PRIV_AWARE			0x0002		/* Is privilege aware */
1330Sstevel@tonic-gate #define	PRIV_AWARE_INHERIT		0x0004		/* Inherit awareness */
1340Sstevel@tonic-gate #define	__PROC_PROTECT			0x0008		/* Private */
135*1676Sjpk #define	NET_MAC_AWARE			0x0010		/* Is MAC aware */
136*1676Sjpk #define	NET_MAC_AWARE_INHERIT		0x0020		/* Inherit MAC aware */
137*1676Sjpk 
138*1676Sjpk /* user-settable flags: */
139*1676Sjpk #define	PRIV_USER	(PRIV_DEBUG | NET_MAC_AWARE | NET_MAC_AWARE_INHERIT)
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * Header of the privilege info data structure; multiple structures can
1430Sstevel@tonic-gate  * follow the privilege sets and priv_impl_info structures.
1440Sstevel@tonic-gate  */
1450Sstevel@tonic-gate typedef struct priv_info {
1460Sstevel@tonic-gate 	uint32_t	priv_info_type;
1470Sstevel@tonic-gate 	uint32_t	priv_info_size;
1480Sstevel@tonic-gate } priv_info_t;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate typedef struct priv_info_uint {
1510Sstevel@tonic-gate 	priv_info_t	info;
1520Sstevel@tonic-gate 	uint_t		val;
1530Sstevel@tonic-gate } priv_info_uint_t;
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate /*
1560Sstevel@tonic-gate  * Global privilege set information item; the actual size of the array is
1570Sstevel@tonic-gate  * {priv_setsize}.
1580Sstevel@tonic-gate  */
1590Sstevel@tonic-gate typedef struct priv_info_set {
1600Sstevel@tonic-gate 	priv_info_t	info;
1610Sstevel@tonic-gate 	priv_chunk_t	set[1];
1620Sstevel@tonic-gate } priv_info_set_t;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate /*
1650Sstevel@tonic-gate  * names[1] is a place holder which can contain multiple NUL terminated,
1660Sstevel@tonic-gate  * non-empty strings.
1670Sstevel@tonic-gate  */
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate typedef struct priv_info_names {
1700Sstevel@tonic-gate 	priv_info_t	info;
1710Sstevel@tonic-gate 	int		cnt;		/* number of strings */
1720Sstevel@tonic-gate 	char		names[1];	/* "string1\0string2\0 ..stringN\0" */
1730Sstevel@tonic-gate } priv_info_names_t;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate  * Privilege information types.
1770Sstevel@tonic-gate  */
1780Sstevel@tonic-gate #define	PRIV_INFO_SETNAMES		0x0001
1790Sstevel@tonic-gate #define	PRIV_INFO_PRIVNAMES		0x0002
1800Sstevel@tonic-gate #define	PRIV_INFO_BASICPRIVS		0x0003
1810Sstevel@tonic-gate #define	PRIV_INFO_FLAGS			0x0004
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate /*
1840Sstevel@tonic-gate  * Special "privileges" used to indicate special conditions in privilege
1850Sstevel@tonic-gate  * debugging/tracing code.
1860Sstevel@tonic-gate  */
1870Sstevel@tonic-gate #define	PRIV_ALL			(-1)	/* All privileges required */
1880Sstevel@tonic-gate #define	PRIV_MULTIPLE			(-2)	/* More than one */
1890Sstevel@tonic-gate #define	PRIV_NONE			(-3)	/* No value */
1900Sstevel@tonic-gate #define	PRIV_ALLZONE			(-4)	/* All privileges in zone */
1910Sstevel@tonic-gate #define	PRIV_GLOBAL			(-5)	/* Must be in global zone */
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #ifdef _KERNEL
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #define	PRIV_ALLOC			0x1
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate struct proc;
1980Sstevel@tonic-gate struct prpriv;
1990Sstevel@tonic-gate struct cred;
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate extern int priv_prgetprivsize(struct prpriv *);
2020Sstevel@tonic-gate extern void cred2prpriv(const struct cred *, struct prpriv *);
2030Sstevel@tonic-gate extern int priv_pr_spriv(struct proc *, struct prpriv *, const struct cred *);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate extern priv_impl_info_t *priv_hold_implinfo(void);
2060Sstevel@tonic-gate extern void priv_release_implinfo(void);
2070Sstevel@tonic-gate extern size_t priv_get_implinfo_size(void);
2080Sstevel@tonic-gate extern const priv_set_t *priv_getset(const struct cred *, int);
2090Sstevel@tonic-gate extern void priv_getinfo(const struct cred *, void *);
2100Sstevel@tonic-gate extern int priv_getbyname(const char *, uint_t);
2110Sstevel@tonic-gate extern int priv_getsetbyname(const char *, int);
2120Sstevel@tonic-gate extern const char *priv_getbynum(int);
2130Sstevel@tonic-gate extern const char *priv_getsetbynum(int);
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate extern void priv_emptyset(priv_set_t *);
2160Sstevel@tonic-gate extern void priv_fillset(priv_set_t *);
2170Sstevel@tonic-gate extern void priv_addset(priv_set_t *, int);
2180Sstevel@tonic-gate extern void priv_delset(priv_set_t *, int);
2190Sstevel@tonic-gate extern boolean_t priv_ismember(const priv_set_t *, int);
2200Sstevel@tonic-gate extern boolean_t priv_isemptyset(const priv_set_t *);
2210Sstevel@tonic-gate extern boolean_t priv_isfullset(const priv_set_t *);
2220Sstevel@tonic-gate extern boolean_t priv_isequalset(const priv_set_t *, const priv_set_t *);
2230Sstevel@tonic-gate extern boolean_t priv_issubset(const priv_set_t *, const priv_set_t *);
2240Sstevel@tonic-gate extern int priv_proc_cred_perm(const struct cred *, struct proc *,
2250Sstevel@tonic-gate 	struct cred **, int);
2260Sstevel@tonic-gate extern void priv_intersect(const priv_set_t *, priv_set_t *);
2270Sstevel@tonic-gate extern void priv_union(const priv_set_t *, priv_set_t *);
2280Sstevel@tonic-gate extern void priv_inverse(priv_set_t *);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate extern void priv_set_PA(cred_t *);
2310Sstevel@tonic-gate extern void priv_adjust_PA(cred_t *);
2320Sstevel@tonic-gate extern boolean_t priv_can_clear_PA(const cred_t *);
2330Sstevel@tonic-gate 
234*1676Sjpk extern int setpflags(uint_t, uint_t, cred_t *);
235*1676Sjpk extern uint_t getpflags(uint_t, const cred_t *);
236*1676Sjpk 
2370Sstevel@tonic-gate #endif /* _KERNEL */
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate #ifdef	__cplusplus
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate #endif
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate #endif	/* _SYS_PRIV_H */
244