winsdb: the we_are_owner in winsdb_lookup() needs to be per address
authorStefan Metzmacher <metze@sernet.de>
Tue, 18 Mar 2008 15:08:02 +0000 (16:08 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 19 Jan 2009 06:05:50 +0000 (07:05 +0100)
This fixes a bug where #1C addresses are registered with different
WINS-Servers and a merged #1C record.

metze
(from samba4wins tree 72e055394a0fd1f543be9c196b4179356a1033f6)

source4/nbt_server/wins/winsdb.c

index 945914ccdfb4b2c1cd0cd89e6c4739fd01b0cfae..5fb688b7b7037d1b19c304874d8803efce163749 100644 (file)
@@ -613,7 +613,6 @@ NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_
        struct ldb_message_element *el;
        struct nbt_name *name;
        uint32_t i, j, num_values;
-       bool we_are_owner = false;
 
        rec = talloc(mem_ctx, struct winsdb_record);
        if (rec == NULL) {
@@ -674,26 +673,6 @@ NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_
                goto failed;
        }
 
-       if (strcmp(rec->wins_owner, h->local_owner) == 0) {
-               we_are_owner = true;
-       }
-
-       /* 
-        * see if it has already expired
-        * 
-        * NOTE: only expire owned records this way!
-        *       w2k3 resolves expired replicas
-        *       which are in active state
-        */
-       if (!rec->is_static &&
-           rec->expire_time <= now &&
-           rec->state == WREPL_STATE_ACTIVE &&
-           we_are_owner) {
-               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;
@@ -701,12 +680,26 @@ NTSTATUS winsdb_record(struct winsdb_handle *h, struct ldb_message *msg, TALLOC_
        }
 
        for (i=0,j=0;i<num_values;i++) {
+               bool we_are_owner = false;
+
                status = winsdb_addr_decode(h, rec, &el->values[i], rec->addresses, &rec->addresses[j]);
                if (!NT_STATUS_IS_OK(status)) goto failed;
 
+               if (strcmp(rec->addresses[j]->wins_owner, h->local_owner) == 0) {
+                       we_are_owner = true;
+               }
+
                /*
                 * the record isn't static and is active
-                * then don't add the address if it's expired
+                * then don't add the address if it's expired,
+                * but only if we're the owner of the address
+                *
+                * This is important for SGROUP records,
+                * because each server thinks he's the owner of the
+                * record and the record isn't replicated on a
+                * name_refresh. So addresses owned by another owner
+                * could expire, but we still need to return them
+                * (as windows does).
                 */
                if (!rec->is_static &&
                    rec->addresses[j]->expire_time <= now &&