r11093: Implement wb_queue_domain_send: If the domain is not yet initialized, do...
[amitay/samba.git] / source4 / winbind / wb_async_helpers.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Volker Lendecke 2005
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /*
21   a composite API for finding a DC and its name
22 */
23
24 #include "includes.h"
25 #include "libcli/composite/composite.h"
26 #include "libcli/smb_composite/smb_composite.h"
27 #include "winbind/wb_async_helpers.h"
28 #include "winbind/wb_server.h"
29 #include "smbd/service_stream.h"
30
31 #include "librpc/gen_ndr/nbt.h"
32 #include "librpc/gen_ndr/samr.h"
33 #include "lib/messaging/irpc.h"
34 #include "librpc/gen_ndr/irpc.h"
35 #include "librpc/gen_ndr/ndr_irpc.h"
36 #include "libcli/raw/libcliraw.h"
37 #include "librpc/gen_ndr/ndr_netlogon.h"
38 #include "librpc/gen_ndr/ndr_lsa.h"
39 #include "libcli/auth/credentials.h"
40
41 struct finddcs_state {
42         struct composite_context *ctx;
43         struct messaging_context *msg_ctx;
44
45         const char *domain_name;
46         const struct dom_sid *domain_sid;
47
48         struct nbtd_getdcname r;
49
50         int num_dcs;
51         struct nbt_dc_name *dcs;
52 };
53
54 static void finddcs_resolve(struct composite_context *ctx);
55 static void finddcs_getdc(struct irpc_request *ireq);
56
57 struct composite_context *wb_finddcs_send(const char *domain_name,
58                                           const struct dom_sid *domain_sid,
59                                           struct event_context *event_ctx,
60                                           struct messaging_context *msg_ctx)
61 {
62         struct composite_context *result, *ctx;
63         struct finddcs_state *state;
64         struct nbt_name name;
65
66         result = talloc_zero(NULL, struct composite_context);
67         if (result == NULL) goto failed;
68         result->state = COMPOSITE_STATE_IN_PROGRESS;
69         result->async.fn = NULL;
70         result->event_ctx = event_ctx;
71
72         state = talloc(result, struct finddcs_state);
73         if (state == NULL) goto failed;
74         state->ctx = result;
75         result->private_data = state;
76
77         state->domain_name = talloc_strdup(state, domain_name);
78         if (state->domain_name == NULL) goto failed;
79         state->domain_sid = dom_sid_dup(state, domain_sid);
80         if (state->domain_sid == NULL) goto failed;
81         state->msg_ctx = msg_ctx;
82
83         make_nbt_name(&name, state->domain_name, 0x1c);
84         ctx = resolve_name_send(&name, result->event_ctx,
85                                 lp_name_resolve_order());
86
87         if (ctx == NULL) goto failed;
88         ctx->async.fn = finddcs_resolve;
89         ctx->async.private_data = state;
90
91         return result;
92
93 failed:
94         talloc_free(result);
95         return NULL;
96 }
97
98 static void finddcs_resolve(struct composite_context *ctx)
99 {
100         struct finddcs_state *state =
101                 talloc_get_type(ctx->async.private_data, struct finddcs_state);
102         struct irpc_request *ireq;
103         uint32_t *nbt_servers;
104         const char *address;
105
106         state->ctx->status = resolve_name_recv(ctx, state, &address);
107         if (!composite_is_ok(state->ctx)) return;
108
109         state->num_dcs = 1;
110         state->dcs = talloc_array(state, struct nbt_dc_name, state->num_dcs);
111         if (composite_nomem(state->dcs, state->ctx)) return;
112
113         state->dcs[0].address = talloc_steal(state->dcs, address);
114
115         nbt_servers = irpc_servers_byname(state->msg_ctx, "nbt_server");
116         if ((nbt_servers == NULL) || (nbt_servers[0] == 0)) {
117                 composite_error(state->ctx, NT_STATUS_NO_LOGON_SERVERS);
118                 return;
119         }
120
121         state->r.in.domainname = state->domain_name;
122         state->r.in.ip_address = state->dcs[0].address;
123         state->r.in.my_computername = lp_netbios_name();
124         state->r.in.my_accountname = talloc_asprintf(state, "%s$",
125                                                      lp_netbios_name());
126         if (composite_nomem(state->r.in.my_accountname, state->ctx)) return;
127         state->r.in.account_control = ACB_WSTRUST;
128         state->r.in.domain_sid = dom_sid_dup(state, state->domain_sid);
129         if (composite_nomem(state->r.in.domain_sid, state->ctx)) return;
130
131         ireq = irpc_call_send(state->msg_ctx, nbt_servers[0],
132                               &dcerpc_table_irpc, DCERPC_NBTD_GETDCNAME,
133                               &state->r, state);
134         composite_continue_irpc(state->ctx, ireq, finddcs_getdc, state);
135 }
136
137 static void finddcs_getdc(struct irpc_request *ireq)
138 {
139         struct finddcs_state *state =
140                 talloc_get_type(ireq->async.private, struct finddcs_state);
141
142         state->ctx->status = irpc_call_recv(ireq);
143         talloc_free(ireq);
144         if (!composite_is_ok(state->ctx)) return;
145
146         state->dcs[0].name = talloc_steal(state->dcs, state->r.out.dcname);
147         composite_done(state->ctx);
148 }
149
150 NTSTATUS wb_finddcs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
151                          int *num_dcs, struct nbt_dc_name **dcs)
152 {
153         NTSTATUS status =composite_wait(c);
154         if (NT_STATUS_IS_OK(status)) {
155                 struct finddcs_state *state =
156                         talloc_get_type(c->private_data, struct finddcs_state);
157                 *num_dcs = state->num_dcs;
158                 *dcs = talloc_steal(mem_ctx, state->dcs);
159         }
160         talloc_free(c);
161         return status;
162 }
163
164 NTSTATUS wb_finddcs(const char *domain_name, const struct dom_sid *domain_sid,
165                     struct event_context *event_ctx,
166                     struct messaging_context *msg_ctx,
167                     TALLOC_CTX *mem_ctx,
168                     int *num_dcs, struct nbt_dc_name **dcs)
169 {
170         struct composite_context *c = wb_finddcs_send(domain_name, domain_sid,
171                                                       event_ctx, msg_ctx);
172         return wb_finddcs_recv(c, mem_ctx, num_dcs, dcs);
173 }
174
175 struct get_schannel_creds_state {
176         struct composite_context *ctx;
177         struct cli_credentials *wks_creds;
178         struct dcerpc_pipe *p;
179         struct netr_ServerReqChallenge r;
180
181         struct creds_CredentialState *creds_state;
182         struct netr_Credential netr_cred;
183         uint32_t negotiate_flags;
184         struct netr_ServerAuthenticate2 a;
185 };
186
187 static void get_schannel_creds_recv_auth(struct rpc_request *req);
188 static void get_schannel_creds_recv_chal(struct rpc_request *req);
189 static void get_schannel_creds_recv_pipe(struct composite_context *ctx);
190
191 struct composite_context *wb_get_schannel_creds_send(struct cli_credentials *wks_creds,
192                                                      struct smbcli_tree *tree,
193                                                      struct event_context *ev)
194 {
195         struct composite_context *result, *ctx;
196         struct get_schannel_creds_state *state;
197
198         result = talloc_zero(NULL, struct composite_context);
199         if (result == NULL) goto failed;
200         result->state = COMPOSITE_STATE_IN_PROGRESS;
201         result->async.fn = NULL;
202         result->event_ctx = ev;
203
204         state = talloc(result, struct get_schannel_creds_state);
205         if (state == NULL) goto failed;
206         result->private_data = state;
207         state->ctx = result;
208
209         state->wks_creds = wks_creds;
210
211         state->p = dcerpc_pipe_init(state, ev);
212         if (state->p == NULL) goto failed;
213
214         ctx = dcerpc_pipe_open_smb_send(state->p->conn, tree, "\\netlogon");
215         if (ctx == NULL) goto failed;
216
217         ctx->async.fn = get_schannel_creds_recv_pipe;
218         ctx->async.private_data = state;
219         return result;
220
221  failed:
222         talloc_free(result);
223         return NULL;
224 }
225
226 static void get_schannel_creds_recv_pipe(struct composite_context *ctx)
227 {
228         struct get_schannel_creds_state *state =
229                 talloc_get_type(ctx->async.private_data,
230                                 struct get_schannel_creds_state);
231         struct rpc_request *req;
232
233         state->ctx->status = dcerpc_pipe_open_smb_recv(ctx);
234         if (!composite_is_ok(state->ctx)) return;
235
236         state->ctx->status = dcerpc_bind_auth_none(state->p,
237                                                    DCERPC_NETLOGON_UUID,
238                                                    DCERPC_NETLOGON_VERSION);
239         if (!composite_is_ok(state->ctx)) return;
240
241         state->r.in.computer_name =
242                 cli_credentials_get_workstation(state->wks_creds);
243         state->r.in.server_name =
244                 talloc_asprintf(state, "\\\\%s",
245                                 dcerpc_server_name(state->p));
246         if (composite_nomem(state->r.in.server_name, state->ctx)) return;
247
248         state->r.in.credentials = talloc(state, struct netr_Credential);
249         if (composite_nomem(state->r.in.credentials, state->ctx)) return;
250
251         state->r.out.credentials = talloc(state, struct netr_Credential);
252         if (composite_nomem(state->r.out.credentials, state->ctx)) return;
253
254         generate_random_buffer(state->r.in.credentials->data,
255                                sizeof(state->r.in.credentials->data));
256
257         req = dcerpc_netr_ServerReqChallenge_send(state->p, state, &state->r);
258         composite_continue_rpc(state->ctx, req,
259                                get_schannel_creds_recv_chal, state);
260 }
261
262 static void get_schannel_creds_recv_chal(struct rpc_request *req)
263 {
264         struct get_schannel_creds_state *state =
265                 talloc_get_type(req->async.private,
266                                 struct get_schannel_creds_state);
267         const struct samr_Password *mach_pwd;
268
269         state->ctx->status = dcerpc_ndr_request_recv(req);
270         if (!composite_is_ok(state->ctx)) return;
271         state->ctx->status = state->r.out.result;
272         if (!composite_is_ok(state->ctx)) return;
273
274         state->creds_state = talloc(state, struct creds_CredentialState);
275         if (composite_nomem(state->creds_state, state->ctx)) return;
276
277         mach_pwd = cli_credentials_get_nt_hash(state->wks_creds, state);
278         if (composite_nomem(mach_pwd, state->ctx)) return;
279
280         state->negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
281
282         creds_client_init(state->creds_state, state->r.in.credentials,
283                           state->r.out.credentials, mach_pwd,
284                           &state->netr_cred, state->negotiate_flags);
285
286         state->a.in.server_name =
287                 talloc_reference(state, state->r.in.server_name);
288         state->a.in.account_name =
289                 cli_credentials_get_username(state->wks_creds);
290         state->a.in.secure_channel_type =
291                 cli_credentials_get_secure_channel_type(state->wks_creds);
292         state->a.in.computer_name =
293                 cli_credentials_get_workstation(state->wks_creds);
294         state->a.in.negotiate_flags = &state->negotiate_flags;
295         state->a.out.negotiate_flags = &state->negotiate_flags;
296         state->a.in.credentials = &state->netr_cred;
297         state->a.out.credentials = &state->netr_cred;
298
299         req = dcerpc_netr_ServerAuthenticate2_send(state->p, state, &state->a);
300         composite_continue_rpc(state->ctx, req,
301                                get_schannel_creds_recv_auth, state);
302 }
303
304 static void get_schannel_creds_recv_auth(struct rpc_request *req)
305 {
306         struct get_schannel_creds_state *state =
307                 talloc_get_type(req->async.private,
308                                 struct get_schannel_creds_state);
309
310         state->ctx->status = dcerpc_ndr_request_recv(req);
311         if (!NT_STATUS_IS_OK(state->ctx->status)) goto done;
312         state->ctx->status = state->a.out.result;
313         if (!NT_STATUS_IS_OK(state->ctx->status)) goto done;
314
315         if (!creds_client_check(state->creds_state,
316                                 state->a.out.credentials)) {
317                 DEBUG(5, ("Server got us invalid creds\n"));
318                 state->ctx->status = NT_STATUS_UNSUCCESSFUL;
319                 goto done;
320         }
321
322         cli_credentials_set_netlogon_creds(state->wks_creds,
323                                            state->creds_state);
324
325         state->ctx->state = COMPOSITE_STATE_DONE;
326
327  done:
328         if (!NT_STATUS_IS_OK(state->ctx->status)) {
329                 state->ctx->state = COMPOSITE_STATE_ERROR;
330         }
331         if ((state->ctx->state >= COMPOSITE_STATE_DONE) &&
332             (state->ctx->async.fn != NULL)) {
333                 state->ctx->async.fn(state->ctx);
334         }
335 }
336
337 NTSTATUS wb_get_schannel_creds_recv(struct composite_context *c,
338                                     TALLOC_CTX *mem_ctx,
339                                     struct dcerpc_pipe **netlogon_pipe)
340 {
341         NTSTATUS status = composite_wait(c);
342         if (NT_STATUS_IS_OK(status)) {
343                 struct get_schannel_creds_state *state =
344                         talloc_get_type(c->private_data,
345                                         struct get_schannel_creds_state);
346                 *netlogon_pipe = talloc_steal(mem_ctx, state->p);
347         }
348         talloc_free(c);
349         return status;
350 }
351
352 NTSTATUS wb_get_schannel_creds(struct cli_credentials *wks_creds,
353                                struct smbcli_tree *tree,
354                                struct event_context *event_ctx,
355                                TALLOC_CTX *mem_ctx,
356                                struct dcerpc_pipe **netlogon_pipe)
357 {
358         struct composite_context *c =
359                 wb_get_schannel_creds_send(wks_creds, tree, event_ctx);
360         return wb_get_schannel_creds_recv(c, mem_ctx, netlogon_pipe);
361 }
362
363 struct lsa_lookupnames_state {
364         struct composite_context *ctx;
365         uint32_t num_names;
366         struct lsa_LookupNames r;
367         struct lsa_TransSidArray sids;
368         uint32_t count;
369         struct wb_sid_object **result;
370 };
371
372 static void lsa_lookupnames_recv_sids(struct rpc_request *req);
373
374 struct composite_context *wb_lsa_lookupnames_send(struct dcerpc_pipe *lsa_pipe,
375                                                   struct policy_handle *handle,
376                                                   int num_names,
377                                                   const char **names)
378 {
379         struct composite_context *result;
380         struct rpc_request *req;
381         struct lsa_lookupnames_state *state;
382
383         struct lsa_String *lsa_names;
384         int i;
385
386         result = talloc_zero(NULL, struct composite_context);
387         if (result == NULL) goto failed;
388         result->state = COMPOSITE_STATE_IN_PROGRESS;
389         result->async.fn = NULL;
390         result->event_ctx = lsa_pipe->conn->event_ctx;
391
392         state = talloc(result, struct lsa_lookupnames_state);
393         if (state == NULL) goto failed;
394         result->private_data = state;
395         state->ctx = result;
396
397         state->sids.count = 0;
398         state->sids.sids = NULL;
399         state->num_names = num_names;
400         state->count = 0;
401
402         lsa_names = talloc_array(state, struct lsa_String, num_names);
403         if (lsa_names == NULL) goto failed;
404
405         for (i=0; i<num_names; i++) {
406                 lsa_names[i].string = names[i];
407         }
408
409         state->r.in.handle = handle;
410         state->r.in.num_names = num_names;
411         state->r.in.names = lsa_names;
412         state->r.in.sids = &state->sids;
413         state->r.in.level = 1;
414         state->r.in.count = &state->count;
415         state->r.out.count = &state->count;
416         state->r.out.sids = &state->sids;
417
418         req = dcerpc_lsa_LookupNames_send(lsa_pipe, state, &state->r);
419         if (req == NULL) goto failed;
420
421         req->async.callback = lsa_lookupnames_recv_sids;
422         req->async.private = state;
423         return result;
424
425  failed:
426         talloc_free(result);
427         return NULL;
428 }
429
430 static void lsa_lookupnames_recv_sids(struct rpc_request *req)
431 {
432         struct lsa_lookupnames_state *state =
433                 talloc_get_type(req->async.private,
434                                 struct lsa_lookupnames_state);
435         int i;
436
437         state->ctx->status = dcerpc_ndr_request_recv(req);
438         if (!composite_is_ok(state->ctx)) return;
439         state->ctx->status = state->r.out.result;
440         if (!NT_STATUS_IS_OK(state->ctx->status) &&
441             !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
442                 composite_error(state->ctx, state->ctx->status);
443                 return;
444         }
445
446         state->result = talloc_array(state, struct wb_sid_object *,
447                                      state->num_names);
448         if (composite_nomem(state->result, state->ctx)) return;
449
450         for (i=0; i<state->num_names; i++) {
451                 struct lsa_TranslatedSid *sid = &state->r.out.sids->sids[i];
452                 struct lsa_TrustInformation *dom;
453
454                 state->result[i] = talloc_zero(state->result,
455                                                struct wb_sid_object);
456                 if (composite_nomem(state->result[i], state->ctx)) return;
457
458                 state->result[i]->type = sid->sid_type;
459                 if (state->result[i]->type == SID_NAME_UNKNOWN) {
460                         continue;
461                 }
462
463                 if (sid->sid_index >= state->r.out.domains->count) {
464                         composite_error(state->ctx,
465                                         NT_STATUS_INVALID_PARAMETER);
466                         return;
467                 }
468
469                 dom = &state->r.out.domains->domains[sid->sid_index];
470
471                 state->result[i]->sid = dom_sid_add_rid(state->result[i],
472                                                         dom->sid, sid->rid);
473         }
474
475         composite_done(state->ctx);
476 }
477
478 NTSTATUS wb_lsa_lookupnames_recv(struct composite_context *c,
479                                  TALLOC_CTX *mem_ctx,
480                                  struct wb_sid_object ***sids)
481 {
482         NTSTATUS status = composite_wait(c);
483         if (NT_STATUS_IS_OK(status)) {
484                 struct lsa_lookupnames_state *state =
485                         talloc_get_type(c->private_data,
486                                         struct lsa_lookupnames_state);
487                 *sids = talloc_steal(mem_ctx, state->result);
488         }
489         talloc_free(c);
490         return status;
491 }
492
493 NTSTATUS wb_lsa_lookupnames(struct dcerpc_pipe *lsa_pipe, 
494                             struct policy_handle *handle,
495                             int num_names, const char **names,
496                             TALLOC_CTX *mem_ctx,
497                             struct wb_sid_object ***sids)
498 {
499         struct composite_context *c =
500                 wb_lsa_lookupnames_send(lsa_pipe, handle, num_names, names);
501         return wb_lsa_lookupnames_recv(c, mem_ctx, sids);
502 }
503
504 struct cmd_lookupname_state {
505         struct composite_context *ctx;
506         struct wbsrv_call *call;
507         struct wbsrv_domain *domain;
508         const char *name;
509         struct wb_sid_object *result;
510 };
511
512 static struct composite_context *lookupname_send_req(void *p);
513 static NTSTATUS lookupname_recv_req(struct composite_context *ctx, void *p);
514
515 struct composite_context *wb_cmd_lookupname_send(struct wbsrv_call *call,
516                                                  const char *name)
517 {
518         struct cmd_lookupname_state *state;
519         struct wbsrv_service *service = call->wbconn->listen_socket->service;
520
521         state = talloc(NULL, struct cmd_lookupname_state);
522         state->domain = service->domains;
523         state->call = call;
524         state->name = talloc_strdup(state, name);
525         state->ctx = wb_queue_domain_send(state, state->domain,
526                                           call->event_ctx,
527                                           call->wbconn->conn->msg_ctx,
528                                           lookupname_send_req,
529                                           lookupname_recv_req,
530                                           state);
531         if (state->ctx == NULL) {
532                 talloc_free(state);
533                 return NULL;
534         }
535         state->ctx->private_data = state;
536         return state->ctx;
537 }
538
539 static struct composite_context *lookupname_send_req(void *p)
540 {
541         struct cmd_lookupname_state *state =
542                 talloc_get_type(p, struct cmd_lookupname_state);
543
544         return wb_lsa_lookupnames_send(state->domain->lsa_pipe,
545                                        state->domain->lsa_policy,
546                                        1, &state->name);
547 }
548
549 static NTSTATUS lookupname_recv_req(struct composite_context *ctx, void *p)
550 {
551         struct cmd_lookupname_state *state =
552                 talloc_get_type(p, struct cmd_lookupname_state);
553         struct wb_sid_object **sids;
554         NTSTATUS status;
555
556         status = wb_lsa_lookupnames_recv(ctx, state, &sids);
557         if (NT_STATUS_IS_OK(status)) {
558                 state->result = sids[0];
559         }
560         return status;
561 }
562
563 NTSTATUS wb_cmd_lookupname_recv(struct composite_context *c,
564                                 TALLOC_CTX *mem_ctx,
565                                 struct wb_sid_object **sid)
566 {
567         struct cmd_lookupname_state *state =
568                 talloc_get_type(c->private_data, struct cmd_lookupname_state);
569         NTSTATUS status = composite_wait(c);
570         if (NT_STATUS_IS_OK(status)) {
571                 *sid = talloc_steal(mem_ctx, state->result);
572         }
573         talloc_free(state);
574         return status;
575 }
576
577 NTSTATUS wb_cmd_lookupname(struct wbsrv_call *call, const char *name,
578                            TALLOC_CTX *mem_ctx, struct wb_sid_object **sid)
579 {
580         struct composite_context *c =
581                 wb_cmd_lookupname_send(call, name);
582         return wb_cmd_lookupname_recv(c, mem_ctx, sid);
583 }
584
585 struct cmd_checkmachacc_state {
586         struct composite_context *ctx;
587         struct wbsrv_call *call;
588         struct wbsrv_domain *domain;
589 };
590
591 static void cmd_checkmachacc_recv_init(struct composite_context *ctx);
592
593 struct composite_context *wb_cmd_checkmachacc_send(struct wbsrv_call *call)
594 {
595         struct composite_context *result, *ctx;
596         struct cmd_checkmachacc_state *state;
597         struct wbsrv_service *service = call->wbconn->listen_socket->service;
598
599         result = talloc(call, struct composite_context);
600         if (result == NULL) goto failed;
601         result->state = COMPOSITE_STATE_IN_PROGRESS;
602         result->async.fn = NULL;
603         result->event_ctx = call->event_ctx;
604
605         state = talloc(result, struct cmd_checkmachacc_state);
606         if (state == NULL) goto failed;
607         state->ctx = result;
608         result->private_data = state;
609         state->call = call;
610
611         state->domain = service->domains;
612
613         ctx = wb_init_domain_send(state->domain, result->event_ctx, 
614                                   call->wbconn->conn->msg_ctx);
615         if (ctx == NULL) goto failed;
616         ctx->async.fn = cmd_checkmachacc_recv_init;
617         ctx->async.private_data = state;
618
619         return result;
620
621  failed:
622         talloc_free(result);
623         return NULL;
624 }
625
626 static void cmd_checkmachacc_recv_init(struct composite_context *ctx)
627 {
628         struct cmd_checkmachacc_state *state =
629                 talloc_get_type(ctx->async.private_data,
630                                 struct cmd_checkmachacc_state);
631
632         state->ctx->status = wb_init_domain_recv(ctx);
633         if (!composite_is_ok(state->ctx)) return;
634
635         composite_done(state->ctx);
636 }
637
638 NTSTATUS wb_cmd_checkmachacc_recv(struct composite_context *c)
639 {
640         NTSTATUS status = composite_wait(c);
641         talloc_free(c);
642         return status;
643 }
644
645 NTSTATUS wb_cmd_checkmachacc(struct wbsrv_call *call)
646 {
647         struct composite_context *c = wb_cmd_checkmachacc_send(call);
648         return wb_cmd_checkmachacc_recv(c);
649 }
650
651 static void composite_netr_LogonSamLogon_recv_rpc(struct rpc_request *req);
652
653 struct composite_context *composite_netr_LogonSamLogon_send(struct dcerpc_pipe *p,
654                                                             TALLOC_CTX *mem_ctx,
655                                                             struct netr_LogonSamLogon *r)
656 {
657         struct composite_context *result;
658         struct rpc_request *req;
659
660         result = talloc(mem_ctx, struct composite_context);
661         if (result == NULL) goto failed;
662         result->state = COMPOSITE_STATE_IN_PROGRESS;
663         result->async.fn = NULL;
664         result->event_ctx = p->conn->event_ctx;
665
666         req = dcerpc_netr_LogonSamLogon_send(p, mem_ctx, r);
667         if (req == NULL) goto failed;
668         req->async.callback = composite_netr_LogonSamLogon_recv_rpc;
669         req->async.private = result;
670         return result;
671
672  failed:
673         talloc_free(result);
674         return NULL;
675 }
676
677 static void composite_netr_LogonSamLogon_recv_rpc(struct rpc_request *req)
678 {
679         struct composite_context *ctx =
680                 talloc_get_type(req->async.private, struct composite_context);
681
682         ctx->status = dcerpc_ndr_request_recv(req);
683         if (!composite_is_ok(ctx)) return;
684         composite_done(ctx);
685 }
686
687 NTSTATUS composite_netr_LogonSamLogon_recv(struct composite_context *ctx)
688 {
689         NTSTATUS status = composite_wait(ctx);
690         talloc_free(ctx);
691         return status;
692 }