s4-winbind: Use winbindd in the AD DC for fl2003dc and plugin_s4_dc
[Samba/wip.git] / source4 / libnet / groupman.c
blobc91eff365cfb54cd65218b63de572ee774648d8d
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 a composite function for manipulating (add/edit/del) groups via samr pipe
24 #include "includes.h"
25 #include "libcli/composite/composite.h"
26 #include "libnet/libnet.h"
27 #include "librpc/gen_ndr/ndr_samr_c.h"
30 struct groupadd_state {
31 struct dcerpc_binding_handle *binding_handle;
32 struct policy_handle domain_handle;
33 struct samr_CreateDomainGroup creategroup;
34 struct policy_handle group_handle;
35 uint32_t group_rid;
37 void (*monitor_fn)(struct monitor_msg*);
41 static void continue_groupadd_created(struct tevent_req *subreq);
44 struct composite_context* libnet_rpc_groupadd_send(TALLOC_CTX *mem_ctx,
45 struct tevent_context *ev,
46 struct dcerpc_binding_handle *b,
47 struct libnet_rpc_groupadd *io,
48 void (*monitor)(struct monitor_msg*))
50 struct composite_context *c;
51 struct groupadd_state *s;
52 struct tevent_req *subreq;
54 if (!b || !io) return NULL;
56 c = composite_create(mem_ctx, ev);
57 if (c == NULL) return NULL;
59 s = talloc_zero(c, struct groupadd_state);
60 if (composite_nomem(s, c)) return c;
62 c->private_data = s;
64 s->domain_handle = io->in.domain_handle;
65 s->binding_handle= b;
66 s->monitor_fn = monitor;
68 s->creategroup.in.domain_handle = &s->domain_handle;
70 s->creategroup.in.name = talloc_zero(c, struct lsa_String);
71 if (composite_nomem(s->creategroup.in.name, c)) return c;
73 s->creategroup.in.name->string = talloc_strdup(c, io->in.groupname);
74 if (composite_nomem(s->creategroup.in.name->string, c)) return c;
76 s->creategroup.in.access_mask = 0;
78 s->creategroup.out.group_handle = &s->group_handle;
79 s->creategroup.out.rid = &s->group_rid;
81 subreq = dcerpc_samr_CreateDomainGroup_r_send(s, c->event_ctx,
82 s->binding_handle,
83 &s->creategroup);
84 if (composite_nomem(subreq, c)) return c;
86 tevent_req_set_callback(subreq, continue_groupadd_created, c);
87 return c;
91 NTSTATUS libnet_rpc_groupadd_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
92 struct libnet_rpc_groupadd *io)
94 NTSTATUS status;
95 struct groupadd_state *s;
97 status = composite_wait(c);
98 if (NT_STATUS_IS_OK(status) && io) {
99 s = talloc_get_type(c->private_data, struct groupadd_state);
100 io->out.group_handle = s->group_handle;
103 talloc_free(c);
104 return status;
108 static void continue_groupadd_created(struct tevent_req *subreq)
110 struct composite_context *c;
111 struct groupadd_state *s;
113 c = tevent_req_callback_data(subreq, struct composite_context);
114 s = talloc_get_type(c->private_data, struct groupadd_state);
116 c->status = dcerpc_samr_CreateDomainGroup_r_recv(subreq, s);
117 TALLOC_FREE(subreq);
118 if (!composite_is_ok(c)) return;
120 c->status = s->creategroup.out.result;
121 if (!NT_STATUS_IS_OK(c->status)) {
122 composite_error(c, c->status);
123 return;
126 composite_done(c);
130 NTSTATUS libnet_rpc_groupadd(struct tevent_context *ev,
131 struct dcerpc_binding_handle *b,
132 TALLOC_CTX *mem_ctx,
133 struct libnet_rpc_groupadd *io)
135 struct composite_context *c;
137 c = libnet_rpc_groupadd_send(mem_ctx, ev, b, io, NULL);
138 return libnet_rpc_groupadd_recv(c, mem_ctx, io);