xref: /titanic_41/usr/src/uts/common/sys/sid.h (revision 418e2f3050b6a419bd7c37e2ed3d8dd99b7cc261)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_SID_H
28 #define	_SYS_SID_H
29 
30 #include <sys/types.h>
31 #include <sys/avl.h>
32 #ifdef _KERNEL
33 #include <sys/zone.h>
34 #endif
35 
36 /*
37  * Kernel SID data structure and functions.
38  */
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /* sidsys subcodes */
44 #define	SIDSYS_ALLOC_IDS	0
45 /* Flags for ALLOC_IDS */
46 #define	SID_EXTEND_RANGE	0
47 #define	SID_NEW_RANGE		1
48 
49 #define	SIDSYS_IDMAP_REG	1
50 #define	SIDSYS_IDMAP_UNREG	2
51 #define	SIDSYS_IDMAP_FLUSH_KCACHE 3
52 
53 #define	SIDSYS_SID2ID	0
54 #define	SIDSYS_ID2SID	1
55 
56 #ifdef _KERNEL
57 #define	KSIDLIST_MEM(n)	(sizeof (ksidlist_t) + ((n) - 1) * sizeof (ksid_t))
58 
59 /* Domains are stored in AVL trees so we can share them among SIDs */
60 typedef struct ksiddomain {
61 	uint_t		kd_ref;
62 	uint_t		kd_len;
63 	char		*kd_name;	/* Domain part of SID */
64 	avl_node_t	kd_link;
65 } ksiddomain_t;
66 
67 typedef struct ksid {
68 	uid_t		ks_id;		/* Cache of (ephemeral) uid */
69 	uint32_t	ks_rid;		/* Rid part of the name */
70 	uint32_t	ks_attr;	/* Attribute */
71 	ksiddomain_t	*ks_domain;	/* Domain descsriptor */
72 } ksid_t;
73 
74 typedef enum ksid_index {
75 	KSID_USER,
76 	KSID_GROUP,
77 	KSID_OWNER,
78 	KSID_COUNT			/* Must be last */
79 } ksid_index_t;
80 
81 /*
82  * As no memory may be allocated for credentials while holding p_crlock,
83  * all sub data structures need to be ref counted.
84  */
85 
86 typedef struct ksidlist {
87 	uint_t		ksl_ref;
88 	uint_t		ksl_nsid;
89 	uint_t		ksl_neid;	/* Number of ids which are ephemeral */
90 	ksid_t		ksl_sids[1];	/* Allocate ksl_nsid times */
91 } ksidlist_t;
92 
93 typedef struct credsid {
94 	uint_t		kr_ref;			/* Reference count */
95 	ksid_t		kr_sidx[KSID_COUNT];	/* User, group, default owner */
96 	ksidlist_t	*kr_sidlist;		/* List of SIDS */
97 } credsid_t;
98 
99 const char *ksid_getdomain(ksid_t *);
100 uint_t ksid_getrid(ksid_t *);
101 uid_t ksid_getid(ksid_t *);
102 
103 int ksid_lookupbyuid(zone_t *, uid_t, ksid_t *);
104 int ksid_lookupbygid(zone_t *, gid_t, ksid_t *);
105 void ksid_rele(ksid_t *);
106 
107 credsid_t *kcrsid_alloc(void);
108 
109 credsid_t *kcrsid_setsid(credsid_t *, ksid_t *, ksid_index_t);
110 credsid_t *kcrsid_setsidlist(credsid_t *, ksidlist_t *);
111 
112 void kcrsid_rele(credsid_t *);
113 void kcrsid_hold(credsid_t *);
114 void kcrsidcopy_to(const credsid_t *okcr, credsid_t *nkcr);
115 
116 void ksiddomain_rele(ksiddomain_t *);
117 void ksiddomain_hold(ksiddomain_t *);
118 void ksidlist_rele(ksidlist_t *);
119 void ksidlist_hold(ksidlist_t *);
120 
121 ksiddomain_t *ksid_lookupdomain(const char *);
122 
123 ksidlist_t *kcrsid_gidstosids(zone_t *, int, gid_t *);
124 
125 #else
126 
127 int allocids(int, int, uid_t *, int, gid_t *);
128 int __idmap_reg(int);
129 int __idmap_unreg(int);
130 int __idmap_flush_kcache(void);
131 
132 #endif /* _KERNEL */
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif /* _SYS_SID_H */
139