messaging4: Add "goto fail" to imessaging_init
[Samba.git] / source4 / libnet / libnet_group.c
blob512d6fbf9f9028edea068fc6fd20b51d40a46f3e
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Rafal Szczesniak 2007
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "libnet/libnet.h"
23 #include "libcli/composite/composite.h"
24 #include "librpc/gen_ndr/lsa.h"
25 #include "librpc/gen_ndr/ndr_lsa_c.h"
26 #include "librpc/gen_ndr/samr.h"
27 #include "librpc/gen_ndr/ndr_samr_c.h"
28 #include "libcli/security/security.h"
31 struct create_group_state {
32 struct libnet_context *ctx;
33 struct libnet_CreateGroup r;
34 struct libnet_DomainOpen domain_open;
35 struct libnet_rpc_groupadd group_add;
37 /* information about the progress */
38 void (*monitor_fn)(struct monitor_msg *);
42 static void continue_domain_opened(struct composite_context *ctx);
43 static void continue_rpc_group_added(struct composite_context *ctx);
46 struct composite_context* libnet_CreateGroup_send(struct libnet_context *ctx,
47 TALLOC_CTX *mem_ctx,
48 struct libnet_CreateGroup *r,
49 void (*monitor)(struct monitor_msg*))
51 struct composite_context *c;
52 struct create_group_state *s;
53 struct composite_context *create_req;
54 bool prereq_met = false;
56 /* composite context allocation and setup */
57 c = composite_create(mem_ctx, ctx->event_ctx);
58 if (c == NULL) return NULL;
60 s = talloc_zero(c, struct create_group_state);
61 if (composite_nomem(s, c)) return c;
63 c->private_data = s;
65 s->ctx = ctx;
66 s->r = *r;
67 ZERO_STRUCT(s->r.out);
69 /* prerequisite: make sure we have a valid samr domain handle */
70 prereq_met = samr_domain_opened(ctx, c, s->r.in.domain_name, &c, &s->domain_open,
71 continue_domain_opened, monitor);
72 if (!prereq_met) return c;
74 /* prepare arguments of rpc group add call */
75 s->group_add.in.groupname = r->in.group_name;
76 s->group_add.in.domain_handle = ctx->samr.handle;
78 /* send the request */
79 create_req = libnet_rpc_groupadd_send(s, s->ctx->event_ctx,
80 ctx->samr.samr_handle,
81 &s->group_add, monitor);
82 if (composite_nomem(create_req, c)) return c;
84 composite_continue(c, create_req, continue_rpc_group_added, c);
85 return c;
89 static void continue_domain_opened(struct composite_context *ctx)
91 struct composite_context *c;
92 struct create_group_state *s;
93 struct composite_context *create_req;
95 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
96 s = talloc_get_type_abort(c->private_data, struct create_group_state);
98 c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open);
99 if (!composite_is_ok(c)) return;
101 /* prepare arguments of groupadd call */
102 s->group_add.in.groupname = s->r.in.group_name;
103 s->group_add.in.domain_handle = s->ctx->samr.handle;
105 /* send the request */
106 create_req = libnet_rpc_groupadd_send(s, s->ctx->event_ctx,
107 s->ctx->samr.samr_handle,
108 &s->group_add, s->monitor_fn);
109 if (composite_nomem(create_req, c)) return;
111 composite_continue(c, create_req, continue_rpc_group_added, c);
115 static void continue_rpc_group_added(struct composite_context *ctx)
117 struct composite_context *c;
118 struct create_group_state *s;
120 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
121 s = talloc_get_type_abort(c->private_data, struct create_group_state);
123 /* receive result of group add call */
124 c->status = libnet_rpc_groupadd_recv(ctx, c, &s->group_add);
125 if (!composite_is_ok(c)) return;
127 /* we're done */
128 composite_done(c);
133 * Receive result of CreateGroup call
135 * @param c composite context returned by send request routine
136 * @param mem_ctx memory context of this call
137 * @param r pointer to a structure containing arguments and result of this call
138 * @return nt status
140 NTSTATUS libnet_CreateGroup_recv(struct composite_context *c,
141 TALLOC_CTX *mem_ctx,
142 struct libnet_CreateGroup *r)
144 NTSTATUS status;
146 status = composite_wait(c);
147 if (!NT_STATUS_IS_OK(status)) {
148 r->out.error_string = talloc_strdup(mem_ctx, nt_errstr(status));
151 talloc_free(c);
152 return status;
157 * Create domain group
159 * @param ctx initialised libnet context
160 * @param mem_ctx memory context of this call
161 * @param io pointer to structure containing arguments and result of this call
162 * @return nt status
164 NTSTATUS libnet_CreateGroup(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
165 struct libnet_CreateGroup *io)
167 struct composite_context *c;
169 c = libnet_CreateGroup_send(ctx, mem_ctx, io, NULL);
170 return libnet_CreateGroup_recv(c, mem_ctx, io);
174 struct group_info_state {
175 struct libnet_context *ctx;
176 const char *domain_name;
177 enum libnet_GroupInfo_level level;
178 const char *group_name;
179 const char *sid_string;
180 struct libnet_LookupName lookup;
181 struct libnet_DomainOpen domopen;
182 struct libnet_rpc_groupinfo info;
184 /* information about the progress */
185 void (*monitor_fn)(struct monitor_msg *);
189 static void continue_domain_open_info(struct composite_context *ctx);
190 static void continue_name_found(struct composite_context *ctx);
191 static void continue_group_info(struct composite_context *ctx);
194 * Sends request to get group information
196 * @param ctx initialised libnet context
197 * @param mem_ctx memory context of this call
198 * @param io pointer to structure containing arguments the call
199 * @param monitor function pointer for receiving monitor messages
200 * @return composite context of this request
202 struct composite_context* libnet_GroupInfo_send(struct libnet_context *ctx,
203 TALLOC_CTX *mem_ctx,
204 struct libnet_GroupInfo *io,
205 void (*monitor)(struct monitor_msg*))
207 struct composite_context *c;
208 struct group_info_state *s;
209 bool prereq_met = false;
210 struct composite_context *lookup_req, *info_req;
212 /* composite context allocation and setup */
213 c = composite_create(mem_ctx, ctx->event_ctx);
214 if (c == NULL) return NULL;
216 s = talloc_zero(c, struct group_info_state);
217 if (composite_nomem(s, c)) return c;
219 c->private_data = s;
221 /* store arguments in the state structure */
222 s->monitor_fn = monitor;
223 s->ctx = ctx;
224 s->domain_name = talloc_strdup(c, io->in.domain_name);
225 s->level = io->in.level;
226 switch(s->level) {
227 case GROUP_INFO_BY_NAME:
228 s->group_name = talloc_strdup(c, io->in.data.group_name);
229 s->sid_string = NULL;
230 break;
231 case GROUP_INFO_BY_SID:
232 s->group_name = NULL;
233 s->sid_string = dom_sid_string(c, io->in.data.group_sid);
234 break;
237 /* prerequisite: make sure the domain is opened */
238 prereq_met = samr_domain_opened(ctx, c, s->domain_name, &c, &s->domopen,
239 continue_domain_open_info, monitor);
240 if (!prereq_met) return c;
242 switch(s->level) {
243 case GROUP_INFO_BY_NAME:
244 /* prepare arguments for LookupName call */
245 s->lookup.in.name = s->group_name;
246 s->lookup.in.domain_name = s->domain_name;
248 /* send the request */
249 lookup_req = libnet_LookupName_send(s->ctx, c, &s->lookup, s->monitor_fn);
250 if (composite_nomem(lookup_req, c)) return c;
252 /* set the next stage */
253 composite_continue(c, lookup_req, continue_name_found, c);
254 break;
255 case GROUP_INFO_BY_SID:
256 /* prepare arguments for groupinfo call */
257 s->info.in.domain_handle = s->ctx->samr.handle;
258 s->info.in.sid = s->sid_string;
259 /* we're looking for all information available */
260 s->info.in.level = GROUPINFOALL;
262 /* send the request */
263 info_req = libnet_rpc_groupinfo_send(s, s->ctx->event_ctx,
264 s->ctx->samr.samr_handle,
265 &s->info, s->monitor_fn);
266 if (composite_nomem(info_req, c)) return c;
268 /* set the next stage */
269 composite_continue(c, info_req, continue_group_info, c);
270 break;
273 return c;
278 * Stage 0.5 (optional): receive opened domain and send lookup name request
280 static void continue_domain_open_info(struct composite_context *ctx)
282 struct composite_context *c;
283 struct group_info_state *s;
284 struct composite_context *lookup_req, *info_req;
286 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
287 s = talloc_get_type_abort(c->private_data, struct group_info_state);
289 /* receive domain handle */
290 c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domopen);
291 if (!composite_is_ok(c)) return;
293 switch(s->level) {
294 case GROUP_INFO_BY_NAME:
295 /* prepare arguments for LookupName call */
296 s->lookup.in.name = s->group_name;
297 s->lookup.in.domain_name = s->domain_name;
299 /* send the request */
300 lookup_req = libnet_LookupName_send(s->ctx, c, &s->lookup, s->monitor_fn);
301 if (composite_nomem(lookup_req, c)) return;
303 /* set the next stage */
304 composite_continue(c, lookup_req, continue_name_found, c);
305 break;
306 case GROUP_INFO_BY_SID:
307 /* prepare arguments for groupinfo call */
308 s->info.in.domain_handle = s->ctx->samr.handle;
309 s->info.in.sid = s->sid_string;
310 /* we're looking for all information available */
311 s->info.in.level = GROUPINFOALL;
313 /* send the request */
314 info_req = libnet_rpc_groupinfo_send(s, s->ctx->event_ctx,
315 s->ctx->samr.samr_handle,
316 &s->info, s->monitor_fn);
317 if (composite_nomem(info_req, c)) return;
319 /* set the next stage */
320 composite_continue(c, info_req, continue_group_info, c);
321 break;
328 * Stage 1: Receive SID found and send request for group info
330 static void continue_name_found(struct composite_context *ctx)
332 struct composite_context *c;
333 struct group_info_state *s;
334 struct composite_context *info_req;
336 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
337 s = talloc_get_type_abort(c->private_data, struct group_info_state);
339 /* receive SID assiociated with name found */
340 c->status = libnet_LookupName_recv(ctx, c, &s->lookup);
341 if (!composite_is_ok(c)) return;
343 /* Is is a group SID actually ? */
344 if (s->lookup.out.sid_type != SID_NAME_DOM_GRP &&
345 s->lookup.out.sid_type != SID_NAME_ALIAS) {
346 composite_error(c, NT_STATUS_NO_SUCH_GROUP);
347 return;
350 /* prepare arguments for groupinfo call */
351 s->info.in.domain_handle = s->ctx->samr.handle;
352 s->info.in.groupname = s->group_name;
353 s->info.in.sid = s->lookup.out.sidstr;
354 /* we're looking for all information available */
355 s->info.in.level = GROUPINFOALL;
357 /* send the request */
358 info_req = libnet_rpc_groupinfo_send(s, s->ctx->event_ctx,
359 s->ctx->samr.samr_handle,
360 &s->info, s->monitor_fn);
361 if (composite_nomem(info_req, c)) return;
363 /* set the next stage */
364 composite_continue(c, info_req, continue_group_info, c);
369 * Stage 2: Receive group information
371 static void continue_group_info(struct composite_context *ctx)
373 struct composite_context *c;
374 struct group_info_state *s;
376 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
377 s = talloc_get_type_abort(c->private_data, struct group_info_state);
379 /* receive group information */
380 c->status = libnet_rpc_groupinfo_recv(ctx, c, &s->info);
381 if (!composite_is_ok(c)) return;
383 /* we're done */
384 composite_done(c);
389 * Receive group information
391 * @param c composite context returned by libnet_GroupInfo_send
392 * @param mem_ctx memory context of this call
393 * @param io pointer to structure receiving results of the call
394 * @result nt status
396 NTSTATUS libnet_GroupInfo_recv(struct composite_context* c, TALLOC_CTX *mem_ctx,
397 struct libnet_GroupInfo *io)
399 NTSTATUS status;
400 struct group_info_state *s;
402 status = composite_wait(c);
403 if (NT_STATUS_IS_OK(status)) {
404 /* put the results into io structure if everything went fine */
405 s = talloc_get_type_abort(c->private_data, struct group_info_state);
407 io->out.group_name = talloc_steal(mem_ctx,
408 s->info.out.info.all.name.string);
409 io->out.group_sid = talloc_steal(mem_ctx, s->lookup.out.sid);
410 io->out.num_members = s->info.out.info.all.num_members;
411 io->out.description = talloc_steal(mem_ctx, s->info.out.info.all.description.string);
413 io->out.error_string = talloc_strdup(mem_ctx, "Success");
415 } else {
416 io->out.error_string = talloc_asprintf(mem_ctx, "Error: %s", nt_errstr(status));
419 talloc_free(c);
420 return status;
425 * Obtains specified group information
427 * @param ctx initialised libnet context
428 * @param mem_ctx memory context of the call
429 * @param io pointer to a structure containing arguments and results of the call
431 NTSTATUS libnet_GroupInfo(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
432 struct libnet_GroupInfo *io)
434 struct composite_context *c = libnet_GroupInfo_send(ctx, mem_ctx,
435 io, NULL);
436 return libnet_GroupInfo_recv(c, mem_ctx, io);
440 struct grouplist_state {
441 struct libnet_context *ctx;
442 const char *domain_name;
443 struct lsa_DomainInfo dominfo;
444 int page_size;
445 uint32_t resume_index;
446 struct grouplist *groups;
447 uint32_t count;
449 struct libnet_DomainOpen domain_open;
450 struct lsa_QueryInfoPolicy query_domain;
451 struct samr_EnumDomainGroups group_list;
453 void (*monitor_fn)(struct monitor_msg*);
457 static void continue_lsa_domain_opened(struct composite_context *ctx);
458 static void continue_domain_queried(struct tevent_req *subreq);
459 static void continue_samr_domain_opened(struct composite_context *ctx);
460 static void continue_groups_enumerated(struct tevent_req *subreq);
464 * Sends request to list (enumerate) group accounts
466 * @param ctx initialised libnet context
467 * @param mem_ctx memory context of this call
468 * @param io pointer to structure containing arguments and results of this call
469 * @param monitor function pointer for receiving monitor messages
470 * @return compostite context of this request
472 struct composite_context *libnet_GroupList_send(struct libnet_context *ctx,
473 TALLOC_CTX *mem_ctx,
474 struct libnet_GroupList *io,
475 void (*monitor)(struct monitor_msg*))
477 struct composite_context *c;
478 struct grouplist_state *s;
479 struct tevent_req *subreq;
480 bool prereq_met = false;
482 /* composite context allocation and setup */
483 c = composite_create(mem_ctx, ctx->event_ctx);
484 if (c == NULL) return NULL;
486 s = talloc_zero(c, struct grouplist_state);
487 if (composite_nomem(s, c)) return c;
489 c->private_data = s;
491 /* store the arguments in the state structure */
492 s->ctx = ctx;
493 s->page_size = io->in.page_size;
494 s->resume_index = io->in.resume_index;
495 s->domain_name = talloc_strdup(c, io->in.domain_name);
496 s->monitor_fn = monitor;
498 /* make sure we have lsa domain handle before doing anything */
499 prereq_met = lsa_domain_opened(ctx, c, s->domain_name, &c, &s->domain_open,
500 continue_lsa_domain_opened, monitor);
501 if (!prereq_met) return c;
503 /* prepare arguments of QueryDomainInfo call */
504 s->query_domain.in.handle = &ctx->lsa.handle;
505 s->query_domain.in.level = LSA_POLICY_INFO_DOMAIN;
506 s->query_domain.out.info = talloc_zero(c, union lsa_PolicyInformation *);
507 if (composite_nomem(s->query_domain.out.info, c)) return c;
509 /* send the request */
510 subreq = dcerpc_lsa_QueryInfoPolicy_r_send(s, c->event_ctx,
511 ctx->lsa.pipe->binding_handle,
512 &s->query_domain);
513 if (composite_nomem(subreq, c)) return c;
515 tevent_req_set_callback(subreq, continue_domain_queried, c);
516 return c;
521 * Stage 0.5 (optional): receive lsa domain handle and send
522 * request to query domain info
524 static void continue_lsa_domain_opened(struct composite_context *ctx)
526 struct composite_context *c;
527 struct grouplist_state *s;
528 struct tevent_req *subreq;
530 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
531 s = talloc_get_type_abort(c->private_data, struct grouplist_state);
533 /* receive lsa domain handle */
534 c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open);
535 if (!composite_is_ok(c)) return;
537 /* prepare arguments of QueryDomainInfo call */
538 s->query_domain.in.handle = &s->ctx->lsa.handle;
539 s->query_domain.in.level = LSA_POLICY_INFO_DOMAIN;
540 s->query_domain.out.info = talloc_zero(c, union lsa_PolicyInformation *);
541 if (composite_nomem(s->query_domain.out.info, c)) return;
543 /* send the request */
544 subreq = dcerpc_lsa_QueryInfoPolicy_r_send(s, c->event_ctx,
545 s->ctx->lsa.pipe->binding_handle,
546 &s->query_domain);
547 if (composite_nomem(subreq, c)) return;
549 tevent_req_set_callback(subreq, continue_domain_queried, c);
554 * Stage 1: receive domain info and request to enum groups
555 * provided a valid samr handle is opened
557 static void continue_domain_queried(struct tevent_req *subreq)
559 struct composite_context *c;
560 struct grouplist_state *s;
561 bool prereq_met = false;
563 c = tevent_req_callback_data(subreq, struct composite_context);
564 s = talloc_get_type_abort(c->private_data, struct grouplist_state);
566 /* receive result of rpc request */
567 c->status = dcerpc_lsa_QueryInfoPolicy_r_recv(subreq, s);
568 TALLOC_FREE(subreq);
569 if (!composite_is_ok(c)) return;
571 /* get the returned domain info */
572 s->dominfo = (*s->query_domain.out.info)->domain;
574 /* make sure we have samr domain handle before continuing */
575 prereq_met = samr_domain_opened(s->ctx, c, s->domain_name, &c, &s->domain_open,
576 continue_samr_domain_opened, s->monitor_fn);
577 if (!prereq_met) return;
579 /* prepare arguments od EnumDomainGroups call */
580 s->group_list.in.domain_handle = &s->ctx->samr.handle;
581 s->group_list.in.max_size = s->page_size;
582 s->group_list.in.resume_handle = &s->resume_index;
583 s->group_list.out.resume_handle = &s->resume_index;
584 s->group_list.out.num_entries = talloc(s, uint32_t);
585 if (composite_nomem(s->group_list.out.num_entries, c)) return;
586 s->group_list.out.sam = talloc(s, struct samr_SamArray *);
587 if (composite_nomem(s->group_list.out.sam, c)) return;
589 /* send the request */
590 subreq = dcerpc_samr_EnumDomainGroups_r_send(s, c->event_ctx,
591 s->ctx->samr.pipe->binding_handle,
592 &s->group_list);
593 if (composite_nomem(subreq, c)) return;
595 tevent_req_set_callback(subreq, continue_groups_enumerated, c);
600 * Stage 1.5 (optional): receive samr domain handle
601 * and request to enumerate accounts
603 static void continue_samr_domain_opened(struct composite_context *ctx)
605 struct composite_context *c;
606 struct grouplist_state *s;
607 struct tevent_req *subreq;
609 c = talloc_get_type_abort(ctx->async.private_data, struct composite_context);
610 s = talloc_get_type_abort(c->private_data, struct grouplist_state);
612 /* receive samr domain handle */
613 c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open);
614 if (!composite_is_ok(c)) return;
616 /* prepare arguments of EnumDomainGroups call */
617 s->group_list.in.domain_handle = &s->ctx->samr.handle;
618 s->group_list.in.max_size = s->page_size;
619 s->group_list.in.resume_handle = &s->resume_index;
620 s->group_list.out.resume_handle = &s->resume_index;
621 s->group_list.out.num_entries = talloc(s, uint32_t);
622 if (composite_nomem(s->group_list.out.num_entries, c)) return;
623 s->group_list.out.sam = talloc(s, struct samr_SamArray *);
624 if (composite_nomem(s->group_list.out.sam, c)) return;
626 /* send the request */
627 subreq = dcerpc_samr_EnumDomainGroups_r_send(s, c->event_ctx,
628 s->ctx->samr.pipe->binding_handle,
629 &s->group_list);
630 if (composite_nomem(subreq, c)) return;
632 tevent_req_set_callback(subreq, continue_groups_enumerated, c);
637 * Stage 2: receive enumerated groups and their rids
639 static void continue_groups_enumerated(struct tevent_req *subreq)
641 struct composite_context *c;
642 struct grouplist_state *s;
643 uint32_t i;
645 c = tevent_req_callback_data(subreq, struct composite_context);
646 s = talloc_get_type_abort(c->private_data, struct grouplist_state);
648 /* receive result of rpc request */
649 c->status = dcerpc_samr_EnumDomainGroups_r_recv(subreq, s);
650 TALLOC_FREE(subreq);
651 if (!composite_is_ok(c)) return;
653 /* get the actual status of the rpc call result
654 (instead of rpc layer) */
655 c->status = s->group_list.out.result;
657 /* we're interested in status "ok" as well as two
658 enum-specific status codes */
659 if (NT_STATUS_IS_OK(c->status) ||
660 NT_STATUS_EQUAL(c->status, STATUS_MORE_ENTRIES) ||
661 NT_STATUS_EQUAL(c->status, NT_STATUS_NO_MORE_ENTRIES)) {
663 /* get enumerated accounts counter and resume handle (the latter allows
664 making subsequent call to continue enumeration) */
665 s->resume_index = *s->group_list.out.resume_handle;
666 s->count = *s->group_list.out.num_entries;
668 /* prepare returned group accounts array */
669 s->groups = talloc_array(c, struct grouplist, (*s->group_list.out.sam)->count);
670 if (composite_nomem(s->groups, c)) return;
672 for (i = 0; i < (*s->group_list.out.sam)->count; i++) {
673 struct dom_sid *group_sid;
674 struct samr_SamEntry *entry = &(*s->group_list.out.sam)->entries[i];
675 struct dom_sid *domain_sid = (*s->query_domain.out.info)->domain.sid;
677 /* construct group sid from returned rid and queried domain sid */
678 group_sid = dom_sid_add_rid(c, domain_sid, entry->idx);
679 if (composite_nomem(group_sid, c)) return;
681 /* groupname */
682 s->groups[i].groupname = talloc_strdup(s->groups, entry->name.string);
683 if (composite_nomem(s->groups[i].groupname, c)) return;
685 /* sid string */
686 s->groups[i].sid = dom_sid_string(s->groups, group_sid);
687 if (composite_nomem(s->groups[i].sid, c)) return;
690 /* that's it */
691 composite_done(c);
692 return;
693 } else {
694 /* something went wrong */
695 composite_error(c, c->status);
696 return;
702 * Receive result of GroupList call
704 * @param c composite context returned by send request routine
705 * @param mem_ctx memory context of this call
706 * @param io pointer to structure containing arguments and result of this call
707 * @param nt status
709 NTSTATUS libnet_GroupList_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
710 struct libnet_GroupList *io)
712 NTSTATUS status;
713 struct grouplist_state *s;
715 if (c == NULL || mem_ctx == NULL || io == NULL) {
716 talloc_free(c);
717 return NT_STATUS_INVALID_PARAMETER;
720 status = composite_wait(c);
721 if (NT_STATUS_IS_OK(status) ||
722 NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES) ||
723 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
725 s = talloc_get_type_abort(c->private_data, struct grouplist_state);
727 /* get results from composite context */
728 io->out.count = s->count;
729 io->out.resume_index = s->resume_index;
730 io->out.groups = talloc_steal(mem_ctx, s->groups);
732 if (NT_STATUS_IS_OK(status)) {
733 io->out.error_string = talloc_asprintf(mem_ctx, "Success");
734 } else {
735 /* success, but we're not done yet */
736 io->out.error_string = talloc_asprintf(mem_ctx, "Success (status: %s)",
737 nt_errstr(status));
740 } else {
741 io->out.error_string = talloc_asprintf(mem_ctx, "Error: %s", nt_errstr(status));
744 talloc_free(c);
745 return status;
750 * Enumerate domain groups
752 * @param ctx initialised libnet context
753 * @param mem_ctx memory context of this call
754 * @param io pointer to structure containing arguments and result of this call
755 * @return nt status
757 NTSTATUS libnet_GroupList(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
758 struct libnet_GroupList *io)
760 struct composite_context *c;
762 c = libnet_GroupList_send(ctx, mem_ctx, io, NULL);
763 return libnet_GroupList_recv(c, mem_ctx, io);