14321Scasper /* 24321Scasper * CDDL HEADER START 34321Scasper * 44321Scasper * The contents of this file are subject to the terms of the 54321Scasper * Common Development and Distribution License (the "License"). 64321Scasper * You may not use this file except in compliance with the License. 74321Scasper * 84321Scasper * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 94321Scasper * or http://www.opensolaris.org/os/licensing. 104321Scasper * See the License for the specific language governing permissions 114321Scasper * and limitations under the License. 124321Scasper * 134321Scasper * When distributing Covered Code, include this CDDL HEADER in each 144321Scasper * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 154321Scasper * If applicable, add the following below this CDDL HEADER, with the 164321Scasper * fields enclosed by brackets "[]" replaced with your own identifying 174321Scasper * information: Portions Copyright [yyyy] [name of copyright owner] 184321Scasper * 194321Scasper * CDDL HEADER END 204321Scasper */ 214321Scasper 224321Scasper /* 23*11963SAfshin.Ardakani@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 244321Scasper * Use is subject to license terms. 254321Scasper */ 264321Scasper 274321Scasper #ifndef _SYS_SID_H 284321Scasper #define _SYS_SID_H 294321Scasper 304321Scasper #include <sys/types.h> 314321Scasper #include <sys/avl.h> 325771Sjp151216 #ifdef _KERNEL 335771Sjp151216 #include <sys/zone.h> 345771Sjp151216 #endif 354321Scasper 364321Scasper /* 374321Scasper * Kernel SID data structure and functions. 384321Scasper */ 394321Scasper #ifdef __cplusplus 404321Scasper extern "C" { 414321Scasper #endif 424321Scasper 434321Scasper /* sidsys subcodes */ 444321Scasper #define SIDSYS_ALLOC_IDS 0 454321Scasper /* Flags for ALLOC_IDS */ 465771Sjp151216 #define SID_EXTEND_RANGE 0 475771Sjp151216 #define SID_NEW_RANGE 1 484321Scasper 494321Scasper #define SIDSYS_IDMAP_REG 1 504321Scasper #define SIDSYS_IDMAP_UNREG 2 51*11963SAfshin.Ardakani@Sun.COM #define SIDSYS_IDMAP_FLUSH_KCACHE 3 524321Scasper 534321Scasper #define SIDSYS_SID2ID 0 544321Scasper #define SIDSYS_ID2SID 1 554321Scasper 564321Scasper #ifdef _KERNEL 575331Samw #define KSIDLIST_MEM(n) (sizeof (ksidlist_t) + ((n) - 1) * sizeof (ksid_t)) 585331Samw 594321Scasper /* Domains are stored in AVL trees so we can share them among SIDs */ 604321Scasper typedef struct ksiddomain { 614321Scasper uint_t kd_ref; 624321Scasper uint_t kd_len; 634321Scasper char *kd_name; /* Domain part of SID */ 644321Scasper avl_node_t kd_link; 654321Scasper } ksiddomain_t; 664321Scasper 674321Scasper typedef struct ksid { 684321Scasper uid_t ks_id; /* Cache of (ephemeral) uid */ 694321Scasper uint32_t ks_rid; /* Rid part of the name */ 704321Scasper uint32_t ks_attr; /* Attribute */ 714321Scasper ksiddomain_t *ks_domain; /* Domain descsriptor */ 724321Scasper } ksid_t; 734321Scasper 744321Scasper typedef enum ksid_index { 754321Scasper KSID_USER, 764321Scasper KSID_GROUP, 774321Scasper KSID_OWNER, 784321Scasper KSID_COUNT /* Must be last */ 794321Scasper } ksid_index_t; 804321Scasper 814321Scasper /* 824321Scasper * As no memory may be allocated for credentials while holding p_crlock, 834321Scasper * all sub data structures need to be ref counted. 844321Scasper */ 854321Scasper 864321Scasper typedef struct ksidlist { 874321Scasper uint_t ksl_ref; 884321Scasper uint_t ksl_nsid; 894321Scasper uint_t ksl_neid; /* Number of ids which are ephemeral */ 904321Scasper ksid_t ksl_sids[1]; /* Allocate ksl_nsid times */ 914321Scasper } ksidlist_t; 924321Scasper 934321Scasper typedef struct credsid { 944321Scasper uint_t kr_ref; /* Reference count */ 954321Scasper ksid_t kr_sidx[KSID_COUNT]; /* User, group, default owner */ 964321Scasper ksidlist_t *kr_sidlist; /* List of SIDS */ 974321Scasper } credsid_t; 984321Scasper 994321Scasper const char *ksid_getdomain(ksid_t *); 1004321Scasper uint_t ksid_getrid(ksid_t *); 1017847SMark.Shellenbaum@Sun.COM uid_t ksid_getid(ksid_t *); 1024321Scasper 1035771Sjp151216 int ksid_lookupbyuid(zone_t *, uid_t, ksid_t *); 1045771Sjp151216 int ksid_lookupbygid(zone_t *, gid_t, ksid_t *); 1054321Scasper void ksid_rele(ksid_t *); 1064321Scasper 1074321Scasper credsid_t *kcrsid_alloc(void); 1084321Scasper 1094321Scasper credsid_t *kcrsid_setsid(credsid_t *, ksid_t *, ksid_index_t); 1104321Scasper credsid_t *kcrsid_setsidlist(credsid_t *, ksidlist_t *); 1114321Scasper 1124321Scasper void kcrsid_rele(credsid_t *); 1134321Scasper void kcrsid_hold(credsid_t *); 1144321Scasper void kcrsidcopy_to(const credsid_t *okcr, credsid_t *nkcr); 1154321Scasper 1164321Scasper void ksiddomain_rele(ksiddomain_t *); 1174321Scasper void ksiddomain_hold(ksiddomain_t *); 1184321Scasper void ksidlist_rele(ksidlist_t *); 1194321Scasper void ksidlist_hold(ksidlist_t *); 1204321Scasper 1214321Scasper ksiddomain_t *ksid_lookupdomain(const char *); 1224321Scasper 1235771Sjp151216 ksidlist_t *kcrsid_gidstosids(zone_t *, int, gid_t *); 1244321Scasper 1254321Scasper #else 1264321Scasper 1274321Scasper int allocids(int, int, uid_t *, int, gid_t *); 128*11963SAfshin.Ardakani@Sun.COM int __idmap_reg(int); 129*11963SAfshin.Ardakani@Sun.COM int __idmap_unreg(int); 130*11963SAfshin.Ardakani@Sun.COM int __idmap_flush_kcache(void); 1314321Scasper 1324321Scasper #endif /* _KERNEL */ 1334321Scasper 1344321Scasper #ifdef __cplusplus 1354321Scasper } 1364321Scasper #endif 1374321Scasper 1384321Scasper #endif /* _SYS_SID_H */ 139