1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

r12618: use our primary interface address or the "winsdb:local_owner" -address

as winsOwner: attrbute for owned records

metze
(This used to be commit 37dece8304)
This commit is contained in:
Stefan Metzmacher 2005-12-30 21:12:15 +00:00 committed by Gerald (Jerry) Carter
parent 0391b1cb3a
commit 905c3ff8e1
7 changed files with 48 additions and 44 deletions

View File

@ -165,14 +165,14 @@ failed:
"172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z;" "172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z;"
are valid records are valid records
*/ */
static NTSTATUS winsdb_addr_decode(struct winsdb_record *rec, struct ldb_val *val, static NTSTATUS winsdb_addr_decode(struct winsdb_handle *h, struct winsdb_record *rec, struct ldb_val *val,
TALLOC_CTX *mem_ctx, struct winsdb_addr **_addr) TALLOC_CTX *mem_ctx, struct winsdb_addr **_addr)
{ {
NTSTATUS status; NTSTATUS status;
struct winsdb_addr *addr; struct winsdb_addr *addr;
char *address; const char *address;
char *wins_owner; const char *wins_owner;
char *expire_time; const char *expire_time;
char *p; char *p;
addr = talloc(mem_ctx, struct winsdb_addr); addr = talloc(mem_ctx, struct winsdb_addr);
@ -216,6 +216,9 @@ static NTSTATUS winsdb_addr_decode(struct winsdb_record *rec, struct ldb_val *va
} }
*p = '\0';p++; *p = '\0';p++;
if (strcmp(wins_owner, "0.0.0.0") == 0) {
wins_owner = h->local_owner;
}
addr->wins_owner = talloc_strdup(addr, wins_owner); addr->wins_owner = talloc_strdup(addr, wins_owner);
if (!addr->wins_owner) { if (!addr->wins_owner) {
status = NT_STATUS_NO_MEMORY; status = NT_STATUS_NO_MEMORY;
@ -393,7 +396,7 @@ NTSTATUS winsdb_lookup(struct winsdb_handle *h,
talloc_steal(tmp_ctx, res); talloc_steal(tmp_ctx, res);
status = winsdb_record(res->msgs[0], tmp_ctx, &rec); status = winsdb_record(h, res->msgs[0], tmp_ctx, &rec);
if (!NT_STATUS_IS_OK(status)) goto failed; if (!NT_STATUS_IS_OK(status)) goto failed;
/* see if it has already expired */ /* see if it has already expired */
@ -414,7 +417,7 @@ failed:
return status; return status;
} }
NTSTATUS winsdb_record(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, struct winsdb_record **_rec)
{ {
NTSTATUS status; NTSTATUS status;
struct winsdb_record *rec; struct winsdb_record *rec;
@ -453,12 +456,8 @@ NTSTATUS winsdb_record(struct ldb_message *msg, TALLOC_CTX *mem_ctx, struct wins
talloc_steal(rec, rec->wins_owner); talloc_steal(rec, rec->wins_owner);
talloc_steal(rec, rec->registered_by); talloc_steal(rec, rec->registered_by);
if (!rec->wins_owner) { if (!rec->wins_owner || strcmp(rec->wins_owner, "0.0.0.0") == 0) {
rec->wins_owner = talloc_strdup(rec, WINSDB_OWNER_LOCAL); rec->wins_owner = h->local_owner;
if (rec->wins_owner == NULL) {
status = NT_STATUS_NO_MEMORY;
goto failed;
}
} }
el = ldb_msg_find_element(msg, "address"); el = ldb_msg_find_element(msg, "address");
@ -488,7 +487,7 @@ NTSTATUS winsdb_record(struct ldb_message *msg, TALLOC_CTX *mem_ctx, struct wins
} }
for (i=0;i<num_values;i++) { for (i=0;i<num_values;i++) {
status = winsdb_addr_decode(rec, &el->values[i], rec->addresses, &rec->addresses[i]); status = winsdb_addr_decode(h, rec, &el->values[i], rec->addresses, &rec->addresses[i]);
if (!NT_STATUS_IS_OK(status)) goto failed; if (!NT_STATUS_IS_OK(status)) goto failed;
} }
rec->addresses[i] = NULL; rec->addresses[i] = NULL;
@ -596,7 +595,7 @@ uint8_t winsdb_add(struct winsdb_handle *h, struct winsdb_record *rec, uint32_t
if (rec->version == 0) goto failed; if (rec->version == 0) goto failed;
} }
if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) { if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) {
rec->wins_owner = WINSDB_OWNER_LOCAL; rec->wins_owner = h->local_owner;
} }
msg = winsdb_message(wins_db, rec, tmp_ctx); msg = winsdb_message(wins_db, rec, tmp_ctx);
@ -637,7 +636,7 @@ uint8_t winsdb_modify(struct winsdb_handle *h, struct winsdb_record *rec, uint32
if (rec->version == 0) goto failed; if (rec->version == 0) goto failed;
} }
if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) { if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) {
rec->wins_owner = WINSDB_OWNER_LOCAL; rec->wins_owner = h->local_owner;
} }
msg = winsdb_message(wins_db, rec, tmp_ctx); msg = winsdb_message(wins_db, rec, tmp_ctx);
@ -698,6 +697,7 @@ failed:
struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx) struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx)
{ {
struct winsdb_handle *h = NULL; struct winsdb_handle *h = NULL;
const char *owner;
h = talloc(mem_ctx, struct winsdb_handle); h = talloc(mem_ctx, struct winsdb_handle);
if (!h) return NULL; if (!h) return NULL;
@ -706,6 +706,14 @@ struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx)
system_session(h), NULL, 0, NULL); system_session(h), NULL, 0, NULL);
if (!h->ldb) goto failed; if (!h->ldb) goto failed;
owner = lp_parm_string(-1, "winsdb", "local_owner");
if (!owner) {
owner = iface_n_ip(0);
}
h->local_owner = talloc_strdup(h, owner);
if (!h->local_owner) goto failed;
return h; return h;
failed: failed:
talloc_free(h); talloc_free(h);

