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 /* 229151SThomas.Haynes@Sun.COM * Copyright 2009 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 #include <sys/types.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef __cplusplus 400Sstevel@tonic-gate extern "C" { 410Sstevel@tonic-gate #endif 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * The credential is an opaque kernel private data structure defined in 450Sstevel@tonic-gate * <sys/cred_impl.h>. 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate 480Sstevel@tonic-gate typedef struct cred cred_t; 490Sstevel@tonic-gate 500Sstevel@tonic-gate #ifdef _KERNEL 510Sstevel@tonic-gate 520Sstevel@tonic-gate #define CRED() curthread->t_cred 530Sstevel@tonic-gate 540Sstevel@tonic-gate struct proc; /* cred.h is included in proc.h */ 550Sstevel@tonic-gate struct prcred; 564321Scasper struct ksid; 574321Scasper struct ksidlist; 586134Scasper struct credklpd; 59*11134SCasper.Dik@Sun.COM struct credgrp; 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 *); 819151SThomas.Haynes@Sun.COM extern void crset_zone_privall(cred_t *); 820Sstevel@tonic-gate extern int groupmember(gid_t, const cred_t *); 830Sstevel@tonic-gate extern int supgroupmember(gid_t, const cred_t *); 840Sstevel@tonic-gate extern int hasprocperm(const cred_t *, const cred_t *); 850Sstevel@tonic-gate extern int prochasprocperm(struct proc *, struct proc *, const cred_t *); 860Sstevel@tonic-gate extern int crcmp(const cred_t *, const cred_t *); 871676Sjpk extern cred_t *zone_kcred(void); 880Sstevel@tonic-gate 890Sstevel@tonic-gate extern uid_t crgetuid(const cred_t *); 900Sstevel@tonic-gate extern uid_t crgetruid(const cred_t *); 910Sstevel@tonic-gate extern uid_t crgetsuid(const cred_t *); 920Sstevel@tonic-gate extern gid_t crgetgid(const cred_t *); 930Sstevel@tonic-gate extern gid_t crgetrgid(const cred_t *); 940Sstevel@tonic-gate extern gid_t crgetsgid(const cred_t *); 950Sstevel@tonic-gate extern zoneid_t crgetzoneid(const cred_t *); 960Sstevel@tonic-gate extern projid_t crgetprojid(const cred_t *); 970Sstevel@tonic-gate 984321Scasper extern cred_t *crgetmapped(const cred_t *); 994321Scasper 1001676Sjpk 1010Sstevel@tonic-gate extern const struct auditinfo_addr *crgetauinfo(const cred_t *); 1020Sstevel@tonic-gate extern struct auditinfo_addr *crgetauinfo_modifiable(cred_t *); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate extern uint_t crgetref(const cred_t *); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate extern const gid_t *crgetgroups(const cred_t *); 107*11134SCasper.Dik@Sun.COM extern const gid_t *crgetggroups(const struct credgrp *); 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate extern int crgetngroups(const cred_t *); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Sets real, effective and/or saved uid/gid; 1130Sstevel@tonic-gate * -1 argument accepted as "no change". 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate extern int crsetresuid(cred_t *, uid_t, uid_t, uid_t); 1160Sstevel@tonic-gate extern int crsetresgid(cred_t *, gid_t, gid_t, gid_t); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * Sets real, effective and saved uids/gids all to the same 1200Sstevel@tonic-gate * values. Both values must be non-negative and <= MAXUID 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate extern int crsetugid(cred_t *, uid_t, gid_t); 1230Sstevel@tonic-gate 124*11134SCasper.Dik@Sun.COM /* 125*11134SCasper.Dik@Sun.COM * Functions to handle the supplemental group list. 126*11134SCasper.Dik@Sun.COM */ 1270Sstevel@tonic-gate extern int crsetgroups(cred_t *, int, gid_t *); 128*11134SCasper.Dik@Sun.COM extern struct credgrp *crgrpcopyin(int, gid_t *); 129*11134SCasper.Dik@Sun.COM extern void crgrprele(struct credgrp *); 130*11134SCasper.Dik@Sun.COM extern void crsetcredgrp(cred_t *, struct credgrp *); 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Private interface for setting zone association of credential. 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate struct zone; 1360Sstevel@tonic-gate extern void crsetzone(cred_t *, struct zone *); 1371676Sjpk extern struct zone *crgetzone(const cred_t *); 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate /* 1400Sstevel@tonic-gate * Private interface for setting project id in credential. 1410Sstevel@tonic-gate */ 1420Sstevel@tonic-gate extern void crsetprojid(cred_t *, projid_t); 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate * Private interface for nfs. 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate extern cred_t *crnetadjust(cred_t *); 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* 1500Sstevel@tonic-gate * Private interface for procfs. 1510Sstevel@tonic-gate */ 1520Sstevel@tonic-gate extern void cred2prcred(const cred_t *, struct prcred *); 1530Sstevel@tonic-gate 1541676Sjpk /* 1551676Sjpk * Private interfaces for Rampart Trusted Solaris. 1561676Sjpk */ 1571676Sjpk struct ts_label_s; 1581676Sjpk extern struct ts_label_s *crgetlabel(const cred_t *); 1591676Sjpk extern boolean_t crisremote(const cred_t *); 1601676Sjpk 1614321Scasper /* 1624321Scasper * Private interfaces for ephemeral uids. 1634321Scasper */ 1645771Sjp151216 #define VALID_UID(id, zn) \ 1655771Sjp151216 ((id) <= MAXUID || valid_ephemeral_uid((zn), (id))) 1665771Sjp151216 1675771Sjp151216 #define VALID_GID(id, zn) \ 1685771Sjp151216 ((id) <= MAXUID || valid_ephemeral_gid((zn), (id))) 1694321Scasper 1705771Sjp151216 extern boolean_t valid_ephemeral_uid(struct zone *, uid_t); 1715771Sjp151216 extern boolean_t valid_ephemeral_gid(struct zone *, gid_t); 1724321Scasper 1735771Sjp151216 extern int eph_uid_alloc(struct zone *, int, uid_t *, int); 1745771Sjp151216 extern int eph_gid_alloc(struct zone *, int, gid_t *, int); 1754321Scasper 1764321Scasper extern void crsetsid(cred_t *, struct ksid *, int); 1774321Scasper extern void crsetsidlist(cred_t *, struct ksidlist *); 1784321Scasper 1794321Scasper extern struct ksid *crgetsid(const cred_t *, int); 1804321Scasper extern struct ksidlist *crgetsidlist(const cred_t *); 1814321Scasper 1825331Samw extern int crsetpriv(cred_t *, ...); 1835331Samw 1846134Scasper extern struct credklpd *crgetcrklpd(const cred_t *); 1856134Scasper extern void crsetcrklpd(cred_t *, struct credklpd *); 1866134Scasper 1870Sstevel@tonic-gate #endif /* _KERNEL */ 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #ifdef __cplusplus 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate #endif 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate #endif /* _SYS_CRED_H */ 194