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 5*1676Sjpk * Common Development and Distribution License (the "License"). 6*1676Sjpk * 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 /* 22*1676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate * 250Sstevel@tonic-gate * File with private definitions for the ucred structure for use by the 260Sstevel@tonic-gate * kernel and library routines. 270Sstevel@tonic-gate */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifndef _SYS_UCRED_H 300Sstevel@tonic-gate #define _SYS_UCRED_H 310Sstevel@tonic-gate 320Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/procfs.h> 360Sstevel@tonic-gate #include <sys/cred.h> 370Sstevel@tonic-gate #include <sys/priv.h> 38*1676Sjpk #include <sys/tsol/label.h> 39*1676Sjpk #include <sys/tsol/label_macro.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifdef _KERNEL 420Sstevel@tonic-gate #include <c2/audit.h> 430Sstevel@tonic-gate #else 440Sstevel@tonic-gate #include <bsm/audit.h> 450Sstevel@tonic-gate #endif 460Sstevel@tonic-gate 470Sstevel@tonic-gate #ifndef _KERNEL 480Sstevel@tonic-gate #include <unistd.h> 490Sstevel@tonic-gate #endif 500Sstevel@tonic-gate 510Sstevel@tonic-gate #ifdef __cplusplus 520Sstevel@tonic-gate extern "C" { 530Sstevel@tonic-gate #endif 540Sstevel@tonic-gate 550Sstevel@tonic-gate 560Sstevel@tonic-gate 570Sstevel@tonic-gate #if defined(_KERNEL) || _STRUCTURED_PROC != 0 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * bitness neutral struct 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * Add new fixed fields at the end of the structure. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate struct ucred_s { 640Sstevel@tonic-gate uint32_t uc_size; /* Size of the full structure */ 650Sstevel@tonic-gate uint32_t uc_credoff; /* Credential offset: 0 - no cred */ 660Sstevel@tonic-gate uint32_t uc_privoff; /* Privilege offset: 0 - no privs */ 670Sstevel@tonic-gate pid_t uc_pid; /* Process id */ 680Sstevel@tonic-gate uint32_t uc_audoff; /* Audit info offset: 0 - no aud */ 690Sstevel@tonic-gate zoneid_t uc_zoneid; /* Zone id */ 700Sstevel@tonic-gate projid_t uc_projid; /* Project id */ 71*1676Sjpk uint32_t uc_labeloff; /* label offset: 0 - no label */ 720Sstevel@tonic-gate /* The rest goes here */ 730Sstevel@tonic-gate }; 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* Get the process credentials */ 760Sstevel@tonic-gate #define UCCRED(uc) (prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \ 770Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_credoff) 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* Get the process privileges */ 800Sstevel@tonic-gate #define UCPRIV(uc) (prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \ 810Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_privoff) 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* Get the process audit info */ 840Sstevel@tonic-gate #define UCAUD(uc) (auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \ 850Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_audoff) 860Sstevel@tonic-gate 87*1676Sjpk /* Get peer security label info */ 88*1676Sjpk #define UCLABEL(uc) (bslabel_t *)(((uc)->uc_labeloff == 0) ? NULL : \ 89*1676Sjpk ((char *)(uc)) + (uc)->uc_labeloff) 90*1676Sjpk 910Sstevel@tonic-gate #define UCRED_CRED_OFF (sizeof (struct ucred_s)) 920Sstevel@tonic-gate 930Sstevel@tonic-gate #endif /* _KERNEL || _STRUCTURED_PROC != 0 */ 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * SYS_ucredsys subcodes. 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate #define UCREDSYS_UCREDGET 0 990Sstevel@tonic-gate #define UCREDSYS_GETPEERUCRED 1 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate #ifdef _KERNEL 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate extern uint32_t ucredsize; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate #define UCRED_PRIV_OFF (UCRED_CRED_OFF + sizeof (prcred_t) + \ 1060Sstevel@tonic-gate (ngroups_max - 1) * sizeof (gid_t)) 1070Sstevel@tonic-gate #define UCRED_AUD_OFF (UCRED_PRIV_OFF + priv_prgetprivsize(NULL)) 108*1676Sjpk #define UCRED_LABEL_OFF (UCRED_AUD_OFF + get_audit_ucrsize()) 109*1676Sjpk #define UCRED_SIZE (UCRED_LABEL_OFF + sizeof (bslabel_t)) 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate struct proc; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate extern struct ucred_s *pgetucred(struct proc *); 114*1676Sjpk extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *, 115*1676Sjpk const cred_t *); 1160Sstevel@tonic-gate extern int get_audit_ucrsize(void); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate #else 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* Definition only valid for structured proc. */ 1210Sstevel@tonic-gate #if _STRUCTURED_PROC != 0 1220Sstevel@tonic-gate #define UCRED_SIZE(ip) (sizeof (struct ucred_s) + sizeof (prcred_t) + \ 1230Sstevel@tonic-gate ((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \ 1240Sstevel@tonic-gate sizeof (prpriv_t) + \ 1250Sstevel@tonic-gate sizeof (priv_chunk_t) * \ 1260Sstevel@tonic-gate ((ip)->priv_setsize * (ip)->priv_nsets - 1) + \ 1270Sstevel@tonic-gate (ip)->priv_infosize + \ 128*1676Sjpk sizeof (auditinfo64_addr_t) + \ 129*1676Sjpk sizeof (bslabel_t)) 1300Sstevel@tonic-gate #endif 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate extern struct ucred_s *_ucred_alloc(void); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate #endif 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate #ifdef __cplusplus 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate #endif 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #endif /* _SYS_UCRED_H */ 141