xref: /titanic_51/usr/src/uts/common/sys/cred.h (revision 67dbe2be0c0f1e2eb428b89088bb5667e8f0b9f6)
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 /*
22546a3997SThomas Haynes  * Copyright 2009 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 #include <sys/types.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * The credential is an opaque kernel private data structure defined in
457c478bd9Sstevel@tonic-gate  * <sys/cred_impl.h>.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate typedef struct cred cred_t;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifdef _KERNEL
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	CRED()		curthread->t_cred
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate struct proc;				/* cred.h is included in proc.h */
557c478bd9Sstevel@tonic-gate struct prcred;
56f48205beScasper struct ksid;
57f48205beScasper struct ksidlist;
58ddf7fe95Scasper struct credklpd;
59*67dbe2beSCasper H.S. Dik struct credgrp;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate struct auditinfo_addr;			/* cred.h is included in audit.h */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate extern int ngroups_max;
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * kcred is used when you need all privileges.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate extern struct cred *kcred;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate extern void cred_init(void);
707c478bd9Sstevel@tonic-gate extern void crhold(cred_t *);
717c478bd9Sstevel@tonic-gate extern void crfree(cred_t *);
727c478bd9Sstevel@tonic-gate extern cred_t *cralloc(void);		/* all but ref uninitialized */
73f48205beScasper extern cred_t *cralloc_ksid(void);	/* cralloc() + ksid alloc'ed */
747c478bd9Sstevel@tonic-gate extern cred_t *crget(void);		/* initialized */
757c478bd9Sstevel@tonic-gate extern cred_t *crcopy(cred_t *);
767c478bd9Sstevel@tonic-gate extern void crcopy_to(cred_t *, cred_t *);
777c478bd9Sstevel@tonic-gate extern cred_t *crdup(cred_t *);
787c478bd9Sstevel@tonic-gate extern void crdup_to(cred_t *, cred_t *);
797c478bd9Sstevel@tonic-gate extern cred_t *crgetcred(void);
807c478bd9Sstevel@tonic-gate extern void crset(struct proc *, cred_t *);
81546a3997SThomas Haynes extern void crset_zone_privall(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 *);
107*67dbe2beSCasper H.S. Dik extern const gid_t *crgetggroups(const struct credgrp *);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate extern int crgetngroups(const cred_t *);
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * Sets real, effective and/or saved uid/gid;
1137c478bd9Sstevel@tonic-gate  * -1 argument accepted as "no change".
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t);
1167c478bd9Sstevel@tonic-gate extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * Sets real, effective and saved uids/gids all to the same
1207c478bd9Sstevel@tonic-gate  * values.  Both values must be non-negative and <= MAXUID
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate extern int crsetugid(cred_t *, uid_t, gid_t);
1237c478bd9Sstevel@tonic-gate 
124*67dbe2beSCasper H.S. Dik /*
125*67dbe2beSCasper H.S. Dik  * Functions to handle the supplemental group list.
126*67dbe2beSCasper H.S. Dik  */
1277c478bd9Sstevel@tonic-gate extern int crsetgroups(cred_t *, int, gid_t *);
128*67dbe2beSCasper H.S. Dik extern struct credgrp *crgrpcopyin(int, gid_t *);
129*67dbe2beSCasper H.S. Dik extern void crgrprele(struct credgrp *);
130*67dbe2beSCasper H.S. Dik extern void crsetcredgrp(cred_t *, struct credgrp *);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Private interface for setting zone association of credential.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate struct zone;
1367c478bd9Sstevel@tonic-gate extern void crsetzone(cred_t *, struct zone *);
13745916cd2Sjpk extern struct zone *crgetzone(const cred_t *);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate  * Private interface for setting project id in credential.
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate extern void crsetprojid(cred_t *, projid_t);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * Private interface for nfs.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate extern cred_t *crnetadjust(cred_t *);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * Private interface for procfs.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate extern void cred2prcred(const cred_t *, struct prcred *);
1537c478bd9Sstevel@tonic-gate 
15445916cd2Sjpk /*
15545916cd2Sjpk  * Private interfaces for Rampart Trusted Solaris.
15645916cd2Sjpk  */
15745916cd2Sjpk struct ts_label_s;
15845916cd2Sjpk extern struct ts_label_s *crgetlabel(const cred_t *);
15945916cd2Sjpk extern boolean_t crisremote(const cred_t *);
16045916cd2Sjpk 
161f48205beScasper /*
162f48205beScasper  * Private interfaces for ephemeral uids.
163f48205beScasper  */
164bda89588Sjp151216 #define	VALID_UID(id, zn)					\
165bda89588Sjp151216 	((id) <= MAXUID || valid_ephemeral_uid((zn), (id)))
166f48205beScasper 
167bda89588Sjp151216 #define	VALID_GID(id, zn)					\
168bda89588Sjp151216 	((id) <= MAXUID || valid_ephemeral_gid((zn), (id)))
169f48205beScasper 
170bda89588Sjp151216 extern boolean_t valid_ephemeral_uid(struct zone *, uid_t);
171bda89588Sjp151216 extern boolean_t valid_ephemeral_gid(struct zone *, gid_t);
172bda89588Sjp151216 
173bda89588Sjp151216 extern int eph_uid_alloc(struct zone *, int, uid_t *, int);
174bda89588Sjp151216 extern int eph_gid_alloc(struct zone *, int, gid_t *, int);
175f48205beScasper 
176f48205beScasper extern void crsetsid(cred_t *, struct ksid *, int);
177f48205beScasper extern void crsetsidlist(cred_t *, struct ksidlist *);
178f48205beScasper 
179f48205beScasper extern struct ksid *crgetsid(const cred_t *, int);
180f48205beScasper extern struct ksidlist *crgetsidlist(const cred_t *);
181f48205beScasper 
182da6c28aaSamw extern int crsetpriv(cred_t *, ...);
183da6c28aaSamw 
184ddf7fe95Scasper extern struct credklpd *crgetcrklpd(const cred_t *);
185ddf7fe95Scasper extern void crsetcrklpd(cred_t *, struct credklpd *);
186ddf7fe95Scasper 
1877c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate #endif
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #endif	/* _SYS_CRED_H */
194