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 /* 22*11134SCasper.Dik@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 * 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 #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/procfs.h> 340Sstevel@tonic-gate #include <sys/cred.h> 350Sstevel@tonic-gate #include <sys/priv.h> 361676Sjpk #include <sys/tsol/label.h> 371676Sjpk #include <sys/tsol/label_macro.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef _KERNEL 400Sstevel@tonic-gate #include <c2/audit.h> 410Sstevel@tonic-gate #else 420Sstevel@tonic-gate #include <bsm/audit.h> 430Sstevel@tonic-gate #endif 440Sstevel@tonic-gate 450Sstevel@tonic-gate #ifndef _KERNEL 460Sstevel@tonic-gate #include <unistd.h> 470Sstevel@tonic-gate #endif 480Sstevel@tonic-gate 490Sstevel@tonic-gate #ifdef __cplusplus 500Sstevel@tonic-gate extern "C" { 510Sstevel@tonic-gate #endif 520Sstevel@tonic-gate 530Sstevel@tonic-gate 540Sstevel@tonic-gate 550Sstevel@tonic-gate #if defined(_KERNEL) || _STRUCTURED_PROC != 0 560Sstevel@tonic-gate /* 570Sstevel@tonic-gate * bitness neutral struct 580Sstevel@tonic-gate * 590Sstevel@tonic-gate * Add new fixed fields at the end of the structure. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate struct ucred_s { 620Sstevel@tonic-gate uint32_t uc_size; /* Size of the full structure */ 630Sstevel@tonic-gate uint32_t uc_credoff; /* Credential offset: 0 - no cred */ 640Sstevel@tonic-gate uint32_t uc_privoff; /* Privilege offset: 0 - no privs */ 650Sstevel@tonic-gate pid_t uc_pid; /* Process id */ 660Sstevel@tonic-gate uint32_t uc_audoff; /* Audit info offset: 0 - no aud */ 670Sstevel@tonic-gate zoneid_t uc_zoneid; /* Zone id */ 680Sstevel@tonic-gate projid_t uc_projid; /* Project id */ 691676Sjpk uint32_t uc_labeloff; /* label offset: 0 - no label */ 700Sstevel@tonic-gate /* The rest goes here */ 710Sstevel@tonic-gate }; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* Get the process credentials */ 740Sstevel@tonic-gate #define UCCRED(uc) (prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \ 750Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_credoff) 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* Get the process privileges */ 780Sstevel@tonic-gate #define UCPRIV(uc) (prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \ 790Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_privoff) 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* Get the process audit info */ 820Sstevel@tonic-gate #define UCAUD(uc) (auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \ 830Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_audoff) 840Sstevel@tonic-gate 851676Sjpk /* Get peer security label info */ 861676Sjpk #define UCLABEL(uc) (bslabel_t *)(((uc)->uc_labeloff == 0) ? NULL : \ 871676Sjpk ((char *)(uc)) + (uc)->uc_labeloff) 881676Sjpk 890Sstevel@tonic-gate #endif /* _KERNEL || _STRUCTURED_PROC != 0 */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * SYS_ucredsys subcodes. 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate #define UCREDSYS_UCREDGET 0 950Sstevel@tonic-gate #define UCREDSYS_GETPEERUCRED 1 960Sstevel@tonic-gate 970Sstevel@tonic-gate #ifdef _KERNEL 980Sstevel@tonic-gate 99*11134SCasper.Dik@Sun.COM extern uint32_t ucredminsize(const cred_t *); 1000Sstevel@tonic-gate 101*11134SCasper.Dik@Sun.COM #define UCRED_PRIV_OFF (sizeof (struct ucred_s)) 1020Sstevel@tonic-gate #define UCRED_AUD_OFF (UCRED_PRIV_OFF + priv_prgetprivsize(NULL)) 1031676Sjpk #define UCRED_LABEL_OFF (UCRED_AUD_OFF + get_audit_ucrsize()) 104*11134SCasper.Dik@Sun.COM 105*11134SCasper.Dik@Sun.COM /* The prcred_t has a variable size; it should be last. */ 106*11134SCasper.Dik@Sun.COM #define UCRED_CRED_OFF (UCRED_LABEL_OFF + \ 107*11134SCasper.Dik@Sun.COM (is_system_labeled() ? sizeof (bslabel_t) : 0)) 108*11134SCasper.Dik@Sun.COM 109*11134SCasper.Dik@Sun.COM #define UCRED_SIZE (UCRED_CRED_OFF + sizeof (prcred_t) + \ 110*11134SCasper.Dik@Sun.COM (ngroups_max - 1) * sizeof (gid_t)) 111*11134SCasper.Dik@Sun.COM 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate struct proc; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate extern struct ucred_s *pgetucred(struct proc *); 1161676Sjpk extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *, 1171676Sjpk const cred_t *); 1180Sstevel@tonic-gate extern int get_audit_ucrsize(void); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate #else 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* Definition only valid for structured proc. */ 1230Sstevel@tonic-gate #if _STRUCTURED_PROC != 0 1240Sstevel@tonic-gate #define UCRED_SIZE(ip) (sizeof (struct ucred_s) + sizeof (prcred_t) + \ 1250Sstevel@tonic-gate ((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \ 1260Sstevel@tonic-gate sizeof (prpriv_t) + \ 1270Sstevel@tonic-gate sizeof (priv_chunk_t) * \ 1280Sstevel@tonic-gate ((ip)->priv_setsize * (ip)->priv_nsets - 1) + \ 1290Sstevel@tonic-gate (ip)->priv_infosize + \ 1301676Sjpk sizeof (auditinfo64_addr_t) + \ 1311676Sjpk sizeof (bslabel_t)) 1320Sstevel@tonic-gate #endif 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate extern struct ucred_s *_ucred_alloc(void); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate #endif 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate #ifdef __cplusplus 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate #endif 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate #endif /* _SYS_UCRED_H */ 143