2 Unix SMB/CIFS implementation.
4 WINS Replication server
6 Copyright (C) Stefan Metzmacher 2005
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "dlinklist.h"
25 #include "lib/events/events.h"
26 #include "lib/socket/socket.h"
27 #include "smbd/service_task.h"
28 #include "smbd/service_stream.h"
29 #include "lib/messaging/irpc.h"
30 #include "librpc/gen_ndr/ndr_winsrepl.h"
31 #include "wrepl_server/wrepl_server.h"
32 #include "nbt_server/wins/winsdb.h"
33 #include "ldb/include/ldb.h"
34 #include "libcli/composite/composite.h"
35 #include "libcli/wrepl/winsrepl.h"
36 #include "wrepl_server/wrepl_out_helpers.h"
38 static void wreplsrv_out_partner_push(struct wreplsrv_partner *partner, BOOL propagate);
40 static void wreplsrv_push_handler_creq(struct composite_context *creq)
42 struct wreplsrv_partner *partner = talloc_get_type(creq->async.private_data, struct wreplsrv_partner);
43 struct wreplsrv_push_notify_io *old_notify_io;
45 partner->push.last_status = wreplsrv_push_notify_recv(partner->push.creq);
46 partner->push.creq = NULL;
47 partner->push.last_run = timeval_current();
49 old_notify_io = partner->push.notify_io;
50 partner->push.notify_io = NULL;
52 if (NT_STATUS_IS_OK(partner->push.last_status)) {
53 partner->push.error_count = 0;
54 DEBUG(2,("wreplsrv_push_notify(%s): %s\n",
55 partner->address, nt_errstr(partner->push.last_status)));
59 partner->push.error_count++;
61 if (partner->push.error_count > 1) {
62 DEBUG(1,("wreplsrv_push_notify(%s): %s: error_count: %u: giving up\n",
63 partner->address, nt_errstr(partner->push.last_status),
64 partner->push.error_count));
68 DEBUG(1,("wreplsrv_push_notify(%s): %s: error_count: %u: retry\n",
69 partner->address, nt_errstr(partner->push.last_status),
70 partner->push.error_count));
71 wreplsrv_out_partner_push(partner, old_notify_io->in.propagate);
73 talloc_free(old_notify_io);
76 static void wreplsrv_out_partner_push(struct wreplsrv_partner *partner, BOOL propagate)
78 /* a push for this partner is currently in progress, so we're done */
79 if (partner->push.creq) return;
81 /* now prepare the push notify */
82 partner->push.notify_io = talloc(partner, struct wreplsrv_push_notify_io);
83 if (!partner->push.notify_io) {
87 partner->push.notify_io->in.partner = partner;
88 partner->push.notify_io->in.inform = partner->push.use_inform;
89 partner->push.notify_io->in.propagate = propagate;
90 partner->push.creq = wreplsrv_push_notify_send(partner->push.notify_io, partner->push.notify_io);
91 if (!partner->push.creq) {
92 DEBUG(1,("wreplsrv_push_notify_send(%s) failed\n",
97 partner->push.creq->async.fn = wreplsrv_push_handler_creq;
98 partner->push.creq->async.private_data = partner;
102 talloc_free(partner->push.notify_io);
103 partner->push.notify_io = NULL;
104 DEBUG(1,("wreplsrv_push_notify_send(%s) failed nomem? (ignoring)\n",
109 static uint32_t wreplsrv_calc_change_count(struct wreplsrv_partner *partner)
111 /* TODO: add a real implementation here */
115 uint32_t wreplsrv_out_push_run(struct wreplsrv_service *service, uint32_t next_interval)
117 struct wreplsrv_partner *partner;
118 uint32_t change_count;
120 for (partner = service->partners; partner; partner = partner->next) {
121 /* if it's not a push partner, go to the next partner */
122 if (!(partner->type & WINSREPL_PARTNER_PUSH)) continue;
124 /* if push notifies are disabled for this partner, go to the next partner */
125 if (partner->push.change_count == 0) continue;
127 /* get the actual change count for the partner */
128 change_count = wreplsrv_calc_change_count(partner);
130 /* if the configured change count isn't reached, go to the next partner */
131 if (change_count < partner->push.change_count) continue;
133 wreplsrv_out_partner_push(partner, False);
136 return next_interval;