10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 224321Scasper * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 310Sstevel@tonic-gate * under license from the Regents of the University of California. 320Sstevel@tonic-gate */ 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifndef _SYS_CRED_H 350Sstevel@tonic-gate #define _SYS_CRED_H 360Sstevel@tonic-gate 370Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <sys/types.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifdef __cplusplus 420Sstevel@tonic-gate extern "C" { 430Sstevel@tonic-gate #endif 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * The credential is an opaque kernel private data structure defined in 470Sstevel@tonic-gate * <sys/cred_impl.h>. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate typedef struct cred cred_t; 510Sstevel@tonic-gate 520Sstevel@tonic-gate #ifdef _KERNEL 530Sstevel@tonic-gate 540Sstevel@tonic-gate #define CRED() curthread->t_cred 550Sstevel@tonic-gate 560Sstevel@tonic-gate struct proc; /* cred.h is included in proc.h */ 570Sstevel@tonic-gate struct prcred; 584321Scasper struct ksid; 594321Scasper struct ksidlist; 600Sstevel@tonic-gate 610Sstevel@tonic-gate struct auditinfo_addr; /* cred.h is included in audit.h */ 620Sstevel@tonic-gate 630Sstevel@tonic-gate extern int ngroups_max; 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * kcred is used when you need all privileges. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate extern struct cred *kcred; 680Sstevel@tonic-gate 690Sstevel@tonic-gate extern void cred_init(void); 700Sstevel@tonic-gate extern void crhold(cred_t *); 710Sstevel@tonic-gate extern void crfree(cred_t *); 720Sstevel@tonic-gate extern cred_t *cralloc(void); /* all but ref uninitialized */ 734321Scasper extern cred_t *cralloc_ksid(void); /* cralloc() + ksid alloc'ed */ 740Sstevel@tonic-gate extern cred_t *crget(void); /* initialized */ 750Sstevel@tonic-gate extern cred_t *crcopy(cred_t *); 760Sstevel@tonic-gate extern void crcopy_to(cred_t *, cred_t *); 770Sstevel@tonic-gate extern cred_t *crdup(cred_t *); 780Sstevel@tonic-gate extern void crdup_to(cred_t *, cred_t *); 790Sstevel@tonic-gate extern cred_t *crgetcred(void); 800Sstevel@tonic-gate extern void crset(struct proc *, cred_t *); 810Sstevel@tonic-gate extern int groupmember(gid_t, const cred_t *); 820Sstevel@tonic-gate extern int supgroupmember(gid_t, const cred_t *); 830Sstevel@tonic-gate extern int hasprocperm(const cred_t *, const cred_t *); 840Sstevel@tonic-gate extern int prochasprocperm(struct proc *, struct proc *, const cred_t *); 850Sstevel@tonic-gate extern int crcmp(const cred_t *, const cred_t *); 861676Sjpk extern cred_t *zone_kcred(void); 870Sstevel@tonic-gate 880Sstevel@tonic-gate extern uid_t crgetuid(const cred_t *); 890Sstevel@tonic-gate extern uid_t crgetruid(const cred_t *); 900Sstevel@tonic-gate extern uid_t crgetsuid(const cred_t *); 910Sstevel@tonic-gate extern gid_t crgetgid(const cred_t *); 920Sstevel@tonic-gate extern gid_t crgetrgid(const cred_t *); 930Sstevel@tonic-gate extern gid_t crgetsgid(const cred_t *); 940Sstevel@tonic-gate extern zoneid_t crgetzoneid(const cred_t *); 950Sstevel@tonic-gate extern projid_t crgetprojid(const cred_t *); 960Sstevel@tonic-gate 974321Scasper extern cred_t *crgetmapped(const cred_t *); 984321Scasper 991676Sjpk 1000Sstevel@tonic-gate extern const struct auditinfo_addr *crgetauinfo(const cred_t *); 1010Sstevel@tonic-gate extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate extern uint_t crgetref(const cred_t *); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate extern const gid_t *crgetgroups(const cred_t *); 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate extern int crgetngroups(const cred_t *); 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Sets real, effective and/or saved uid/gid; 1110Sstevel@tonic-gate * -1 argument accepted as "no change". 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t); 1140Sstevel@tonic-gate extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Sets real, effective and saved uids/gids all to the same 1180Sstevel@tonic-gate * values. Both values must be non-negative and <= MAXUID 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate extern int crsetugid(cred_t *, uid_t, gid_t); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate extern int crsetgroups(cred_t *, int, gid_t *); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Private interface for setting zone association of credential. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate struct zone; 1280Sstevel@tonic-gate extern void crsetzone(cred_t *, struct zone *); 1291676Sjpk extern struct zone *crgetzone(const cred_t *); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* 1320Sstevel@tonic-gate * Private interface for setting project id in credential. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate extern void crsetprojid(cred_t *, projid_t); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * Private interface for nfs. 1380Sstevel@tonic-gate */ 1390Sstevel@tonic-gate extern cred_t *crnetadjust(cred_t *); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Private interface for procfs. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate extern void cred2prcred(const cred_t *, struct prcred *); 1450Sstevel@tonic-gate 1461676Sjpk /* 1471676Sjpk * Private interfaces for Rampart Trusted Solaris. 1481676Sjpk */ 1491676Sjpk struct ts_label_s; 1501676Sjpk extern struct ts_label_s *crgetlabel(const cred_t *); 1511676Sjpk extern boolean_t crisremote(const cred_t *); 1521676Sjpk 1534321Scasper /* 1544321Scasper * Private interfaces for ephemeral uids. 1554321Scasper */ 1564321Scasper #define VALID_UID(id) \ 1574321Scasper ((id) <= MAXUID || valid_ephemeral_uid((id))) 1584321Scasper #define VALID_GID(id) \ 1594321Scasper ((id) <= MAXUID || valid_ephemeral_gid((id))) 1604321Scasper 1614321Scasper extern boolean_t valid_ephemeral_uid(uid_t); 1624321Scasper extern boolean_t valid_ephemeral_gid(gid_t); 1634321Scasper 1644321Scasper extern int eph_uid_alloc(int, uid_t *, int); 1654321Scasper extern int eph_gid_alloc(int, gid_t *, int); 1664321Scasper 1674321Scasper extern void crsetsid(cred_t *, struct ksid *, int); 1684321Scasper extern void crsetsidlist(cred_t *, struct ksidlist *); 1694321Scasper 1704321Scasper extern struct ksid *crgetsid(const cred_t *, int); 1714321Scasper extern struct ksidlist *crgetsidlist(const cred_t *); 1724321Scasper 173*5331Samw extern int crsetpriv(cred_t *, ...); 174*5331Samw 1750Sstevel@tonic-gate #endif /* _KERNEL */ 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate #ifdef __cplusplus 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate #endif 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate #endif /* _SYS_CRED_H */ 182