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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 #pragma weak _ucred_free = ucred_free
29 #pragma weak _ucred_get = ucred_get
30 #pragma weak _ucred_getegid = ucred_getegid
31 #pragma weak _ucred_geteuid = ucred_geteuid
32 #pragma weak _ucred_getgroups = ucred_getgroups
33 #pragma weak _ucred_getpflags = ucred_getpflags
34 #pragma weak _ucred_getpid = ucred_getpid
35 #pragma weak _ucred_getzoneid = ucred_getzoneid
36 #pragma weak _ucred_getprojid = ucred_getprojid
37 #pragma weak _ucred_getprivset = ucred_getprivset
38 #pragma weak _ucred_getrgid = ucred_getrgid
39 #pragma weak _ucred_getruid = ucred_getruid
40 #pragma weak _ucred_getsgid = ucred_getsgid
41 #pragma weak _ucred_getsuid = ucred_getsuid
42 #pragma weak _ucred_getauid = ucred_getauid
43 #pragma weak _ucred_getasid = ucred_getasid
44 #pragma weak _ucred_getatid = ucred_getatid
45 #pragma weak _ucred_getamask = ucred_getamask
46 #pragma weak _ucred_size = ucred_size
50 #define _STRUCTURED_PROC 1
52 #include "priv_private.h"
64 #include <sys/ucred.h>
65 #include <sys/procfs.h>
66 #include <sys/sysmacros.h>
73 size_t sz
= ucred_size();
78 r
->uc_size
= (uint32_t)sz
;
84 ucred_free(ucred_t
*uc
)
100 if (syscall(SYS_ucredsys
, UCREDSYS_UCREDGET
, pid
, uc
) != 0) {
109 ucred_geteuid(const ucred_t
*uc
)
111 /* LINTED: alignment */
112 const prcred_t
*cr
= UCCRED(uc
);
119 return (cr
->pr_euid
);
123 ucred_getruid(const ucred_t
*uc
)
125 /* LINTED: alignment */
126 const prcred_t
*cr
= UCCRED(uc
);
133 return (cr
->pr_ruid
);
137 ucred_getsuid(const ucred_t
*uc
)
139 /* LINTED: alignment */
140 const prcred_t
*cr
= UCCRED(uc
);
147 return (cr
->pr_suid
);
151 ucred_getegid(const ucred_t
*uc
)
153 /* LINTED: alignment */
154 const prcred_t
*cr
= UCCRED(uc
);
161 return (cr
->pr_egid
);
165 ucred_getrgid(const ucred_t
*uc
)
167 /* LINTED: alignment */
168 const prcred_t
*cr
= UCCRED(uc
);
175 return (cr
->pr_rgid
);
179 ucred_getsgid(const ucred_t
*uc
)
181 /* LINTED: alignment */
182 const prcred_t
*cr
= UCCRED(uc
);
189 return (cr
->pr_sgid
);
193 ucred_getgroups(const ucred_t
*uc
, const gid_t
**grps
)
195 /* LINTED: alignment */
196 const prcred_t
*cr
= UCCRED(uc
);
203 if (cr
->pr_ngroups
> 0)
204 *grps
= &cr
->pr_groups
[0];
208 return (cr
->pr_ngroups
);
212 ucred_getprivset(const ucred_t
*uc
, priv_ptype_t set
)
214 /* LINTED: alignment */
215 const prpriv_t
*pr
= UCPRIV(uc
);
216 int pset
= priv_getsetbyname(set
);
219 if (pr
== NULL
|| pset
== -1) {
226 return ((const priv_set_t
*)
227 &pr
->pr_sets
[d
->pd_pinfo
->priv_setsize
* pset
]);
231 ucred_getpid(const ucred_t
*uc
)
234 if (uc
->uc_pid
== -1)
241 ucred_getprojid(const ucred_t
*uc
)
244 if (uc
->uc_projid
== -1)
247 return (uc
->uc_projid
);
251 ucred_getzoneid(const ucred_t
*uc
)
254 if (uc
->uc_zoneid
< MIN_ZONEID
|| uc
->uc_zoneid
> MAX_ZONEID
) {
259 return (uc
->uc_zoneid
);
263 * For now, assume single bit flags.
266 ucred_getpflags(const ucred_t
*uc
, uint_t flag
)
268 /* LINTED: alignment */
269 prpriv_t
*pr
= UCPRIV(uc
);
277 end
= (char *)pr
+ PRIV_PRPRIV_SIZE(pr
);
278 x
= end
- pr
->pr_infosize
;
281 /* LINTED: alignment */
282 priv_info_t
*pi
= (priv_info_t
*)x
;
283 priv_info_uint_t
*pii
;
285 switch (pi
->priv_info_type
) {
286 case PRIV_INFO_FLAGS
:
287 /* LINTED: alignment */
288 pii
= (priv_info_uint_t
*)x
;
289 return ((pii
->val
& flag
) ? 1 : 0);
291 /* Forward progress */
292 if (pi
->priv_info_size
< sizeof (priv_info_t
))
294 x
+= pi
->priv_info_size
;
302 ucred_getauid(const ucred_t
*uc
)
304 /* LINTED: alignment */
305 const auditinfo64_addr_t
*ainfo
= UCAUD(uc
);
308 return (AU_NOAUDITID
);
310 return (ainfo
->ai_auid
);
314 ucred_getasid(const ucred_t
*uc
)
316 /* LINTED: alignment */
317 const auditinfo64_addr_t
*ainfo
= UCAUD(uc
);
320 return ((au_asid_t
)-1);
322 return (ainfo
->ai_asid
);
325 const au_tid64_addr_t
*
326 ucred_getatid(const ucred_t
*uc
)
328 /* LINTED: alignment */
329 const auditinfo64_addr_t
*ainfo
= UCAUD(uc
);
336 return (&ainfo
->ai_termid
);
340 ucred_getamask(const ucred_t
*uc
)
342 /* LINTED: alignment */
343 const auditinfo64_addr_t
*ainfo
= UCAUD(uc
);
350 return (&ainfo
->ai_mask
);
360 return (d
->pd_ucredsize
);