xref: /titanic_52/usr/src/uts/common/sys/cred.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
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
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * 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 /*
22*45916cd2Sjpk  * Copyright 2006 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;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate struct auditinfo_addr;			/* cred.h is included in audit.h */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate extern int ngroups_max;
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * kcred is used when you need all privileges.
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate extern struct cred *kcred;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate extern void cred_init(void);
687c478bd9Sstevel@tonic-gate extern void crhold(cred_t *);
697c478bd9Sstevel@tonic-gate extern void crfree(cred_t *);
707c478bd9Sstevel@tonic-gate extern cred_t *cralloc(void);		/* all but ref uninitialized */
717c478bd9Sstevel@tonic-gate extern cred_t *crget(void);		/* initialized */
727c478bd9Sstevel@tonic-gate extern cred_t *crcopy(cred_t *);
737c478bd9Sstevel@tonic-gate extern void crcopy_to(cred_t *, cred_t *);
747c478bd9Sstevel@tonic-gate extern cred_t *crdup(cred_t *);
757c478bd9Sstevel@tonic-gate extern void crdup_to(cred_t *, cred_t *);
767c478bd9Sstevel@tonic-gate extern cred_t *crgetcred(void);
777c478bd9Sstevel@tonic-gate extern void crset(struct proc *, cred_t *);
787c478bd9Sstevel@tonic-gate extern int groupmember(gid_t, const cred_t *);
797c478bd9Sstevel@tonic-gate extern int supgroupmember(gid_t, const cred_t *);
807c478bd9Sstevel@tonic-gate extern int hasprocperm(const cred_t *, const cred_t *);
817c478bd9Sstevel@tonic-gate extern int prochasprocperm(struct proc *, struct proc *, const cred_t *);
827c478bd9Sstevel@tonic-gate extern int crcmp(const cred_t *, const cred_t *);
83*45916cd2Sjpk extern cred_t *zone_kcred(void);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern uid_t crgetuid(const cred_t *);
867c478bd9Sstevel@tonic-gate extern uid_t crgetruid(const cred_t *);
877c478bd9Sstevel@tonic-gate extern uid_t crgetsuid(const cred_t *);
887c478bd9Sstevel@tonic-gate extern gid_t crgetgid(const cred_t *);
897c478bd9Sstevel@tonic-gate extern gid_t crgetrgid(const cred_t *);
907c478bd9Sstevel@tonic-gate extern gid_t crgetsgid(const cred_t *);
917c478bd9Sstevel@tonic-gate extern zoneid_t crgetzoneid(const cred_t *);
927c478bd9Sstevel@tonic-gate extern projid_t crgetprojid(const cred_t *);
937c478bd9Sstevel@tonic-gate 
94*45916cd2Sjpk 
957c478bd9Sstevel@tonic-gate extern const struct auditinfo_addr *crgetauinfo(const cred_t *);
967c478bd9Sstevel@tonic-gate extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate extern uint_t crgetref(const cred_t *);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate extern const gid_t *crgetgroups(const cred_t *);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate extern int crgetngroups(const cred_t *);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * Sets real, effective and/or saved uid/gid;
1067c478bd9Sstevel@tonic-gate  * -1 argument accepted as "no change".
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t);
1097c478bd9Sstevel@tonic-gate extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t);
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * Sets real, effective and saved uids/gids all to the same
1137c478bd9Sstevel@tonic-gate  * values.  Both values must be non-negative and <= MAXUID
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate extern int crsetugid(cred_t *, uid_t, gid_t);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate extern int crsetgroups(cred_t *, int, gid_t *);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * Private interface for setting zone association of credential.
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate struct zone;
1237c478bd9Sstevel@tonic-gate extern void crsetzone(cred_t *, struct zone *);
124*45916cd2Sjpk extern struct zone *crgetzone(const cred_t *);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * Private interface for setting project id in credential.
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate extern void crsetprojid(cred_t *, projid_t);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * Private interface for nfs.
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate extern cred_t *crnetadjust(cred_t *);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Private interface for procfs.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate extern void cred2prcred(const cred_t *, struct prcred *);
1407c478bd9Sstevel@tonic-gate 
141*45916cd2Sjpk /*
142*45916cd2Sjpk  * Private interfaces for Rampart Trusted Solaris.
143*45916cd2Sjpk  */
144*45916cd2Sjpk struct ts_label_s;
145*45916cd2Sjpk extern struct ts_label_s *crgetlabel(const cred_t *);
146*45916cd2Sjpk extern boolean_t crisremote(const cred_t *);
147*45916cd2Sjpk 
1487c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate #endif
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #endif	/* _SYS_CRED_H */
155