xref: /titanic_51/usr/src/uts/common/sys/ucred.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * File with private definitions for the ucred structure for use by the
27  * kernel and library routines.
28  */
29 
30 #ifndef	_SYS_UCRED_H
31 #define	_SYS_UCRED_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/types.h>
36 #include <sys/procfs.h>
37 #include <sys/cred.h>
38 #include <sys/priv.h>
39 
40 #ifdef _KERNEL
41 #include <c2/audit.h>
42 #else
43 #include <bsm/audit.h>
44 #endif
45 
46 #ifndef _KERNEL
47 #include <unistd.h>
48 #endif
49 
50 #ifdef	__cplusplus
51 extern "C" {
52 #endif
53 
54 
55 
56 #if defined(_KERNEL) || _STRUCTURED_PROC != 0
57 /*
58  * bitness neutral struct
59  *
60  * Add new fixed fields at the end of the structure.
61  */
62 struct ucred_s {
63 	uint32_t	uc_size;	/* Size of the full structure */
64 	uint32_t	uc_credoff;	/* Credential offset: 0 - no cred */
65 	uint32_t	uc_privoff;	/* Privilege offset: 0 - no privs */
66 	pid_t		uc_pid;		/* Process id */
67 	uint32_t	uc_audoff;	/* Audit info offset: 0 - no aud */
68 	zoneid_t	uc_zoneid;	/* Zone id */
69 	projid_t	uc_projid;	/* Project id */
70 					/* The rest goes here */
71 };
72 
73 /* Get the process credentials */
74 #define	UCCRED(uc)	(prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \
75 				((char *)(uc)) + (uc)->uc_credoff)
76 
77 /* Get the process privileges */
78 #define	UCPRIV(uc)	(prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \
79 				((char *)(uc)) + (uc)->uc_privoff)
80 
81 /* Get the process audit info */
82 #define	UCAUD(uc)	(auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \
83 				((char *)(uc)) + (uc)->uc_audoff)
84 
85 #define	UCRED_CRED_OFF	(sizeof (struct ucred_s))
86 
87 #endif /* _KERNEL || _STRUCTURED_PROC != 0 */
88 
89 /*
90  * SYS_ucredsys subcodes.
91  */
92 #define	UCREDSYS_UCREDGET	0
93 #define	UCREDSYS_GETPEERUCRED	1
94 
95 #ifdef _KERNEL
96 
97 extern uint32_t ucredsize;
98 
99 #define	UCRED_PRIV_OFF	(UCRED_CRED_OFF + sizeof (prcred_t) + \
100 			    (ngroups_max - 1) * sizeof (gid_t))
101 #define	UCRED_AUD_OFF	(UCRED_PRIV_OFF + priv_prgetprivsize(NULL))
102 #define	UCRED_SIZE	(UCRED_AUD_OFF + get_audit_ucrsize())
103 
104 struct proc;
105 
106 extern struct ucred_s *pgetucred(struct proc *);
107 extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *);
108 extern int get_audit_ucrsize(void);
109 
110 #else
111 
112 /* Definition only valid for structured proc. */
113 #if _STRUCTURED_PROC != 0
114 #define	UCRED_SIZE(ip)	(sizeof (struct ucred_s) + sizeof (prcred_t) + \
115 			((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \
116 			sizeof (prpriv_t) + \
117 			sizeof (priv_chunk_t) * \
118 			((ip)->priv_setsize * (ip)->priv_nsets - 1) + \
119 			(ip)->priv_infosize + \
120 			sizeof (auditinfo64_addr_t))
121 #endif
122 
123 extern struct ucred_s *_ucred_alloc(void);
124 
125 #endif
126 
127 #ifdef	__cplusplus
128 }
129 #endif
130 
131 #endif	/* _SYS_UCRED_H */
132