s3: Fix up various string "const" warnings
[Samba/ekacnet.git] / source3 / winbindd / wb_getgrsid.c
blob03d71e45b918fe2ca55330b468e924964bb4ca87
1 /*
2 Unix SMB/CIFS implementation.
3 async getgrsid
4 Copyright (C) Volker Lendecke 2009
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/>.
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "librpc/gen_ndr/cli_wbint.h"
24 struct wb_getgrsid_state {
25 struct tevent_context *ev;
26 struct dom_sid sid;
27 int max_nesting;
28 const char *domname;
29 const char *name;
30 enum lsa_SidType type;
31 gid_t gid;
32 struct talloc_dict *members;
35 static void wb_getgrsid_lookupsid_done(struct tevent_req *subreq);
36 static void wb_getgrsid_sid2gid_done(struct tevent_req *subreq);
37 static void wb_getgrsid_got_members(struct tevent_req *subreq);
39 struct tevent_req *wb_getgrsid_send(TALLOC_CTX *mem_ctx,
40 struct tevent_context *ev,
41 const struct dom_sid *group_sid,
42 int max_nesting)
44 struct tevent_req *req, *subreq;
45 struct wb_getgrsid_state *state;
47 req = tevent_req_create(mem_ctx, &state, struct wb_getgrsid_state);
48 if (req == NULL) {
49 return NULL;
51 sid_copy(&state->sid, group_sid);
52 state->ev = ev;
53 state->max_nesting = max_nesting;
55 subreq = wb_lookupsid_send(state, ev, &state->sid);
56 if (tevent_req_nomem(subreq, req)) {
57 return tevent_req_post(req, ev);
59 tevent_req_set_callback(subreq, wb_getgrsid_lookupsid_done, req);
60 return req;
63 static void wb_getgrsid_lookupsid_done(struct tevent_req *subreq)
65 struct tevent_req *req = tevent_req_callback_data(
66 subreq, struct tevent_req);
67 struct wb_getgrsid_state *state = tevent_req_data(
68 req, struct wb_getgrsid_state);
69 NTSTATUS status;
71 status = wb_lookupsid_recv(subreq, state, &state->type,
72 &state->domname, &state->name);
73 TALLOC_FREE(subreq);
74 if (!NT_STATUS_IS_OK(status)) {
75 tevent_req_nterror(req, status);
76 return;
79 switch (state->type) {
80 case SID_NAME_DOM_GRP:
81 case SID_NAME_ALIAS:
82 case SID_NAME_WKN_GRP:
83 break;
84 default:
85 tevent_req_nterror(req, NT_STATUS_NO_SUCH_GROUP);
86 return;
89 subreq = wb_sid2gid_send(state, state->ev, &state->sid);
90 if (tevent_req_nomem(subreq, req)) {
91 return;
93 tevent_req_set_callback(subreq, wb_getgrsid_sid2gid_done, req);
96 static void wb_getgrsid_sid2gid_done(struct tevent_req *subreq)
98 struct tevent_req *req = tevent_req_callback_data(
99 subreq, struct tevent_req);
100 struct wb_getgrsid_state *state = tevent_req_data(
101 req, struct wb_getgrsid_state);
102 NTSTATUS status;
104 status = wb_sid2gid_recv(subreq, &state->gid);
105 TALLOC_FREE(subreq);
106 if (!NT_STATUS_IS_OK(status)) {
107 tevent_req_nterror(req, status);
108 return;
110 subreq = wb_group_members_send(state, state->ev, &state->sid,
111 state->type, state->max_nesting);
112 if (tevent_req_nomem(subreq, req)) {
113 return;
115 tevent_req_set_callback(subreq, wb_getgrsid_got_members, req);
118 static void wb_getgrsid_got_members(struct tevent_req *subreq)
120 struct tevent_req *req = tevent_req_callback_data(
121 subreq, struct tevent_req);
122 struct wb_getgrsid_state *state = tevent_req_data(
123 req, struct wb_getgrsid_state);
124 NTSTATUS status;
126 status = wb_group_members_recv(subreq, state, &state->members);
127 TALLOC_FREE(subreq);
128 if (!NT_STATUS_IS_OK(status)) {
129 tevent_req_nterror(req, status);
130 return;
132 tevent_req_done(req);
135 NTSTATUS wb_getgrsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
136 const char **domname, const char **name, gid_t *gid,
137 struct talloc_dict **members)
139 struct wb_getgrsid_state *state = tevent_req_data(
140 req, struct wb_getgrsid_state);
141 NTSTATUS status;
143 if (tevent_req_is_nterror(req, &status)) {
144 return status;
146 *domname = talloc_move(mem_ctx, &state->domname);
147 *name = talloc_move(mem_ctx, &state->name);
148 *gid = state->gid;
149 *members = talloc_move(mem_ctx, &state->members);
150 return NT_STATUS_OK;