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 "winbind/wb_async_helpers.h"
28 #include "lib/messaging/irpc.h"
29 #include "librpc/gen_ndr/ndr_irpc.h"
30 #include "libcli/auth/credentials.h"
32 struct finddcs_state {
33 struct composite_context *ctx;
34 struct messaging_context *msg_ctx;
36 const char *domain_name;
37 const struct dom_sid *domain_sid;
39 struct nbtd_getdcname r;
42 struct nbt_dc_name *dcs;
45 static void finddcs_resolve(struct composite_context *ctx);
46 static void finddcs_getdc(struct irpc_request *ireq);
48 struct composite_context *wb_finddcs_send(TALLOC_CTX *mem_ctx,
49 const char *domain_name,
50 const struct dom_sid *domain_sid,
51 struct event_context *event_ctx,
52 struct messaging_context *msg_ctx)
54 struct composite_context *result, *ctx;
55 struct finddcs_state *state;
58 result = talloc(mem_ctx, struct composite_context);
59 if (result == NULL) goto failed;
60 result->state = COMPOSITE_STATE_IN_PROGRESS;
61 result->async.fn = NULL;
62 result->event_ctx = event_ctx;
64 state = talloc(result, struct finddcs_state);
65 if (state == NULL) goto failed;
67 result->private_data = state;
69 state->domain_name = talloc_strdup(state, domain_name);
70 if (state->domain_name == NULL) goto failed;
71 state->domain_sid = dom_sid_dup(state, domain_sid);
72 if (state->domain_sid == NULL) goto failed;
73 state->msg_ctx = msg_ctx;
75 make_nbt_name(&name, state->domain_name, 0x1c);
76 ctx = resolve_name_send(&name, result->event_ctx,
77 lp_name_resolve_order());
79 if (ctx == NULL) goto failed;
80 ctx->async.fn = finddcs_resolve;
81 ctx->async.private_data = state;
90 static void finddcs_resolve(struct composite_context *ctx)
92 struct finddcs_state *state =
93 talloc_get_type(ctx->async.private_data, struct finddcs_state);
94 struct irpc_request *ireq;
95 uint32_t *nbt_servers;
98 state->ctx->status = resolve_name_recv(ctx, state, &address);
99 if (!composite_is_ok(state->ctx)) return;
102 state->dcs = talloc_array(state, struct nbt_dc_name, state->num_dcs);
103 if (composite_nomem(state->dcs, state->ctx)) return;
105 state->dcs[0].address = talloc_steal(state->dcs, address);
107 nbt_servers = irpc_servers_byname(state->msg_ctx, "nbt_server");
108 if ((nbt_servers == NULL) || (nbt_servers[0] == 0)) {
109 composite_error(state->ctx, NT_STATUS_NO_LOGON_SERVERS);
113 state->r.in.domainname = state->domain_name;
114 state->r.in.ip_address = state->dcs[0].address;
115 state->r.in.my_computername = lp_netbios_name();
116 state->r.in.my_accountname = talloc_asprintf(state, "%s$",
118 if (composite_nomem(state->r.in.my_accountname, state->ctx)) return;
119 state->r.in.account_control = ACB_WSTRUST;
120 state->r.in.domain_sid = dom_sid_dup(state, state->domain_sid);
121 if (composite_nomem(state->r.in.domain_sid, state->ctx)) return;
123 ireq = irpc_call_send(state->msg_ctx, nbt_servers[0],
124 &dcerpc_table_irpc, DCERPC_NBTD_GETDCNAME,
126 composite_continue_irpc(state->ctx, ireq, finddcs_getdc, state);
129 static void finddcs_getdc(struct irpc_request *ireq)
131 struct finddcs_state *state =
132 talloc_get_type(ireq->async.private, struct finddcs_state);
134 state->ctx->status = irpc_call_recv(ireq);
135 if (!composite_is_ok(state->ctx)) return;
137 state->dcs[0].name = talloc_steal(state->dcs, state->r.out.dcname);
138 composite_done(state->ctx);
141 NTSTATUS wb_finddcs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
142 int *num_dcs, struct nbt_dc_name **dcs)
144 NTSTATUS status = composite_wait(c);
145 if (NT_STATUS_IS_OK(status)) {
146 struct finddcs_state *state =
147 talloc_get_type(c->private_data, struct finddcs_state);
148 *num_dcs = state->num_dcs;
149 *dcs = talloc_steal(mem_ctx, state->dcs);
155 NTSTATUS wb_finddcs(TALLOC_CTX *mem_ctx,
156 const char *domain_name, const struct dom_sid *domain_sid,
157 struct event_context *event_ctx,
158 struct messaging_context *msg_ctx,
159 int *num_dcs, struct nbt_dc_name **dcs)
161 struct composite_context *c = wb_finddcs_send(mem_ctx,
162 domain_name, domain_sid,
164 return wb_finddcs_recv(c, mem_ctx, num_dcs, dcs);
167 struct get_schannel_creds_state {
168 struct cli_credentials *wks_creds;
169 struct dcerpc_pipe *p;
170 struct netr_ServerReqChallenge r;
172 struct creds_CredentialState *creds_state;
173 struct netr_Credential netr_cred;
174 uint32_t negotiate_flags;
175 struct netr_ServerAuthenticate2 a;
178 static void get_schannel_creds_recv_anonbind(struct composite_context *creq);
179 static void get_schannel_creds_recv_auth(struct rpc_request *req);
180 static void get_schannel_creds_recv_chal(struct rpc_request *req);
181 static void get_schannel_creds_recv_pipe(struct composite_context *ctx);
183 struct composite_context *wb_get_schannel_creds_send(TALLOC_CTX *mem_ctx,
184 struct cli_credentials *wks_creds,
185 struct smbcli_tree *tree,
186 struct event_context *ev)
188 struct composite_context *c, *creq;
189 struct get_schannel_creds_state *state;
191 c = talloc_zero(mem_ctx, struct composite_context);
192 if (c == NULL) return NULL;
194 state = talloc(c, struct get_schannel_creds_state);
196 c->status = NT_STATUS_NO_MEMORY;
200 c->state = COMPOSITE_STATE_IN_PROGRESS;
201 c->private_data = state;
204 state->wks_creds = wks_creds;
206 state->p = dcerpc_pipe_init(state, ev);
207 if (state->p == NULL) {
208 c->status = NT_STATUS_NO_MEMORY;
212 creq = dcerpc_pipe_open_smb_send(state->p->conn, tree, "\\netlogon");
214 c->status = NT_STATUS_NO_MEMORY;
218 creq->async.fn = get_schannel_creds_recv_pipe;
219 creq->async.private_data = c;
224 composite_error(c, c->status);
228 static void get_schannel_creds_recv_pipe(struct composite_context *creq)
230 struct composite_context *c =
231 talloc_get_type(creq->async.private_data,
232 struct composite_context);
233 struct get_schannel_creds_state *state =
234 talloc_get_type(c->private_data,
235 struct get_schannel_creds_state);
237 c->status = dcerpc_pipe_open_smb_recv(creq);
238 if (!composite_is_ok(c)) return;
240 creq = dcerpc_bind_auth_none_send(state, state->p,
241 &dcerpc_table_netlogon);
242 composite_continue(c, creq, get_schannel_creds_recv_anonbind, c);
245 static void get_schannel_creds_recv_anonbind(struct composite_context *creq)
247 struct composite_context *c =
248 talloc_get_type(creq->async.private_data,
249 struct composite_context);
250 struct get_schannel_creds_state *state =
251 talloc_get_type(c->private_data,
252 struct get_schannel_creds_state);
253 struct rpc_request *req;
255 c->status = dcerpc_bind_auth_none_recv(creq);
256 if (!composite_is_ok(c)) return;
258 state->r.in.computer_name =
259 cli_credentials_get_workstation(state->wks_creds);
260 state->r.in.server_name =
261 talloc_asprintf(state, "\\\\%s",
262 dcerpc_server_name(state->p));
263 if (composite_nomem(state->r.in.server_name, c)) return;
265 state->r.in.credentials = talloc(state, struct netr_Credential);
266 if (composite_nomem(state->r.in.credentials, c)) return;
268 state->r.out.credentials = talloc(state, struct netr_Credential);
269 if (composite_nomem(state->r.out.credentials, c)) return;
271 generate_random_buffer(state->r.in.credentials->data,
272 sizeof(state->r.in.credentials->data));
274 req = dcerpc_netr_ServerReqChallenge_send(state->p, state, &state->r);
275 composite_continue_rpc(c, req, get_schannel_creds_recv_chal, c);
278 static void get_schannel_creds_recv_chal(struct rpc_request *req)
280 struct composite_context *c =
281 talloc_get_type(req->async.private,
282 struct composite_context);
283 struct get_schannel_creds_state *state =
284 talloc_get_type(c->private_data,
285 struct get_schannel_creds_state);
286 const struct samr_Password *mach_pwd;
288 c->status = dcerpc_ndr_request_recv(req);
289 if (!composite_is_ok(c)) return;
290 c->status = state->r.out.result;
291 if (!composite_is_ok(c)) return;
293 state->creds_state = talloc(state, struct creds_CredentialState);
294 if (composite_nomem(state->creds_state, c)) return;
296 mach_pwd = cli_credentials_get_nt_hash(state->wks_creds, state);
297 if (composite_nomem(mach_pwd, c)) return;
299 state->negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
301 creds_client_init(state->creds_state, state->r.in.credentials,
302 state->r.out.credentials, mach_pwd,
303 &state->netr_cred, state->negotiate_flags);
305 state->a.in.server_name =
306 talloc_reference(state, state->r.in.server_name);
307 state->a.in.account_name =
308 cli_credentials_get_username(state->wks_creds);
309 state->a.in.secure_channel_type =
310 cli_credentials_get_secure_channel_type(state->wks_creds);
311 state->a.in.computer_name =
312 cli_credentials_get_workstation(state->wks_creds);
313 state->a.in.negotiate_flags = &state->negotiate_flags;
314 state->a.out.negotiate_flags = &state->negotiate_flags;
315 state->a.in.credentials = &state->netr_cred;
316 state->a.out.credentials = &state->netr_cred;
318 req = dcerpc_netr_ServerAuthenticate2_send(state->p, state, &state->a);
319 composite_continue_rpc(c, req, get_schannel_creds_recv_auth, c);
322 static void get_schannel_creds_recv_auth(struct rpc_request *req)
324 struct composite_context *c =
325 talloc_get_type(req->async.private,
326 struct composite_context);
327 struct get_schannel_creds_state *state =
328 talloc_get_type(c->private_data,
329 struct get_schannel_creds_state);
331 c->status = dcerpc_ndr_request_recv(req);
332 if (!composite_is_ok(c)) return;
333 c->status = state->a.out.result;
334 if (!composite_is_ok(c)) return;
336 if (!creds_client_check(state->creds_state,
337 state->a.out.credentials)) {
338 DEBUG(5, ("Server got us invalid creds\n"));
339 composite_error(c, NT_STATUS_UNSUCCESSFUL);
343 cli_credentials_set_netlogon_creds(state->wks_creds,
349 NTSTATUS wb_get_schannel_creds_recv(struct composite_context *c,
351 struct dcerpc_pipe **netlogon_pipe)
353 NTSTATUS status = composite_wait(c);
354 if (NT_STATUS_IS_OK(status)) {
355 struct get_schannel_creds_state *state =
356 talloc_get_type(c->private_data,
357 struct get_schannel_creds_state);
358 *netlogon_pipe = talloc_steal(mem_ctx, state->p);
364 NTSTATUS wb_get_schannel_creds(TALLOC_CTX *mem_ctx,
365 struct cli_credentials *wks_creds,
366 struct smbcli_tree *tree,
367 struct event_context *event_ctx,
368 struct dcerpc_pipe **netlogon_pipe)
370 struct composite_context *c =
371 wb_get_schannel_creds_send(mem_ctx, wks_creds, tree,
373 return wb_get_schannel_creds_recv(c, mem_ctx, netlogon_pipe);
376 struct lsa_lookupsids_state {
377 struct composite_context *ctx;
379 struct lsa_LookupSids r;
380 struct lsa_SidArray sids;
381 struct lsa_TransNameArray names;
383 struct wb_sid_object **result;
386 static void lsa_lookupsids_recv_names(struct rpc_request *req);
388 struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
389 struct dcerpc_pipe *lsa_pipe,
390 struct policy_handle *handle,
392 const struct dom_sid **sids)
394 struct composite_context *result;
395 struct rpc_request *req;
396 struct lsa_lookupsids_state *state;
399 result = talloc(mem_ctx, struct composite_context);
400 if (result == NULL) goto failed;
401 result->state = COMPOSITE_STATE_IN_PROGRESS;
402 result->async.fn = NULL;
403 result->event_ctx = lsa_pipe->conn->event_ctx;
405 state = talloc(result, struct lsa_lookupsids_state);
406 if (state == NULL) goto failed;
407 result->private_data = state;
410 state->sids.num_sids = num_sids;
411 state->sids.sids = talloc_array(state, struct lsa_SidPtr, num_sids);
412 if (state->sids.sids == NULL) goto failed;
414 for (i=0; i<num_sids; i++) {
415 state->sids.sids[i].sid = dom_sid_dup(state->sids.sids,
417 if (state->sids.sids[i].sid == NULL) goto failed;
421 state->num_sids = num_sids;
422 state->names.count = 0;
423 state->names.names = NULL;
425 state->r.in.handle = handle;
426 state->r.in.sids = &state->sids;
427 state->r.in.names = &state->names;
428 state->r.in.level = 1;
429 state->r.in.count = &state->count;
430 state->r.out.names = &state->names;
431 state->r.out.count = &state->count;
433 req = dcerpc_lsa_LookupSids_send(lsa_pipe, state, &state->r);
434 if (req == NULL) goto failed;
436 req->async.callback = lsa_lookupsids_recv_names;
437 req->async.private = state;
445 static void lsa_lookupsids_recv_names(struct rpc_request *req)
447 struct lsa_lookupsids_state *state =
448 talloc_get_type(req->async.private,
449 struct lsa_lookupsids_state);
452 state->ctx->status = dcerpc_ndr_request_recv(req);
453 if (!composite_is_ok(state->ctx)) return;
454 state->ctx->status = state->r.out.result;
455 if (!NT_STATUS_IS_OK(state->ctx->status) &&
456 !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
457 composite_error(state->ctx, state->ctx->status);
461 state->result = talloc_array(state, struct wb_sid_object *,
463 if (composite_nomem(state->result, state->ctx)) return;
465 for (i=0; i<state->num_sids; i++) {
466 struct lsa_TranslatedName *name =
467 &state->r.out.names->names[i];
468 struct lsa_TrustInformation *dom;
470 state->result[i] = talloc_zero(state->result,
471 struct wb_sid_object);
472 if (composite_nomem(state->result[i], state->ctx)) return;
474 state->result[i]->type = name->sid_type;
475 if (state->result[i]->type == SID_NAME_UNKNOWN) {
479 if (name->sid_index >= state->r.out.domains->count) {
480 composite_error(state->ctx,
481 NT_STATUS_INVALID_PARAMETER);
485 dom = &state->r.out.domains->domains[name->sid_index];
486 state->result[i]->domain = talloc_reference(state->result[i],
488 if ((name->sid_type == SID_NAME_DOMAIN) ||
489 (name->name.string == NULL)) {
490 state->result[i]->name =
491 talloc_strdup(state->result[i], "");
493 state->result[i]->name =
494 talloc_steal(state->result[i],
498 if (composite_nomem(state->result[i]->name, state->ctx)) {
503 composite_done(state->ctx);
506 NTSTATUS wb_lsa_lookupsids_recv(struct composite_context *c,
508 struct wb_sid_object ***names)
510 NTSTATUS status = composite_wait(c);
511 if (NT_STATUS_IS_OK(status)) {
512 struct lsa_lookupsids_state *state =
513 talloc_get_type(c->private_data,
514 struct lsa_lookupsids_state);
515 *names = talloc_steal(mem_ctx, state->result);
521 NTSTATUS wb_lsa_lookupsids(TALLOC_CTX *mem_ctx,
522 struct dcerpc_pipe *lsa_pipe,
523 struct policy_handle *handle,
524 int num_sids, const struct dom_sid **sids,
525 struct wb_sid_object ***names)
527 struct composite_context *c =
528 wb_lsa_lookupsids_send(mem_ctx, lsa_pipe, handle,
530 return wb_lsa_lookupnames_recv(c, mem_ctx, names);
535 struct lsa_lookupnames_state {
536 struct composite_context *ctx;
538 struct lsa_LookupNames r;
539 struct lsa_TransSidArray sids;
541 struct wb_sid_object **result;
544 static void lsa_lookupnames_recv_sids(struct rpc_request *req);
546 struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
547 struct dcerpc_pipe *lsa_pipe,
548 struct policy_handle *handle,
552 struct composite_context *result;
553 struct rpc_request *req;
554 struct lsa_lookupnames_state *state;
556 struct lsa_String *lsa_names;
559 result = talloc(mem_ctx, struct composite_context);
560 if (result == NULL) goto failed;
561 result->state = COMPOSITE_STATE_IN_PROGRESS;
562 result->async.fn = NULL;
563 result->event_ctx = lsa_pipe->conn->event_ctx;
565 state = talloc(result, struct lsa_lookupnames_state);
566 if (state == NULL) goto failed;
567 result->private_data = state;
570 state->sids.count = 0;
571 state->sids.sids = NULL;
572 state->num_names = num_names;
575 lsa_names = talloc_array(state, struct lsa_String, num_names);
576 if (lsa_names == NULL) goto failed;
578 for (i=0; i<num_names; i++) {
579 lsa_names[i].string = names[i];
582 state->r.in.handle = handle;
583 state->r.in.num_names = num_names;
584 state->r.in.names = lsa_names;
585 state->r.in.sids = &state->sids;
586 state->r.in.level = 1;
587 state->r.in.count = &state->count;
588 state->r.out.count = &state->count;
589 state->r.out.sids = &state->sids;
591 req = dcerpc_lsa_LookupNames_send(lsa_pipe, state, &state->r);
592 if (req == NULL) goto failed;
594 req->async.callback = lsa_lookupnames_recv_sids;
595 req->async.private = state;
603 static void lsa_lookupnames_recv_sids(struct rpc_request *req)
605 struct lsa_lookupnames_state *state =
606 talloc_get_type(req->async.private,
607 struct lsa_lookupnames_state);
610 state->ctx->status = dcerpc_ndr_request_recv(req);
611 if (!composite_is_ok(state->ctx)) return;
612 state->ctx->status = state->r.out.result;
613 if (!NT_STATUS_IS_OK(state->ctx->status) &&
614 !NT_STATUS_EQUAL(state->ctx->status, STATUS_SOME_UNMAPPED)) {
615 composite_error(state->ctx, state->ctx->status);
619 state->result = talloc_array(state, struct wb_sid_object *,
621 if (composite_nomem(state->result, state->ctx)) return;
623 for (i=0; i<state->num_names; i++) {
624 struct lsa_TranslatedSid *sid = &state->r.out.sids->sids[i];
625 struct lsa_TrustInformation *dom;
627 state->result[i] = talloc_zero(state->result,
628 struct wb_sid_object);
629 if (composite_nomem(state->result[i], state->ctx)) return;
631 state->result[i]->type = sid->sid_type;
632 if (state->result[i]->type == SID_NAME_UNKNOWN) {
636 if (sid->sid_index >= state->r.out.domains->count) {
637 composite_error(state->ctx,
638 NT_STATUS_INVALID_PARAMETER);
642 dom = &state->r.out.domains->domains[sid->sid_index];
644 state->result[i]->sid = dom_sid_add_rid(state->result[i],
648 composite_done(state->ctx);
651 NTSTATUS wb_lsa_lookupnames_recv(struct composite_context *c,
653 struct wb_sid_object ***sids)
655 NTSTATUS status = composite_wait(c);
656 if (NT_STATUS_IS_OK(status)) {
657 struct lsa_lookupnames_state *state =
658 talloc_get_type(c->private_data,
659 struct lsa_lookupnames_state);
660 *sids = talloc_steal(mem_ctx, state->result);
666 NTSTATUS wb_lsa_lookupnames(TALLOC_CTX *mem_ctx,
667 struct dcerpc_pipe *lsa_pipe,
668 struct policy_handle *handle,
669 int num_names, const char **names,
670 struct wb_sid_object ***sids)
672 struct composite_context *c =
673 wb_lsa_lookupnames_send(mem_ctx, lsa_pipe, handle,
675 return wb_lsa_lookupnames_recv(c, mem_ctx, sids);
680 struct cmd_checkmachacc_state {
681 struct composite_context *ctx;
682 struct wbsrv_call *call;
683 struct wbsrv_domain *domain;
686 static void cmd_checkmachacc_recv_init(struct composite_context *ctx);
688 struct composite_context *wb_cmd_checkmachacc_send(struct wbsrv_call *call)
690 struct composite_context *result, *ctx;
691 struct cmd_checkmachacc_state *state;
692 struct wbsrv_service *service = call->wbconn->listen_socket->service;
694 result = talloc(call, struct composite_context);
695 if (result == NULL) goto failed;
696 result->state = COMPOSITE_STATE_IN_PROGRESS;
697 result->async.fn = NULL;
698 result->event_ctx = call->event_ctx;
700 state = talloc(result, struct cmd_checkmachacc_state);
701 if (state == NULL) goto failed;
703 result->private_data = state;
706 state->domain = service->domains;
708 ctx = wb_init_domain_send(service, state->domain);
709 if (ctx == NULL) goto failed;
710 ctx->async.fn = cmd_checkmachacc_recv_init;
711 ctx->async.private_data = state;
720 static void cmd_checkmachacc_recv_init(struct composite_context *ctx)
722 struct cmd_checkmachacc_state *state =
723 talloc_get_type(ctx->async.private_data,
724 struct cmd_checkmachacc_state);
726 state->ctx->status = wb_init_domain_recv(ctx);
727 if (!composite_is_ok(state->ctx)) return;
729 composite_done(state->ctx);
732 NTSTATUS wb_cmd_checkmachacc_recv(struct composite_context *c)
734 NTSTATUS status = composite_wait(c);
739 NTSTATUS wb_cmd_checkmachacc(struct wbsrv_call *call)
741 struct composite_context *c = wb_cmd_checkmachacc_send(call);
742 return wb_cmd_checkmachacc_recv(c);
746 struct samr_getuserdomgroups_state {
747 struct composite_context *ctx;
748 struct dcerpc_pipe *samr_pipe;
753 struct policy_handle *user_handle;
754 struct samr_OpenUser o;
755 struct samr_GetGroupsForUser g;
759 static void samr_usergroups_recv_open(struct rpc_request *req);
760 static void samr_usergroups_recv_groups(struct rpc_request *req);
761 static void samr_usergroups_recv_close(struct rpc_request *req);
763 struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
764 struct dcerpc_pipe *samr_pipe,
765 struct policy_handle *domain_handle,
768 struct composite_context *result;
769 struct rpc_request *req;
770 struct samr_getuserdomgroups_state *state;
772 result = talloc(mem_ctx, struct composite_context);
773 if (result == NULL) goto failed;
774 result->state = COMPOSITE_STATE_IN_PROGRESS;
775 result->async.fn = NULL;
776 result->event_ctx = samr_pipe->conn->event_ctx;
778 state = talloc(result, struct samr_getuserdomgroups_state);
779 if (state == NULL) goto failed;
780 result->private_data = state;
783 state->samr_pipe = samr_pipe;
785 state->user_handle = talloc(state, struct policy_handle);
786 if (state->user_handle == NULL) goto failed;
788 state->o.in.domain_handle = domain_handle;
789 state->o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
790 state->o.in.rid = rid;
791 state->o.out.user_handle = state->user_handle;
793 req = dcerpc_samr_OpenUser_send(state->samr_pipe, state, &state->o);
794 if (req == NULL) goto failed;
796 req->async.callback = samr_usergroups_recv_open;
797 req->async.private = state;
805 static void samr_usergroups_recv_open(struct rpc_request *req)
807 struct samr_getuserdomgroups_state *state =
808 talloc_get_type(req->async.private,
809 struct samr_getuserdomgroups_state);
811 state->ctx->status = dcerpc_ndr_request_recv(req);
812 if (!composite_is_ok(state->ctx)) return;
813 state->ctx->status = state->o.out.result;
814 if (!composite_is_ok(state->ctx)) return;
816 state->g.in.user_handle = state->user_handle;
818 req = dcerpc_samr_GetGroupsForUser_send(state->samr_pipe, state,
820 composite_continue_rpc(state->ctx, req, samr_usergroups_recv_groups,
824 static void samr_usergroups_recv_groups(struct rpc_request *req)
826 struct samr_getuserdomgroups_state *state =
827 talloc_get_type(req->async.private,
828 struct samr_getuserdomgroups_state);
830 state->ctx->status = dcerpc_ndr_request_recv(req);
831 if (!composite_is_ok(state->ctx)) return;
832 state->ctx->status = state->g.out.result;
833 if (!composite_is_ok(state->ctx)) return;
835 state->c.in.handle = state->user_handle;
836 state->c.out.handle = state->user_handle;
838 req = dcerpc_samr_Close_send(state->samr_pipe, state, &state->c);
839 composite_continue_rpc(state->ctx, req, samr_usergroups_recv_close,
843 static void samr_usergroups_recv_close(struct rpc_request *req)
845 struct samr_getuserdomgroups_state *state =
846 talloc_get_type(req->async.private,
847 struct samr_getuserdomgroups_state);
849 state->ctx->status = dcerpc_ndr_request_recv(req);
850 if (!composite_is_ok(state->ctx)) return;
851 state->ctx->status = state->c.out.result;
852 if (!composite_is_ok(state->ctx)) return;
854 composite_done(state->ctx);
857 NTSTATUS wb_samr_userdomgroups_recv(struct composite_context *ctx,
859 int *num_rids, uint32_t **rids)
861 struct samr_getuserdomgroups_state *state =
862 talloc_get_type(ctx->private_data,
863 struct samr_getuserdomgroups_state);
866 NTSTATUS status = composite_wait(ctx);
867 if (!NT_STATUS_IS_OK(status)) goto done;
869 *num_rids = state->g.out.rids->count;
870 *rids = talloc_array(mem_ctx, uint32_t, *num_rids);
872 status = NT_STATUS_NO_MEMORY;
876 for (i=0; i<*num_rids; i++) {
877 (*rids)[i] = state->g.out.rids->rids[i].rid;