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 /* 234321Scasper * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 314321Scasper 324321Scasper #include <sys/types.h> 334321Scasper #include <sys/avl.h> 344321Scasper 354321Scasper /* 364321Scasper * Kernel SID data structure and functions. 374321Scasper */ 384321Scasper #ifdef __cplusplus 394321Scasper extern "C" { 404321Scasper #endif 414321Scasper 424321Scasper /* sidsys subcodes */ 434321Scasper #define SIDSYS_ALLOC_IDS 0 444321Scasper /* Flags for ALLOC_IDS */ 454321Scasper #define SID_EXTEND_RANGE 0 464321Scasper #define SID_NEW_RANGE 1 474321Scasper 484321Scasper #define SIDSYS_IDMAP_REG 1 494321Scasper #define SIDSYS_IDMAP_UNREG 2 504321Scasper 514321Scasper #define SIDSYS_SID2ID 0 524321Scasper #define SIDSYS_ID2SID 1 534321Scasper 544321Scasper #ifdef _KERNEL 55*5331Samw #define KSIDLIST_MEM(n) (sizeof (ksidlist_t) + ((n) - 1) * sizeof (ksid_t)) 56*5331Samw 574321Scasper /* Domains are stored in AVL trees so we can share them among SIDs */ 584321Scasper typedef struct ksiddomain { 594321Scasper uint_t kd_ref; 604321Scasper uint_t kd_len; 614321Scasper char *kd_name; /* Domain part of SID */ 624321Scasper avl_node_t kd_link; 634321Scasper } ksiddomain_t; 644321Scasper 654321Scasper typedef struct ksid { 664321Scasper uid_t ks_id; /* Cache of (ephemeral) uid */ 674321Scasper uint32_t ks_rid; /* Rid part of the name */ 684321Scasper uint32_t ks_attr; /* Attribute */ 694321Scasper ksiddomain_t *ks_domain; /* Domain descsriptor */ 704321Scasper } ksid_t; 714321Scasper 724321Scasper typedef enum ksid_index { 734321Scasper KSID_USER, 744321Scasper KSID_GROUP, 754321Scasper KSID_OWNER, 764321Scasper KSID_COUNT /* Must be last */ 774321Scasper } ksid_index_t; 784321Scasper 794321Scasper /* 804321Scasper * As no memory may be allocated for credentials while holding p_crlock, 814321Scasper * all sub data structures need to be ref counted. 824321Scasper */ 834321Scasper 844321Scasper typedef struct ksidlist { 854321Scasper uint_t ksl_ref; 864321Scasper uint_t ksl_nsid; 874321Scasper uint_t ksl_neid; /* Number of ids which are ephemeral */ 884321Scasper ksid_t ksl_sids[1]; /* Allocate ksl_nsid times */ 894321Scasper } ksidlist_t; 904321Scasper 914321Scasper typedef struct credsid { 924321Scasper uint_t kr_ref; /* Reference count */ 934321Scasper ksid_t kr_sidx[KSID_COUNT]; /* User, group, default owner */ 944321Scasper ksidlist_t *kr_sidlist; /* List of SIDS */ 954321Scasper } credsid_t; 964321Scasper 974321Scasper const char *ksid_getdomain(ksid_t *); 984321Scasper uint_t ksid_getrid(ksid_t *); 994321Scasper 1004520Snw141292 int ksid_lookupbyuid(uid_t, ksid_t *); 1014520Snw141292 int ksid_lookupbygid(gid_t, ksid_t *); 1024321Scasper void ksid_rele(ksid_t *); 1034321Scasper 1044321Scasper credsid_t *kcrsid_alloc(void); 1054321Scasper 1064321Scasper credsid_t *kcrsid_setsid(credsid_t *, ksid_t *, ksid_index_t); 1074321Scasper credsid_t *kcrsid_setsidlist(credsid_t *, ksidlist_t *); 1084321Scasper 1094321Scasper void kcrsid_rele(credsid_t *); 1104321Scasper void kcrsid_hold(credsid_t *); 1114321Scasper void kcrsidcopy_to(const credsid_t *okcr, credsid_t *nkcr); 1124321Scasper 1134321Scasper void ksiddomain_rele(ksiddomain_t *); 1144321Scasper void ksiddomain_hold(ksiddomain_t *); 1154321Scasper void ksidlist_rele(ksidlist_t *); 1164321Scasper void ksidlist_hold(ksidlist_t *); 1174321Scasper 1184321Scasper ksiddomain_t *ksid_lookupdomain(const char *); 1194321Scasper 1204321Scasper ksidlist_t *kcrsid_gidstosids(int, gid_t *); 1214321Scasper 1224321Scasper #else 1234321Scasper 1244321Scasper int allocids(int, int, uid_t *, int, gid_t *); 1254321Scasper int idmap_reg(int); 1264321Scasper int idmap_unreg(int); 1274321Scasper 1284321Scasper #endif /* _KERNEL */ 1294321Scasper 1304321Scasper #ifdef __cplusplus 1314321Scasper } 1324321Scasper #endif 1334321Scasper 1344321Scasper #endif /* _SYS_SID_H */ 135