2 Unix SMB/CIFS implementation.
4 async seqnums, update the seqnums in winbindd_cache.c
6 Copyright (C) Volker Lendecke 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "librpc/gen_ndr/ndr_winbind_c.h"
26 struct wb_seqnums_state
{
30 struct tevent_req
**subreqs
;
31 struct winbindd_domain
**domains
;
36 static void wb_seqnums_done(struct tevent_req
*subreq
);
38 struct tevent_req
*wb_seqnums_send(TALLOC_CTX
*mem_ctx
,
39 struct tevent_context
*ev
)
41 struct tevent_req
*req
;
42 struct wb_seqnums_state
*state
;
43 struct winbindd_domain
*domain
;
46 req
= tevent_req_create(mem_ctx
, &state
, struct wb_seqnums_state
);
50 state
->num_received
= 0;
51 state
->num_domains
= 0;
53 for (domain
= domain_list(); domain
!= NULL
; domain
= domain
->next
) {
54 state
->num_domains
+= 1;
57 state
->subreqs
= talloc_array(state
, struct tevent_req
*,
59 state
->domains
= talloc_zero_array(state
, struct winbindd_domain
*,
61 state
->stati
= talloc_array(state
, NTSTATUS
, state
->num_domains
);
62 state
->seqnums
= talloc_array(state
, uint32_t, state
->num_domains
);
64 if ((state
->subreqs
== NULL
) || (state
->domains
== NULL
) ||
65 (state
->stati
== NULL
) || (state
->seqnums
== NULL
)) {
66 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
67 return tevent_req_post(req
, ev
);
72 for (domain
= domain_list(); domain
!= NULL
; domain
= domain
->next
) {
73 state
->domains
[i
] = domain
;
74 state
->subreqs
[i
] = wb_seqnum_send(state
->subreqs
, ev
, domain
);
75 if (tevent_req_nomem(state
->subreqs
[i
], req
)) {
76 /* Don't even start all the other requests */
77 TALLOC_FREE(state
->subreqs
);
78 return tevent_req_post(req
, ev
);
80 tevent_req_set_callback(state
->subreqs
[i
], wb_seqnums_done
,
87 static void wb_seqnums_done(struct tevent_req
*subreq
)
89 struct tevent_req
*req
= tevent_req_callback_data(
90 subreq
, struct tevent_req
);
91 struct wb_seqnums_state
*state
= tevent_req_data(
92 req
, struct wb_seqnums_state
);
97 status
= wb_seqnum_recv(subreq
, &seqnum
);
99 for (i
=0; i
<state
->num_domains
; i
++) {
100 if (subreq
== state
->subreqs
[i
]) {
104 if (i
< state
->num_domains
) {
107 state
->subreqs
[i
] = NULL
;
108 state
->stati
[i
] = status
;
109 if (NT_STATUS_IS_OK(status
)) {
110 state
->seqnums
[i
] = seqnum
;
113 * This first assignment might be removed
116 state
->domains
[i
]->sequence_number
= seqnum
;
118 if (!wcache_store_seqnum(state
->domains
[i
]->name
,
121 DEBUG(1, ("wcache_store_seqnum failed for "
123 state
->domains
[i
]->name
));
130 state
->num_received
+= 1;
132 if (state
->num_received
>= state
->num_domains
) {
133 tevent_req_done(req
);
137 NTSTATUS
wb_seqnums_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
138 int *num_domains
, struct winbindd_domain
***domains
,
139 NTSTATUS
**stati
, uint32_t **seqnums
)
141 struct wb_seqnums_state
*state
= tevent_req_data(
142 req
, struct wb_seqnums_state
);
145 if (tevent_req_is_nterror(req
, &status
)) {
148 *num_domains
= state
->num_domains
;
149 *domains
= talloc_move(mem_ctx
, &state
->domains
);
150 *stati
= talloc_move(mem_ctx
, &state
->stati
);
151 *seqnums
= talloc_move(mem_ctx
, &state
->seqnums
);