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(TALLOC_CTX *mem_ctx,
58 const char *domain_name,
59 const struct dom_sid *domain_sid,
60 struct event_context *event_ctx,
61 struct messaging_context *msg_ctx)
63 struct composite_context *result, *ctx;
64 struct finddcs_state *state;
67 result = talloc(mem_ctx, struct composite_context);
68 if (result == NULL) goto failed;
69 result->state = COMPOSITE_STATE_IN_PROGRESS;
70 result->async.fn = NULL;
71 result->event_ctx = event_ctx;
73 state = talloc(result, struct finddcs_state);
74 if (state == NULL) goto failed;
76 result->private_data = state;
78 state->domain_name = talloc_strdup(state, domain_name);
79 if (state->domain_name == NULL) goto failed;
80 state->domain_sid = dom_sid_dup(state, domain_sid);
81 if (state->domain_sid == NULL) goto failed;
82 state->msg_ctx = msg_ctx;
84 make_nbt_name(&name, state->domain_name, 0x1c);
85 ctx = resolve_name_send(&name, result->event_ctx,
86 lp_name_resolve_order());
88 if (ctx == NULL) goto failed;
89 ctx->async.fn = finddcs_resolve;
90 ctx->async.private_data = state;
99 static void finddcs_resolve(struct composite_context *ctx)
101 struct finddcs_state *state =
102 talloc_get_type(ctx->async.private_data, struct finddcs_state);
103 struct irpc_request *ireq;
104 uint32_t *nbt_servers;
107 state->ctx->status = resolve_name_recv(ctx, state, &address);
108 if (!composite_is_ok(state->ctx)) return;
111 state->dcs = talloc_array(state, struct nbt_dc_name, state->num_dcs);
112 if (composite_nomem(state->dcs, state->ctx)) return;
114 state->dcs[0].address = talloc_steal(state->dcs, address);
116 nbt_servers = irpc_servers_byname(state->msg_ctx, "nbt_server");
117 if ((nbt_servers == NULL) || (nbt_servers[0] == 0)) {
118 composite_error(state->ctx, NT_STATUS_NO_LOGON_SERVERS);
122 state->r.in.domainname = state->domain_name;
123 state->r.in.ip_address = state->dcs[0].address;
124 state->r.in.my_computername = lp_netbios_name();
125 state->r.in.my_accountname = talloc_asprintf(state, "%s$",
127 if (composite_nomem(state->r.in.my_accountname, state->ctx)) return;
128 state->r.in.account_control = ACB_WSTRUST;
129 state->r.in.domain_sid = dom_sid_dup(state, state->domain_sid);
130 if (composite_nomem(state->r.in.domain_sid, state->ctx)) return;
132 ireq = irpc_call_send(state->msg_ctx, nbt_servers[0],
133 &dcerpc_table_irpc, DCERPC_NBTD_GETDCNAME,
135 composite_continue_irpc(state->ctx, ireq, finddcs_getdc, state);
138 static void finddcs_getdc(struct irpc_request *ireq)
140 struct finddcs_state *state =
141 talloc_get_type(ireq->async.private, struct finddcs_state);
143 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(TALLOC_CTX *mem_ctx,
165 const char *domain_name, const struct dom_sid *domain_sid,
166 struct event_context *event_ctx,
167 struct messaging_context *msg_ctx,
168 int *num_dcs, struct nbt_dc_name **dcs)
170 struct composite_context *c = wb_finddcs_send(mem_ctx,
171 domain_name, domain_sid,
173 return wb_finddcs_recv(c, mem_ctx, num_dcs, dcs);
176 struct get_schannel_creds_state {
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_anonbind(struct composite_context *creq);
188 static void get_schannel_creds_recv_auth(struct rpc_request *req);
189 static void get_schannel_creds_recv_chal(struct rpc_request *req);
190 static void get_schannel_creds_recv_pipe(struct composite_context *ctx);
192 struct composite_context *wb_get_schannel_creds_send(TALLOC_CTX *mem_ctx,
193 struct cli_credentials *wks_creds,
194 struct smbcli_tree *tree,
195 struct event_context *ev)
197 struct composite_context *c, *creq;
198 struct get_schannel_creds_state *state;
200 c = talloc_zero(mem_ctx, struct composite_context);
201 if (c == NULL) return NULL;
203 state = talloc(c, struct get_schannel_creds_state);
205 c->status = NT_STATUS_NO_MEMORY;
209 c->state = COMPOSITE_STATE_IN_PROGRESS;
210 c->private_data = state;
213 state->wks_creds = wks_creds;
215 state->p = dcerpc_pipe_init(state, ev);
216 if (state->p == NULL) {
217 c->status = NT_STATUS_NO_MEMORY;
221 creq = dcerpc_pipe_open_smb_send(state->p->conn, tree, "\\netlogon");
223 c->status = NT_STATUS_NO_MEMORY;
227 creq->async.fn = get_schannel_creds_recv_pipe;
228 creq->async.private_data = c;
233 composite_error(c, c->status);
237 static void get_schannel_creds_recv_pipe(struct composite_context *creq)
239 struct composite_context *c =
240 talloc_get_type(creq->async.private_data,
241 struct composite_context);
242 struct get_schannel_creds_state *state =
243 talloc_get_type(c->private_data,
244 struct get_schannel_creds_state);
246 c->status = dcerpc_pipe_open_smb_recv(creq);
247 if (!composite_is_ok(c)) return;
249 creq = dcerpc_bind_auth_none_send(state, state->p,
250 &dcerpc_table_netlogon);
251 composite_continue(c, creq, get_schannel_creds_recv_anonbind, c);
254 static void get_schannel_creds_recv_anonbind(struct composite_context *creq)
256 struct composite_context *c =
257 talloc_get_type(creq->async.private_data,
258 struct composite_context);
259 struct get_schannel_creds_state *state =
260 talloc_get_type(c->private_data,
261 struct get_schannel_creds_state);
262 struct rpc_request *req;
264 c->status = dcerpc_bind_auth_none_recv(creq);
265 if (!composite_is_ok(c)) return;
267 state->r.in.computer_name =
268 cli_credentials_get_workstation(state->wks_creds);
269 state->r.in.server_name =
270 talloc_asprintf(state, "\\\\%s",
271 dcerpc_server_name(state->p));
272 if (composite_nomem(state->r.in.server_name, c)) return;
274 state->r.in.credentials = talloc(state, struct netr_Credential);
275 if (composite_nomem(state->r.in.credentials, c)) return;
277 state->r.out.credentials = talloc(state, struct netr_Credential);
278 if (composite_nomem(state->r.out.credentials, c)) return;
280 generate_random_buffer(state->r.in.credentials->data,
281 sizeof(state->r.in.credentials->data));
283 req = dcerpc_netr_ServerReqChallenge_send(state->p, state, &state->r);
284 composite_continue_rpc(c, req, get_schannel_creds_recv_chal, c);
287 static void get_schannel_creds_recv_chal(struct rpc_request *req)
289 struct composite_context *c =
290 talloc_get_type(req->async.private,
291 struct composite_context);
292 struct get_schannel_creds_state *state =
293 talloc_get_type(c->private_data,
294 struct get_schannel_creds_state);
295 const struct samr_Password *mach_pwd;
297 c->status = dcerpc_ndr_request_recv(req);
298 if (!composite_is_ok(c)) return;
299 c->status = state->r.out.result;
300 if (!composite_is_ok(c)) return;
302 state->creds_state = talloc(state, struct creds_CredentialState);
303 if (composite_nomem(state->creds_state, c)) return;
305 mach_pwd = cli_credentials_get_nt_hash(state->wks_creds, state);
306 if (composite_nomem(mach_pwd, c)) return;
308 state->negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
310 creds_client_init(state->creds_state, state->r.in.credentials,
311 state->r.out.credentials, mach_pwd,
312 &state->netr_cred, state->negotiate_flags);
314 state->a.in.server_name =
315 talloc_reference(state, state->r.in.server_name);
316 state->a.in.account_name =
317 cli_credentials_get_username(state->wks_creds);
318 state->a.in.secure_channel_type =
319 cli_credentials_get_secure_channel_type(state->wks_creds);
320 state->a.in.computer_name =
321 cli_credentials_get_workstation(state->wks_creds);
322 state->a.in.negotiate_flags = &state->negotiate_flags;
323 state->a.out.negotiate_flags = &state->negotiate_flags;
324 state->a.in.credentials = &state->netr_cred;
325 state->a.out.credentials = &state->netr_cred;
327 req = dcerpc_netr_ServerAuthenticate2_send(state->p, state, &state->a);
328 composite_continue_rpc(c, req, get_schannel_creds_recv_auth, c);
331 static void get_schannel_creds_recv_auth(struct rpc_request *req)
333 struct composite_context *c =
334 talloc_get_type(req->async.private,
335 struct composite_context);
336 struct get_schannel_creds_state *state =
337 talloc_get_type(c->private_data,
338 struct get_schannel_creds_state);
340 c->status = dcerpc_ndr_request_recv(req);
341 if (!composite_is_ok(c)) return;
342 c->status = state->a.out.result;
343 if (!composite_is_ok(c)) return;
345 if (!creds_client_check(state->creds_state,
346 state->a.out.credentials)) {
347 DEBUG(5, ("Server got us invalid creds\n"));
348 composite_error(c, NT_STATUS_UNSUCCESSFUL);
352 cli_credentials_set_netlogon_creds(state->wks_creds,
358 NTSTATUS wb_get_schannel_creds_recv(struct composite_context *c,
360 struct dcerpc_pipe **netlogon_pipe)
362 NTSTATUS status = composite_wait(c);
363 if (NT_STATUS_IS_OK(status)) {
364 struct get_schannel_creds_state *state =
365 talloc_get_type(c->private_data,
366 struct get_schannel_creds_state);
367 *netlogon_pipe = talloc_steal(mem_ctx, state->p);
373 NTSTATUS wb_get_schannel_creds(TALLOC_CTX *mem_ctx,
374 struct cli_credentials *wks_creds,
375 struct smbcli_tree *tree,
376 struct event_context *event_ctx,
377 struct dcerpc_pipe **netlogon_pipe)
379 struct composite_context *c =
380 wb_get_schannel_creds_send(mem_ctx, wks_creds, tree,
382 return wb_get_schannel_creds_recv(c, mem_ctx, netlogon_pipe);
385 struct lsa_lookupsids_state {
386 struct composite_context *ctx;
388 struct lsa_LookupSids r;
389 struct lsa_SidArray sids;
390 struct lsa_TransNameArray names;
392 struct wb_sid_object **result;
395 static void lsa_lookupsids_recv_names(struct rpc_request *req);
397 struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
398 struct dcerpc_pipe *lsa_pipe,
399 struct policy_handle *handle,
401 const struct dom_sid **sids)
403 struct composite_context *result;
404 struct rpc_request *req;
405 struct lsa_lookupsids_state *state;
408 result = talloc(mem_ctx, struct composite_context);
409 if (result == NULL) goto failed;
410 result->state = COMPOSITE_STATE_IN_PROGRESS;
411 result->async.fn = NULL;
412 result->event_ctx = lsa_pipe->conn->event_ctx;
414 state = talloc(result, struct lsa_lookupsids_state);
415 if (state == NULL) goto failed;
416 result->private_data = state;
419 state->sids.num_sids = num_sids;
420 state->sids.sids = talloc_array(state, struct lsa_SidPtr, num_sids);
421 if (state->sids.sids == NULL) goto failed;
423 for (i=0; i<num_sids; i++) {
424 state->sids.sids[i].sid = dom_sid_dup(state->sids.sids,
426 if (state->sids.sids[i].sid == NULL) goto failed;
430 state->num_sids = num_sids;
431 state->names.count = 0;
432 state->names.names = NULL;
434 state->r.in.handle = handle;
435 state->r.in.sids = &state->sids;
436 state->r.in.names = &state->names;
437 state->r.in.level = 1;
438 state->r.in.count = &state->count;
439 state->r.out.names = &state->names;
440 state->r.out.count = &state->count;
442 req = dcerpc_lsa_LookupSids_send(lsa_pipe, state, &state->r);
443 if (req == NULL) goto failed;
445 req->async.callback = lsa_lookupsids_recv_names;
446 req->async.private = state;
454 static void lsa_lookupsids_recv_names(struct rpc_request *req)
456 struct lsa_lookupsids_state *state =
457 talloc_get_type(req->async.private,
458 struct lsa_lookupsids_state);
461 state->ctx->status = dcerpc_ndr_request_recv(req);
462 if (!composite_is_ok(state->ctx)) return;
463 state->ctx->status = state->r.out.result;
464 if (!NT_STATUS_IS_OK(state->ctx->status) &&
465 !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
466 composite_error(state->ctx, state->ctx->status);
470 state->result = talloc_array(state, struct wb_sid_object *,
472 if (composite_nomem(state->result, state->ctx)) return;
474 for (i=0; i<state->num_sids; i++) {
475 struct lsa_TranslatedName *name =
476 &state->r.out.names->names[i];
477 struct lsa_TrustInformation *dom;
479 state->result[i] = talloc_zero(state->result,
480 struct wb_sid_object);
481 if (composite_nomem(state->result[i], state->ctx)) return;
483 state->result[i]->type = name->sid_type;
484 if (state->result[i]->type == SID_NAME_UNKNOWN) {
488 if (name->sid_index >= state->r.out.domains->count) {
489 composite_error(state->ctx,
490 NT_STATUS_INVALID_PARAMETER);
494 dom = &state->r.out.domains->domains[name->sid_index];
495 state->result[i]->domain = talloc_reference(state->result[i],
497 if ((name->sid_type == SID_NAME_DOMAIN) ||
498 (name->name.string == NULL)) {
499 state->result[i]->name =
500 talloc_strdup(state->result[i], "");
502 state->result[i]->name =
503 talloc_steal(state->result[i],
507 if (composite_nomem(state->result[i]->name, state->ctx)) {
512 composite_done(state->ctx);
515 NTSTATUS wb_lsa_lookupsids_recv(struct composite_context *c,
517 struct wb_sid_object ***names)
519 NTSTATUS status = composite_wait(c);
520 if (NT_STATUS_IS_OK(status)) {
521 struct lsa_lookupsids_state *state =
522 talloc_get_type(c->private_data,
523 struct lsa_lookupsids_state);
524 *names = talloc_steal(mem_ctx, state->result);
530 NTSTATUS wb_lsa_lookupsids(TALLOC_CTX *mem_ctx,
531 struct dcerpc_pipe *lsa_pipe,
532 struct policy_handle *handle,
533 int num_sids, const struct dom_sid **sids,
534 struct wb_sid_object ***names)
536 struct composite_context *c =
537 wb_lsa_lookupsids_send(mem_ctx, lsa_pipe, handle,
539 return wb_lsa_lookupnames_recv(c, mem_ctx, names);
544 struct lsa_lookupnames_state {
545 struct composite_context *ctx;
547 struct lsa_LookupNames r;
548 struct lsa_TransSidArray sids;
550 struct wb_sid_object **result;
553 static void lsa_lookupnames_recv_sids(struct rpc_request *req);
555 struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
556 struct dcerpc_pipe *lsa_pipe,
557 struct policy_handle *handle,
561 struct composite_context *result;
562 struct rpc_request *req;
563 struct lsa_lookupnames_state *state;
565 struct lsa_String *lsa_names;
568 result = talloc(mem_ctx, struct composite_context);
569 if (result == NULL) goto failed;
570 result->state = COMPOSITE_STATE_IN_PROGRESS;
571 result->async.fn = NULL;
572 result->event_ctx = lsa_pipe->conn->event_ctx;
574 state = talloc(result, struct lsa_lookupnames_state);
575 if (state == NULL) goto failed;
576 result->private_data = state;
579 state->sids.count = 0;
580 state->sids.sids = NULL;
581 state->num_names = num_names;
584 lsa_names = talloc_array(state, struct lsa_String, num_names);
585 if (lsa_names == NULL) goto failed;
587 for (i=0; i<num_names; i++) {
588 lsa_names[i].string = names[i];
591 state->r.in.handle = handle;
592 state->r.in.num_names = num_names;
593 state->r.in.names = lsa_names;
594 state->r.in.sids = &state->sids;
595 state->r.in.level = 1;
596 state->r.in.count = &state->count;
597 state->r.out.count = &state->count;
598 state->r.out.sids = &state->sids;
600 req = dcerpc_lsa_LookupNames_send(lsa_pipe, state, &state->r);
601 if (req == NULL) goto failed;
603 req->async.callback = lsa_lookupnames_recv_sids;
604 req->async.private = state;
612 static void lsa_lookupnames_recv_sids(struct rpc_request *req)
614 struct lsa_lookupnames_state *state =
615 talloc_get_type(req->async.private,
616 struct lsa_lookupnames_state);
619 state->ctx->status = dcerpc_ndr_request_recv(req);
620 if (!composite_is_ok(state->ctx)) return;
621 state->ctx->status = state->r.out.result;
622 if (!NT_STATUS_IS_OK(state->ctx->status) &&
623 !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
624 composite_error(state->ctx, state->ctx->status);
628 state->result = talloc_array(state, struct wb_sid_object *,
630 if (composite_nomem(state->result, state->ctx)) return;
632 for (i=0; i<state->num_names; i++) {
633 struct lsa_TranslatedSid *sid = &state->r.out.sids->sids[i];
634 struct lsa_TrustInformation *dom;
636 state->result[i] = talloc_zero(state->result,
637 struct wb_sid_object);
638 if (composite_nomem(state->result[i], state->ctx)) return;
640 state->result[i]->type = sid->sid_type;
641 if (state->result[i]->type == SID_NAME_UNKNOWN) {
645 if (sid->sid_index >= state->r.out.domains->count) {
646 composite_error(state->ctx,
647 NT_STATUS_INVALID_PARAMETER);
651 dom = &state->r.out.domains->domains[sid->sid_index];
653 state->result[i]->sid = dom_sid_add_rid(state->result[i],
657 composite_done(state->ctx);
660 NTSTATUS wb_lsa_lookupnames_recv(struct composite_context *c,
662 struct wb_sid_object ***sids)
664 NTSTATUS status = composite_wait(c);
665 if (NT_STATUS_IS_OK(status)) {
666 struct lsa_lookupnames_state *state =
667 talloc_get_type(c->private_data,
668 struct lsa_lookupnames_state);
669 *sids = talloc_steal(mem_ctx, state->result);
675 NTSTATUS wb_lsa_lookupnames(TALLOC_CTX *mem_ctx,
676 struct dcerpc_pipe *lsa_pipe,
677 struct policy_handle *handle,
678 int num_names, const char **names,
679 struct wb_sid_object ***sids)
681 struct composite_context *c =
682 wb_lsa_lookupnames_send(mem_ctx, lsa_pipe, handle,
684 return wb_lsa_lookupnames_recv(c, mem_ctx, sids);
689 struct cmd_checkmachacc_state {
690 struct composite_context *ctx;
691 struct wbsrv_call *call;
692 struct wbsrv_domain *domain;
695 static void cmd_checkmachacc_recv_init(struct composite_context *ctx);
697 struct composite_context *wb_cmd_checkmachacc_send(struct wbsrv_call *call)
699 struct composite_context *result, *ctx;
700 struct cmd_checkmachacc_state *state;
701 struct wbsrv_service *service = call->wbconn->listen_socket->service;
703 result = talloc(call, struct composite_context);
704 if (result == NULL) goto failed;
705 result->state = COMPOSITE_STATE_IN_PROGRESS;
706 result->async.fn = NULL;
707 result->event_ctx = call->event_ctx;
709 state = talloc(result, struct cmd_checkmachacc_state);
710 if (state == NULL) goto failed;
712 result->private_data = state;
715 state->domain = service->domains;
717 ctx = wb_init_domain_send(service, state->domain);
718 if (ctx == NULL) goto failed;
719 ctx->async.fn = cmd_checkmachacc_recv_init;
720 ctx->async.private_data = state;
729 static void cmd_checkmachacc_recv_init(struct composite_context *ctx)
731 struct cmd_checkmachacc_state *state =
732 talloc_get_type(ctx->async.private_data,
733 struct cmd_checkmachacc_state);
735 state->ctx->status = wb_init_domain_recv(ctx);
736 if (!composite_is_ok(state->ctx)) return;
738 composite_done(state->ctx);
741 NTSTATUS wb_cmd_checkmachacc_recv(struct composite_context *c)
743 NTSTATUS status = composite_wait(c);
748 NTSTATUS wb_cmd_checkmachacc(struct wbsrv_call *call)
750 struct composite_context *c = wb_cmd_checkmachacc_send(call);
751 return wb_cmd_checkmachacc_recv(c);
755 struct samr_getuserdomgroups_state {
756 struct composite_context *ctx;
757 struct dcerpc_pipe *samr_pipe;
762 struct policy_handle *user_handle;
763 struct samr_OpenUser o;
764 struct samr_GetGroupsForUser g;
768 static void samr_usergroups_recv_open(struct rpc_request *req);
769 static void samr_usergroups_recv_groups(struct rpc_request *req);
770 static void samr_usergroups_recv_close(struct rpc_request *req);
772 struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
773 struct dcerpc_pipe *samr_pipe,
774 struct policy_handle *domain_handle,
777 struct composite_context *result;
778 struct rpc_request *req;
779 struct samr_getuserdomgroups_state *state;
781 result = talloc(mem_ctx, struct composite_context);
782 if (result == NULL) goto failed;
783 result->state = COMPOSITE_STATE_IN_PROGRESS;
784 result->async.fn = NULL;
785 result->event_ctx = samr_pipe->conn->event_ctx;
787 state = talloc(result, struct samr_getuserdomgroups_state);
788 if (state == NULL) goto failed;
789 result->private_data = state;
792 state->samr_pipe = samr_pipe;
794 state->user_handle = talloc(state, struct policy_handle);
795 if (state->user_handle == NULL) goto failed;
797 state->o.in.domain_handle = domain_handle;
798 state->o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
799 state->o.in.rid = rid;
800 state->o.out.user_handle = state->user_handle;
802 req = dcerpc_samr_OpenUser_send(state->samr_pipe, state, &state->o);
803 if (req == NULL) goto failed;
805 req->async.callback = samr_usergroups_recv_open;
806 req->async.private = state;
814 static void samr_usergroups_recv_open(struct rpc_request *req)
816 struct samr_getuserdomgroups_state *state =
817 talloc_get_type(req->async.private,
818 struct samr_getuserdomgroups_state);
820 state->ctx->status = dcerpc_ndr_request_recv(req);
821 if (!composite_is_ok(state->ctx)) return;
822 state->ctx->status = state->o.out.result;
823 if (!composite_is_ok(state->ctx)) return;
825 state->g.in.user_handle = state->user_handle;
827 req = dcerpc_samr_GetGroupsForUser_send(state->samr_pipe, state,
829 composite_continue_rpc(state->ctx, req, samr_usergroups_recv_groups,
833 static void samr_usergroups_recv_groups(struct rpc_request *req)
835 struct samr_getuserdomgroups_state *state =
836 talloc_get_type(req->async.private,
837 struct samr_getuserdomgroups_state);
839 state->ctx->status = dcerpc_ndr_request_recv(req);
840 if (!composite_is_ok(state->ctx)) return;
841 state->ctx->status = state->g.out.result;
842 if (!composite_is_ok(state->ctx)) return;
844 state->c.in.handle = state->user_handle;
845 state->c.out.handle = state->user_handle;
847 req = dcerpc_samr_Close_send(state->samr_pipe, state, &state->c);
848 composite_continue_rpc(state->ctx, req, samr_usergroups_recv_close,
852 static void samr_usergroups_recv_close(struct rpc_request *req)
854 struct samr_getuserdomgroups_state *state =
855 talloc_get_type(req->async.private,
856 struct samr_getuserdomgroups_state);
858 state->ctx->status = dcerpc_ndr_request_recv(req);
859 if (!composite_is_ok(state->ctx)) return;
860 state->ctx->status = state->c.out.result;
861 if (!composite_is_ok(state->ctx)) return;
863 composite_done(state->ctx);
866 NTSTATUS wb_samr_userdomgroups_recv(struct composite_context *ctx,
868 int *num_rids, uint32_t **rids)
870 struct samr_getuserdomgroups_state *state =
871 talloc_get_type(ctx->private_data,
872 struct samr_getuserdomgroups_state);
875 NTSTATUS status = composite_wait(ctx);
876 if (!NT_STATUS_IS_OK(status)) goto done;
878 *num_rids = state->g.out.rids->count;
879 *rids = talloc_array(mem_ctx, uint32_t, *num_rids);
881 status = NT_STATUS_NO_MEMORY;
885 for (i=0; i<*num_rids; i++) {
886 (*rids)[i] = state->g.out.rids->rids[i].rid;