xref: /titanic_51/usr/src/uts/common/sys/cred.h (revision ddf7fe95b8ad67aa16deb427a0b78f4dd4ff22b1)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22bda89588Sjp151216  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
317c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifndef _SYS_CRED_H
357c478bd9Sstevel@tonic-gate #define	_SYS_CRED_H
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * The credential is an opaque kernel private data structure defined in
477c478bd9Sstevel@tonic-gate  * <sys/cred_impl.h>.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate typedef struct cred cred_t;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #ifdef _KERNEL
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #define	CRED()		curthread->t_cred
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate struct proc;				/* cred.h is included in proc.h */
577c478bd9Sstevel@tonic-gate struct prcred;
58f48205beScasper struct ksid;
59f48205beScasper struct ksidlist;
60*ddf7fe95Scasper struct credklpd;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate struct auditinfo_addr;			/* cred.h is included in audit.h */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate extern int ngroups_max;
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * kcred is used when you need all privileges.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate extern struct cred *kcred;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate extern void cred_init(void);
717c478bd9Sstevel@tonic-gate extern void crhold(cred_t *);
727c478bd9Sstevel@tonic-gate extern void crfree(cred_t *);
737c478bd9Sstevel@tonic-gate extern cred_t *cralloc(void);		/* all but ref uninitialized */
74f48205beScasper extern cred_t *cralloc_ksid(void);	/* cralloc() + ksid alloc'ed */
757c478bd9Sstevel@tonic-gate extern cred_t *crget(void);		/* initialized */
767c478bd9Sstevel@tonic-gate extern cred_t *crcopy(cred_t *);
777c478bd9Sstevel@tonic-gate extern void crcopy_to(cred_t *, cred_t *);
787c478bd9Sstevel@tonic-gate extern cred_t *crdup(cred_t *);
797c478bd9Sstevel@tonic-gate extern void crdup_to(cred_t *, cred_t *);
807c478bd9Sstevel@tonic-gate extern cred_t *crgetcred(void);
817c478bd9Sstevel@tonic-gate extern void crset(struct proc *, cred_t *);
827c478bd9Sstevel@tonic-gate extern int groupmember(gid_t, const cred_t *);
837c478bd9Sstevel@tonic-gate extern int supgroupmember(gid_t, const cred_t *);
847c478bd9Sstevel@tonic-gate extern int hasprocperm(const cred_t *, const cred_t *);
857c478bd9Sstevel@tonic-gate extern int prochasprocperm(struct proc *, struct proc *, const cred_t *);
867c478bd9Sstevel@tonic-gate extern int crcmp(const cred_t *, const cred_t *);
8745916cd2Sjpk extern cred_t *zone_kcred(void);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern uid_t crgetuid(const cred_t *);
907c478bd9Sstevel@tonic-gate extern uid_t crgetruid(const cred_t *);
917c478bd9Sstevel@tonic-gate extern uid_t crgetsuid(const cred_t *);
927c478bd9Sstevel@tonic-gate extern gid_t crgetgid(const cred_t *);
937c478bd9Sstevel@tonic-gate extern gid_t crgetrgid(const cred_t *);
947c478bd9Sstevel@tonic-gate extern gid_t crgetsgid(const cred_t *);
957c478bd9Sstevel@tonic-gate extern zoneid_t crgetzoneid(const cred_t *);
967c478bd9Sstevel@tonic-gate extern projid_t crgetprojid(const cred_t *);
977c478bd9Sstevel@tonic-gate 
98f48205beScasper extern cred_t *crgetmapped(const cred_t *);
99f48205beScasper 
10045916cd2Sjpk 
1017c478bd9Sstevel@tonic-gate extern const struct auditinfo_addr *crgetauinfo(const cred_t *);
1027c478bd9Sstevel@tonic-gate extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate extern uint_t crgetref(const cred_t *);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate extern const gid_t *crgetgroups(const cred_t *);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate extern int crgetngroups(const cred_t *);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Sets real, effective and/or saved uid/gid;
1127c478bd9Sstevel@tonic-gate  * -1 argument accepted as "no change".
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t);
1157c478bd9Sstevel@tonic-gate extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Sets real, effective and saved uids/gids all to the same
1197c478bd9Sstevel@tonic-gate  * values.  Both values must be non-negative and <= MAXUID
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate extern int crsetugid(cred_t *, uid_t, gid_t);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate extern int crsetgroups(cred_t *, int, gid_t *);
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * Private interface for setting zone association of credential.
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate struct zone;
1297c478bd9Sstevel@tonic-gate extern void crsetzone(cred_t *, struct zone *);
13045916cd2Sjpk extern struct zone *crgetzone(const cred_t *);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Private interface for setting project id in credential.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate extern void crsetprojid(cred_t *, projid_t);
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * Private interface for nfs.
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate extern cred_t *crnetadjust(cred_t *);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * Private interface for procfs.
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate extern void cred2prcred(const cred_t *, struct prcred *);
1467c478bd9Sstevel@tonic-gate 
14745916cd2Sjpk /*
14845916cd2Sjpk  * Private interfaces for Rampart Trusted Solaris.
14945916cd2Sjpk  */
15045916cd2Sjpk struct ts_label_s;
15145916cd2Sjpk extern struct ts_label_s *crgetlabel(const cred_t *);
15245916cd2Sjpk extern boolean_t crisremote(const cred_t *);
15345916cd2Sjpk 
154f48205beScasper /*
155f48205beScasper  * Private interfaces for ephemeral uids.
156f48205beScasper  */
157bda89588Sjp151216 #define	VALID_UID(id, zn)					\
158bda89588Sjp151216 	((id) <= MAXUID || valid_ephemeral_uid((zn), (id)))
159f48205beScasper 
160bda89588Sjp151216 #define	VALID_GID(id, zn)					\
161bda89588Sjp151216 	((id) <= MAXUID || valid_ephemeral_gid((zn), (id)))
162f48205beScasper 
163bda89588Sjp151216 extern boolean_t valid_ephemeral_uid(struct zone *, uid_t);
164bda89588Sjp151216 extern boolean_t valid_ephemeral_gid(struct zone *, gid_t);
165bda89588Sjp151216 
166bda89588Sjp151216 extern int eph_uid_alloc(struct zone *, int, uid_t *, int);
167bda89588Sjp151216 extern int eph_gid_alloc(struct zone *, int, gid_t *, int);
168f48205beScasper 
169f48205beScasper extern void crsetsid(cred_t *, struct ksid *, int);
170f48205beScasper extern void crsetsidlist(cred_t *, struct ksidlist *);
171f48205beScasper 
172f48205beScasper extern struct ksid *crgetsid(const cred_t *, int);
173f48205beScasper extern struct ksidlist *crgetsidlist(const cred_t *);
174f48205beScasper 
175da6c28aaSamw extern int crsetpriv(cred_t *, ...);
176da6c28aaSamw 
177*ddf7fe95Scasper extern struct credklpd *crgetcrklpd(const cred_t *);
178*ddf7fe95Scasper extern void crsetcrklpd(cred_t *, struct credklpd *);
179*ddf7fe95Scasper 
1807c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate #endif
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #endif	/* _SYS_CRED_H */
187