xref: /illumos-gate/usr/src/uts/common/sys/sid.h (revision 3d7072f8bd27709dba14f6fe336f149d25d9e207)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/avl.h>
34 
35 /*
36  * Kernel SID data structure and functions.
37  */
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /* sidsys subcodes */
43 #define	SIDSYS_ALLOC_IDS	0
44 /* Flags for ALLOC_IDS */
45 #define		SID_EXTEND_RANGE	0
46 #define		SID_NEW_RANGE		1
47 
48 #define	SIDSYS_IDMAP_REG	1
49 #define	SIDSYS_IDMAP_UNREG	2
50 
51 #define	SIDSYS_SID2ID	0
52 #define	SIDSYS_ID2SID	1
53 
54 typedef struct domsid {
55 	uint_t	ds_rid;
56 	char	ds_dom[1];
57 } domsid_t;
58 
59 typedef struct sidmap_call {
60 	int	sc_type;
61 	union	sc_val_u {
62 		uid_t		sc_id;
63 		domsid_t	sc_sid;
64 	} sc_val;
65 } sidmap_call_t;
66 
67 
68 #ifdef _KERNEL
69 /* Domains are stored in AVL trees so we can share them among SIDs */
70 typedef struct ksiddomain {
71 	uint_t		kd_ref;
72 	uint_t		kd_len;
73 	char		*kd_name;	/* Domain part of SID */
74 	avl_node_t	kd_link;
75 } ksiddomain_t;
76 
77 typedef struct ksid {
78 	uid_t		ks_id;		/* Cache of (ephemeral) uid */
79 	uint32_t	ks_rid;		/* Rid part of the name */
80 	uint32_t	ks_attr;	/* Attribute */
81 	ksiddomain_t	*ks_domain;	/* Domain descsriptor */
82 } ksid_t;
83 
84 typedef enum ksid_index {
85 	KSID_USER,
86 	KSID_GROUP,
87 	KSID_OWNER,
88 	KSID_COUNT			/* Must be last */
89 } ksid_index_t;
90 
91 /*
92  * As no memory may be allocated for credentials while holding p_crlock,
93  * all sub data structures need to be ref counted.
94  */
95 
96 typedef struct ksidlist {
97 	uint_t		ksl_ref;
98 	uint_t		ksl_nsid;
99 	uint_t		ksl_neid;	/* Number of ids which are ephemeral */
100 	ksid_t		ksl_sids[1];	/* Allocate ksl_nsid times */
101 } ksidlist_t;
102 
103 #define	KSIDLIST_MEM(n)	(sizeof (ksidlist_t) + ((n) - 1) * sizeof (ksid_t))
104 
105 typedef struct credsid {
106 	uint_t		kr_ref;			/* Reference count */
107 	ksid_t		kr_sidx[KSID_COUNT];	/* User, group, default owner */
108 	ksidlist_t	*kr_sidlist;		/* List of SIDS */
109 } credsid_t;
110 
111 const char *ksid_getdomain(ksid_t *);
112 uint_t ksid_getrid(ksid_t *);
113 
114 int ksid_lookup(uid_t, ksid_t *);
115 void ksid_rele(ksid_t *);
116 
117 credsid_t *kcrsid_alloc(void);
118 
119 credsid_t *kcrsid_setsid(credsid_t *, ksid_t *, ksid_index_t);
120 credsid_t *kcrsid_setsidlist(credsid_t *, ksidlist_t *);
121 
122 void kcrsid_rele(credsid_t *);
123 void kcrsid_hold(credsid_t *);
124 void kcrsidcopy_to(const credsid_t *okcr, credsid_t *nkcr);
125 
126 void ksiddomain_rele(ksiddomain_t *);
127 void ksiddomain_hold(ksiddomain_t *);
128 void ksidlist_rele(ksidlist_t *);
129 void ksidlist_hold(ksidlist_t *);
130 
131 ksiddomain_t *ksid_lookupdomain(const char *);
132 
133 ksidlist_t *kcrsid_gidstosids(int, gid_t *);
134 
135 int idmap_call_byid(uid_t, ksid_t *);
136 uid_t idmap_call_bysid(ksid_t *);
137 
138 #else
139 
140 int allocids(int, int, uid_t *, int, gid_t *);
141 int idmap_reg(int);
142 int idmap_unreg(int);
143 
144 #endif /* _KERNEL */
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif /* _SYS_SID_H */
151