02ad285abb1ff822ab2ac68f4f4da4ef98f5be62
[metze/samba/wb-ndr.git] / source / winbindd / winbindd_idmap.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Async helpers for blocking functions
5
6    Copyright (C) Volker Lendecke 2005
7    Copyright (C) Gerald Carter 2006
8    Copyright (C) Simo Sorce 2007
9
10    The helpers always consist of three functions:
11
12    * A request setup function that takes the necessary parameters together
13      with a continuation function that is to be called upon completion
14
15    * A private continuation function that is internal only. This is to be
16      called by the lower-level functions in do_async(). Its only task is to
17      properly call the continuation function named above.
18
19    * A worker function that is called inside the appropriate child process.
20
21    This program is free software; you can redistribute it and/or modify
22    it under the terms of the GNU General Public License as published by
23    the Free Software Foundation; either version 3 of the License, or
24    (at your option) any later version.
25
26    This program is distributed in the hope that it will be useful,
27    but WITHOUT ANY WARRANTY; without even the implied warranty of
28    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29    GNU General Public License for more details.
30
31    You should have received a copy of the GNU General Public License
32    along with this program.  If not, see <http://www.gnu.org/licenses/>.
33 */
34
35 #include "includes.h"
36 #include "winbindd.h"
37
38 #undef DBGC_CLASS
39 #define DBGC_CLASS DBGC_WINBIND
40
41 static const struct winbindd_child_dispatch_table idmap_dispatch_table[];
42
43 static struct winbindd_child static_idmap_child;
44
45 void init_idmap_child(void)
46 {
47         setup_child(&static_idmap_child,
48                     idmap_dispatch_table,
49                     "log.winbindd", "idmap");
50 }
51
52 struct winbindd_child *idmap_child(void)
53 {
54         return &static_idmap_child;
55 }
56
57 static void ndr_child_get_idmap_sid2uid(struct winbindd_domain *domain,
58                                         struct winbindd_cli_state *state,
59                                         struct winbind_get_idmap *r)
60 {
61         uid_t uid;
62         NTSTATUS result;
63
64         DEBUG(3, ("sid to uid '%s'\n", sid_string_tos(r->in.req.sid)));
65
66         /* Find uid for this sid and return it, possibly ask the slow remote idmap */
67
68         result = idmap_sid_to_uid(r->in.req.sid, &uid);
69         if (!NT_STATUS_IS_OK(result)) {
70                 DEBUG(1, ("Can't map '%s' to uid: %s\n",
71                         sid_string_tos(r->in.req.sid),
72                         nt_errstr(result)));
73                 r->out.result = WINBIND_STATUS_FOOBAR;
74                 return;
75         }
76
77         DEBUG(10, ("sid %s mapped to uid %u\n",
78                 sid_string_tos(r->in.req.sid), uid));
79
80         r->out.rep->uid = uid;
81         r->out.result = WINBIND_STATUS_OK;
82 }
83
84 static void ndr_child_get_idmap_sid2gid(struct winbindd_domain *domain,
85                                         struct winbindd_cli_state *state,
86                                         struct winbind_get_idmap *r)
87 {
88         gid_t gid;
89         NTSTATUS result;
90
91         DEBUG(3, ("sid to gid '%s'\n", sid_string_tos(r->in.req.sid)));
92
93         /* Find uid for this sid and return it, possibly ask the slow remote idmap */
94
95         result = idmap_sid_to_gid(r->in.req.sid, &gid);
96         if (!NT_STATUS_IS_OK(result)) {
97                 DEBUG(1, ("Can't map '%s' to gid: %s\n",
98                         sid_string_tos(r->in.req.sid),
99                         nt_errstr(result)));
100                 r->out.result = WINBIND_STATUS_FOOBAR;
101                 return;
102         }
103
104         DEBUG(10, ("sid %s mapped to gid %u\n",
105                 sid_string_tos(r->in.req.sid), gid));
106
107         r->out.rep->gid = gid;
108         r->out.result = WINBIND_STATUS_OK;
109 }
110
111 static void ndr_child_get_idmap_uid2sid(struct winbindd_domain *domain,
112                                         struct winbindd_cli_state *state,
113                                         struct winbind_get_idmap *r)
114 {
115         DOM_SID sid;
116         uid_t uid;
117         NTSTATUS result;
118
119         DEBUG(3, ("uid to sid '%llu'\n",
120                 (unsigned long long)r->in.req.uid));
121
122         /* the IDMAP subsystem only knows about uint32_t id's yet */
123         if (r->in.req.uid > UINT32_MAX) {
124                 DEBUG(1, ("Can't map uid '%llu' to sid\n",
125                         (unsigned long long)r->in.req.uid));
126                 r->out.result = WINBIND_STATUS_FOOBAR;
127                 return;
128         }
129
130         /* Find uid for this sid and return it, possibly ask the slow remote idmap */
131
132         uid = r->in.req.uid;
133
134         result = idmap_uid_to_sid(&sid, uid);
135         if (!NT_STATUS_IS_OK(result)) {
136                 DEBUG(1, ("Can't map uid '%u' to sid: %s\n",
137                         uid, nt_errstr(result)));
138                 r->out.result = WINBIND_STATUS_FOOBAR;
139                 return;
140         }
141
142         DEBUG(10, ("uid %u mapped to sid %s\n",
143                 uid, sid_string_tos(&sid)));
144
145         r->out.rep->sid = sid_dup_talloc(r, &sid);
146         if (!r->out.rep->sid) {
147                 r->out.result = WINBIND_STATUS_NO_MEMORY;
148                 return;
149         }
150
151         r->out.result = WINBIND_STATUS_OK;
152 }
153
154 static void ndr_child_get_idmap_gid2sid(struct winbindd_domain *domain,
155                                         struct winbindd_cli_state *state,
156                                         struct winbind_get_idmap *r)
157 {
158         DOM_SID sid;
159         gid_t gid;
160         NTSTATUS result;
161
162         DEBUG(3, ("gid to sid '%llu'\n",
163                 (unsigned long long)r->in.req.gid));
164
165         /* the IDMAP subsystem only knows about uint32_t id's yet */
166         if (r->in.req.gid > UINT32_MAX) {
167                 DEBUG(1, ("Can't map gid '%llu' to sid\n",
168                         (unsigned long long)r->in.req.gid));
169                 r->out.result = WINBIND_STATUS_FOOBAR;
170                 return;
171         }
172
173         /* Find uid for this sid and return it, possibly ask the slow remote idmap */
174         gid = r->in.req.gid;
175
176         result = idmap_gid_to_sid(&sid, gid);
177         if (!NT_STATUS_IS_OK(result)) {
178                 DEBUG(1, ("Can't map gid '%u' to sid: %s\n",
179                         gid, nt_errstr(result)));
180                 r->out.result = WINBIND_STATUS_FOOBAR;
181                 return;
182         }
183
184         DEBUG(10, ("gid %u mapped to sid %s\n",
185                 gid, sid_string_tos(&sid)));
186
187         r->out.rep->sid = sid_dup_talloc(r, &sid);
188         if (!r->out.rep->sid) {
189                 r->out.result = WINBIND_STATUS_NO_MEMORY;
190                 return;
191         }
192
193         r->out.result = WINBIND_STATUS_OK;
194 }
195
196 void winbindd_ndr_child_get_idmap(struct winbindd_domain *domain,
197                                   struct winbindd_cli_state *state)
198 {
199         struct winbind_get_idmap *r;
200
201         r = talloc_get_type_abort(state->c.ndr.r,
202                                   struct winbind_get_idmap);
203
204         switch (*r->in.level) {
205         case WINBIND_IDMAP_LEVEL_SID_TO_UID:
206                 ndr_child_get_idmap_sid2uid(domain, state, r);
207                 return;
208
209         case WINBIND_IDMAP_LEVEL_SID_TO_GID:
210                 ndr_child_get_idmap_sid2gid(domain, state, r);
211                 return;
212
213         case WINBIND_IDMAP_LEVEL_UID_TO_SID:
214                 ndr_child_get_idmap_uid2sid(domain, state, r);
215                 return;
216
217         case WINBIND_IDMAP_LEVEL_GID_TO_SID:
218                 ndr_child_get_idmap_gid2sid(domain, state, r);
219                 return;
220         }
221
222         r->out.result = WINBIND_STATUS_UNKNOWN_LEVEL;
223         return;
224 }
225
226 static void ndr_child_set_idmap_allocate_uid(struct winbindd_domain *domain,
227                                              struct winbindd_cli_state *state,
228                                              struct winbind_set_idmap *r)
229 {
230         NTSTATUS result;
231         struct unixid xid;
232
233         DEBUG(3, ("allocate_uid\n"));
234
235         result = idmap_allocate_uid(&xid);
236         if (!NT_STATUS_IS_OK(result)) {
237                 DEBUG(1,("Can't allocate uid: %s\n",
238                          nt_errstr(result)));
239                 r->out.result = WINBIND_STATUS_FOOBAR;
240                 return;
241         }
242
243         DEBUG(10, ("allocte_uid: %u\n",
244                    xid.id));
245
246         r->out.rep->uid = xid.id;
247
248         r->out.result = WINBIND_STATUS_OK;
249 }
250
251 static void ndr_child_set_idmap_allocate_gid(struct winbindd_domain *domain,
252                                              struct winbindd_cli_state *state,
253                                              struct winbind_set_idmap *r)
254 {
255         NTSTATUS result;
256         struct unixid xid;
257
258         DEBUG(3, ("allocate_gid\n"));
259
260         result = idmap_allocate_gid(&xid);
261         if (!NT_STATUS_IS_OK(result)) {
262                 DEBUG(1,("Can't allocate gid: %s\n",
263                          nt_errstr(result)));
264                 r->out.result = WINBIND_STATUS_FOOBAR;
265                 return;
266         }
267
268         DEBUG(10, ("allocte_gid: %u\n",
269                    xid.id));
270
271         r->out.rep->gid = xid.id;
272
273         r->out.result = WINBIND_STATUS_OK;
274 }
275
276 static void ndr_child_set_idmap_set_mapping(struct winbindd_domain *domain,
277                                             struct winbindd_cli_state *state,
278                                             struct winbind_set_idmap *r)
279 {
280         NTSTATUS result;
281
282         DEBUG(3,("set_mapping: sid %s -> %u type:%u\n",
283                  sid_string_tos(r->in.req.mapping.sid),
284                  r->in.req.mapping.xid.id,
285                  r->in.req.mapping.xid.type));
286
287         result = idmap_set_mapping(&r->in.req.mapping);
288         if (!NT_STATUS_IS_OK(result)) {
289                 DEBUG(1,("Can't set mapping: %s\n",
290                          nt_errstr(result)));
291                 r->out.result = WINBIND_STATUS_FOOBAR;
292                 return;
293         }
294
295         r->out.result = WINBIND_STATUS_OK;
296 }
297
298 static void ndr_child_set_idmap_set_hwm(struct winbindd_domain *domain,
299                                         struct winbindd_cli_state *state,
300                                         struct winbind_set_idmap *r)
301 {
302         NTSTATUS result;
303
304         DEBUG(3,("set_hwm: %u type:%u\n",
305                  r->in.req.hwm.id,
306                  r->in.req.hwm.type));
307
308         switch (r->in.req.hwm.type) {
309         case ID_TYPE_UID:
310                 result = idmap_set_uid_hwm(&r->in.req.hwm);
311                 break;
312         case ID_TYPE_GID:
313                 result = idmap_set_gid_hwm(&r->in.req.hwm);
314                 break;
315         default:
316                 result = NT_STATUS_INVALID_PARAMETER;
317                 break;
318         }
319
320         if (!NT_STATUS_IS_OK(result)) {
321                 DEBUG(1,("Can't set hwm: %s\n",
322                          nt_errstr(result)));
323                 r->out.result = WINBIND_STATUS_FOOBAR;
324                 return;
325         }
326
327         r->out.result = WINBIND_STATUS_OK;
328 }
329
330 void winbindd_ndr_child_set_idmap(struct winbindd_domain *domain,
331                                   struct winbindd_cli_state *state)
332 {
333         struct winbind_set_idmap *r;
334
335         r = talloc_get_type_abort(state->c.ndr.r,
336                                   struct winbind_set_idmap);
337
338         switch (*r->in.level) {
339         case WINBIND_SET_IDMAP_LEVEL_ALLOCATE_UID:
340                 ndr_child_set_idmap_allocate_uid(domain, state, r);
341                 return;
342
343         case WINBIND_SET_IDMAP_LEVEL_ALLOCATE_GID:
344                 ndr_child_set_idmap_allocate_gid(domain, state, r);
345                 return;
346
347         case WINBIND_SET_IDMAP_LEVEL_SET_MAPPING:
348                 ndr_child_set_idmap_set_mapping(domain, state, r);
349                 return;
350
351         case WINBIND_SET_IDMAP_LEVEL_SET_HWM:
352                 ndr_child_set_idmap_set_hwm(domain, state, r);
353                 return;
354         }
355
356         r->out.result = WINBIND_STATUS_UNKNOWN_LEVEL;
357         return;
358 }
359
360 static void winbindd_set_hwm_recv(TALLOC_CTX *mem_ctx, bool success,
361                                    struct winbindd_response *response,
362                                    void *c, void *private_data)
363 {
364         void (*cont)(void *priv, bool succ) = (void (*)(void *, bool))c;
365
366         if (!success) {
367                 DEBUG(5, ("Could not trigger idmap_set_hwm\n"));
368                 cont(private_data, False);
369                 return;
370         }
371
372         if (response->result != WINBINDD_OK) {
373                 DEBUG(5, ("idmap_set_hwm returned an error\n"));
374                 cont(private_data, False);
375                 return;
376         }
377
378         cont(private_data, True);
379 }
380
381 void winbindd_set_hwm_async(TALLOC_CTX *mem_ctx, const struct unixid *xid,
382                              void (*cont)(void *private_data, bool success),
383                              void *private_data)
384 {
385         struct winbindd_request request;
386         ZERO_STRUCT(request);
387         request.cmd = WINBINDD_DUAL_SET_HWM;
388         request.data.dual_idmapset.id = xid->id;
389         request.data.dual_idmapset.type = xid->type;
390
391         do_async(mem_ctx, idmap_child(), &request, winbindd_set_hwm_recv,
392                  (void *)cont, private_data);
393 }
394
395 enum winbindd_result winbindd_dual_set_hwm(struct winbindd_domain *domain,
396                                             struct winbindd_cli_state *state)
397 {
398         struct unixid xid;
399         NTSTATUS result;
400
401         DEBUG(3, ("[%5lu]: dual_set_hwm\n", (unsigned long)state->pid));
402
403         xid.id = state->request.data.dual_idmapset.id;
404         xid.type = state->request.data.dual_idmapset.type;
405
406         switch (xid.type) {
407         case ID_TYPE_UID:
408                 result = idmap_set_uid_hwm(&xid);
409                 break;
410         case ID_TYPE_GID:
411                 result = idmap_set_gid_hwm(&xid);
412                 break;
413         default:
414                 return WINBINDD_ERROR;
415         }
416         return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
417 }
418
419 static void winbindd_sid2uid_recv(TALLOC_CTX *mem_ctx, bool success,
420                                     struct winbindd_ndr_call *c,
421                                     void *_r,
422                                     void *_cont,
423                                     void *private_data)
424 {
425         void (*cont)(void *priv, bool succ, uid_t) =
426                 (void (*)(void *, bool, uid_t))_cont;
427         struct winbind_get_idmap *r =
428                 talloc_get_type_abort(_r, struct winbind_get_idmap);
429         uid_t uid;
430
431         if (!success) {
432                 DEBUG(5, ("Could not get_idmap(sid2uid)\n"));
433                 TALLOC_FREE(r);
434                 cont(private_data, false, (uid_t)-1);
435                 return;
436         }
437
438         if (r->out.result != WINBIND_STATUS_OK) {
439                 DEBUG(5, ("get_idmap(sid2uid) returned an error:0x%08X\n",
440                         r->out.result));
441                 TALLOC_FREE(r);
442                 cont(private_data, false, (uid_t)-1);
443                 return;
444         }
445
446         if (r->out.rep->uid > UINT32_MAX) {
447                 DEBUG(1, ("get_idmap(sid2uid) returned a 64bit uid %llu\n",
448                         (unsigned long long)r->out.rep->uid));
449                 TALLOC_FREE(r);
450                 cont(private_data, false, (uid_t)-1);
451                 return;
452         }
453
454         uid = r->out.rep->uid;
455         TALLOC_FREE(r);
456         cont(private_data, true, uid);
457 }
458
459 void winbindd_sid2uid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
460                          void (*cont)(void *private_data, bool success, uid_t uid),
461                          void *private_data)
462 {
463         struct winbind_get_idmap *r = NULL;
464
465         DEBUG(7,("winbindd_sid2uid_async: Resolving %s to a uid\n",
466                 sid_string_tos(sid)));
467
468         r = TALLOC_P(mem_ctx, struct winbind_get_idmap);
469         if (!r) goto nomem;
470         r->in.level = TALLOC_P(r, enum winbind_get_idmap_level);
471         if (!r->in.level) goto nomem;
472
473         *r->in.level    = WINBIND_IDMAP_LEVEL_SID_TO_UID;
474         r->in.req.sid   = discard_const(sid);
475
476         do_async_ndr(mem_ctx, idmap_child(),
477                      NDR_WINBIND_GET_IDMAP, r,
478                      winbindd_sid2uid_recv, r,
479                      (void *)cont, private_data);
480         return;
481 nomem:
482         TALLOC_FREE(r);
483         cont(private_data, false, (uid_t)-1);
484         return;
485 }
486
487 static void winbindd_sid2gid_recv(TALLOC_CTX *mem_ctx, bool success,
488                                     struct winbindd_ndr_call *c,
489                                     void *_r,
490                                     void *_cont,
491                                     void *private_data)
492 {
493         void (*cont)(void *priv, bool succ, gid_t) =
494                 (void (*)(void *, bool, gid_t))_cont;
495         struct winbind_get_idmap *r =
496                 talloc_get_type_abort(_r, struct winbind_get_idmap);
497         gid_t gid;
498
499         if (!success) {
500                 DEBUG(5, ("Could not get_idmap(sid2gid)\n"));
501                 TALLOC_FREE(r);
502                 cont(private_data, false, (gid_t)-1);
503                 return;
504         }
505
506         if (r->out.result != WINBIND_STATUS_OK) {
507                 DEBUG(5, ("get_idmap(sid2gid) returned an error:0x%08X\n",
508                         r->out.result));
509                 TALLOC_FREE(r);
510                 cont(private_data, false, (gid_t)-1);
511                 return;
512         }
513
514         if (r->out.rep->gid > UINT32_MAX) {
515                 DEBUG(1, ("get_idmap(sid2gid) returned a 64bit gid %llu\n",
516                         (unsigned long long)r->out.rep->gid));
517                 TALLOC_FREE(r);
518                 cont(private_data, false, (gid_t)-1);
519                 return;
520         }
521
522         gid = r->out.rep->gid;
523         TALLOC_FREE(r);
524         cont(private_data, true, gid);
525 }
526
527 void winbindd_sid2gid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
528                          void (*cont)(void *private_data, bool success, gid_t gid),
529                          void *private_data)
530 {
531         struct winbind_get_idmap *r = NULL;
532
533         DEBUG(7,("winbindd_sid2gid_async: Resolving %s to a gid\n",
534                 sid_string_tos(sid)));
535
536         r = TALLOC_P(mem_ctx, struct winbind_get_idmap);
537         if (!r) goto nomem;
538         r->in.level = TALLOC_P(r, enum winbind_get_idmap_level);
539         if (!r->in.level) goto nomem;
540
541         *r->in.level    = WINBIND_IDMAP_LEVEL_SID_TO_GID;
542         r->in.req.sid   = discard_const(sid);
543
544         do_async_ndr(mem_ctx, idmap_child(),
545                      NDR_WINBIND_GET_IDMAP, r,
546                      winbindd_sid2gid_recv, r,
547                      (void *)cont, private_data);
548         return;
549 nomem:
550         TALLOC_FREE(r);
551         cont(private_data, false, (gid_t)-1);
552         return;
553 }
554
555 static void winbindd_uid2sid_recv(TALLOC_CTX *mem_ctx, bool success,
556                                     struct winbindd_ndr_call *c,
557                                     void *_r,
558                                     void *_cont,
559                                     void *private_data)
560 {
561         void (*cont)(void *priv, bool succ, const char *sid) =
562                 (void (*)(void *, bool, const char *))_cont;
563         struct winbind_get_idmap *r =
564                 talloc_get_type_abort(_r, struct winbind_get_idmap);
565         const char *sid;
566
567         if (!success) {
568                 DEBUG(5, ("Could not get_idmap(uid2sid)\n"));
569                 TALLOC_FREE(r);
570                 cont(private_data, false, NULL);
571                 return;
572         }
573
574         if (r->out.result != WINBIND_STATUS_OK) {
575                 DEBUG(5, ("get_idmap(uid2sid) returned an error:0x%08X\n",
576                         r->out.result));
577                 TALLOC_FREE(r);
578                 cont(private_data, false, NULL);
579                 return;
580         }
581
582         sid = dom_sid_string(mem_ctx, r->out.rep->sid);
583         if (!sid) {
584                 TALLOC_FREE(r);
585                 cont(private_data, false, NULL);
586                 return;
587         }
588
589         TALLOC_FREE(r);
590         cont(private_data, true, sid);
591 }
592
593 void winbindd_uid2sid_async(TALLOC_CTX *mem_ctx, uid_t uid,
594                             void (*cont)(void *private_data, bool success, const char *sid),
595                             void *private_data)
596 {
597         struct winbind_get_idmap *r = NULL;
598
599         DEBUG(7,("winbindd_uid2sid_async: Resolving %u to a sid\n",
600                 uid));
601
602         r = TALLOC_P(mem_ctx, struct winbind_get_idmap);
603         if (!r) goto nomem;
604         r->in.level = TALLOC_P(r, enum winbind_get_idmap_level);
605         if (!r->in.level) goto nomem;
606
607         *r->in.level    = WINBIND_IDMAP_LEVEL_UID_TO_SID;
608         r->in.req.uid   = uid;
609
610         do_async_ndr(mem_ctx, idmap_child(),
611                      NDR_WINBIND_GET_IDMAP, r,
612                      winbindd_uid2sid_recv, r,
613                      (void *)cont, private_data);
614         return;
615 nomem:
616         TALLOC_FREE(r);
617         cont(private_data, false, NULL);
618         return;
619 }
620
621 static void winbindd_gid2sid_recv(TALLOC_CTX *mem_ctx, bool success,
622                                   struct winbindd_ndr_call *c,
623                                   void *_r,
624                                   void *_cont,
625                                   void *private_data)
626 {
627         void (*cont)(void *priv, bool succ, const char *sid) =
628                 (void (*)(void *, bool, const char *))_cont;
629         struct winbind_get_idmap *r =
630                 talloc_get_type_abort(_r, struct winbind_get_idmap);
631         const char *sid;
632
633         if (!success) {
634                 DEBUG(5, ("Could not get_idmap(gid2sid)\n"));
635                 TALLOC_FREE(r);
636                 cont(private_data, false, NULL);
637                 return;
638         }
639
640         if (r->out.result != WINBIND_STATUS_OK) {
641                 DEBUG(5, ("get_idmap(gid2sid) returned an error:0x%08X\n",
642                         r->out.result));
643                 TALLOC_FREE(r);
644                 cont(private_data, false, NULL);
645                 return;
646         }
647
648         sid = dom_sid_string(mem_ctx, r->out.rep->sid);
649         if (!sid) {
650                 TALLOC_FREE(r);
651                 cont(private_data, false, NULL);
652                 return;
653         }
654
655         TALLOC_FREE(r);
656         cont(private_data, true, sid);
657 }
658
659 void winbindd_gid2sid_async(TALLOC_CTX *mem_ctx, gid_t gid,
660                             void (*cont)(void *private_data, bool success, const char *sid),
661                             void *private_data)
662 {
663         struct winbind_get_idmap *r = NULL;
664
665         DEBUG(7,("winbindd_gid2sid_async: Resolving %u to a sid\n",
666                 gid));
667
668         r = TALLOC_P(mem_ctx, struct winbind_get_idmap);
669         if (!r) goto nomem;
670         r->in.level = TALLOC_P(r, enum winbind_get_idmap_level);
671         if (!r->in.level) goto nomem;
672
673         *r->in.level    = WINBIND_IDMAP_LEVEL_GID_TO_SID;
674         r->in.req.gid   = gid;
675
676         do_async_ndr(mem_ctx, idmap_child(),
677                      NDR_WINBIND_GET_IDMAP, r,
678                      winbindd_gid2sid_recv, r,
679                      (void *)cont, private_data);
680         return;
681 nomem:
682         TALLOC_FREE(r);
683         cont(private_data, false, NULL);
684         return;
685 }
686
687 static const struct winbindd_child_dispatch_table idmap_dispatch_table[] = {
688         {
689                 .name           = "DUAL_SET_HWMS",
690                 .struct_cmd     = WINBINDD_DUAL_SET_HWM,
691                 .struct_fn      = winbindd_dual_set_hwm,
692         },{
693                 .name           = "NDR_WINBIND_GET_IDMAP",
694                 .ndr_opnum      = NDR_WINBIND_GET_IDMAP,
695                 .ndr_fn         = winbindd_ndr_child_get_idmap,
696         },{
697                 .name           = "NDR_WINBIND_SET_IDMAP",
698                 .ndr_opnum      = NDR_WINBIND_SET_IDMAP,
699                 .ndr_fn         = winbindd_ndr_child_set_idmap,
700         },{
701                 .name           = NULL,
702         }
703 };