s3-printing: use spoolss types and structs while getting and deleting drivers.
[Samba/fernandojvsilva.git] / source3 / winbindd / wb_next_pwent.c
blob25ab7b38d3a27200e205e8bbe82f1ade1062a634
1 /*
2 Unix SMB/CIFS implementation.
3 async next_pwent
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_next_pwent_state {
25 struct tevent_context *ev;
26 struct getpwent_state *gstate;
27 struct winbindd_pw *pw;
30 static void wb_next_pwent_fetch_done(struct tevent_req *subreq);
31 static void wb_next_pwent_fill_done(struct tevent_req *subreq);
33 struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx,
34 struct tevent_context *ev,
35 struct getpwent_state *gstate,
36 struct winbindd_pw *pw)
38 struct tevent_req *req, *subreq;
39 struct wb_next_pwent_state *state;
41 req = tevent_req_create(mem_ctx, &state, struct wb_next_pwent_state);
42 if (req == NULL) {
43 return NULL;
45 state->ev = ev;
46 state->gstate = gstate;
47 state->pw = pw;
49 if (state->gstate->next_user >= state->gstate->num_users) {
50 TALLOC_FREE(state->gstate->users);
52 if (state->gstate->domain == NULL) {
53 state->gstate->domain = domain_list();
54 } else {
55 state->gstate->domain = state->gstate->domain->next;
58 if (state->gstate->domain == NULL) {
59 tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
60 return tevent_req_post(req, ev);
62 subreq = wb_query_user_list_send(state, state->ev,
63 state->gstate->domain);
64 if (tevent_req_nomem(subreq, req)) {
65 return tevent_req_post(req, ev);
67 tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
68 return req;
71 subreq = wb_fill_pwent_send(
72 state, state->ev,
73 &state->gstate->users[state->gstate->next_user],
74 state->pw);
75 if (tevent_req_nomem(subreq, req)) {
76 return tevent_req_post(req, ev);
78 tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
79 return req;
82 static void wb_next_pwent_fetch_done(struct tevent_req *subreq)
84 struct tevent_req *req = tevent_req_callback_data(
85 subreq, struct tevent_req);
86 struct wb_next_pwent_state *state = tevent_req_data(
87 req, struct wb_next_pwent_state);
88 NTSTATUS status;
90 status = wb_query_user_list_recv(subreq, state->gstate,
91 &state->gstate->num_users,
92 &state->gstate->users);
93 TALLOC_FREE(subreq);
94 if (!NT_STATUS_IS_OK(status)) {
95 /* Ignore errors here, just log it */
96 DEBUG(10, ("query_user_list for domain %s returned %s\n",
97 state->gstate->domain->name,
98 nt_errstr(status)));
99 state->gstate->num_users = 0;
102 if (state->gstate->num_users == 0) {
103 state->gstate->domain = state->gstate->domain->next;
104 if (state->gstate->domain == NULL) {
105 tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
106 return;
108 subreq = wb_query_user_list_send(state, state->ev,
109 state->gstate->domain);
110 if (tevent_req_nomem(subreq, req)) {
111 return;
113 tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
114 return;
117 state->gstate->next_user = 0;
119 subreq = wb_fill_pwent_send(
120 state, state->ev,
121 &state->gstate->users[state->gstate->next_user],
122 state->pw);
123 if (tevent_req_nomem(subreq, req)) {
124 return;
126 tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
129 static void wb_next_pwent_fill_done(struct tevent_req *subreq)
131 struct tevent_req *req = tevent_req_callback_data(
132 subreq, struct tevent_req);
133 struct wb_next_pwent_state *state = tevent_req_data(
134 req, struct wb_next_pwent_state);
135 NTSTATUS status;
137 status = wb_fill_pwent_recv(subreq);
138 TALLOC_FREE(subreq);
139 if (!NT_STATUS_IS_OK(status)) {
140 tevent_req_nterror(req, status);
141 return;
143 state->gstate->next_user += 1;
144 tevent_req_done(req);
147 NTSTATUS wb_next_pwent_recv(struct tevent_req *req)
149 return tevent_req_simple_recv_ntstatus(req);