xref: /titanic_41/usr/src/uts/common/sys/ucred.h (revision b72c368a02e0464faeef362bc5a1cf0fc69981da)
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 2009 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 #include <sys/types.h>
33 #include <sys/procfs.h>
34 #include <sys/cred.h>
35 #include <sys/priv.h>
36 #include <sys/tsol/label.h>
37 #include <sys/tsol/label_macro.h>
38 
39 #ifdef _KERNEL
40 #include <c2/audit.h>
41 #else
42 #include <bsm/audit.h>
43 #endif
44 
45 #ifndef _KERNEL
46 #include <unistd.h>
47 #endif
48 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 
54 
55 #if defined(_KERNEL) || _STRUCTURED_PROC != 0
56 /*
57  * bitness neutral struct
58  *
59  * Add new fixed fields at the end of the structure.
60  */
61 struct ucred_s {
62 	uint32_t	uc_size;	/* Size of the full structure */
63 	uint32_t	uc_credoff;	/* Credential offset: 0 - no cred */
64 	uint32_t	uc_privoff;	/* Privilege offset: 0 - no privs */
65 	pid_t		uc_pid;		/* Process id */
66 	uint32_t	uc_audoff;	/* Audit info offset: 0 - no aud */
67 	zoneid_t	uc_zoneid;	/* Zone id */
68 	projid_t	uc_projid;	/* Project id */
69 	uint32_t	uc_labeloff;	/* label offset: 0 - no label */
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 /* Get peer security label info */
86 #define	UCLABEL(uc)	(bslabel_t *)(((uc)->uc_labeloff == 0) ? NULL : \
87 				((char *)(uc)) + (uc)->uc_labeloff)
88 
89 #endif /* _KERNEL || _STRUCTURED_PROC != 0 */
90 
91 /*
92  * SYS_ucredsys subcodes.
93  */
94 #define	UCREDSYS_UCREDGET	0
95 #define	UCREDSYS_GETPEERUCRED	1
96 
97 #ifdef _KERNEL
98 
99 extern uint32_t ucredminsize(const cred_t *);
100 
101 #define	UCRED_PRIV_OFF	(sizeof (struct ucred_s))
102 #define	UCRED_AUD_OFF	(UCRED_PRIV_OFF + priv_prgetprivsize(NULL))
103 #define	UCRED_LABEL_OFF	(UCRED_AUD_OFF + get_audit_ucrsize())
104 
105 /* The prcred_t has a variable size; it should be last. */
106 #define	UCRED_CRED_OFF	(UCRED_LABEL_OFF + \
107 			    (is_system_labeled() ? sizeof (bslabel_t) : 0))
108 
109 #define	UCRED_SIZE	(UCRED_CRED_OFF + sizeof (prcred_t) + \
110 			    (ngroups_max - 1) * sizeof (gid_t))
111 
112 
113 struct proc;
114 
115 extern struct ucred_s *pgetucred(struct proc *);
116 extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *,
117     const cred_t *);
118 extern int get_audit_ucrsize(void);
119 
120 #else
121 
122 /* Definition only valid for structured proc. */
123 #if _STRUCTURED_PROC != 0
124 #define	UCRED_SIZE(ip)	(sizeof (struct ucred_s) + sizeof (prcred_t) + \
125 			((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \
126 			sizeof (prpriv_t) + \
127 			sizeof (priv_chunk_t) * \
128 			((ip)->priv_setsize * (ip)->priv_nsets - 1) + \
129 			(ip)->priv_infosize + \
130 			sizeof (auditinfo64_addr_t) + \
131 			sizeof (bslabel_t))
132 #endif
133 
134 extern struct ucred_s *_ucred_alloc(void);
135 
136 #endif
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif	/* _SYS_UCRED_H */
143