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