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