1c5c4113dSnw /*
2c5c4113dSnw  * CDDL HEADER START
3c5c4113dSnw  *
4c5c4113dSnw  * The contents of this file are subject to the terms of the
5c5c4113dSnw  * Common Development and Distribution License (the "License").
6c5c4113dSnw  * You may not use this file except in compliance with the License.
7c5c4113dSnw  *
8c5c4113dSnw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5c4113dSnw  * or http://www.opensolaris.org/os/licensing.
10c5c4113dSnw  * See the License for the specific language governing permissions
11c5c4113dSnw  * and limitations under the License.
12c5c4113dSnw  *
13c5c4113dSnw  * When distributing Covered Code, include this CDDL HEADER in each
14c5c4113dSnw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5c4113dSnw  * If applicable, add the following below this CDDL HEADER, with the
16c5c4113dSnw  * fields enclosed by brackets "[]" replaced with your own identifying
17c5c4113dSnw  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5c4113dSnw  *
19c5c4113dSnw  * CDDL HEADER END
20c5c4113dSnw  */
21c5c4113dSnw 
22c5c4113dSnw /*
23f7b4b2feSjp  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24c5c4113dSnw  * Use is subject to license terms.
25*32c2a899SGordon Ross  *
26*32c2a899SGordon Ross  * Copyright 2023 RackTop Systems, Inc.
27c5c4113dSnw  */
28c5c4113dSnw 
29c5c4113dSnw /*
30c5c4113dSnw  * Windows to Solaris Identity Mapping kernel API
31c5c4113dSnw  * This header file contains private definitions.
32c5c4113dSnw  */
33c5c4113dSnw 
34c5c4113dSnw #ifndef _KIDMAP_PRIV_H
35c5c4113dSnw #define	_KIDMAP_PRIV_H
36c5c4113dSnw 
37c5c4113dSnw #include <sys/avl.h>
38c5c4113dSnw 
39c5c4113dSnw #ifdef	__cplusplus
40c5c4113dSnw extern "C" {
41c5c4113dSnw #endif
42c5c4113dSnw 
43*32c2a899SGordon Ross #define	KIDMAP_HASH_SIZE	(1<<8)
44*32c2a899SGordon Ross #define	KIDMAP_HASH_MASK	(KIDMAP_HASH_SIZE-1)
45*32c2a899SGordon Ross 
4632ff2b3cSJulian Pullen typedef struct sid2pid {
4732ff2b3cSJulian Pullen 	avl_node_t	avl_link;
4832ff2b3cSJulian Pullen 	struct sid2pid	*flink;
4932ff2b3cSJulian Pullen 	struct sid2pid	*blink;
5032ff2b3cSJulian Pullen 	const char 	*sid_prefix;
5132ff2b3cSJulian Pullen 	uint32_t	rid;
5232ff2b3cSJulian Pullen 	uid_t		uid;
5332ff2b3cSJulian Pullen 	time_t		uid_ttl;
5432ff2b3cSJulian Pullen 	gid_t		gid;
5532ff2b3cSJulian Pullen 	time_t		gid_ttl;
5632ff2b3cSJulian Pullen 	int		is_user;
5732ff2b3cSJulian Pullen } sid2pid_t;
5832ff2b3cSJulian Pullen 
5932ff2b3cSJulian Pullen 
6032ff2b3cSJulian Pullen typedef struct pid2sid {
6132ff2b3cSJulian Pullen 	avl_node_t	avl_link;
6232ff2b3cSJulian Pullen 	struct pid2sid	*flink;
6332ff2b3cSJulian Pullen 	struct pid2sid	*blink;
6432ff2b3cSJulian Pullen 	const char 	*sid_prefix;
6532ff2b3cSJulian Pullen 	uint32_t	rid;
6632ff2b3cSJulian Pullen 	uid_t		pid;
6732ff2b3cSJulian Pullen 	time_t		ttl;
6832ff2b3cSJulian Pullen } pid2sid_t;
6932ff2b3cSJulian Pullen 
70c5c4113dSnw 
71d15447b6Sjp 
72d15447b6Sjp typedef struct idmap_sid2pid_cache {
73d15447b6Sjp 	avl_tree_t		tree;
74d15447b6Sjp 	kmutex_t		mutex;
7532ff2b3cSJulian Pullen 	struct sid2pid		head;
76d15447b6Sjp 	time_t			purge_time;
77d15447b6Sjp 	int			uid_num;
78d15447b6Sjp 	int			gid_num;
79d15447b6Sjp 	int			pid_num;
80d15447b6Sjp } idmap_sid2pid_cache_t;
81d15447b6Sjp 
82d15447b6Sjp 
83d15447b6Sjp typedef struct idmap_pid2sid_cache {
84c5c4113dSnw 	avl_tree_t		tree;
85c5c4113dSnw 	kmutex_t		mutex;
8632ff2b3cSJulian Pullen 	struct pid2sid		head;
87c5c4113dSnw 	time_t			purge_time;
88d15447b6Sjp } idmap_pid2sid_cache_t;
89c5c4113dSnw 
900b10de9fSjp 
910b10de9fSjp /*
920b10de9fSjp  * There is a cache for every mapping request because a group SID
930b10de9fSjp  * on Windows can be set in a file owner field and versa-visa.
940b10de9fSjp  * To stop this causing problems on Solaris a SID can map to
950b10de9fSjp  * both a UID and a GID.
960b10de9fSjp  */
97c5c4113dSnw typedef struct idmap_cache {
98*32c2a899SGordon Ross 	idmap_sid2pid_cache_t	sid2pid_hash[KIDMAP_HASH_SIZE];
99*32c2a899SGordon Ross 	idmap_pid2sid_cache_t	uid2sid_hash[KIDMAP_HASH_SIZE];
100*32c2a899SGordon Ross 	idmap_pid2sid_cache_t	gid2sid_hash[KIDMAP_HASH_SIZE];
101c5c4113dSnw } idmap_cache_t;
102c5c4113dSnw 
103c5c4113dSnw 
104c5c4113dSnw void
105c5c4113dSnw kidmap_cache_create(idmap_cache_t *cache);
106c5c4113dSnw 
107c5c4113dSnw void
108c5c4113dSnw kidmap_cache_delete(idmap_cache_t *cache);
109c5c4113dSnw 
1100b10de9fSjp void
1110b10de9fSjp kidmap_cache_purge(idmap_cache_t *cache);
1120b10de9fSjp 
113d15447b6Sjp 
114c5c4113dSnw int
1150b10de9fSjp kidmap_cache_lookup_uidbysid(idmap_cache_t *cache, const char *sid_prefix,
1160b10de9fSjp 			uint32_t rid, uid_t *uid);
117c5c4113dSnw 
118c5c4113dSnw int
1190b10de9fSjp kidmap_cache_lookup_gidbysid(idmap_cache_t *cache, const char *sid_prefix,
1200b10de9fSjp 			uint32_t rid, gid_t *gid);
1210b10de9fSjp 
1220b10de9fSjp int
1230b10de9fSjp kidmap_cache_lookup_pidbysid(idmap_cache_t *cache, const char *sid_prefix,
124c5c4113dSnw 			uint32_t rid, uid_t *pid, int *is_user);
125c5c4113dSnw 
1260b10de9fSjp int
1270b10de9fSjp kidmap_cache_lookup_sidbyuid(idmap_cache_t *cache, const char **sid_prefix,
1280b10de9fSjp 			uint32_t *rid, uid_t uid);
1290b10de9fSjp 
1300b10de9fSjp int
1310b10de9fSjp kidmap_cache_lookup_sidbygid(idmap_cache_t *cache, const char **sid_prefix,
1320b10de9fSjp 			uint32_t *rid, gid_t gid);
1330b10de9fSjp 
1340b10de9fSjp 
1350b10de9fSjp void
136d15447b6Sjp kidmap_cache_add_sid2uid(idmap_cache_t *cache, const char *sid_prefix,
137d15447b6Sjp 			uint32_t rid, uid_t uid, int direction);
1380b10de9fSjp 
139c5c4113dSnw void
140d15447b6Sjp kidmap_cache_add_sid2gid(idmap_cache_t *cache, const char *sid_prefix,
141d15447b6Sjp 			uint32_t rid, gid_t gid, int direction);
142c5c4113dSnw 
143c5c4113dSnw void
144d15447b6Sjp kidmap_cache_add_sid2pid(idmap_cache_t *cache, const char *sid_prefix,
145d15447b6Sjp 			uint32_t rid, uid_t pid, int is_user, int direction);
146f7b4b2feSjp void
147f7b4b2feSjp kidmap_cache_get_data(idmap_cache_t *cache, size_t *uidbysid, size_t *gidbysid,
148f7b4b2feSjp 			size_t *pidbysid, size_t *sidbyuid, size_t *sidbygid);
149c5c4113dSnw int
150c5c4113dSnw kidmap_start(void);
151c5c4113dSnw 
152c5c4113dSnw int
153c5c4113dSnw kidmap_stop(void);
154c5c4113dSnw 
155c5c4113dSnw void
156c5c4113dSnw kidmap_sid_prefix_store_init(void);
157c5c4113dSnw 
158c5c4113dSnw const char *
159c5c4113dSnw kidmap_find_sid_prefix(const char *sid_prefix);
160c5c4113dSnw 
161c5c4113dSnw #ifdef	__cplusplus
162c5c4113dSnw }
163c5c4113dSnw #endif
164c5c4113dSnw 
165c5c4113dSnw #endif	/* _KIDMAP_PRIV_H */
166