2 Unix SMB/CIFS implementation.
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/>.
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
);
46 state
->gstate
= gstate
;
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();
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
);
71 subreq
= wb_fill_pwent_send(
73 &state
->gstate
->users
[state
->gstate
->next_user
],
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
);
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
);
90 status
= wb_query_user_list_recv(subreq
, state
->gstate
,
91 &state
->gstate
->num_users
,
92 &state
->gstate
->users
);
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
,
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
);
108 subreq
= wb_query_user_list_send(state
, state
->ev
,
109 state
->gstate
->domain
);
110 if (tevent_req_nomem(subreq
, req
)) {
113 tevent_req_set_callback(subreq
, wb_next_pwent_fetch_done
, req
);
117 state
->gstate
->next_user
= 0;
119 subreq
= wb_fill_pwent_send(
121 &state
->gstate
->users
[state
->gstate
->next_user
],
123 if (tevent_req_nomem(subreq
, req
)) {
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
);
137 status
= wb_fill_pwent_recv(subreq
);
139 if (!NT_STATUS_IS_OK(status
)) {
140 tevent_req_nterror(req
, status
);
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
);