2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)ucred.h 8.4 (Berkeley) 1/9/95
38 #include <bsm/audit.h>
47 * Please do not inspect cr_uid directly to determine superuserness. The
48 * priv(9) interface should be used to check for privilege.
50 #if defined(_KERNEL) || defined(_WANT_UCRED)
52 u_int cr_ref; /* reference count */
53 #define cr_startcopy cr_uid
54 uid_t cr_uid; /* effective user id */
55 uid_t cr_ruid; /* real user id */
56 uid_t cr_svuid; /* saved user id */
57 int cr_ngroups; /* number of groups */
58 gid_t cr_rgid; /* real group id */
59 gid_t cr_svgid; /* saved group id */
60 struct uidinfo *cr_uidinfo; /* per euid resource consumption */
61 struct uidinfo *cr_ruidinfo; /* per ruid resource consumption */
62 struct prison *cr_prison; /* jail(2) */
63 struct loginclass *cr_loginclass; /* login class */
64 u_int cr_flags; /* credential flags */
65 void *cr_pspare2[2]; /* general use 2 */
66 #define cr_endcopy cr_label
67 struct label *cr_label; /* MAC label */
68 struct auditinfo_addr cr_audit; /* Audit properties. */
69 gid_t *cr_groups; /* groups */
70 int cr_agroups; /* Available groups */
71 gid_t cr_smallgroups[XU_NGROUPS]; /* storage for small groups */
73 #define NOCRED ((struct ucred *)0) /* no credential available */
74 #define FSCRED ((struct ucred *)-1) /* filesystem credential */
75 #endif /* _KERNEL || _WANT_UCRED */
80 #define CRED_FLAG_CAPMODE 0x00000001 /* In capability mode. */
83 * This is the external representation of struct ucred.
86 u_int cr_version; /* structure layout version */
87 uid_t cr_uid; /* effective user id */
88 short cr_ngroups; /* number of groups */
89 gid_t cr_groups[XU_NGROUPS]; /* groups */
90 void *_cr_unused1; /* compatibility with old ucred */
92 #define XUCRED_VERSION 0
94 /* This can be used for both ucred and xucred structures. */
95 #define cr_gid cr_groups[0]
101 void change_egid(struct ucred *newcred, gid_t egid);
102 void change_euid(struct ucred *newcred, struct uidinfo *euip);
103 void change_rgid(struct ucred *newcred, gid_t rgid);
104 void change_ruid(struct ucred *newcred, struct uidinfo *ruip);
105 void change_svgid(struct ucred *newcred, gid_t svgid);
106 void change_svuid(struct ucred *newcred, uid_t svuid);
107 void crcopy(struct ucred *dest, struct ucred *src);
108 struct ucred *crcopysafe(struct proc *p, struct ucred *cr);
109 struct ucred *crdup(struct ucred *cr);
110 void crextend(struct ucred *cr, int n);
111 void proc_set_cred_init(struct proc *p, struct ucred *cr);
112 struct ucred *proc_set_cred(struct proc *p, struct ucred *cr);
113 void crfree(struct ucred *cr);
114 struct ucred *crget(void);
115 struct ucred *crhold(struct ucred *cr);
116 void cru2x(struct ucred *cr, struct xucred *xcr);
117 void crsetgroups(struct ucred *cr, int n, gid_t *groups);
118 int groupmember(gid_t gid, struct ucred *cred);
121 #endif /* !_SYS_UCRED_H_ */