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 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * 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*67dbe2beSCasper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate * 257c478bd9Sstevel@tonic-gate * File with private definitions for the ucred structure for use by the 267c478bd9Sstevel@tonic-gate * kernel and library routines. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _SYS_UCRED_H 307c478bd9Sstevel@tonic-gate #define _SYS_UCRED_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/procfs.h> 347c478bd9Sstevel@tonic-gate #include <sys/cred.h> 357c478bd9Sstevel@tonic-gate #include <sys/priv.h> 3645916cd2Sjpk #include <sys/tsol/label.h> 3745916cd2Sjpk #include <sys/tsol/label_macro.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef _KERNEL 407c478bd9Sstevel@tonic-gate #include <c2/audit.h> 417c478bd9Sstevel@tonic-gate #else 427c478bd9Sstevel@tonic-gate #include <bsm/audit.h> 437c478bd9Sstevel@tonic-gate #endif 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifndef _KERNEL 467c478bd9Sstevel@tonic-gate #include <unistd.h> 477c478bd9Sstevel@tonic-gate #endif 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #ifdef __cplusplus 507c478bd9Sstevel@tonic-gate extern "C" { 517c478bd9Sstevel@tonic-gate #endif 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || _STRUCTURED_PROC != 0 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * bitness neutral struct 587c478bd9Sstevel@tonic-gate * 597c478bd9Sstevel@tonic-gate * Add new fixed fields at the end of the structure. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate struct ucred_s { 627c478bd9Sstevel@tonic-gate uint32_t uc_size; /* Size of the full structure */ 637c478bd9Sstevel@tonic-gate uint32_t uc_credoff; /* Credential offset: 0 - no cred */ 647c478bd9Sstevel@tonic-gate uint32_t uc_privoff; /* Privilege offset: 0 - no privs */ 657c478bd9Sstevel@tonic-gate pid_t uc_pid; /* Process id */ 667c478bd9Sstevel@tonic-gate uint32_t uc_audoff; /* Audit info offset: 0 - no aud */ 677c478bd9Sstevel@tonic-gate zoneid_t uc_zoneid; /* Zone id */ 687c478bd9Sstevel@tonic-gate projid_t uc_projid; /* Project id */ 6945916cd2Sjpk uint32_t uc_labeloff; /* label offset: 0 - no label */ 707c478bd9Sstevel@tonic-gate /* The rest goes here */ 717c478bd9Sstevel@tonic-gate }; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* Get the process credentials */ 747c478bd9Sstevel@tonic-gate #define UCCRED(uc) (prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \ 757c478bd9Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_credoff) 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* Get the process privileges */ 787c478bd9Sstevel@tonic-gate #define UCPRIV(uc) (prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \ 797c478bd9Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_privoff) 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* Get the process audit info */ 827c478bd9Sstevel@tonic-gate #define UCAUD(uc) (auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \ 837c478bd9Sstevel@tonic-gate ((char *)(uc)) + (uc)->uc_audoff) 847c478bd9Sstevel@tonic-gate 8545916cd2Sjpk /* Get peer security label info */ 8645916cd2Sjpk #define UCLABEL(uc) (bslabel_t *)(((uc)->uc_labeloff == 0) ? NULL : \ 8745916cd2Sjpk ((char *)(uc)) + (uc)->uc_labeloff) 8845916cd2Sjpk 897c478bd9Sstevel@tonic-gate #endif /* _KERNEL || _STRUCTURED_PROC != 0 */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * SYS_ucredsys subcodes. 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate #define UCREDSYS_UCREDGET 0 957c478bd9Sstevel@tonic-gate #define UCREDSYS_GETPEERUCRED 1 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #ifdef _KERNEL 987c478bd9Sstevel@tonic-gate 99*67dbe2beSCasper H.S. Dik extern uint32_t ucredminsize(const cred_t *); 1007c478bd9Sstevel@tonic-gate 101*67dbe2beSCasper H.S. Dik #define UCRED_PRIV_OFF (sizeof (struct ucred_s)) 1027c478bd9Sstevel@tonic-gate #define UCRED_AUD_OFF (UCRED_PRIV_OFF + priv_prgetprivsize(NULL)) 10345916cd2Sjpk #define UCRED_LABEL_OFF (UCRED_AUD_OFF + get_audit_ucrsize()) 104*67dbe2beSCasper H.S. Dik 105*67dbe2beSCasper H.S. Dik /* The prcred_t has a variable size; it should be last. */ 106*67dbe2beSCasper H.S. Dik #define UCRED_CRED_OFF (UCRED_LABEL_OFF + \ 107*67dbe2beSCasper H.S. Dik (is_system_labeled() ? sizeof (bslabel_t) : 0)) 108*67dbe2beSCasper H.S. Dik 109*67dbe2beSCasper H.S. Dik #define UCRED_SIZE (UCRED_CRED_OFF + sizeof (prcred_t) + \ 110*67dbe2beSCasper H.S. Dik (ngroups_max - 1) * sizeof (gid_t)) 111*67dbe2beSCasper H.S. Dik 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate struct proc; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate extern struct ucred_s *pgetucred(struct proc *); 11645916cd2Sjpk extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *, 11745916cd2Sjpk const cred_t *); 1187c478bd9Sstevel@tonic-gate extern int get_audit_ucrsize(void); 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #else 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* Definition only valid for structured proc. */ 1237c478bd9Sstevel@tonic-gate #if _STRUCTURED_PROC != 0 1247c478bd9Sstevel@tonic-gate #define UCRED_SIZE(ip) (sizeof (struct ucred_s) + sizeof (prcred_t) + \ 1257c478bd9Sstevel@tonic-gate ((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \ 1267c478bd9Sstevel@tonic-gate sizeof (prpriv_t) + \ 1277c478bd9Sstevel@tonic-gate sizeof (priv_chunk_t) * \ 1287c478bd9Sstevel@tonic-gate ((ip)->priv_setsize * (ip)->priv_nsets - 1) + \ 1297c478bd9Sstevel@tonic-gate (ip)->priv_infosize + \ 13045916cd2Sjpk sizeof (auditinfo64_addr_t) + \ 13145916cd2Sjpk sizeof (bslabel_t)) 1327c478bd9Sstevel@tonic-gate #endif 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate extern struct ucred_s *_ucred_alloc(void); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #endif 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate #endif 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif /* _SYS_UCRED_H */ 143