xref: /titanic_50/usr/src/uts/common/sys/cred.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * Portions of this source code were derived from Berkeley 4.3 BSD
31  * under license from the Regents of the University of California.
32  */
33 
34 #ifndef _SYS_CRED_H
35 #define	_SYS_CRED_H
36 
37 #pragma ident	"%Z%%M%	%I%	%E% SMI"
38 
39 #include <sys/types.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * The credential is an opaque kernel private data structure defined in
47  * <sys/cred_impl.h>.
48  */
49 
50 typedef struct cred cred_t;
51 
52 #ifdef _KERNEL
53 
54 #define	CRED()		curthread->t_cred
55 
56 struct proc;				/* cred.h is included in proc.h */
57 struct prcred;
58 struct ksid;
59 struct ksidlist;
60 struct credklpd;
61 
62 struct auditinfo_addr;			/* cred.h is included in audit.h */
63 
64 extern int ngroups_max;
65 /*
66  * kcred is used when you need all privileges.
67  */
68 extern struct cred *kcred;
69 
70 extern void cred_init(void);
71 extern void crhold(cred_t *);
72 extern void crfree(cred_t *);
73 extern cred_t *cralloc(void);		/* all but ref uninitialized */
74 extern cred_t *cralloc_ksid(void);	/* cralloc() + ksid alloc'ed */
75 extern cred_t *crget(void);		/* initialized */
76 extern cred_t *crcopy(cred_t *);
77 extern void crcopy_to(cred_t *, cred_t *);
78 extern cred_t *crdup(cred_t *);
79 extern void crdup_to(cred_t *, cred_t *);
80 extern cred_t *crgetcred(void);
81 extern void crset(struct proc *, cred_t *);
82 extern int groupmember(gid_t, const cred_t *);
83 extern int supgroupmember(gid_t, const cred_t *);
84 extern int hasprocperm(const cred_t *, const cred_t *);
85 extern int prochasprocperm(struct proc *, struct proc *, const cred_t *);
86 extern int crcmp(const cred_t *, const cred_t *);
87 extern cred_t *zone_kcred(void);
88 
89 extern uid_t crgetuid(const cred_t *);
90 extern uid_t crgetruid(const cred_t *);
91 extern uid_t crgetsuid(const cred_t *);
92 extern gid_t crgetgid(const cred_t *);
93 extern gid_t crgetrgid(const cred_t *);
94 extern gid_t crgetsgid(const cred_t *);
95 extern zoneid_t crgetzoneid(const cred_t *);
96 extern projid_t crgetprojid(const cred_t *);
97 
98 extern cred_t *crgetmapped(const cred_t *);
99 
100 
101 extern const struct auditinfo_addr *crgetauinfo(const cred_t *);
102 extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *);
103 
104 extern uint_t crgetref(const cred_t *);
105 
106 extern const gid_t *crgetgroups(const cred_t *);
107 
108 extern int crgetngroups(const cred_t *);
109 
110 /*
111  * Sets real, effective and/or saved uid/gid;
112  * -1 argument accepted as "no change".
113  */
114 extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t);
115 extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t);
116 
117 /*
118  * Sets real, effective and saved uids/gids all to the same
119  * values.  Both values must be non-negative and <= MAXUID
120  */
121 extern int crsetugid(cred_t *, uid_t, gid_t);
122 
123 extern int crsetgroups(cred_t *, int, gid_t *);
124 
125 /*
126  * Private interface for setting zone association of credential.
127  */
128 struct zone;
129 extern void crsetzone(cred_t *, struct zone *);
130 extern struct zone *crgetzone(const cred_t *);
131 
132 /*
133  * Private interface for setting project id in credential.
134  */
135 extern void crsetprojid(cred_t *, projid_t);
136 
137 /*
138  * Private interface for nfs.
139  */
140 extern cred_t *crnetadjust(cred_t *);
141 
142 /*
143  * Private interface for procfs.
144  */
145 extern void cred2prcred(const cred_t *, struct prcred *);
146 
147 /*
148  * Private interfaces for Rampart Trusted Solaris.
149  */
150 struct ts_label_s;
151 extern struct ts_label_s *crgetlabel(const cred_t *);
152 extern boolean_t crisremote(const cred_t *);
153 
154 /*
155  * Private interfaces for ephemeral uids.
156  */
157 #define	VALID_UID(id, zn)					\
158 	((id) <= MAXUID || valid_ephemeral_uid((zn), (id)))
159 
160 #define	VALID_GID(id, zn)					\
161 	((id) <= MAXUID || valid_ephemeral_gid((zn), (id)))
162 
163 extern boolean_t valid_ephemeral_uid(struct zone *, uid_t);
164 extern boolean_t valid_ephemeral_gid(struct zone *, gid_t);
165 
166 extern int eph_uid_alloc(struct zone *, int, uid_t *, int);
167 extern int eph_gid_alloc(struct zone *, int, gid_t *, int);
168 
169 extern void crsetsid(cred_t *, struct ksid *, int);
170 extern void crsetsidlist(cred_t *, struct ksidlist *);
171 
172 extern struct ksid *crgetsid(const cred_t *, int);
173 extern struct ksidlist *crgetsidlist(const cred_t *);
174 
175 extern int crsetpriv(cred_t *, ...);
176 
177 extern struct credklpd *crgetcrklpd(const cred_t *);
178 extern void crsetcrklpd(cred_t *, struct credklpd *);
179 
180 #endif	/* _KERNEL */
181 
182 #ifdef	__cplusplus
183 }
184 #endif
185 
186 #endif	/* _SYS_CRED_H */
187