1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
22f96bd5c8SAlan Wright  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24b819cea2SGordon Ross  *
25a73d9d5eSGordon Ross  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
26*f920d1d1SGordon Ross  * Copyright 2023 RackTop Systems, Inc.
27da6c28aaSamw  */
28da6c28aaSamw 
29da6c28aaSamw #ifndef _SMB_IDMAP_H
30da6c28aaSamw #define	_SMB_IDMAP_H
31da6c28aaSamw 
32b819cea2SGordon Ross #if defined(_KERNEL) /* intentionally not || defined(_FAKE_KERNEL) */
33da6c28aaSamw #include <sys/kidmap.h>
34da6c28aaSamw #else
35da6c28aaSamw #include <idmap.h>
36da6c28aaSamw #endif
37da6c28aaSamw 
386537f381Sas #include <smbsrv/smb_sid.h>
39da6c28aaSamw 
40da6c28aaSamw #ifdef __cplusplus
41da6c28aaSamw extern "C" {
42da6c28aaSamw #endif
43da6c28aaSamw 
44da6c28aaSamw /*
45da6c28aaSamw  * SMB ID mapping
46da6c28aaSamw  *
47da6c28aaSamw  * Solaris ID mapping service (aka Winchester) works with domain SIDs
48da6c28aaSamw  * and RIDs where domain SIDs are in string format. CIFS service works
49da6c28aaSamw  * with binary SIDs understanable by CIFS clients. A layer of SMB ID
50da6c28aaSamw  * mapping functions are implemeted to hide the SID conversion details
51da6c28aaSamw  * and also hide the handling of array of batch mapping requests.
52da6c28aaSamw  */
53da6c28aaSamw 
54da6c28aaSamw #define	SMB_IDMAP_UNKNOWN	-1
55da6c28aaSamw #define	SMB_IDMAP_GROUP		0
56da6c28aaSamw #define	SMB_IDMAP_USER		1
57f96bd5c8SAlan Wright #define	SMB_IDMAP_OWNERAT	2
58f96bd5c8SAlan Wright #define	SMB_IDMAP_GROUPAT	3
59f96bd5c8SAlan Wright #define	SMB_IDMAP_EVERYONE	4
60da6c28aaSamw 
61da6c28aaSamw #define	SMB_IDMAP_SID2ID	0x0001
62da6c28aaSamw #define	SMB_IDMAP_ID2SID	0x0002
63a73d9d5eSGordon Ross #define	SMB_IDMAP_SKIP_ERRS	0x0004
64da6c28aaSamw 
65da6c28aaSamw /*
66da6c28aaSamw  * smb_idmap_t
67da6c28aaSamw  *
68da6c28aaSamw  * sim_idtype: ID type (output in sid->uid mapping)
69da6c28aaSamw  * sim_id:     UID/GID (output in sid->uid mapping)
70da6c28aaSamw  */
71da6c28aaSamw typedef struct smb_idmap {
72da6c28aaSamw 	int		sim_idtype;
73da6c28aaSamw 	uid_t		*sim_id;
74da6c28aaSamw 	char		*sim_domsid;
75da6c28aaSamw 	uint32_t	sim_rid;
766537f381Sas 	smb_sid_t	*sim_sid;
77da6c28aaSamw 	idmap_stat	sim_stat;
78da6c28aaSamw } smb_idmap_t;
79da6c28aaSamw 
80da6c28aaSamw typedef struct smb_idmap_batch {
81da6c28aaSamw 	uint16_t		sib_nmap;
82*f920d1d1SGordon Ross 	uint16_t		sib_nerr;
83da6c28aaSamw 	uint32_t		sib_flags;
84da6c28aaSamw 	uint32_t		sib_size;
85a73d9d5eSGordon Ross 	smb_idmap_t		*sib_maps;
86a73d9d5eSGordon Ross 	idmap_get_handle_t	*sib_idmaph;
87da6c28aaSamw } smb_idmap_batch_t;
88da6c28aaSamw 
89*f920d1d1SGordon Ross typedef void (*smb_idmap_batch_errcb_t)(smb_idmap_batch_t *, smb_idmap_t *);
90*f920d1d1SGordon Ross 
916537f381Sas idmap_stat smb_idmap_getsid(uid_t, int, smb_sid_t **);
926537f381Sas idmap_stat smb_idmap_getid(smb_sid_t *, uid_t *, int *);
93da6c28aaSamw 
94da6c28aaSamw void smb_idmap_batch_destroy(smb_idmap_batch_t *);
95da6c28aaSamw idmap_stat smb_idmap_batch_create(smb_idmap_batch_t *, uint16_t, int);
96*f920d1d1SGordon Ross idmap_stat smb_idmap_batch_getmappings(smb_idmap_batch_t *,
97*f920d1d1SGordon Ross     smb_idmap_batch_errcb_t);
98da6c28aaSamw idmap_stat smb_idmap_batch_getid(idmap_get_handle_t *, smb_idmap_t *,
996537f381Sas     smb_sid_t *, int);
100da6c28aaSamw idmap_stat smb_idmap_batch_getsid(idmap_get_handle_t *, smb_idmap_t *,
101da6c28aaSamw     uid_t, int);
102da6c28aaSamw 
103da6c28aaSamw #ifdef __cplusplus
104da6c28aaSamw }
105da6c28aaSamw #endif
106da6c28aaSamw 
107da6c28aaSamw 
108da6c28aaSamw #endif /* _SMB_IDMAP_H */
109