cred.h revision 4321:a8930ec16e52
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 2007 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
42extern "C" {
43#endif
44
45/*
46 * The credential is an opaque kernel private data structure defined in
47 * <sys/cred_impl.h>.
48 */
49
50typedef struct cred cred_t;
51
52#ifdef _KERNEL
53
54#define	CRED()		curthread->t_cred
55
56struct proc;				/* cred.h is included in proc.h */
57struct prcred;
58struct ksid;
59struct ksidlist;
60
61struct auditinfo_addr;			/* cred.h is included in audit.h */
62
63extern int ngroups_max;
64/*
65 * kcred is used when you need all privileges.
66 */
67extern struct cred *kcred;
68
69extern void cred_init(void);
70extern void crhold(cred_t *);
71extern void crfree(cred_t *);
72extern cred_t *cralloc(void);		/* all but ref uninitialized */
73extern cred_t *cralloc_ksid(void);	/* cralloc() + ksid alloc'ed */
74extern cred_t *crget(void);		/* initialized */
75extern cred_t *crcopy(cred_t *);
76extern void crcopy_to(cred_t *, cred_t *);
77extern cred_t *crdup(cred_t *);
78extern void crdup_to(cred_t *, cred_t *);
79extern cred_t *crgetcred(void);
80extern void crset(struct proc *, cred_t *);
81extern int groupmember(gid_t, const cred_t *);
82extern int supgroupmember(gid_t, const cred_t *);
83extern int hasprocperm(const cred_t *, const cred_t *);
84extern int prochasprocperm(struct proc *, struct proc *, const cred_t *);
85extern int crcmp(const cred_t *, const cred_t *);
86extern cred_t *zone_kcred(void);
87
88extern uid_t crgetuid(const cred_t *);
89extern uid_t crgetruid(const cred_t *);
90extern uid_t crgetsuid(const cred_t *);
91extern gid_t crgetgid(const cred_t *);
92extern gid_t crgetrgid(const cred_t *);
93extern gid_t crgetsgid(const cred_t *);
94extern zoneid_t crgetzoneid(const cred_t *);
95extern projid_t crgetprojid(const cred_t *);
96
97extern cred_t *crgetmapped(const cred_t *);
98
99
100extern const struct auditinfo_addr *crgetauinfo(const cred_t *);
101extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *);
102
103extern uint_t crgetref(const cred_t *);
104
105extern const gid_t *crgetgroups(const cred_t *);
106
107extern int crgetngroups(const cred_t *);
108
109/*
110 * Sets real, effective and/or saved uid/gid;
111 * -1 argument accepted as "no change".
112 */
113extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t);
114extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t);
115
116/*
117 * Sets real, effective and saved uids/gids all to the same
118 * values.  Both values must be non-negative and <= MAXUID
119 */
120extern int crsetugid(cred_t *, uid_t, gid_t);
121
122extern int crsetgroups(cred_t *, int, gid_t *);
123
124/*
125 * Private interface for setting zone association of credential.
126 */
127struct zone;
128extern void crsetzone(cred_t *, struct zone *);
129extern struct zone *crgetzone(const cred_t *);
130
131/*
132 * Private interface for setting project id in credential.
133 */
134extern void crsetprojid(cred_t *, projid_t);
135
136/*
137 * Private interface for nfs.
138 */
139extern cred_t *crnetadjust(cred_t *);
140
141/*
142 * Private interface for procfs.
143 */
144extern void cred2prcred(const cred_t *, struct prcred *);
145
146/*
147 * Private interfaces for Rampart Trusted Solaris.
148 */
149struct ts_label_s;
150extern struct ts_label_s *crgetlabel(const cred_t *);
151extern boolean_t crisremote(const cred_t *);
152
153/*
154 * Private interfaces for ephemeral uids.
155 */
156#define	VALID_UID(id)					\
157	((id) <= MAXUID || valid_ephemeral_uid((id)))
158#define	VALID_GID(id)					\
159	((id) <= MAXUID || valid_ephemeral_gid((id)))
160
161extern boolean_t valid_ephemeral_uid(uid_t);
162extern boolean_t valid_ephemeral_gid(gid_t);
163
164extern int eph_uid_alloc(int, uid_t *, int);
165extern int eph_gid_alloc(int, gid_t *, int);
166
167extern void crsetsid(cred_t *, struct ksid *, int);
168extern void crsetsidlist(cred_t *, struct ksidlist *);
169
170extern struct ksid *crgetsid(const cred_t *, int);
171extern struct ksidlist *crgetsidlist(const cred_t *);
172
173#endif	/* _KERNEL */
174
175#ifdef	__cplusplus
176}
177#endif
178
179#endif	/* _SYS_CRED_H */
180