xref: /titanic_51/usr/src/uts/common/idmap/kidmap_priv.h (revision 19449258028e6813f0b7a606b554b2fa37a390ec)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Windows to Solaris Identity Mapping kernel API
29  * This header file contains private definitions.
30  */
31 
32 #ifndef _KIDMAP_PRIV_H
33 #define	_KIDMAP_PRIV_H
34 
35 #include <sys/avl.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct sid2pid {
42 	avl_node_t	avl_link;
43 	struct sid2pid	*flink;
44 	struct sid2pid	*blink;
45 	const char 	*sid_prefix;
46 	uint32_t	rid;
47 	uid_t		uid;
48 	time_t		uid_ttl;
49 	gid_t		gid;
50 	time_t		gid_ttl;
51 	int		is_user;
52 } sid2pid_t;
53 
54 
55 typedef struct pid2sid {
56 	avl_node_t	avl_link;
57 	struct pid2sid	*flink;
58 	struct pid2sid	*blink;
59 	const char 	*sid_prefix;
60 	uint32_t	rid;
61 	uid_t		pid;
62 	time_t		ttl;
63 } pid2sid_t;
64 
65 
66 
67 typedef struct idmap_sid2pid_cache {
68 	avl_tree_t		tree;
69 	kmutex_t		mutex;
70 	struct sid2pid		head;
71 	time_t			purge_time;
72 	int			uid_num;
73 	int			gid_num;
74 	int			pid_num;
75 } idmap_sid2pid_cache_t;
76 
77 
78 typedef struct idmap_pid2sid_cache {
79 	avl_tree_t		tree;
80 	kmutex_t		mutex;
81 	struct pid2sid		head;
82 	time_t			purge_time;
83 } idmap_pid2sid_cache_t;
84 
85 
86 /*
87  * There is a cache for every mapping request because a group SID
88  * on Windows can be set in a file owner field and versa-visa.
89  * To stop this causing problems on Solaris a SID can map to
90  * both a UID and a GID.
91  */
92 typedef struct idmap_cache {
93 	idmap_sid2pid_cache_t	sid2pid;
94 	idmap_pid2sid_cache_t	uid2sid;
95 	idmap_pid2sid_cache_t	gid2sid;
96 } idmap_cache_t;
97 
98 
99 void
100 kidmap_cache_create(idmap_cache_t *cache);
101 
102 void
103 kidmap_cache_delete(idmap_cache_t *cache);
104 
105 void
106 kidmap_cache_purge(idmap_cache_t *cache);
107 
108 
109 int
110 kidmap_cache_lookup_uidbysid(idmap_cache_t *cache, const char *sid_prefix,
111 			uint32_t rid, uid_t *uid);
112 
113 int
114 kidmap_cache_lookup_gidbysid(idmap_cache_t *cache, const char *sid_prefix,
115 			uint32_t rid, gid_t *gid);
116 
117 int
118 kidmap_cache_lookup_pidbysid(idmap_cache_t *cache, const char *sid_prefix,
119 			uint32_t rid, uid_t *pid, int *is_user);
120 
121 int
122 kidmap_cache_lookup_sidbyuid(idmap_cache_t *cache, const char **sid_prefix,
123 			uint32_t *rid, uid_t uid);
124 
125 int
126 kidmap_cache_lookup_sidbygid(idmap_cache_t *cache, const char **sid_prefix,
127 			uint32_t *rid, gid_t gid);
128 
129 
130 void
131 kidmap_cache_add_sid2uid(idmap_cache_t *cache, const char *sid_prefix,
132 			uint32_t rid, uid_t uid, int direction);
133 
134 void
135 kidmap_cache_add_sid2gid(idmap_cache_t *cache, const char *sid_prefix,
136 			uint32_t rid, gid_t gid, int direction);
137 
138 void
139 kidmap_cache_add_sid2pid(idmap_cache_t *cache, const char *sid_prefix,
140 			uint32_t rid, uid_t pid, int is_user, int direction);
141 void
142 kidmap_cache_get_data(idmap_cache_t *cache, size_t *uidbysid, size_t *gidbysid,
143 			size_t *pidbysid, size_t *sidbyuid, size_t *sidbygid);
144 int
145 kidmap_start(void);
146 
147 int
148 kidmap_stop(void);
149 
150 void
151 kidmap_sid_prefix_store_init(void);
152 
153 const char *
154 kidmap_find_sid_prefix(const char *sid_prefix);
155 
156 #ifdef	__cplusplus
157 }
158 #endif
159 
160 #endif	/* _KIDMAP_PRIV_H */
161