2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2005
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.
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.
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.
21 a composite API for finding a DC and its name
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"
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"
41 struct finddcs_state {
42 struct composite_context *ctx;
43 struct messaging_context *msg_ctx;
45 const char *domain_name;
46 const struct dom_sid *domain_sid;
48 struct nbtd_getdcname r;
51 struct nbt_dc_name *dcs;
54 static void finddcs_resolve(struct composite_context *ctx);
55 static void finddcs_getdc(struct irpc_request *ireq);
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)
62 struct composite_context *result, *ctx;
63 struct finddcs_state *state;
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;
72 state = talloc(result, struct finddcs_state);
73 if (state == NULL) goto failed;
75 result->private_data = state;
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;
83 make_nbt_name(&name, state->domain_name, 0x1c);
84 ctx = resolve_name_send(&name, result->event_ctx,
85 lp_name_resolve_order());
87 if (ctx == NULL) goto failed;
88 ctx->async.fn = finddcs_resolve;
89 ctx->async.private_data = state;
98 static void finddcs_resolve(struct composite_context *ctx)
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;
106 state->ctx->status = resolve_name_recv(ctx, state, &address);
107 if (!composite_is_ok(state->ctx)) return;
110 state->dcs = talloc_array(state, struct nbt_dc_name, state->num_dcs);
111 if (composite_nomem(state->dcs, state->ctx)) return;
113 state->dcs[0].address = talloc_steal(state->dcs, address);
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);
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$",
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;
131 ireq = irpc_call_send(state->msg_ctx, nbt_servers[0],
132 &dcerpc_table_irpc, DCERPC_NBTD_GETDCNAME,
134 composite_continue_irpc(state->ctx, ireq, finddcs_getdc, state);
137 static void finddcs_getdc(struct irpc_request *ireq)
139 struct finddcs_state *state =
140 talloc_get_type(ireq->async.private, struct finddcs_state);
142 state->ctx->status = irpc_call_recv(ireq);
144 if (!composite_is_ok(state->ctx)) return;
146 state->dcs[0].name = talloc_steal(state->dcs, state->r.out.dcname);
147 composite_done(state->ctx);
150 NTSTATUS wb_finddcs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
151 int *num_dcs, struct nbt_dc_name **dcs)
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);
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,
168 int *num_dcs, struct nbt_dc_name **dcs)
170 struct composite_context *c = wb_finddcs_send(domain_name, domain_sid,
172 return wb_finddcs_recv(c, mem_ctx, num_dcs, dcs);
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;
181 struct creds_CredentialState *creds_state;
182 struct netr_Credential netr_cred;
183 uint32_t negotiate_flags;
184 struct netr_ServerAuthenticate2 a;
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);
191 struct composite_context *wb_get_schannel_creds_send(struct cli_credentials *wks_creds,
192 struct smbcli_tree *tree,
193 struct event_context *ev)
195 struct composite_context *result, *ctx;
196 struct get_schannel_creds_state *state;
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;
204 state = talloc(result, struct get_schannel_creds_state);
205 if (state == NULL) goto failed;
206 result->private_data = state;
209 state->wks_creds = wks_creds;
211 state->p = dcerpc_pipe_init(state, ev);
212 if (state->p == NULL) goto failed;
214 ctx = dcerpc_pipe_open_smb_send(state->p->conn, tree, "\\netlogon");
215 if (ctx == NULL) goto failed;
217 ctx->async.fn = get_schannel_creds_recv_pipe;
218 ctx->async.private_data = state;
226 static void get_schannel_creds_recv_pipe(struct composite_context *ctx)
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;
233 state->ctx->status = dcerpc_pipe_open_smb_recv(ctx);
234 if (!composite_is_ok(state->ctx)) return;
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;
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;
248 state->r.in.credentials = talloc(state, struct netr_Credential);
249 if (composite_nomem(state->r.in.credentials, state->ctx)) return;
251 state->r.out.credentials = talloc(state, struct netr_Credential);
252 if (composite_nomem(state->r.out.credentials, state->ctx)) return;
254 generate_random_buffer(state->r.in.credentials->data,
255 sizeof(state->r.in.credentials->data));
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);
262 static void get_schannel_creds_recv_chal(struct rpc_request *req)
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;
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;
274 state->creds_state = talloc(state, struct creds_CredentialState);
275 if (composite_nomem(state->creds_state, state->ctx)) return;
277 mach_pwd = cli_credentials_get_nt_hash(state->wks_creds, state);
278 if (composite_nomem(mach_pwd, state->ctx)) return;
280 state->negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
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);
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;
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);
304 static void get_schannel_creds_recv_auth(struct rpc_request *req)
306 struct get_schannel_creds_state *state =
307 talloc_get_type(req->async.private,
308 struct get_schannel_creds_state);
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;
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;
322 cli_credentials_set_netlogon_creds(state->wks_creds,
325 state->ctx->state = COMPOSITE_STATE_DONE;
328 if (!NT_STATUS_IS_OK(state->ctx->status)) {
329 state->ctx->state = COMPOSITE_STATE_ERROR;
331 if ((state->ctx->state >= COMPOSITE_STATE_DONE) &&
332 (state->ctx->async.fn != NULL)) {
333 state->ctx->async.fn(state->ctx);
337 NTSTATUS wb_get_schannel_creds_recv(struct composite_context *c,
339 struct dcerpc_pipe **netlogon_pipe)
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);
352 NTSTATUS wb_get_schannel_creds(struct cli_credentials *wks_creds,
353 struct smbcli_tree *tree,
354 struct event_context *event_ctx,
356 struct dcerpc_pipe **netlogon_pipe)
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);
363 struct lsa_lookupsids_state {
364 struct composite_context *ctx;
366 struct lsa_LookupSids r;
367 struct lsa_SidArray sids;
368 struct lsa_TransNameArray names;
370 struct wb_sid_object **result;
373 static void lsa_lookupsids_recv_names(struct rpc_request *req);
375 struct composite_context *wb_lsa_lookupsids_send(struct dcerpc_pipe *lsa_pipe,
376 struct policy_handle *handle,
378 const struct dom_sid **sids)
380 struct composite_context *result;
381 struct rpc_request *req;
382 struct lsa_lookupsids_state *state;
385 result = talloc_zero(NULL, struct composite_context);
386 if (result == NULL) goto failed;
387 result->state = COMPOSITE_STATE_IN_PROGRESS;
388 result->async.fn = NULL;
389 result->event_ctx = lsa_pipe->conn->event_ctx;
391 state = talloc(result, struct lsa_lookupsids_state);
392 if (state == NULL) goto failed;
393 result->private_data = state;
396 state->sids.num_sids = num_sids;
397 state->sids.sids = talloc_array(state, struct lsa_SidPtr, num_sids);
398 if (state->sids.sids == NULL) goto failed;
400 for (i=0; i<num_sids; i++) {
401 state->sids.sids[i].sid = dom_sid_dup(state->sids.sids,
403 if (state->sids.sids[i].sid == NULL) goto failed;
407 state->num_sids = num_sids;
408 state->names.count = 0;
409 state->names.names = NULL;
411 state->r.in.handle = handle;
412 state->r.in.sids = &state->sids;
413 state->r.in.names = &state->names;
414 state->r.in.level = 1;
415 state->r.in.count = &state->count;
416 state->r.out.names = &state->names;
417 state->r.out.count = &state->count;
419 req = dcerpc_lsa_LookupSids_send(lsa_pipe, state, &state->r);
420 if (req == NULL) goto failed;
422 req->async.callback = lsa_lookupsids_recv_names;
423 req->async.private = state;
431 static void lsa_lookupsids_recv_names(struct rpc_request *req)
433 struct lsa_lookupsids_state *state =
434 talloc_get_type(req->async.private,
435 struct lsa_lookupsids_state);
438 state->ctx->status = dcerpc_ndr_request_recv(req);
439 if (!composite_is_ok(state->ctx)) return;
440 state->ctx->status = state->r.out.result;
441 if (!NT_STATUS_IS_OK(state->ctx->status) &&
442 !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
443 composite_error(state->ctx, state->ctx->status);
447 state->result = talloc_array(state, struct wb_sid_object *,
449 if (composite_nomem(state->result, state->ctx)) return;
451 for (i=0; i<state->num_sids; i++) {
452 struct lsa_TranslatedName *name =
453 &state->r.out.names->names[i];
454 struct lsa_TrustInformation *dom;
456 state->result[i] = talloc_zero(state->result,
457 struct wb_sid_object);
458 if (composite_nomem(state->result[i], state->ctx)) return;
460 state->result[i]->type = name->sid_type;
461 if (state->result[i]->type == SID_NAME_UNKNOWN) {
465 if (name->sid_index >= state->r.out.domains->count) {
466 composite_error(state->ctx,
467 NT_STATUS_INVALID_PARAMETER);
471 dom = &state->r.out.domains->domains[name->sid_index];
472 state->result[i]->domain = talloc_reference(state->result[i],
474 if ((name->sid_type == SID_NAME_DOMAIN) ||
475 (name->name.string == NULL)) {
476 state->result[i]->name =
477 talloc_strdup(state->result[i], "");
479 state->result[i]->name =
480 talloc_steal(state->result[i],
484 if (composite_nomem(state->result[i]->name, state->ctx)) {
489 composite_done(state->ctx);
492 NTSTATUS wb_lsa_lookupsids_recv(struct composite_context *c,
494 struct wb_sid_object ***names)
496 NTSTATUS status = composite_wait(c);
497 if (NT_STATUS_IS_OK(status)) {
498 struct lsa_lookupsids_state *state =
499 talloc_get_type(c->private_data,
500 struct lsa_lookupsids_state);
501 *names = talloc_steal(mem_ctx, state->result);
507 NTSTATUS wb_lsa_lookupsids(struct dcerpc_pipe *lsa_pipe,
508 struct policy_handle *handle,
509 int num_sids, const struct dom_sid **sids,
511 struct wb_sid_object ***names)
513 struct composite_context *c =
514 wb_lsa_lookupsids_send(lsa_pipe, handle, num_sids, sids);
515 return wb_lsa_lookupnames_recv(c, mem_ctx, names);
520 struct lsa_lookupnames_state {
521 struct composite_context *ctx;
523 struct lsa_LookupNames r;
524 struct lsa_TransSidArray sids;
526 struct wb_sid_object **result;
529 static void lsa_lookupnames_recv_sids(struct rpc_request *req);
531 struct composite_context *wb_lsa_lookupnames_send(struct dcerpc_pipe *lsa_pipe,
532 struct policy_handle *handle,
536 struct composite_context *result;
537 struct rpc_request *req;
538 struct lsa_lookupnames_state *state;
540 struct lsa_String *lsa_names;
543 result = talloc_zero(NULL, struct composite_context);
544 if (result == NULL) goto failed;
545 result->state = COMPOSITE_STATE_IN_PROGRESS;
546 result->async.fn = NULL;
547 result->event_ctx = lsa_pipe->conn->event_ctx;
549 state = talloc(result, struct lsa_lookupnames_state);
550 if (state == NULL) goto failed;
551 result->private_data = state;
554 state->sids.count = 0;
555 state->sids.sids = NULL;
556 state->num_names = num_names;
559 lsa_names = talloc_array(state, struct lsa_String, num_names);
560 if (lsa_names == NULL) goto failed;
562 for (i=0; i<num_names; i++) {
563 lsa_names[i].string = names[i];
566 state->r.in.handle = handle;
567 state->r.in.num_names = num_names;
568 state->r.in.names = lsa_names;
569 state->r.in.sids = &state->sids;
570 state->r.in.level = 1;
571 state->r.in.count = &state->count;
572 state->r.out.count = &state->count;
573 state->r.out.sids = &state->sids;
575 req = dcerpc_lsa_LookupNames_send(lsa_pipe, state, &state->r);
576 if (req == NULL) goto failed;
578 req->async.callback = lsa_lookupnames_recv_sids;
579 req->async.private = state;
587 static void lsa_lookupnames_recv_sids(struct rpc_request *req)
589 struct lsa_lookupnames_state *state =
590 talloc_get_type(req->async.private,
591 struct lsa_lookupnames_state);
594 state->ctx->status = dcerpc_ndr_request_recv(req);
595 if (!composite_is_ok(state->ctx)) return;
596 state->ctx->status = state->r.out.result;
597 if (!NT_STATUS_IS_OK(state->ctx->status) &&
598 !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
599 composite_error(state->ctx, state->ctx->status);
603 state->result = talloc_array(state, struct wb_sid_object *,
605 if (composite_nomem(state->result, state->ctx)) return;
607 for (i=0; i<state->num_names; i++) {
608 struct lsa_TranslatedSid *sid = &state->r.out.sids->sids[i];
609 struct lsa_TrustInformation *dom;
611 state->result[i] = talloc_zero(state->result,
612 struct wb_sid_object);
613 if (composite_nomem(state->result[i], state->ctx)) return;
615 state->result[i]->type = sid->sid_type;
616 if (state->result[i]->type == SID_NAME_UNKNOWN) {
620 if (sid->sid_index >= state->r.out.domains->count) {
621 composite_error(state->ctx,
622 NT_STATUS_INVALID_PARAMETER);
626 dom = &state->r.out.domains->domains[sid->sid_index];
628 state->result[i]->sid = dom_sid_add_rid(state->result[i],
632 composite_done(state->ctx);
635 NTSTATUS wb_lsa_lookupnames_recv(struct composite_context *c,
637 struct wb_sid_object ***sids)
639 NTSTATUS status = composite_wait(c);
640 if (NT_STATUS_IS_OK(status)) {
641 struct lsa_lookupnames_state *state =
642 talloc_get_type(c->private_data,
643 struct lsa_lookupnames_state);
644 *sids = talloc_steal(mem_ctx, state->result);
650 NTSTATUS wb_lsa_lookupnames(struct dcerpc_pipe *lsa_pipe,
651 struct policy_handle *handle,
652 int num_names, const char **names,
654 struct wb_sid_object ***sids)
656 struct composite_context *c =
657 wb_lsa_lookupnames_send(lsa_pipe, handle, num_names, names);
658 return wb_lsa_lookupnames_recv(c, mem_ctx, sids);
661 struct cmd_checkmachacc_state {
662 struct composite_context *ctx;
663 struct wbsrv_call *call;
664 struct wbsrv_domain *domain;
667 static void cmd_checkmachacc_recv_init(struct composite_context *ctx);
669 struct composite_context *wb_cmd_checkmachacc_send(struct wbsrv_call *call)
671 struct composite_context *result, *ctx;
672 struct cmd_checkmachacc_state *state;
673 struct wbsrv_service *service = call->wbconn->listen_socket->service;
675 result = talloc(call, struct composite_context);
676 if (result == NULL) goto failed;
677 result->state = COMPOSITE_STATE_IN_PROGRESS;
678 result->async.fn = NULL;
679 result->event_ctx = call->event_ctx;
681 state = talloc(result, struct cmd_checkmachacc_state);
682 if (state == NULL) goto failed;
684 result->private_data = state;
687 state->domain = service->domains;
689 ctx = wb_init_domain_send(state->domain, result->event_ctx,
690 call->wbconn->conn->msg_ctx);
691 if (ctx == NULL) goto failed;
692 ctx->async.fn = cmd_checkmachacc_recv_init;
693 ctx->async.private_data = state;
702 static void cmd_checkmachacc_recv_init(struct composite_context *ctx)
704 struct cmd_checkmachacc_state *state =
705 talloc_get_type(ctx->async.private_data,
706 struct cmd_checkmachacc_state);
708 state->ctx->status = wb_init_domain_recv(ctx);
709 if (!composite_is_ok(state->ctx)) return;
711 composite_done(state->ctx);
714 NTSTATUS wb_cmd_checkmachacc_recv(struct composite_context *c)
716 NTSTATUS status = composite_wait(c);
721 NTSTATUS wb_cmd_checkmachacc(struct wbsrv_call *call)
723 struct composite_context *c = wb_cmd_checkmachacc_send(call);
724 return wb_cmd_checkmachacc_recv(c);
727 static void composite_netr_LogonSamLogon_recv_rpc(struct rpc_request *req);
729 struct composite_context *composite_netr_LogonSamLogon_send(struct dcerpc_pipe *p,
731 struct netr_LogonSamLogon *r)
733 struct composite_context *result;
734 struct rpc_request *req;
736 result = talloc(mem_ctx, struct composite_context);
737 if (result == NULL) goto failed;
738 result->state = COMPOSITE_STATE_IN_PROGRESS;
739 result->async.fn = NULL;
740 result->event_ctx = p->conn->event_ctx;
742 req = dcerpc_netr_LogonSamLogon_send(p, mem_ctx, r);
743 if (req == NULL) goto failed;
744 req->async.callback = composite_netr_LogonSamLogon_recv_rpc;
745 req->async.private = result;
753 static void composite_netr_LogonSamLogon_recv_rpc(struct rpc_request *req)
755 struct composite_context *ctx =
756 talloc_get_type(req->async.private, struct composite_context);
758 ctx->status = dcerpc_ndr_request_recv(req);
759 if (!composite_is_ok(ctx)) return;
763 NTSTATUS composite_netr_LogonSamLogon_recv(struct composite_context *ctx)
765 NTSTATUS status = composite_wait(ctx);
770 struct samr_getuserdomgroups_state {
771 struct composite_context *ctx;
772 struct dcerpc_pipe *samr_pipe;
777 struct policy_handle *user_handle;
778 struct samr_OpenUser o;
779 struct samr_GetGroupsForUser g;
783 static void samr_usergroups_recv_open(struct rpc_request *req);
784 static void samr_usergroups_recv_groups(struct rpc_request *req);
785 static void samr_usergroups_recv_close(struct rpc_request *req);
787 struct composite_context *wb_samr_userdomgroups_send(struct dcerpc_pipe *samr_pipe,
788 struct policy_handle *domain_handle,
791 struct composite_context *result;
792 struct rpc_request *req;
793 struct samr_getuserdomgroups_state *state;
795 result = talloc_zero(NULL, struct composite_context);
796 if (result == NULL) goto failed;
797 result->state = COMPOSITE_STATE_IN_PROGRESS;
798 result->async.fn = NULL;
799 result->event_ctx = samr_pipe->conn->event_ctx;
801 state = talloc(result, struct samr_getuserdomgroups_state);
802 if (state == NULL) goto failed;
803 result->private_data = state;
806 state->samr_pipe = samr_pipe;
808 state->user_handle = talloc(state, struct policy_handle);
809 if (state->user_handle == NULL) goto failed;
811 state->o.in.domain_handle = domain_handle;
812 state->o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
813 state->o.in.rid = rid;
814 state->o.out.user_handle = state->user_handle;
816 req = dcerpc_samr_OpenUser_send(state->samr_pipe, state, &state->o);
817 if (req == NULL) goto failed;
819 req->async.callback = samr_usergroups_recv_open;
820 req->async.private = state;
828 static void samr_usergroups_recv_open(struct rpc_request *req)
830 struct samr_getuserdomgroups_state *state =
831 talloc_get_type(req->async.private,
832 struct samr_getuserdomgroups_state);
834 state->ctx->status = dcerpc_ndr_request_recv(req);
835 if (!composite_is_ok(state->ctx)) return;
836 state->ctx->status = state->o.out.result;
837 if (!composite_is_ok(state->ctx)) return;
839 state->g.in.user_handle = state->user_handle;
841 req = dcerpc_samr_GetGroupsForUser_send(state->samr_pipe, state,
843 composite_continue_rpc(state->ctx, req, samr_usergroups_recv_groups,
847 static void samr_usergroups_recv_groups(struct rpc_request *req)
849 struct samr_getuserdomgroups_state *state =
850 talloc_get_type(req->async.private,
851 struct samr_getuserdomgroups_state);
853 state->ctx->status = dcerpc_ndr_request_recv(req);
854 if (!composite_is_ok(state->ctx)) return;
855 state->ctx->status = state->g.out.result;
856 if (!composite_is_ok(state->ctx)) return;
858 state->c.in.handle = state->user_handle;
859 state->c.out.handle = state->user_handle;
861 req = dcerpc_samr_Close_send(state->samr_pipe, state, &state->c);
862 composite_continue_rpc(state->ctx, req, samr_usergroups_recv_close,
866 static void samr_usergroups_recv_close(struct rpc_request *req)
868 struct samr_getuserdomgroups_state *state =
869 talloc_get_type(req->async.private,
870 struct samr_getuserdomgroups_state);
872 state->ctx->status = dcerpc_ndr_request_recv(req);
873 if (!composite_is_ok(state->ctx)) return;
874 state->ctx->status = state->c.out.result;
875 if (!composite_is_ok(state->ctx)) return;
877 composite_done(state->ctx);
880 NTSTATUS wb_samr_userdomgroups_recv(struct composite_context *ctx,
882 int *num_rids, uint32_t **rids)
884 struct samr_getuserdomgroups_state *state =
885 talloc_get_type(ctx->private_data,
886 struct samr_getuserdomgroups_state);
889 NTSTATUS status = composite_wait(ctx);
890 if (!NT_STATUS_IS_OK(status)) goto done;
892 *num_rids = state->g.out.rids->count;
893 *rids = talloc_array(mem_ctx, uint32_t, *num_rids);
895 status = NT_STATUS_NO_MEMORY;
899 for (i=0; i<*num_rids; i++) {
900 (*rids)[i] = state->g.out.rids->rids[i].rid;