s3:winbind: add wb_query_group_list module - async query group list
authorMichael Adam <obnox@samba.org>
Fri, 23 Jan 2015 13:06:40 +0000 (14:06 +0100)
committerGünther Deschner <gd@samba.org>
Mon, 16 Mar 2015 19:26:51 +0000 (20:26 +0100)
Modeled after wb_query_user_list.c

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/winbindd/wb_query_group_list.c [new file with mode: 0644]
source3/winbindd/winbindd_proto.h
source3/wscript_build

diff --git a/source3/winbindd/wb_query_group_list.c b/source3/winbindd/wb_query_group_list.c
new file mode 100644 (file)
index 0000000..703d331
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+   Unix SMB/CIFS implementation.
+   async query_group_list
+   Copyright (C) Volker Lendecke 2009
+   Copyright (C) Michael Adam 2015
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+#include "librpc/gen_ndr/ndr_winbind_c.h"
+
+
+struct wb_query_group_list_state {
+       struct wbint_Principals groups;
+};
+
+static void wb_query_group_list_done(struct tevent_req *subreq);
+
+struct tevent_req *wb_query_group_list_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct winbindd_domain *domain)
+{
+       struct tevent_req *req, *subreq;
+       struct wb_query_group_list_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct wb_query_group_list_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       subreq = dcerpc_wbint_QueryGroupList_send(state, ev,
+                                                 dom_child_handle(domain),
+                                                 &state->groups);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       tevent_req_set_callback(subreq, wb_query_group_list_done, req);
+       return req;
+}
+
+static void wb_query_group_list_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct wb_query_group_list_state *state = tevent_req_data(
+               req, struct wb_query_group_list_state);
+       NTSTATUS status, result;
+
+       status = dcerpc_wbint_QueryGroupList_recv(subreq, state, &result);
+       TALLOC_FREE(subreq);
+       if (any_nt_status_not_ok(status, result, &status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+
+       DEBUG(10, ("dcerpc_wbint_QueryGroupList returned %d groups\n",
+                  state->groups.num_principals));
+
+       tevent_req_done(req);
+}
+
+NTSTATUS wb_query_group_list_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                 int *num_groups,
+                                 struct wbint_Principal **groups)
+{
+       struct wb_query_group_list_state *state = tevent_req_data(
+               req, struct wb_query_group_list_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+
+       *num_groups = state->groups.num_principals;
+       *groups = talloc_move(mem_ctx, &state->groups.principals);
+
+       return NT_STATUS_OK;
+}
index 37931467aa64d7050924bcd6d773d74bff1ec249..93654e13c1830614a8814c0d81b8d7bd64d46dec 100644 (file)
@@ -715,6 +715,14 @@ NTSTATUS wb_query_user_list_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                                 int *num_users,
                                 struct wbint_userinfo **users);
 
+struct tevent_req *wb_query_group_list_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct winbindd_domain *domain);
+NTSTATUS wb_query_group_list_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                 int *num_users,
+                                 struct wbint_Principal **groups);
+
+
 struct tevent_req *wb_fill_pwent_send(TALLOC_CTX *mem_ctx,
                                      struct tevent_context *ev,
                                      struct wbint_userinfo *info,
index dfcdc4a276e8f3f026c91196a82b9bda2c6ec3f8..767217d817a7acaa59c2df0efe089f9fb6ed2aa2 100755 (executable)
@@ -931,6 +931,7 @@ bld.SAMBA3_BINARY('winbindd/winbindd',
                  winbindd/wb_group_members.c
                  winbindd/wb_getgrsid.c
                  winbindd/wb_query_user_list.c
+                 winbindd/wb_query_group_list.c
                  winbindd/wb_fill_pwent.c
                  winbindd/wb_next_pwent.c
                  winbindd/wb_next_grent.c