diff options
Diffstat (limited to 'source4/wrepl_server/wrepl_server.c')
-rw-r--r-- | source4/wrepl_server/wrepl_server.c | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/source4/wrepl_server/wrepl_server.c b/source4/wrepl_server/wrepl_server.c index 97fa23cdf1..b044ef8296 100644 --- a/source4/wrepl_server/wrepl_server.c +++ b/source4/wrepl_server/wrepl_server.c @@ -80,14 +80,17 @@ static NTSTATUS wreplsrv_load_partners(struct wreplsrv_service *service) for (i=0; i < ret; i++) { struct wreplsrv_partner *partner; - partner = talloc(service, struct wreplsrv_partner); + partner = talloc_zero(service, struct wreplsrv_partner); if (partner == NULL) goto failed; + partner->service = service; partner->address = ldb_msg_find_string(res[i], "address", NULL); if (!partner->address) goto failed; partner->name = ldb_msg_find_string(res[i], "name", partner->address); partner->type = ldb_msg_find_int(res[i], "type", WINSREPL_PARTNER_BOTH); partner->pull.interval = ldb_msg_find_int(res[i], "pullInterval", WINSREPL_DEFAULT_PULL_INTERVAL); + partner->pull.retry_interval = ldb_msg_find_int(res[i], "pullRetryInterval", + WINSREPL_DEFAULT_PULL_RETRY_INTERVAL); partner->our_address = ldb_msg_find_string(res[i], "ourAddress", NULL); talloc_steal(partner, partner->address); @@ -104,6 +107,29 @@ failed: return NT_STATUS_FOOBAR; } +BOOL wreplsrv_is_our_address(struct wreplsrv_service *service, const char *address) +{ + const char *our_address; + + if (lp_interfaces() && lp_bind_interfaces_only()) { + int num_interfaces = iface_count(); + int i; + for(i = 0; i < num_interfaces; i++) { + our_address = iface_n_ip(i); + if (strcasecmp(our_address, address) == 0) { + return True; + } + } + } else { + our_address = lp_socket_address(); + if (strcasecmp(our_address, address) == 0) { + return True; + } + } + + return False; +} + uint64_t wreplsrv_local_max_version(struct wreplsrv_service *service) { int ret; @@ -134,6 +160,49 @@ failed: return maxVersion; } +NTSTATUS wreplsrv_fill_wrepl_table(struct wreplsrv_service *service, + TALLOC_CTX *mem_ctx, + struct wrepl_table *table_out, + const char *our_ip, + const char *initiator, + BOOL full_table) +{ + struct wreplsrv_owner *cur; + uint64_t local_max_version; + uint32_t i = 0; + + table_out->partner_count = 0; + table_out->partners = NULL; + table_out->initiator = initiator; + + local_max_version = wreplsrv_local_max_version(service); + if (local_max_version > 0) { + table_out->partner_count++; + } + + for (cur = service->table; full_table && cur; cur = cur->next) { + table_out->partner_count++; + } + + table_out->partners = talloc_array(mem_ctx, struct wrepl_wins_owner, table_out->partner_count); + NT_STATUS_HAVE_NO_MEMORY(table_out->partners); + + if (local_max_version > 0) { + table_out->partners[i].address = our_ip; + table_out->partners[i].min_version = 0; + table_out->partners[i].max_version = local_max_version; + table_out->partners[i].type = 1; + i++; + } + + for (cur = service->table; full_table && cur; cur = cur->next) { + table_out->partners[i] = cur->owner; + i++; + } + + return NT_STATUS_OK; +} + struct wreplsrv_owner *wreplsrv_find_owner(struct wreplsrv_owner *table, const char *wins_owner) { struct wreplsrv_owner *cur; @@ -151,9 +220,9 @@ struct wreplsrv_owner *wreplsrv_find_owner(struct wreplsrv_owner *table, const c update the wins_owner_table max_version, if the given version is the highest version if no entry for the wins_owner exists yet, create one */ -static NTSTATUS wreplsrv_add_table(struct wreplsrv_service *service, - TALLOC_CTX *mem_ctx, struct wreplsrv_owner **_table, - const char *wins_owner, uint64_t version) +NTSTATUS wreplsrv_add_table(struct wreplsrv_service *service, + TALLOC_CTX *mem_ctx, struct wreplsrv_owner **_table, + const char *wins_owner, uint64_t version) { struct wreplsrv_owner *table = *_table; struct wreplsrv_owner *cur; |