xref: /titanic_44/usr/src/lib/smbsrv/libfksmbsrv/common/fksmb_idmap.c (revision b819cea2f73f98c5662230cc9affc8cc84f77fcf)
1*b819cea2SGordon Ross /*
2*b819cea2SGordon Ross  * CDDL HEADER START
3*b819cea2SGordon Ross  *
4*b819cea2SGordon Ross  * The contents of this file are subject to the terms of the
5*b819cea2SGordon Ross  * Common Development and Distribution License (the "License").
6*b819cea2SGordon Ross  * You may not use this file except in compliance with the License.
7*b819cea2SGordon Ross  *
8*b819cea2SGordon Ross  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*b819cea2SGordon Ross  * or http://www.opensolaris.org/os/licensing.
10*b819cea2SGordon Ross  * See the License for the specific language governing permissions
11*b819cea2SGordon Ross  * and limitations under the License.
12*b819cea2SGordon Ross  *
13*b819cea2SGordon Ross  * When distributing Covered Code, include this CDDL HEADER in each
14*b819cea2SGordon Ross  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*b819cea2SGordon Ross  * If applicable, add the following below this CDDL HEADER, with the
16*b819cea2SGordon Ross  * fields enclosed by brackets "[]" replaced with your own identifying
17*b819cea2SGordon Ross  * information: Portions Copyright [yyyy] [name of copyright owner]
18*b819cea2SGordon Ross  *
19*b819cea2SGordon Ross  * CDDL HEADER END
20*b819cea2SGordon Ross  */
21*b819cea2SGordon Ross /*
22*b819cea2SGordon Ross  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23*b819cea2SGordon Ross  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
24*b819cea2SGordon Ross  */
25*b819cea2SGordon Ross 
26*b819cea2SGordon Ross /*
27*b819cea2SGordon Ross  * SMB server interface to idmap
28*b819cea2SGordon Ross  * (smb_idmap_get..., smb_idmap_batch_...)
29*b819cea2SGordon Ross  *
30*b819cea2SGordon Ross  * There are three implementations of this interface:
31*b819cea2SGordon Ross  *	uts/common/fs/smbsrv/smb_idmap.c (smbsrv kmod)
32*b819cea2SGordon Ross  *	lib/smbsrv/libfksmbsrv/common/fksmb_idmap.c (libfksmbsrv)
33*b819cea2SGordon Ross  *	lib/smbsrv/libsmb/common/smb_idmap.c (libsmb)
34*b819cea2SGordon Ross  *
35*b819cea2SGordon Ross  * There are enough differences (relative to the code size)
36*b819cea2SGordon Ross  * that it's more trouble than it's worth to merge them.
37*b819cea2SGordon Ross  *
38*b819cea2SGordon Ross  * This one differs from the others in that it:
39*b819cea2SGordon Ross  *	calls idmap interfaces (libidmap)
40*b819cea2SGordon Ross  *	uses kmem_... interfaces (libfakekernel)
41*b819cea2SGordon Ross  *	uses cmn_err instead of syslog, etc.
42*b819cea2SGordon Ross  */
43*b819cea2SGordon Ross 
44*b819cea2SGordon Ross #include <sys/param.h>
45*b819cea2SGordon Ross #include <sys/types.h>
46*b819cea2SGordon Ross 
47*b819cea2SGordon Ross #include <smbsrv/smb_kproto.h>
48*b819cea2SGordon Ross #include <smbsrv/smb_idmap.h>
49*b819cea2SGordon Ross 
50*b819cea2SGordon Ross static int smb_idmap_batch_binsid(smb_idmap_batch_t *sib);
51*b819cea2SGordon Ross 
52*b819cea2SGordon Ross /*
53*b819cea2SGordon Ross  * Report an idmap error.
54*b819cea2SGordon Ross  */
55*b819cea2SGordon Ross void
smb_idmap_check(const char * s,idmap_stat stat)56*b819cea2SGordon Ross smb_idmap_check(const char *s, idmap_stat stat)
57*b819cea2SGordon Ross {
58*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS) {
59*b819cea2SGordon Ross 		if (s == NULL)
60*b819cea2SGordon Ross 			s = "smb_idmap_check";
61*b819cea2SGordon Ross 
62*b819cea2SGordon Ross 		cmn_err(CE_NOTE, "%s: %d", s, (int)stat);
63*b819cea2SGordon Ross 	}
64*b819cea2SGordon Ross }
65*b819cea2SGordon Ross 
66*b819cea2SGordon Ross /*
67*b819cea2SGordon Ross  * smb_idmap_getsid
68*b819cea2SGordon Ross  *
69*b819cea2SGordon Ross  * Tries to get a mapping for the given uid/gid
70*b819cea2SGordon Ross  * Allocates ->sim_domsid
71*b819cea2SGordon Ross  */
72*b819cea2SGordon Ross idmap_stat
smb_idmap_getsid(uid_t id,int idtype,smb_sid_t ** sid)73*b819cea2SGordon Ross smb_idmap_getsid(uid_t id, int idtype, smb_sid_t **sid)
74*b819cea2SGordon Ross {
75*b819cea2SGordon Ross 	smb_idmap_batch_t sib;
76*b819cea2SGordon Ross 	idmap_stat stat;
77*b819cea2SGordon Ross 
78*b819cea2SGordon Ross 	stat = smb_idmap_batch_create(&sib, 1, SMB_IDMAP_ID2SID);
79*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS)
80*b819cea2SGordon Ross 		return (stat);
81*b819cea2SGordon Ross 
82*b819cea2SGordon Ross 	stat = smb_idmap_batch_getsid(sib.sib_idmaph, &sib.sib_maps[0],
83*b819cea2SGordon Ross 	    id, idtype);
84*b819cea2SGordon Ross 
85*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS) {
86*b819cea2SGordon Ross 		smb_idmap_batch_destroy(&sib);
87*b819cea2SGordon Ross 		return (stat);
88*b819cea2SGordon Ross 	}
89*b819cea2SGordon Ross 
90*b819cea2SGordon Ross 	stat = smb_idmap_batch_getmappings(&sib);
91*b819cea2SGordon Ross 
92*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS) {
93*b819cea2SGordon Ross 		smb_idmap_batch_destroy(&sib);
94*b819cea2SGordon Ross 		return (stat);
95*b819cea2SGordon Ross 	}
96*b819cea2SGordon Ross 
97*b819cea2SGordon Ross 	*sid = smb_sid_dup(sib.sib_maps[0].sim_sid);
98*b819cea2SGordon Ross 
99*b819cea2SGordon Ross 	smb_idmap_batch_destroy(&sib);
100*b819cea2SGordon Ross 
101*b819cea2SGordon Ross 	return (IDMAP_SUCCESS);
102*b819cea2SGordon Ross }
103*b819cea2SGordon Ross 
104*b819cea2SGordon Ross /*
105*b819cea2SGordon Ross  * smb_idmap_getid
106*b819cea2SGordon Ross  *
107*b819cea2SGordon Ross  * Tries to get a mapping for the given SID
108*b819cea2SGordon Ross  */
109*b819cea2SGordon Ross idmap_stat
smb_idmap_getid(smb_sid_t * sid,uid_t * id,int * id_type)110*b819cea2SGordon Ross smb_idmap_getid(smb_sid_t *sid, uid_t *id, int *id_type)
111*b819cea2SGordon Ross {
112*b819cea2SGordon Ross 	smb_idmap_batch_t sib;
113*b819cea2SGordon Ross 	smb_idmap_t *sim;
114*b819cea2SGordon Ross 	idmap_stat stat;
115*b819cea2SGordon Ross 
116*b819cea2SGordon Ross 	stat = smb_idmap_batch_create(&sib, 1, SMB_IDMAP_SID2ID);
117*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS)
118*b819cea2SGordon Ross 		return (stat);
119*b819cea2SGordon Ross 
120*b819cea2SGordon Ross 	sim = &sib.sib_maps[0];
121*b819cea2SGordon Ross 	sim->sim_id = id;
122*b819cea2SGordon Ross 	stat = smb_idmap_batch_getid(sib.sib_idmaph, sim, sid, *id_type);
123*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS) {
124*b819cea2SGordon Ross 		smb_idmap_batch_destroy(&sib);
125*b819cea2SGordon Ross 		return (stat);
126*b819cea2SGordon Ross 	}
127*b819cea2SGordon Ross 
128*b819cea2SGordon Ross 	stat = smb_idmap_batch_getmappings(&sib);
129*b819cea2SGordon Ross 
130*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS) {
131*b819cea2SGordon Ross 		smb_idmap_batch_destroy(&sib);
132*b819cea2SGordon Ross 		return (stat);
133*b819cea2SGordon Ross 	}
134*b819cea2SGordon Ross 
135*b819cea2SGordon Ross 	*id_type = sim->sim_idtype;
136*b819cea2SGordon Ross 	smb_idmap_batch_destroy(&sib);
137*b819cea2SGordon Ross 
138*b819cea2SGordon Ross 	return (IDMAP_SUCCESS);
139*b819cea2SGordon Ross }
140*b819cea2SGordon Ross 
141*b819cea2SGordon Ross /*
142*b819cea2SGordon Ross  * smb_idmap_batch_create
143*b819cea2SGordon Ross  *
144*b819cea2SGordon Ross  * Creates and initializes the context for batch ID mapping.
145*b819cea2SGordon Ross  */
146*b819cea2SGordon Ross idmap_stat
smb_idmap_batch_create(smb_idmap_batch_t * sib,uint16_t nmap,int flags)147*b819cea2SGordon Ross smb_idmap_batch_create(smb_idmap_batch_t *sib, uint16_t nmap, int flags)
148*b819cea2SGordon Ross {
149*b819cea2SGordon Ross 	idmap_stat	stat;
150*b819cea2SGordon Ross 
151*b819cea2SGordon Ross 	if (!sib)
152*b819cea2SGordon Ross 		return (IDMAP_ERR_ARG);
153*b819cea2SGordon Ross 
154*b819cea2SGordon Ross 	bzero(sib, sizeof (smb_idmap_batch_t));
155*b819cea2SGordon Ross 	stat = idmap_get_create(&sib->sib_idmaph);
156*b819cea2SGordon Ross 
157*b819cea2SGordon Ross 	if (stat != IDMAP_SUCCESS) {
158*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_create", stat);
159*b819cea2SGordon Ross 		return (stat);
160*b819cea2SGordon Ross 	}
161*b819cea2SGordon Ross 
162*b819cea2SGordon Ross 	sib->sib_flags = flags;
163*b819cea2SGordon Ross 	sib->sib_nmap = nmap;
164*b819cea2SGordon Ross 	sib->sib_size = nmap * sizeof (smb_idmap_t);
165*b819cea2SGordon Ross 	sib->sib_maps = kmem_zalloc(sib->sib_size, KM_SLEEP);
166*b819cea2SGordon Ross 
167*b819cea2SGordon Ross 	return (IDMAP_SUCCESS);
168*b819cea2SGordon Ross }
169*b819cea2SGordon Ross 
170*b819cea2SGordon Ross /*
171*b819cea2SGordon Ross  * smb_idmap_batch_destroy
172*b819cea2SGordon Ross  *
173*b819cea2SGordon Ross  * Frees the batch ID mapping context.
174*b819cea2SGordon Ross  */
175*b819cea2SGordon Ross void
smb_idmap_batch_destroy(smb_idmap_batch_t * sib)176*b819cea2SGordon Ross smb_idmap_batch_destroy(smb_idmap_batch_t *sib)
177*b819cea2SGordon Ross {
178*b819cea2SGordon Ross 	int i;
179*b819cea2SGordon Ross 
180*b819cea2SGordon Ross 	if (sib == NULL)
181*b819cea2SGordon Ross 		return;
182*b819cea2SGordon Ross 
183*b819cea2SGordon Ross 	if (sib->sib_idmaph) {
184*b819cea2SGordon Ross 		idmap_get_destroy(sib->sib_idmaph);
185*b819cea2SGordon Ross 		sib->sib_idmaph = NULL;
186*b819cea2SGordon Ross 	}
187*b819cea2SGordon Ross 
188*b819cea2SGordon Ross 	if (sib->sib_maps == NULL)
189*b819cea2SGordon Ross 		return;
190*b819cea2SGordon Ross 
191*b819cea2SGordon Ross 	if (sib->sib_flags & SMB_IDMAP_ID2SID) {
192*b819cea2SGordon Ross 		/*
193*b819cea2SGordon Ross 		 * SIDs are allocated only when mapping
194*b819cea2SGordon Ross 		 * UID/GID to SIDs
195*b819cea2SGordon Ross 		 */
196*b819cea2SGordon Ross 		for (i = 0; i < sib->sib_nmap; i++) {
197*b819cea2SGordon Ross 			smb_sid_free(sib->sib_maps[i].sim_sid);
198*b819cea2SGordon Ross 			/* from strdup() in libidmap */
199*b819cea2SGordon Ross 			free(sib->sib_maps[i].sim_domsid);
200*b819cea2SGordon Ross 		}
201*b819cea2SGordon Ross 	}
202*b819cea2SGordon Ross 
203*b819cea2SGordon Ross 	if (sib->sib_size && sib->sib_maps) {
204*b819cea2SGordon Ross 		kmem_free(sib->sib_maps, sib->sib_size);
205*b819cea2SGordon Ross 		sib->sib_maps = NULL;
206*b819cea2SGordon Ross 	}
207*b819cea2SGordon Ross }
208*b819cea2SGordon Ross 
209*b819cea2SGordon Ross /*
210*b819cea2SGordon Ross  * smb_idmap_batch_getid
211*b819cea2SGordon Ross  *
212*b819cea2SGordon Ross  * Queue a request to map the given SID to a UID or GID.
213*b819cea2SGordon Ross  *
214*b819cea2SGordon Ross  * sim->sim_id should point to variable that's supposed to
215*b819cea2SGordon Ross  * hold the returned UID/GID. This needs to be setup by caller
216*b819cea2SGordon Ross  * of this function.
217*b819cea2SGordon Ross  * If requested ID type is known, it's passed as 'idtype',
218*b819cea2SGordon Ross  * if it's unknown it'll be returned in sim->sim_idtype.
219*b819cea2SGordon Ross  */
220*b819cea2SGordon Ross idmap_stat
smb_idmap_batch_getid(idmap_get_handle_t * idmaph,smb_idmap_t * sim,smb_sid_t * sid,int idtype)221*b819cea2SGordon Ross smb_idmap_batch_getid(idmap_get_handle_t *idmaph, smb_idmap_t *sim,
222*b819cea2SGordon Ross     smb_sid_t *sid, int idtype)
223*b819cea2SGordon Ross {
224*b819cea2SGordon Ross 	char sidstr[SMB_SID_STRSZ];
225*b819cea2SGordon Ross 	idmap_stat stat;
226*b819cea2SGordon Ross 	int flag = 0;
227*b819cea2SGordon Ross 
228*b819cea2SGordon Ross 	if (idmaph == NULL || sim == NULL || sid == NULL)
229*b819cea2SGordon Ross 		return (IDMAP_ERR_ARG);
230*b819cea2SGordon Ross 
231*b819cea2SGordon Ross 	smb_sid_tostr(sid, sidstr);
232*b819cea2SGordon Ross 	if (smb_sid_splitstr(sidstr, &sim->sim_rid) != 0)
233*b819cea2SGordon Ross 		return (IDMAP_ERR_SID);
234*b819cea2SGordon Ross 	sim->sim_domsid = sidstr;
235*b819cea2SGordon Ross 	sim->sim_idtype = idtype;
236*b819cea2SGordon Ross 
237*b819cea2SGordon Ross 	switch (idtype) {
238*b819cea2SGordon Ross 	case SMB_IDMAP_USER:
239*b819cea2SGordon Ross 		stat = idmap_get_uidbysid(idmaph, sim->sim_domsid,
240*b819cea2SGordon Ross 		    sim->sim_rid, flag, sim->sim_id, &sim->sim_stat);
241*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_uidbysid", stat);
242*b819cea2SGordon Ross 		break;
243*b819cea2SGordon Ross 
244*b819cea2SGordon Ross 	case SMB_IDMAP_GROUP:
245*b819cea2SGordon Ross 		stat = idmap_get_gidbysid(idmaph, sim->sim_domsid,
246*b819cea2SGordon Ross 		    sim->sim_rid, flag, sim->sim_id, &sim->sim_stat);
247*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_gidbysid", stat);
248*b819cea2SGordon Ross 		break;
249*b819cea2SGordon Ross 
250*b819cea2SGordon Ross 	case SMB_IDMAP_UNKNOWN:
251*b819cea2SGordon Ross 		stat = idmap_get_pidbysid(idmaph, sim->sim_domsid,
252*b819cea2SGordon Ross 		    sim->sim_rid, flag, sim->sim_id, &sim->sim_idtype,
253*b819cea2SGordon Ross 		    &sim->sim_stat);
254*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_pidbysid", stat);
255*b819cea2SGordon Ross 		break;
256*b819cea2SGordon Ross 
257*b819cea2SGordon Ross 	default:
258*b819cea2SGordon Ross 		stat = IDMAP_ERR_ARG;
259*b819cea2SGordon Ross 		break;
260*b819cea2SGordon Ross 	}
261*b819cea2SGordon Ross 
262*b819cea2SGordon Ross 	/* This was copied by idmap_get_Xbysid. */
263*b819cea2SGordon Ross 	sim->sim_domsid = NULL;
264*b819cea2SGordon Ross 
265*b819cea2SGordon Ross 	return (stat);
266*b819cea2SGordon Ross }
267*b819cea2SGordon Ross 
268*b819cea2SGordon Ross /*
269*b819cea2SGordon Ross  * smb_idmap_batch_getsid
270*b819cea2SGordon Ross  *
271*b819cea2SGordon Ross  * Queue a request to map the given UID/GID to a SID.
272*b819cea2SGordon Ross  *
273*b819cea2SGordon Ross  * sim->sim_domsid and sim->sim_rid will contain the mapping
274*b819cea2SGordon Ross  * result upon successful process of the batched request.
275*b819cea2SGordon Ross  * NB: sim_domsid allocated by strdup, here or in libidmap
276*b819cea2SGordon Ross  */
277*b819cea2SGordon Ross idmap_stat
smb_idmap_batch_getsid(idmap_get_handle_t * idmaph,smb_idmap_t * sim,uid_t id,int idtype)278*b819cea2SGordon Ross smb_idmap_batch_getsid(idmap_get_handle_t *idmaph, smb_idmap_t *sim,
279*b819cea2SGordon Ross     uid_t id, int idtype)
280*b819cea2SGordon Ross {
281*b819cea2SGordon Ross 	idmap_stat stat;
282*b819cea2SGordon Ross 	int flag = 0;
283*b819cea2SGordon Ross 
284*b819cea2SGordon Ross 	if (!idmaph || !sim)
285*b819cea2SGordon Ross 		return (IDMAP_ERR_ARG);
286*b819cea2SGordon Ross 
287*b819cea2SGordon Ross 	switch (idtype) {
288*b819cea2SGordon Ross 	case SMB_IDMAP_USER:
289*b819cea2SGordon Ross 		stat = idmap_get_sidbyuid(idmaph, id, flag,
290*b819cea2SGordon Ross 		    &sim->sim_domsid, &sim->sim_rid, &sim->sim_stat);
291*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_sidbyuid", stat);
292*b819cea2SGordon Ross 		break;
293*b819cea2SGordon Ross 
294*b819cea2SGordon Ross 	case SMB_IDMAP_GROUP:
295*b819cea2SGordon Ross 		stat = idmap_get_sidbygid(idmaph, id, flag,
296*b819cea2SGordon Ross 		    &sim->sim_domsid, &sim->sim_rid, &sim->sim_stat);
297*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_sidbygid", stat);
298*b819cea2SGordon Ross 		break;
299*b819cea2SGordon Ross 
300*b819cea2SGordon Ross 	case SMB_IDMAP_OWNERAT:
301*b819cea2SGordon Ross 		/* Current Owner S-1-5-32-766 */
302*b819cea2SGordon Ross 		sim->sim_domsid = strdup(NT_BUILTIN_DOMAIN_SIDSTR);
303*b819cea2SGordon Ross 		sim->sim_rid = SECURITY_CURRENT_OWNER_RID;
304*b819cea2SGordon Ross 		sim->sim_stat = IDMAP_SUCCESS;
305*b819cea2SGordon Ross 		stat = IDMAP_SUCCESS;
306*b819cea2SGordon Ross 		break;
307*b819cea2SGordon Ross 
308*b819cea2SGordon Ross 	case SMB_IDMAP_GROUPAT:
309*b819cea2SGordon Ross 		/* Current Group S-1-5-32-767 */
310*b819cea2SGordon Ross 		sim->sim_domsid = strdup(NT_BUILTIN_DOMAIN_SIDSTR);
311*b819cea2SGordon Ross 		sim->sim_rid = SECURITY_CURRENT_GROUP_RID;
312*b819cea2SGordon Ross 		sim->sim_stat = IDMAP_SUCCESS;
313*b819cea2SGordon Ross 		stat = IDMAP_SUCCESS;
314*b819cea2SGordon Ross 		break;
315*b819cea2SGordon Ross 
316*b819cea2SGordon Ross 	case SMB_IDMAP_EVERYONE:
317*b819cea2SGordon Ross 		/* Everyone S-1-1-0 */
318*b819cea2SGordon Ross 		sim->sim_domsid = strdup(NT_WORLD_AUTH_SIDSTR);
319*b819cea2SGordon Ross 		sim->sim_rid = 0;
320*b819cea2SGordon Ross 		sim->sim_stat = IDMAP_SUCCESS;
321*b819cea2SGordon Ross 		stat = IDMAP_SUCCESS;
322*b819cea2SGordon Ross 		break;
323*b819cea2SGordon Ross 
324*b819cea2SGordon Ross 	default:
325*b819cea2SGordon Ross 		return (IDMAP_ERR_ARG);
326*b819cea2SGordon Ross 	}
327*b819cea2SGordon Ross 
328*b819cea2SGordon Ross 	return (stat);
329*b819cea2SGordon Ross }
330*b819cea2SGordon Ross 
331*b819cea2SGordon Ross /*
332*b819cea2SGordon Ross  * smb_idmap_batch_getmappings
333*b819cea2SGordon Ross  *
334*b819cea2SGordon Ross  * trigger ID mapping service to get the mappings for queued
335*b819cea2SGordon Ross  * requests.
336*b819cea2SGordon Ross  *
337*b819cea2SGordon Ross  * Checks the result of all the queued requests.
338*b819cea2SGordon Ross  */
339*b819cea2SGordon Ross idmap_stat
smb_idmap_batch_getmappings(smb_idmap_batch_t * sib)340*b819cea2SGordon Ross smb_idmap_batch_getmappings(smb_idmap_batch_t *sib)
341*b819cea2SGordon Ross {
342*b819cea2SGordon Ross 	idmap_stat stat = IDMAP_SUCCESS;
343*b819cea2SGordon Ross 	smb_idmap_t *sim;
344*b819cea2SGordon Ross 	int i;
345*b819cea2SGordon Ross 
346*b819cea2SGordon Ross 	if ((stat = idmap_get_mappings(sib->sib_idmaph)) != IDMAP_SUCCESS) {
347*b819cea2SGordon Ross 		smb_idmap_check("idmap_get_mappings", stat);
348*b819cea2SGordon Ross 		return (stat);
349*b819cea2SGordon Ross 	}
350*b819cea2SGordon Ross 
351*b819cea2SGordon Ross 	/*
352*b819cea2SGordon Ross 	 * Check the status for all the queued requests
353*b819cea2SGordon Ross 	 */
354*b819cea2SGordon Ross 	for (i = 0, sim = sib->sib_maps; i < sib->sib_nmap; i++, sim++) {
355*b819cea2SGordon Ross 		if (sim->sim_stat != IDMAP_SUCCESS) {
356*b819cea2SGordon Ross 			if (sib->sib_flags == SMB_IDMAP_SID2ID) {
357*b819cea2SGordon Ross 				cmn_err(CE_NOTE, "[%d] %d (%d)",
358*b819cea2SGordon Ross 				    sim->sim_idtype,
359*b819cea2SGordon Ross 				    sim->sim_rid,
360*b819cea2SGordon Ross 				    sim->sim_stat);
361*b819cea2SGordon Ross 			}
362*b819cea2SGordon Ross 			return (sim->sim_stat);
363*b819cea2SGordon Ross 		}
364*b819cea2SGordon Ross 	}
365*b819cea2SGordon Ross 
366*b819cea2SGordon Ross 	if (smb_idmap_batch_binsid(sib) != 0)
367*b819cea2SGordon Ross 		stat = IDMAP_ERR_OTHER;
368*b819cea2SGordon Ross 
369*b819cea2SGordon Ross 	return (stat);
370*b819cea2SGordon Ross }
371*b819cea2SGordon Ross 
372*b819cea2SGordon Ross /*
373*b819cea2SGordon Ross  * smb_idmap_batch_binsid
374*b819cea2SGordon Ross  *
375*b819cea2SGordon Ross  * Convert sidrids to binary sids
376*b819cea2SGordon Ross  *
377*b819cea2SGordon Ross  * Returns 0 if successful and non-zero upon failure.
378*b819cea2SGordon Ross  */
379*b819cea2SGordon Ross static int
smb_idmap_batch_binsid(smb_idmap_batch_t * sib)380*b819cea2SGordon Ross smb_idmap_batch_binsid(smb_idmap_batch_t *sib)
381*b819cea2SGordon Ross {
382*b819cea2SGordon Ross 	smb_sid_t *sid;
383*b819cea2SGordon Ross 	smb_idmap_t *sim;
384*b819cea2SGordon Ross 	int i;
385*b819cea2SGordon Ross 
386*b819cea2SGordon Ross 	if (sib->sib_flags & SMB_IDMAP_SID2ID)
387*b819cea2SGordon Ross 		/* This operation is not required */
388*b819cea2SGordon Ross 		return (0);
389*b819cea2SGordon Ross 
390*b819cea2SGordon Ross 	sim = sib->sib_maps;
391*b819cea2SGordon Ross 	for (i = 0; i < sib->sib_nmap; sim++, i++) {
392*b819cea2SGordon Ross 		if (sim->sim_domsid == NULL)
393*b819cea2SGordon Ross 			return (-1);
394*b819cea2SGordon Ross 
395*b819cea2SGordon Ross 		sid = smb_sid_fromstr(sim->sim_domsid);
396*b819cea2SGordon Ross 		if (sid == NULL)
397*b819cea2SGordon Ross 			return (-1);
398*b819cea2SGordon Ross 
399*b819cea2SGordon Ross 		sim->sim_sid = smb_sid_splice(sid, sim->sim_rid);
400*b819cea2SGordon Ross 		smb_sid_free(sid);
401*b819cea2SGordon Ross 	}
402*b819cea2SGordon Ross 
403*b819cea2SGordon Ross 	return (0);
404*b819cea2SGordon Ross }
405