2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_GETPWENT
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/>.
23 struct winbindd_getpwent_state {
24 struct tevent_context *ev;
25 struct winbindd_cli_state *cli;
28 struct winbindd_pw *users;
31 static void winbindd_getpwent_done(struct tevent_req *subreq);
33 struct tevent_req *winbindd_getpwent_send(TALLOC_CTX *mem_ctx,
34 struct tevent_context *ev,
35 struct winbindd_cli_state *cli,
36 struct winbindd_request *request)
38 struct tevent_req *req, *subreq;
39 struct winbindd_getpwent_state *state;
41 req = tevent_req_create(mem_ctx, &state,
42 struct winbindd_getpwent_state);
50 DEBUG(3, ("[%5lu]: getpwent\n", (unsigned long)cli->pid));
52 if (cli->pwent_state == NULL) {
53 tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
54 return tevent_req_post(req, ev);
57 state->max_users = MIN(500, request->data.num_entries);
58 if (state->max_users == 0) {
59 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
60 return tevent_req_post(req, ev);
63 state->users = talloc_zero_array(state, struct winbindd_pw,
65 if (tevent_req_nomem(state->users, req)) {
66 return tevent_req_post(req, ev);
69 subreq = wb_next_pwent_send(state, ev, cli->pwent_state,
70 &state->users[state->num_users]);
71 if (tevent_req_nomem(subreq, req)) {
72 return tevent_req_post(req, ev);
74 tevent_req_set_callback(subreq, winbindd_getpwent_done, req);
78 static void winbindd_getpwent_done(struct tevent_req *subreq)
80 struct tevent_req *req = tevent_req_callback_data(
81 subreq, struct tevent_req);
82 struct winbindd_getpwent_state *state = tevent_req_data(
83 req, struct winbindd_getpwent_state);
86 status = wb_next_pwent_recv(subreq);
88 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
89 DEBUG(10, ("winbindd_getpwent_done: done with %d users\n",
90 (int)state->num_users));
91 TALLOC_FREE(state->cli->pwent_state);
95 if (tevent_req_nterror(req, status)) {
98 state->num_users += 1;
99 if (state->num_users >= state->max_users) {
100 DEBUG(10, ("winbindd_getpwent_done: Got enough users: %d\n",
101 (int)state->num_users));
102 tevent_req_done(req);
105 if (state->cli->pwent_state == NULL) {
106 DEBUG(10, ("winbindd_getpwent_done: endpwent called in "
108 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
111 subreq = wb_next_pwent_send(state, state->ev, state->cli->pwent_state,
112 &state->users[state->num_users]);
113 if (tevent_req_nomem(subreq, req)) {
116 tevent_req_set_callback(subreq, winbindd_getpwent_done, req);
119 NTSTATUS winbindd_getpwent_recv(struct tevent_req *req,
120 struct winbindd_response *response)
122 struct winbindd_getpwent_state *state = tevent_req_data(
123 req, struct winbindd_getpwent_state);
126 if (tevent_req_is_nterror(req, &status)) {
127 TALLOC_FREE(state->cli->pwent_state);
128 DEBUG(5, ("getpwent failed: %s\n", nt_errstr(status)));
132 if (state->num_users == 0) {
133 return NT_STATUS_NO_MORE_ENTRIES;
136 response->data.num_entries = state->num_users;
137 response->extra_data.data = talloc_move(response, &state->users);
138 response->length += state->num_users * sizeof(struct winbindd_pw);