xref: /titanic_51/usr/src/uts/common/sys/ucred.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
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*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * 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*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  * File with private definitions for the ucred structure for use by the
267c478bd9Sstevel@tonic-gate  * kernel and library routines.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_UCRED_H
307c478bd9Sstevel@tonic-gate #define	_SYS_UCRED_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/procfs.h>
367c478bd9Sstevel@tonic-gate #include <sys/cred.h>
377c478bd9Sstevel@tonic-gate #include <sys/priv.h>
38*45916cd2Sjpk #include <sys/tsol/label.h>
39*45916cd2Sjpk #include <sys/tsol/label_macro.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef _KERNEL
427c478bd9Sstevel@tonic-gate #include <c2/audit.h>
437c478bd9Sstevel@tonic-gate #else
447c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifndef _KERNEL
487c478bd9Sstevel@tonic-gate #include <unistd.h>
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
527c478bd9Sstevel@tonic-gate extern "C" {
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || _STRUCTURED_PROC != 0
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * bitness neutral struct
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * Add new fixed fields at the end of the structure.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate struct ucred_s {
647c478bd9Sstevel@tonic-gate 	uint32_t	uc_size;	/* Size of the full structure */
657c478bd9Sstevel@tonic-gate 	uint32_t	uc_credoff;	/* Credential offset: 0 - no cred */
667c478bd9Sstevel@tonic-gate 	uint32_t	uc_privoff;	/* Privilege offset: 0 - no privs */
677c478bd9Sstevel@tonic-gate 	pid_t		uc_pid;		/* Process id */
687c478bd9Sstevel@tonic-gate 	uint32_t	uc_audoff;	/* Audit info offset: 0 - no aud */
697c478bd9Sstevel@tonic-gate 	zoneid_t	uc_zoneid;	/* Zone id */
707c478bd9Sstevel@tonic-gate 	projid_t	uc_projid;	/* Project id */
71*45916cd2Sjpk 	uint32_t	uc_labeloff;	/* label offset: 0 - no label */
727c478bd9Sstevel@tonic-gate 					/* The rest goes here */
737c478bd9Sstevel@tonic-gate };
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* Get the process credentials */
767c478bd9Sstevel@tonic-gate #define	UCCRED(uc)	(prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \
777c478bd9Sstevel@tonic-gate 				((char *)(uc)) + (uc)->uc_credoff)
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /* Get the process privileges */
807c478bd9Sstevel@tonic-gate #define	UCPRIV(uc)	(prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \
817c478bd9Sstevel@tonic-gate 				((char *)(uc)) + (uc)->uc_privoff)
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /* Get the process audit info */
847c478bd9Sstevel@tonic-gate #define	UCAUD(uc)	(auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \
857c478bd9Sstevel@tonic-gate 				((char *)(uc)) + (uc)->uc_audoff)
867c478bd9Sstevel@tonic-gate 
87*45916cd2Sjpk /* Get peer security label info */
88*45916cd2Sjpk #define	UCLABEL(uc)	(bslabel_t *)(((uc)->uc_labeloff == 0) ? NULL : \
89*45916cd2Sjpk 				((char *)(uc)) + (uc)->uc_labeloff)
90*45916cd2Sjpk 
917c478bd9Sstevel@tonic-gate #define	UCRED_CRED_OFF	(sizeof (struct ucred_s))
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #endif /* _KERNEL || _STRUCTURED_PROC != 0 */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * SYS_ucredsys subcodes.
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate #define	UCREDSYS_UCREDGET	0
997c478bd9Sstevel@tonic-gate #define	UCREDSYS_GETPEERUCRED	1
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate extern uint32_t ucredsize;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #define	UCRED_PRIV_OFF	(UCRED_CRED_OFF + sizeof (prcred_t) + \
1067c478bd9Sstevel@tonic-gate 			    (ngroups_max - 1) * sizeof (gid_t))
1077c478bd9Sstevel@tonic-gate #define	UCRED_AUD_OFF	(UCRED_PRIV_OFF + priv_prgetprivsize(NULL))
108*45916cd2Sjpk #define	UCRED_LABEL_OFF	(UCRED_AUD_OFF + get_audit_ucrsize())
109*45916cd2Sjpk #define	UCRED_SIZE	(UCRED_LABEL_OFF + sizeof (bslabel_t))
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate struct proc;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate extern struct ucred_s *pgetucred(struct proc *);
114*45916cd2Sjpk extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *,
115*45916cd2Sjpk     const cred_t *);
1167c478bd9Sstevel@tonic-gate extern int get_audit_ucrsize(void);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #else
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /* Definition only valid for structured proc. */
1217c478bd9Sstevel@tonic-gate #if _STRUCTURED_PROC != 0
1227c478bd9Sstevel@tonic-gate #define	UCRED_SIZE(ip)	(sizeof (struct ucred_s) + sizeof (prcred_t) + \
1237c478bd9Sstevel@tonic-gate 			((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \
1247c478bd9Sstevel@tonic-gate 			sizeof (prpriv_t) + \
1257c478bd9Sstevel@tonic-gate 			sizeof (priv_chunk_t) * \
1267c478bd9Sstevel@tonic-gate 			((ip)->priv_setsize * (ip)->priv_nsets - 1) + \
1277c478bd9Sstevel@tonic-gate 			(ip)->priv_infosize + \
128*45916cd2Sjpk 			sizeof (auditinfo64_addr_t) + \
129*45916cd2Sjpk 			sizeof (bslabel_t))
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate extern struct ucred_s *_ucred_alloc(void);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #endif
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate #endif
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #endif	/* _SYS_UCRED_H */
141