xref: /illumos-gate/usr/src/uts/common/sys/cred.h (revision 4de2612967d06c4fdbf524a62556a1e8118a006f)
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 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #ifndef _SYS_CRED_H
36 #define	_SYS_CRED_H
37 
38 #pragma ident	"%Z%%M%	%I%	%E% SMI"
39 
40 #include <sys/types.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * The credential is an opaque kernel private data structure defined in
48  * <sys/cred_impl.h>.
49  */
50 
51 typedef struct cred cred_t;
52 
53 #ifdef _KERNEL
54 
55 #define	CRED()		curthread->t_cred
56 
57 struct proc;				/* cred.h is included in proc.h */
58 struct prcred;
59 
60 struct auditinfo_addr;			/* cred.h is included in audit.h */
61 
62 extern int ngroups_max;
63 /*
64  * kcred is used when you need all privileges.
65  */
66 extern struct cred *kcred;
67 
68 extern void cred_init(void);
69 extern void crhold(cred_t *);
70 extern void crfree(cred_t *);
71 extern cred_t *cralloc(void);		/* all but ref uninitialized */
72 extern cred_t *crget(void);		/* initialized */
73 extern cred_t *crcopy(cred_t *);
74 extern void crcopy_to(cred_t *, cred_t *);
75 extern cred_t *crdup(cred_t *);
76 extern void crdup_to(cred_t *, cred_t *);
77 extern cred_t *crgetcred(void);
78 extern void crset(struct proc *, cred_t *);
79 extern int groupmember(gid_t, const cred_t *);
80 extern int supgroupmember(gid_t, const cred_t *);
81 extern int hasprocperm(const cred_t *, const cred_t *);
82 extern int prochasprocperm(struct proc *, struct proc *, const cred_t *);
83 extern int crcmp(const cred_t *, const cred_t *);
84 
85 extern uid_t crgetuid(const cred_t *);
86 extern uid_t crgetruid(const cred_t *);
87 extern uid_t crgetsuid(const cred_t *);
88 extern gid_t crgetgid(const cred_t *);
89 extern gid_t crgetrgid(const cred_t *);
90 extern gid_t crgetsgid(const cred_t *);
91 extern zoneid_t crgetzoneid(const cred_t *);
92 extern projid_t crgetprojid(const cred_t *);
93 
94 extern const struct auditinfo_addr *crgetauinfo(const cred_t *);
95 extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *);
96 
97 extern uint_t crgetref(const cred_t *);
98 
99 extern const gid_t *crgetgroups(const cred_t *);
100 
101 extern int crgetngroups(const cred_t *);
102 
103 /*
104  * Sets real, effective and/or saved uid/gid;
105  * -1 argument accepted as "no change".
106  */
107 extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t);
108 extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t);
109 
110 /*
111  * Sets real, effective and saved uids/gids all to the same
112  * values.  Both values must be non-negative and <= MAXUID
113  */
114 extern int crsetugid(cred_t *, uid_t, gid_t);
115 
116 extern int crsetgroups(cred_t *, int, gid_t *);
117 
118 /*
119  * Private interface for setting zone association of credential.
120  */
121 struct zone;
122 extern void crsetzone(cred_t *, struct zone *);
123 
124 /*
125  * Private interface for setting project id in credential.
126  */
127 extern void crsetprojid(cred_t *, projid_t);
128 
129 /*
130  * Private interface for nfs.
131  */
132 extern cred_t *crnetadjust(cred_t *);
133 
134 /*
135  * Private interface for procfs.
136  */
137 extern void cred2prcred(const cred_t *, struct prcred *);
138 
139 #endif	/* _KERNEL */
140 
141 #ifdef	__cplusplus
142 }
143 #endif
144 
145 #endif	/* _SYS_CRED_H */
146