xref: /onnv-gate/usr/src/uts/common/sys/priv.h (revision 12273:63678502e95e)
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
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * 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*12273SCasper.Dik@Sun.COM  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef	_SYS_PRIV_H
260Sstevel@tonic-gate #define	_SYS_PRIV_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/cred.h>
300Sstevel@tonic-gate #include <sys/priv_names.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate typedef uint32_t priv_chunk_t;
370Sstevel@tonic-gate typedef struct priv_set priv_set_t;
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifdef _KERNEL
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * Kernel type definitions.
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate typedef int priv_ptype_t;
450Sstevel@tonic-gate typedef int priv_t;
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #else /* _KERNEL */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * Userland type definitions.
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #ifdef __STDC__
540Sstevel@tonic-gate typedef const char *priv_ptype_t;
550Sstevel@tonic-gate typedef const char *priv_t;
560Sstevel@tonic-gate #else
570Sstevel@tonic-gate typedef char *priv_ptype_t;
580Sstevel@tonic-gate typedef char *priv_t;
590Sstevel@tonic-gate #endif
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #endif /* _KERNEL */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate  * priv_op_t indicates a privilege operation type
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate typedef enum priv_op {
670Sstevel@tonic-gate 	PRIV_ON,
680Sstevel@tonic-gate 	PRIV_OFF,
690Sstevel@tonic-gate 	PRIV_SET
700Sstevel@tonic-gate } priv_op_t;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * Privilege system call subcodes.
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #define	PRIVSYS_SETPPRIV	0
770Sstevel@tonic-gate #define	PRIVSYS_GETPPRIV	1
780Sstevel@tonic-gate #define	PRIVSYS_GETIMPLINFO	2
790Sstevel@tonic-gate #define	PRIVSYS_SETPFLAGS	3
800Sstevel@tonic-gate #define	PRIVSYS_GETPFLAGS	4
814321Scasper #define	PRIVSYS_ISSETUGID	5
826134Scasper #define	PRIVSYS_KLPD_REG	6
836134Scasper #define	PRIVSYS_KLPD_UNREG	7
84*12273SCasper.Dik@Sun.COM #define	PRIVSYS_PFEXEC_REG	8
85*12273SCasper.Dik@Sun.COM #define	PRIVSYS_PFEXEC_UNREG	9
86*12273SCasper.Dik@Sun.COM 
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * Maximum length of a user defined privilege name.
900Sstevel@tonic-gate  */
910Sstevel@tonic-gate #define	PRIVNAME_MAX		32
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate  * Privilege interface functions for those parts of the kernel that
950Sstevel@tonic-gate  * know nothing of the privilege internals.
960Sstevel@tonic-gate  *
970Sstevel@tonic-gate  * A privilege implementation can have a varying number of sets; sets
980Sstevel@tonic-gate  * consist of a number of priv_chunk_t's and the size is expressed as such.
990Sstevel@tonic-gate  * The privileges can be represented as
1000Sstevel@tonic-gate  *
1010Sstevel@tonic-gate  *		priv_chunk_t privs[info.priv_nsets][info.priv_setsize]
1020Sstevel@tonic-gate  *		... priv_infosize of extra information ...
1030Sstevel@tonic-gate  *
1040Sstevel@tonic-gate  * Extra data contained in the privilege information consists of chunks
1050Sstevel@tonic-gate  * of data with specified size and type all headed by a priv_info_t header
1060Sstevel@tonic-gate  * which defines both the type of information as well as the size of the
1070Sstevel@tonic-gate  * information.  ((char*)&info)+info->priv_info_size should be rounded up
1080Sstevel@tonic-gate  * to point to the next piece of information.
1090Sstevel@tonic-gate  */
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate typedef struct priv_impl_info {
1120Sstevel@tonic-gate 	uint32_t	priv_headersize;	/* sizeof (priv_impl_info) */
1130Sstevel@tonic-gate 	uint32_t	priv_flags;		/* additional flags */
1140Sstevel@tonic-gate 	uint32_t	priv_nsets;		/* number of priv sets */
1150Sstevel@tonic-gate 	uint32_t	priv_setsize;		/* size in priv_chunk_t */
1160Sstevel@tonic-gate 	uint32_t	priv_max;		/* highest actual valid priv */
1170Sstevel@tonic-gate 	uint32_t	priv_infosize;		/* Per proc. additional info */
1180Sstevel@tonic-gate 	uint32_t	priv_globalinfosize;	/* Per system info */
1190Sstevel@tonic-gate } priv_impl_info_t;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate #define	PRIV_IMPL_INFO_SIZE(p) \
1220Sstevel@tonic-gate 			((p)->priv_headersize + (p)->priv_globalinfosize)
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #define	PRIV_PRPRIV_INFO_OFFSET(p) \
1250Sstevel@tonic-gate 		(sizeof (*(p)) + \
1260Sstevel@tonic-gate 		((p)->pr_nsets * (p)->pr_setsize - 1) * sizeof (priv_chunk_t))
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate #define	PRIV_PRPRIV_SIZE(p) \
1290Sstevel@tonic-gate 		(PRIV_PRPRIV_INFO_OFFSET(p) + (p)->pr_infosize)
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * Per credential flags.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate #define	PRIV_DEBUG			0x0001		/* User debugging */
1350Sstevel@tonic-gate #define	PRIV_AWARE			0x0002		/* Is privilege aware */
1360Sstevel@tonic-gate #define	PRIV_AWARE_INHERIT		0x0004		/* Inherit awareness */
1370Sstevel@tonic-gate #define	__PROC_PROTECT			0x0008		/* Private */
1381676Sjpk #define	NET_MAC_AWARE			0x0010		/* Is MAC aware */
1391676Sjpk #define	NET_MAC_AWARE_INHERIT		0x0020		/* Inherit MAC aware */
1409799SCasper.Dik@Sun.COM #define	PRIV_AWARE_RESET		0x0040		/* Reset on setuid() */
1416134Scasper #define	PRIV_XPOLICY			0x0080		/* Extended policy */
142*12273SCasper.Dik@Sun.COM #define	PRIV_PFEXEC			0x0100		/* As if pfexec'ed */
1431676Sjpk 
1441676Sjpk /* user-settable flags: */
1456134Scasper #define	PRIV_USER	(PRIV_DEBUG | NET_MAC_AWARE | NET_MAC_AWARE_INHERIT |\
146*12273SCasper.Dik@Sun.COM 			    PRIV_XPOLICY | PRIV_AWARE_RESET | PRIV_PFEXEC)
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate /*
1490Sstevel@tonic-gate  * Header of the privilege info data structure; multiple structures can
1500Sstevel@tonic-gate  * follow the privilege sets and priv_impl_info structures.
1510Sstevel@tonic-gate  */
1520Sstevel@tonic-gate typedef struct priv_info {
1530Sstevel@tonic-gate 	uint32_t	priv_info_type;
1540Sstevel@tonic-gate 	uint32_t	priv_info_size;
1550Sstevel@tonic-gate } priv_info_t;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate typedef struct priv_info_uint {
1580Sstevel@tonic-gate 	priv_info_t	info;
1590Sstevel@tonic-gate 	uint_t		val;
1600Sstevel@tonic-gate } priv_info_uint_t;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate /*
1630Sstevel@tonic-gate  * Global privilege set information item; the actual size of the array is
1640Sstevel@tonic-gate  * {priv_setsize}.
1650Sstevel@tonic-gate  */
1660Sstevel@tonic-gate typedef struct priv_info_set {
1670Sstevel@tonic-gate 	priv_info_t	info;
1680Sstevel@tonic-gate 	priv_chunk_t	set[1];
1690Sstevel@tonic-gate } priv_info_set_t;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * names[1] is a place holder which can contain multiple NUL terminated,
1730Sstevel@tonic-gate  * non-empty strings.
1740Sstevel@tonic-gate  */
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate typedef struct priv_info_names {
1770Sstevel@tonic-gate 	priv_info_t	info;
1780Sstevel@tonic-gate 	int		cnt;		/* number of strings */
1790Sstevel@tonic-gate 	char		names[1];	/* "string1\0string2\0 ..stringN\0" */
1800Sstevel@tonic-gate } priv_info_names_t;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate /*
1830Sstevel@tonic-gate  * Privilege information types.
1840Sstevel@tonic-gate  */
1850Sstevel@tonic-gate #define	PRIV_INFO_SETNAMES		0x0001
1860Sstevel@tonic-gate #define	PRIV_INFO_PRIVNAMES		0x0002
1870Sstevel@tonic-gate #define	PRIV_INFO_BASICPRIVS		0x0003
1880Sstevel@tonic-gate #define	PRIV_INFO_FLAGS			0x0004
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate /*
1910Sstevel@tonic-gate  * Special "privileges" used to indicate special conditions in privilege
1920Sstevel@tonic-gate  * debugging/tracing code.
1930Sstevel@tonic-gate  */
1940Sstevel@tonic-gate #define	PRIV_ALL			(-1)	/* All privileges required */
1950Sstevel@tonic-gate #define	PRIV_MULTIPLE			(-2)	/* More than one */
1960Sstevel@tonic-gate #define	PRIV_NONE			(-3)	/* No value */
1970Sstevel@tonic-gate #define	PRIV_ALLZONE			(-4)	/* All privileges in zone */
1980Sstevel@tonic-gate #define	PRIV_GLOBAL			(-5)	/* Must be in global zone */
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate #ifdef _KERNEL
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate #define	PRIV_ALLOC			0x1
2030Sstevel@tonic-gate 
20411537SCasper.Dik@Sun.COM extern int priv_debug;
20511537SCasper.Dik@Sun.COM extern int priv_basic_test;
20611537SCasper.Dik@Sun.COM 
2070Sstevel@tonic-gate struct proc;
2080Sstevel@tonic-gate struct prpriv;
2090Sstevel@tonic-gate struct cred;
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate extern int priv_prgetprivsize(struct prpriv *);
2120Sstevel@tonic-gate extern void cred2prpriv(const struct cred *, struct prpriv *);
2130Sstevel@tonic-gate extern int priv_pr_spriv(struct proc *, struct prpriv *, const struct cred *);
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate extern priv_impl_info_t *priv_hold_implinfo(void);
2160Sstevel@tonic-gate extern void priv_release_implinfo(void);
2170Sstevel@tonic-gate extern size_t priv_get_implinfo_size(void);
2180Sstevel@tonic-gate extern const priv_set_t *priv_getset(const struct cred *, int);
2190Sstevel@tonic-gate extern void priv_getinfo(const struct cred *, void *);
2200Sstevel@tonic-gate extern int priv_getbyname(const char *, uint_t);
2210Sstevel@tonic-gate extern int priv_getsetbyname(const char *, int);
2220Sstevel@tonic-gate extern const char *priv_getbynum(int);
2230Sstevel@tonic-gate extern const char *priv_getsetbynum(int);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate extern void priv_emptyset(priv_set_t *);
2260Sstevel@tonic-gate extern void priv_fillset(priv_set_t *);
2270Sstevel@tonic-gate extern void priv_addset(priv_set_t *, int);
2280Sstevel@tonic-gate extern void priv_delset(priv_set_t *, int);
2290Sstevel@tonic-gate extern boolean_t priv_ismember(const priv_set_t *, int);
2300Sstevel@tonic-gate extern boolean_t priv_isemptyset(const priv_set_t *);
2310Sstevel@tonic-gate extern boolean_t priv_isfullset(const priv_set_t *);
2320Sstevel@tonic-gate extern boolean_t priv_isequalset(const priv_set_t *, const priv_set_t *);
2330Sstevel@tonic-gate extern boolean_t priv_issubset(const priv_set_t *, const priv_set_t *);
2340Sstevel@tonic-gate extern int priv_proc_cred_perm(const struct cred *, struct proc *,
2350Sstevel@tonic-gate 	struct cred **, int);
2360Sstevel@tonic-gate extern void priv_intersect(const priv_set_t *, priv_set_t *);
2370Sstevel@tonic-gate extern void priv_union(const priv_set_t *, priv_set_t *);
2380Sstevel@tonic-gate extern void priv_inverse(priv_set_t *);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate extern void priv_set_PA(cred_t *);
2410Sstevel@tonic-gate extern void priv_adjust_PA(cred_t *);
2429799SCasper.Dik@Sun.COM extern void priv_reset_PA(cred_t *, boolean_t);
2430Sstevel@tonic-gate extern boolean_t priv_can_clear_PA(const cred_t *);
2440Sstevel@tonic-gate 
2451676Sjpk extern int setpflags(uint_t, uint_t, cred_t *);
2461676Sjpk extern uint_t getpflags(uint_t, const cred_t *);
2471676Sjpk 
2480Sstevel@tonic-gate #endif /* _KERNEL */
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate #ifdef	__cplusplus
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate #endif
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate #endif	/* _SYS_PRIV_H */
255