Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : async next_grent
4 : Copyright (C) Volker Lendecke 2009
5 :
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.
10 :
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.
15 :
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/>.
18 : */
19 :
20 : #include "includes.h"
21 : #include "winbindd.h"
22 : #include "librpc/gen_ndr/ndr_winbind_c.h"
23 : #include "passdb/machine_sid.h"
24 :
25 : struct wb_next_grent_state {
26 : struct tevent_context *ev;
27 : int max_nesting;
28 : struct getgrent_state *gstate;
29 : struct winbindd_gr *gr;
30 : struct db_context *members;
31 : };
32 :
33 : static void wb_next_grent_fetch_done(struct tevent_req *subreq);
34 : static void wb_next_grent_getgrsid_done(struct tevent_req *subreq);
35 :
36 3130 : static void wb_next_grent_send_do(struct tevent_req *req,
37 : struct wb_next_grent_state *state)
38 : {
39 : struct tevent_req *subreq;
40 :
41 3130 : if (state->gstate->next_group >= state->gstate->num_groups) {
42 682 : TALLOC_FREE(state->gstate->groups);
43 :
44 682 : state->gstate->domain = wb_next_domain(state->gstate->domain);
45 682 : if (state->gstate->domain == NULL) {
46 136 : tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
47 136 : return;
48 : }
49 :
50 546 : subreq = wb_query_group_list_send(state, state->ev,
51 546 : state->gstate->domain);
52 546 : if (tevent_req_nomem(subreq, req)) {
53 0 : return;
54 : }
55 546 : tevent_req_set_callback(subreq, wb_next_grent_fetch_done, req);
56 546 : return;
57 : }
58 :
59 3672 : subreq = wb_getgrsid_send(
60 : state, state->ev,
61 2448 : &state->gstate->groups[state->gstate->next_group].sid,
62 : state->max_nesting);
63 2448 : if (tevent_req_nomem(subreq, req)) {
64 0 : return;
65 : }
66 2448 : tevent_req_set_callback(subreq, wb_next_grent_getgrsid_done, req);
67 : }
68 :
69 2586 : struct tevent_req *wb_next_grent_send(TALLOC_CTX *mem_ctx,
70 : struct tevent_context *ev,
71 : int max_nesting,
72 : struct getgrent_state *gstate,
73 : struct winbindd_gr *gr)
74 : {
75 : struct tevent_req *req;
76 : struct wb_next_grent_state *state;
77 :
78 2586 : req = tevent_req_create(mem_ctx, &state, struct wb_next_grent_state);
79 2586 : if (req == NULL) {
80 0 : return NULL;
81 : }
82 :
83 2586 : D_INFO("WB command next_grent start.\n");
84 :
85 2586 : state->ev = ev;
86 2586 : state->gstate = gstate;
87 2586 : state->gr = gr;
88 2586 : state->max_nesting = max_nesting;
89 :
90 2586 : wb_next_grent_send_do(req, state);
91 2586 : if (!tevent_req_is_in_progress(req)) {
92 0 : return tevent_req_post(req, ev);
93 : }
94 :
95 2586 : return req;
96 : }
97 :
98 544 : static void wb_next_grent_fetch_done(struct tevent_req *subreq)
99 : {
100 544 : struct tevent_req *req = tevent_req_callback_data(
101 : subreq, struct tevent_req);
102 544 : struct wb_next_grent_state *state = tevent_req_data(
103 : req, struct wb_next_grent_state);
104 : NTSTATUS status;
105 :
106 816 : status = wb_query_group_list_recv(subreq, state->gstate,
107 544 : &state->gstate->num_groups,
108 544 : &state->gstate->groups);
109 544 : TALLOC_FREE(subreq);
110 544 : if (!NT_STATUS_IS_OK(status)) {
111 : /* Ignore errors here, just log it */
112 0 : D_DEBUG("query_group_list for domain %s returned %s\n",
113 : state->gstate->domain->name, nt_errstr(status));
114 0 : state->gstate->num_groups = 0;
115 : }
116 :
117 544 : state->gstate->next_group = 0;
118 :
119 544 : wb_next_grent_send_do(req, state);
120 544 : }
121 :
122 2448 : static void wb_next_grent_getgrsid_done(struct tevent_req *subreq)
123 : {
124 2448 : struct tevent_req *req = tevent_req_callback_data(
125 : subreq, struct tevent_req);
126 2448 : struct wb_next_grent_state *state = tevent_req_data(
127 : req, struct wb_next_grent_state);
128 : const char *domname, *name;
129 : NTSTATUS status;
130 :
131 3672 : status = wb_getgrsid_recv(subreq, talloc_tos(), &domname, &name,
132 2448 : &state->gr->gr_gid, &state->members);
133 2448 : TALLOC_FREE(subreq);
134 :
135 2448 : if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
136 0 : state->gstate->next_group += 1;
137 :
138 0 : wb_next_grent_send_do(req, state);
139 :
140 0 : return;
141 2448 : } else if (tevent_req_nterror(req, status)) {
142 0 : return;
143 : }
144 :
145 2448 : if (!fill_grent(talloc_tos(), state->gr, domname, name,
146 2448 : state->gr->gr_gid)) {
147 0 : D_WARNING("fill_grent failed\n");
148 0 : tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
149 0 : return;
150 : }
151 2448 : state->gstate->next_group += 1;
152 2448 : tevent_req_done(req);
153 : }
154 :
155 2584 : NTSTATUS wb_next_grent_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
156 : struct db_context **members)
157 : {
158 2584 : struct wb_next_grent_state *state = tevent_req_data(
159 : req, struct wb_next_grent_state);
160 : NTSTATUS status;
161 :
162 2584 : D_INFO("WB command next_grent end.\n");
163 2584 : if (tevent_req_is_nterror(req, &status)) {
164 136 : D_WARNING("Failed with %s.\n", nt_errstr(status));
165 136 : return status;
166 : }
167 2448 : *members = talloc_move(mem_ctx, &state->members);
168 2448 : return NT_STATUS_OK;
169 : }
|