View File

@ -20,9 +20,6 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#define WINSDB_OWNER_LOCAL "0.0.0.0"
#define WINSDB_GROUP_ADDRESS "255.255.255.255"
#define WINSDB_FLAG_ALLOC_VERSION (1<<0) #define WINSDB_FLAG_ALLOC_VERSION (1<<0)
#define WINSDB_FLAG_TAKE_OWNERSHIP (1<<1) #define WINSDB_FLAG_TAKE_OWNERSHIP (1<<1)
@ -53,6 +50,9 @@ struct winsdb_record {
struct winsdb_handle { struct winsdb_handle {
/* wins server database handle */ /* wins server database handle */
struct ldb_context *ldb; struct ldb_context *ldb;
/* local owner address */
const char *local_owner;
}; };
struct wins_server { struct wins_server {

View File

@ -91,7 +91,7 @@ static uint8_t wins_register_new(struct nbt_name_socket *nbtsock,
rec.addresses = winsdb_addr_list_add(rec.addresses, rec.addresses = winsdb_addr_list_add(rec.addresses,
address, address,
WINSDB_OWNER_LOCAL, winssrv->wins_db->local_owner,
rec.expire_time); rec.expire_time);
if (rec.addresses == NULL) return NBT_RCODE_SVR; if (rec.addresses == NULL) return NBT_RCODE_SVR;
@ -122,11 +122,11 @@ static uint8_t wins_update_ttl(struct nbt_name_socket *nbtsock,
rec->registered_by = src->addr; rec->registered_by = src->addr;
if (winsdb_addr) { if (winsdb_addr) {
winsdb_addr->wins_owner = WINSDB_OWNER_LOCAL; winsdb_addr->wins_owner = winssrv->wins_db->local_owner;
winsdb_addr->expire_time = rec->expire_time; winsdb_addr->expire_time = rec->expire_time;
} }
if (strcmp(WINSDB_OWNER_LOCAL, rec->wins_owner) != 0) { if (strcmp(winssrv->wins_db->local_owner, rec->wins_owner) != 0) {
modify_flags = WINSDB_FLAG_ALLOC_VERSION | WINSDB_FLAG_TAKE_OWNERSHIP; modify_flags = WINSDB_FLAG_ALLOC_VERSION | WINSDB_FLAG_TAKE_OWNERSHIP;
} }
@ -155,7 +155,7 @@ static uint8_t wins_sgroup_merge(struct nbt_name_socket *nbtsock,
rec->addresses = winsdb_addr_list_add(rec->addresses, rec->addresses = winsdb_addr_list_add(rec->addresses,
address, address,
WINSDB_OWNER_LOCAL, winssrv->wins_db->local_owner,
rec->expire_time); rec->expire_time);
if (rec->addresses == NULL) return NBT_RCODE_SVR; if (rec->addresses == NULL) return NBT_RCODE_SVR;
@ -243,7 +243,7 @@ static void wins_wack_allow(struct wack_state *s)
break; break;
} }
if (found) { if (found) {
rec->addresses[i]->wins_owner = WINSDB_OWNER_LOCAL; rec->addresses[i]->wins_owner = s->winssrv->wins_db->local_owner;
rec->addresses[i]->expire_time = rec->expire_time; rec->addresses[i]->expire_time = rec->expire_time;
continue; continue;
} }
@ -253,7 +253,7 @@ static void wins_wack_allow(struct wack_state *s)
rec->addresses = winsdb_addr_list_add(rec->addresses, rec->addresses = winsdb_addr_list_add(rec->addresses,
s->reg_address, s->reg_address,
WINSDB_OWNER_LOCAL, s->winssrv->wins_db->local_owner,
rec->expire_time); rec->expire_time);
if (rec->addresses == NULL) goto failed; if (rec->addresses == NULL) goto failed;
@ -597,7 +597,7 @@ static void nbtd_winsserver_query(struct nbt_name_socket *nbtsock,
nbtd_negative_name_query_reply(nbtsock, packet, src); nbtd_negative_name_query_reply(nbtsock, packet, src);
return; return;
} }
addresses[0] = WINSDB_GROUP_ADDRESS; addresses[0] = "255.255.255.255";
addresses[1] = NULL; addresses[1] = NULL;
goto found; goto found;
} }

View File

@ -1187,7 +1187,7 @@ static NTSTATUS r_do_sgroup_merge(struct wreplsrv_partner *partner,
} }
/* if we're the owner of the old record, we'll be the owner of the new one too */ /* if we're the owner of the old record, we'll be the owner of the new one too */
if (strcmp(rec->wins_owner, WINSDB_OWNER_LOCAL)==0) { if (strcmp(rec->wins_owner, partner->service->wins_db->local_owner)==0) {
become_owner = True; become_owner = True;
} }
@ -1239,7 +1239,7 @@ static NTSTATUS wreplsrv_apply_one_record(struct wreplsrv_partner *partner,
} }
NT_STATUS_NOT_OK_RETURN(status); NT_STATUS_NOT_OK_RETURN(status);
if (strcmp(rec->wins_owner, WINSDB_OWNER_LOCAL)==0) { if (strcmp(rec->wins_owner, partner->service->wins_db->local_owner)==0) {
local_vs_replica = True; local_vs_replica = True;
} else if (strcmp(rec->wins_owner, owner->address)==0) { } else if (strcmp(rec->wins_owner, owner->address)==0) {
same_owner = True; same_owner = True;

View File

@ -138,7 +138,7 @@ static NTSTATUS wreplsrv_record2wins_name(TALLOC_CTX *mem_ctx,
talloc_steal(mem_ctx, rec->name); talloc_steal(mem_ctx, rec->name);
name->id = rec->version; name->id = rec->version;
name->unknown = WINSDB_GROUP_ADDRESS; name->unknown = "255.255.255.255";
name->flags = WREPL_NAME_FLAGS(rec->type, rec->state, rec->node, rec->is_static); name->flags = WREPL_NAME_FLAGS(rec->type, rec->state, rec->node, rec->is_static);
@ -153,13 +153,8 @@ static NTSTATUS wreplsrv_record2wins_name(TALLOC_CTX *mem_ctx,
NT_STATUS_HAVE_NO_MEMORY(ips); NT_STATUS_HAVE_NO_MEMORY(ips);
for (i = 0; i < num_ips; i++) { for (i = 0; i < num_ips; i++) {
if (strcasecmp(WINSDB_OWNER_LOCAL, rec->addresses[i]->wins_owner) == 0) { ips[i].owner = rec->addresses[i]->wins_owner;
ips[i].owner = talloc_strdup(ips, our_address); talloc_steal(ips, rec->addresses[i]->wins_owner);
NT_STATUS_HAVE_NO_MEMORY(ips[i].owner);
} else {
ips[i].owner = rec->addresses[i]->wins_owner;
talloc_steal(ips, rec->addresses[i]->wins_owner);
}
ips[i].ip = rec->addresses[i]->address; ips[i].ip = rec->addresses[i]->address;
talloc_steal(ips, rec->addresses[i]->address); talloc_steal(ips, rec->addresses[i]->address);
} }
@ -190,7 +185,7 @@ static NTSTATUS wreplsrv_in_send_request(struct wreplsrv_in_call *call)
if (strcmp(call->wreplconn->our_ip, owner_in->address) == 0) { if (strcmp(call->wreplconn->our_ip, owner_in->address) == 0) {
ZERO_STRUCT(local_owner); ZERO_STRUCT(local_owner);
local_owner.owner.address = WINSDB_OWNER_LOCAL; local_owner.owner.address = service->wins_db->local_owner;
local_owner.owner.min_version = 0; local_owner.owner.min_version = 0;
local_owner.owner.max_version = wreplsrv_local_max_version(service); local_owner.owner.max_version = wreplsrv_local_max_version(service);
local_owner.owner.type = 1; local_owner.owner.type = 1;
@ -260,7 +255,7 @@ static NTSTATUS wreplsrv_in_send_request(struct wreplsrv_in_call *call)
NT_STATUS_HAVE_NO_MEMORY(names); NT_STATUS_HAVE_NO_MEMORY(names);
for (i = 0; i < res->count; i++) { for (i = 0; i < res->count; i++) {
status = winsdb_record(res->msgs[i], call, &rec); status = winsdb_record(service->wins_db, res->msgs[i], call, &rec);
NT_STATUS_NOT_OK_RETURN(status); NT_STATUS_NOT_OK_RETURN(status);
status = wreplsrv_record2wins_name(names, call->wreplconn->our_ip, &names[i], rec); status = wreplsrv_record2wins_name(names, call->wreplconn->our_ip, &names[i], rec);

View File

@ -51,7 +51,7 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
filter = talloc_asprintf(tmp_mem, filter = talloc_asprintf(tmp_mem,
"(&(winsOwner=%s)(objectClass=winsRecord)" "(&(winsOwner=%s)(objectClass=winsRecord)"
"(expireTime<=%s)(!(isStatic=1)))", "(expireTime<=%s)(!(isStatic=1)))",
WINSDB_OWNER_LOCAL, now_timestr); service->wins_db->local_owner, now_timestr);
NT_STATUS_HAVE_NO_MEMORY(filter); NT_STATUS_HAVE_NO_MEMORY(filter);
ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res); ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION; if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
@ -63,7 +63,7 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
delete_tombstones = timeval_expired(&tombstone_extra_time); delete_tombstones = timeval_expired(&tombstone_extra_time);
for (i=0; i < res->count; i++) { for (i=0; i < res->count; i++) {
status = winsdb_record(res->msgs[i], tmp_mem, &rec); status = winsdb_record(service->wins_db, res->msgs[i], tmp_mem, &rec);
NT_STATUS_NOT_OK_RETURN(status); NT_STATUS_NOT_OK_RETURN(status);
if (rec->is_static) { if (rec->is_static) {
@ -159,7 +159,7 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
filter = talloc_asprintf(tmp_mem, filter = talloc_asprintf(tmp_mem,
"(&(!(winsOwner=%s))(objectClass=winsRecord)" "(&(!(winsOwner=%s))(objectClass=winsRecord)"
"(!(recordState=%u))(expireTime<=%s)(!(isStatic=1)))", "(!(recordState=%u))(expireTime<=%s)(!(isStatic=1)))",
WINSDB_OWNER_LOCAL, WREPL_STATE_ACTIVE, now_timestr); service->wins_db->local_owner, WREPL_STATE_ACTIVE, now_timestr);
NT_STATUS_HAVE_NO_MEMORY(filter); NT_STATUS_HAVE_NO_MEMORY(filter);
ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res); ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION; if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
@ -171,7 +171,7 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
delete_tombstones = timeval_expired(&tombstone_extra_time); delete_tombstones = timeval_expired(&tombstone_extra_time);
for (i=0; i < res->count; i++) { for (i=0; i < res->count; i++) {
status = winsdb_record(res->msgs[i], tmp_mem, &rec); status = winsdb_record(service->wins_db, res->msgs[i], tmp_mem, &rec);
NT_STATUS_NOT_OK_RETURN(status); NT_STATUS_NOT_OK_RETURN(status);
if (rec->is_static) { if (rec->is_static) {
@ -262,14 +262,14 @@ static NTSTATUS wreplsrv_scavenging_replica_active_records(struct wreplsrv_servi
filter = talloc_asprintf(tmp_mem, filter = talloc_asprintf(tmp_mem,
"(&(!(winsOwner=%s))(objectClass=winsRecord)" "(&(!(winsOwner=%s))(objectClass=winsRecord)"
"(recordState=%u)(expireTime<=%s)(!(isStatic=1)))", "(recordState=%u)(expireTime<=%s)(!(isStatic=1)))",
WINSDB_OWNER_LOCAL, WREPL_STATE_ACTIVE, now_timestr); service->wins_db->local_owner, WREPL_STATE_ACTIVE, now_timestr);
NT_STATUS_HAVE_NO_MEMORY(filter); NT_STATUS_HAVE_NO_MEMORY(filter);
ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res); ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION; if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
talloc_steal(tmp_mem, res); talloc_steal(tmp_mem, res);
for (i=0; i < res->count; i++) { for (i=0; i < res->count; i++) {
status = winsdb_record(res->msgs[i], tmp_mem, &rec); status = winsdb_record(service->wins_db, res->msgs[i], tmp_mem, &rec);
NT_STATUS_NOT_OK_RETURN(status); NT_STATUS_NOT_OK_RETURN(status);
if (rec->is_static) { if (rec->is_static) {

View File

@ -264,7 +264,8 @@ NTSTATUS wreplsrv_add_table(struct wreplsrv_service *service,
struct wreplsrv_owner *table = *_table; struct wreplsrv_owner *table = *_table;
struct wreplsrv_owner *cur; struct wreplsrv_owner *cur;
if (strcmp(WINSDB_OWNER_LOCAL, wins_owner) == 0) { if (strcmp(service->wins_db->local_owner, wins_owner) == 0 ||
strcmp("0.0.0.0", wins_owner) == 0) {
return NT_STATUS_OK; return NT_STATUS_OK;
} }