summaryrefslogtreecommitdiff
path: root/source4/nbt_server/wins
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-01-21 08:53:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:51:20 -0500
commitf25ad21617d7887d68bff3cad31045e8a98e3cae (patch)
tree21df9971bb1decb522c5f6b1122e45c610ee62f3 /source4/nbt_server/wins
parentb19ca85e97bf1eddaa944655b66dadd428688d7e (diff)
downloadsamba-f25ad21617d7887d68bff3cad31045e8a98e3cae.tar.gz
samba-f25ad21617d7887d68bff3cad31045e8a98e3cae.tar.bz2
samba-f25ad21617d7887d68bff3cad31045e8a98e3cae.zip
r13060: - return only active addresses in name query responses
- replicate only active addresses metze (This used to be commit 6325abd95c5df855e8d1de2be9745940a29ba00a)
Diffstat (limited to 'source4/nbt_server/wins')
-rw-r--r--source4/nbt_server/wins/winsdb.c55
-rw-r--r--source4/nbt_server/wins/winsserver.c3
2 files changed, 41 insertions, 17 deletions
diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c
index 3e73d89fdd..e3c02e05f0 100644
--- a/source4/nbt_server/wins/winsdb.c
+++ b/source4/nbt_server/wins/winsdb.c
@@ -446,6 +446,7 @@ NTSTATUS winsdb_lookup(struct winsdb_handle *h,
struct winsdb_record *rec;
struct ldb_context *wins_db = h->ldb;
TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ time_t now = time(NULL);
/* find the record in the WINS database */
ret = ldb_search(wins_db, winsdb_dn(tmp_ctx, name), LDB_SCOPE_BASE,
@@ -461,17 +462,9 @@ NTSTATUS winsdb_lookup(struct winsdb_handle *h,
talloc_steal(tmp_ctx, res);
- status = winsdb_record(h, res->msgs[0], tmp_ctx, &rec);
+ status = winsdb_record(h, res->msgs[0], tmp_ctx, now, &rec);
if (!NT_STATUS_IS_OK(status)) goto failed;
- /* see if it has already expired */
- if (rec->state == WREPL_STATE_ACTIVE &&
- rec->expire_time <= time(NULL)) {
- DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
- nbt_name_string(tmp_ctx, rec->name), timestring(tmp_ctx, rec->expire_time)));
- rec->state = WREPL_STATE_RELEASED;
- }
-
talloc_steal(mem_ctx, rec);
talloc_free(tmp_ctx);
*_rec = rec;
@@ -482,13 +475,13 @@ failed:
return status;
}
-NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_CTX *mem_ctx, struct winsdb_record **_rec)
+NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_CTX *mem_ctx, time_t now, struct winsdb_record **_rec)
{
NTSTATUS status;
struct winsdb_record *rec;
struct ldb_message_element *el;
struct nbt_name *name;
- uint32_t i, num_values;
+ uint32_t i, j, num_values;
rec = talloc(mem_ctx, struct winsdb_record);
if (rec == NULL) {
@@ -549,17 +542,43 @@ NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_
goto failed;
}
+ /* see if it has already expired */
+ if (!rec->is_static &&
+ rec->expire_time <= now &&
+ rec->state == WREPL_STATE_ACTIVE) {
+ DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
+ nbt_name_string(mem_ctx, rec->name), timestring(mem_ctx, rec->expire_time)));
+ rec->state = WREPL_STATE_RELEASED;
+ }
+
rec->addresses = talloc_array(rec, struct winsdb_addr *, num_values+1);
if (rec->addresses == NULL) {
status = NT_STATUS_NO_MEMORY;
goto failed;
}
- for (i=0;i<num_values;i++) {
- status = winsdb_addr_decode(h, rec, &el->values[i], rec->addresses, &rec->addresses[i]);
+ for (i=0,j=0;i<num_values;i++) {
+ status = winsdb_addr_decode(h, rec, &el->values[i], rec->addresses, &rec->addresses[j]);
if (!NT_STATUS_IS_OK(status)) goto failed;
+
+ /*
+ * the record isn't static and is active
+ * then don't add the address if it's expired
+ */
+ if (!rec->is_static &&
+ rec->addresses[j]->expire_time <= now &&
+ rec->state == WREPL_STATE_ACTIVE) {
+ DEBUG(5,("WINS: expiring name addr %s of %s (expired at %s)\n",
+ rec->addresses[j]->address, nbt_name_string(rec->addresses[j], rec->name),
+ timestring(rec->addresses[j], rec->addresses[j]->expire_time)));
+ talloc_free(rec->addresses[j]);
+ rec->addresses[j] = NULL;
+ continue;
+ }
+ j++;
}
- rec->addresses[i] = NULL;
+ rec->addresses[j] = NULL;
+ num_values = j;
if (rec->is_static && rec->state == WREPL_STATE_ACTIVE) {
rec->expire_time = get_time_t_max();
@@ -568,6 +587,14 @@ NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_
}
}
+ if (rec->state == WREPL_STATE_ACTIVE) {
+ if (num_values < 1) {
+ DEBUG(5,("WINS: expiring name %s (because it has no active addresses)\n",
+ nbt_name_string(mem_ctx, rec->name)));
+ rec->state = WREPL_STATE_RELEASED;
+ }
+ }
+
*_rec = rec;
return NT_STATUS_OK;
failed:
diff --git a/source4/nbt_server/wins/winsserver.c b/source4/nbt_server/wins/winsserver.c
index 7d3ab8294b..5cc3a51a00 100644
--- a/source4/nbt_server/wins/winsserver.c
+++ b/source4/nbt_server/wins/winsserver.c
@@ -492,7 +492,6 @@ static void nbtd_winsserver_register(struct nbt_name_socket *nbtsock,
/*
* if the registration is for an address that is currently active, then
* just update the expiry time of the record and the address
- * TODO: is this correct?
*/
winsdb_addr = winsdb_addr_list_check(rec->addresses, address);
if (winsdb_addr) {
@@ -525,9 +524,7 @@ static void nbtd_winsserver_register(struct nbt_name_socket *nbtsock,
/*
* if the registration is for an address that is currently active, then
- * just update the expiry time
* just update the expiry time of the record and the address
- * TODO: is this correct?
*/
winsdb_addr = winsdb_addr_list_check(rec->addresses, address);
if (winsdb_addr) {