This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "system/time.h"
#include "db_wrap.h"
#include "system/network.h"
-#include "netif/netif.h"
+#include "lib/socket/netif.h"
+#include "param/param.h"
uint64_t winsdb_get_maxVersion(struct winsdb_handle *h)
{
TALLOC_CTX *tmp_ctx = talloc_new(ldb);
uint64_t maxVersion = 0;
- dn = ldb_dn_explode(tmp_ctx, "CN=VERSION");
+ dn = ldb_dn_new(tmp_ctx, ldb, "CN=VERSION");
if (!dn) goto failed;
/* find the record in the WINS database */
if (res->count > 1) goto failed;
if (res->count == 1) {
- maxVersion = ldb_msg_find_uint64(res->msgs[0], "maxVersion", 0);
+ maxVersion = ldb_msg_find_attr_as_uint64(res->msgs[0], "maxVersion", 0);
}
failed:
trans = ldb_transaction_start(wins_db);
if (trans != LDB_SUCCESS) goto failed;
- dn = ldb_dn_explode(tmp_ctx, "CN=VERSION");
+ dn = ldb_dn_new(tmp_ctx, wins_db, "CN=VERSION");
if (!dn) goto failed;
/* find the record in the WINS database */
ret = ldb_search(wins_db, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
if (ret != LDB_SUCCESS) goto failed;
+ talloc_steal(tmp_ctx, res);
if (res->count > 1) goto failed;
talloc_steal(tmp_ctx, res);
if (res->count == 1) {
- oldMaxVersion = ldb_msg_find_uint64(res->msgs[0], "maxVersion", 0);
+ oldMaxVersion = ldb_msg_find_attr_as_uint64(res->msgs[0], "maxVersion", 0);
}
if (newMaxVersion == 0) {
msg->dn = dn;
- ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE);
+ ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL);
if (ret != 0) goto failed;
ret = ldb_msg_add_string(msg, "objectClass", "winsMaxVersion");
if (ret != 0) goto failed;
- ret = ldb_msg_add_empty(msg, "maxVersion", LDB_FLAG_MOD_REPLACE);
+ ret = ldb_msg_add_empty(msg, "maxVersion", LDB_FLAG_MOD_REPLACE, NULL);
if (ret != 0) goto failed;
ret = ldb_msg_add_fmt(msg, "maxVersion", "%llu", (long long)newMaxVersion);
if (ret != 0) goto failed;
TALLOC_CTX *tmp_ctx = talloc_new(ldb);
uint64_t seqnumber = 0;
- dn = ldb_dn_explode(tmp_ctx, "@BASEINFO");
+ dn = ldb_dn_new(tmp_ctx, ldb, "@BASEINFO");
if (!dn) goto failed;
/* find the record in the WINS database */
if (res->count > 1) goto failed;
if (res->count == 1) {
- seqnumber = ldb_msg_find_uint64(res->msgs[0], "sequenceNumber", 0);
+ seqnumber = ldb_msg_find_attr_as_uint64(res->msgs[0], "sequenceNumber", 0);
}
failed:
/*
return a DN for a nbt_name
*/
-static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct nbt_name *name)
+static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct nbt_name *name)
{
struct ldb_dn *dn;
- dn = ldb_dn_string_compose(mem_ctx, NULL, "type=0x%02X", name->type);
- if (dn && name->name && *name->name) {
- dn = ldb_dn_string_compose(mem_ctx, dn, "name=%s", name->name);
+ dn = ldb_dn_new_fmt(mem_ctx, ldb, "type=0x%02X", name->type);
+ if (ldb_dn_is_valid(dn) && name->name && *name->name) {
+ ldb_dn_add_child_fmt(dn, "name=%s", name->name);
}
- if (dn && name->scope && *name->scope) {
- dn = ldb_dn_string_compose(mem_ctx, dn, "scope=%s", name->scope);
+ if (ldb_dn_is_valid(dn) && name->scope && *name->scope) {
+ ldb_dn_add_child_fmt(dn, "scope=%s", name->scope);
}
return dn;
}
{
NTSTATUS status;
struct nbt_name *name;
+ unsigned int comp_num;
uint32_t cur = 0;
name = talloc(mem_ctx, struct nbt_name);
goto failed;
}
- if (dn->comp_num > 3) {
+ comp_num = ldb_dn_get_comp_num(dn);
+
+ if (comp_num > 3) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
goto failed;
}
- if (dn->comp_num > cur && strcasecmp("scope", dn->components[cur].name) == 0) {
- name->scope = talloc_steal(name, dn->components[cur].value.data);
+ if (comp_num > cur && strcasecmp("scope", ldb_dn_get_component_name(dn, cur)) == 0) {
+ name->scope = (const char *)talloc_strdup(name, (char *)ldb_dn_get_component_val(dn, cur)->data);
cur++;
} else {
name->scope = NULL;
}
- if (dn->comp_num > cur && strcasecmp("name", dn->components[cur].name) == 0) {
- name->name = talloc_steal(name, dn->components[cur].value.data);
+ if (comp_num > cur && strcasecmp("name", ldb_dn_get_component_name(dn, cur)) == 0) {
+ name->name = (const char *)talloc_strdup(name, (char *)ldb_dn_get_component_val(dn, cur)->data);
cur++;
} else {
name->name = talloc_strdup(name, "");
}
}
- if (dn->comp_num > cur && strcasecmp("type", dn->components[cur].name) == 0) {
- name->type = strtoul((char *)dn->components[cur].value.data, NULL, 0);
+ if (comp_num > cur && strcasecmp("type", ldb_dn_get_component_name(dn, cur)) == 0) {
+ name->type = strtoul((char *)ldb_dn_get_component_val(dn, cur)->data, NULL, 0);
cur++;
} else {
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
p = strchr(address, ';');
if (!p) {
/* support old entries, with only the address */
- addr->address = talloc_steal(addr, val->data);
+ addr->address = (const char *)talloc_steal(addr, val->data);
addr->wins_owner = talloc_reference(addr, rec->wins_owner);
if (!addr->wins_owner) {
status = NT_STATUS_NO_MEMORY;
val.data = discard_const_p(uint8_t, str);
val.length = strlen(str);
- return ldb_msg_add_value(msg, attr_name, &val);
+ return ldb_msg_add_value(msg, attr_name, &val, NULL);
}
struct winsdb_addr **winsdb_addr_list_make(TALLOC_CTX *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,
+ ret = ldb_search(wins_db, winsdb_dn(tmp_ctx, wins_db, name), LDB_SCOPE_BASE,
NULL, NULL, &res);
+ talloc_steal(tmp_ctx, res);
if (ret != LDB_SUCCESS || res->count > 1) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
goto failed;
goto failed;
}
- talloc_steal(tmp_ctx, res);
-
status = winsdb_record(h, res->msgs[0], tmp_ctx, now, &rec);
if (!NT_STATUS_IS_OK(status)) goto failed;
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) {
/* parse it into a more convenient winsdb_record structure */
rec->name = name;
- rec->type = ldb_msg_find_int(msg, "recordType", WREPL_TYPE_UNIQUE);
- rec->state = ldb_msg_find_int(msg, "recordState", WREPL_STATE_RELEASED);
- rec->node = ldb_msg_find_int(msg, "nodeType", WREPL_NODE_B);
- rec->is_static = ldb_msg_find_int(msg, "isStatic", 0);
- rec->expire_time = ldb_string_to_time(ldb_msg_find_string(msg, "expireTime", NULL));
- rec->version = ldb_msg_find_uint64(msg, "versionID", 0);
- rec->wins_owner = ldb_msg_find_string(msg, "winsOwner", NULL);
- rec->registered_by = ldb_msg_find_string(msg, "registeredBy", NULL);
+ rec->type = ldb_msg_find_attr_as_int(msg, "recordType", WREPL_TYPE_UNIQUE);
+ rec->state = ldb_msg_find_attr_as_int(msg, "recordState", WREPL_STATE_RELEASED);
+ rec->node = ldb_msg_find_attr_as_int(msg, "nodeType", WREPL_NODE_B);
+ rec->is_static = ldb_msg_find_attr_as_int(msg, "isStatic", 0);
+ rec->expire_time = ldb_string_to_time(ldb_msg_find_attr_as_string(msg, "expireTime", NULL));
+ rec->version = ldb_msg_find_attr_as_uint64(msg, "versionID", 0);
+ rec->wins_owner = ldb_msg_find_attr_as_string(msg, "winsOwner", NULL);
+ rec->registered_by = ldb_msg_find_attr_as_string(msg, "registeredBy", NULL);
talloc_steal(rec, rec->wins_owner);
talloc_steal(rec, rec->registered_by);
goto failed;
}
- /* see if it has already expired */
+ 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) {
+ 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;
*/
if (!rec->is_static &&
rec->addresses[j]->expire_time <= now &&
- rec->state == WREPL_STATE_ACTIVE) {
+ rec->state == WREPL_STATE_ACTIVE &&
+ we_are_owner) {
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)));
return NT_STATUS_OK;
failed:
if (NT_STATUS_EQUAL(NT_STATUS_INTERNAL_DB_CORRUPTION, status)) {
- DEBUG(1,("winsdb_record: corrupted record: %s\n", ldb_dn_linearize(rec, msg->dn)));
+ DEBUG(1,("winsdb_record: corrupted record: %s\n", ldb_dn_get_linearized(msg->dn)));
}
talloc_free(rec);
return status;
goto failed;
}
- msg->dn = winsdb_dn(msg, rec->name);
+ msg->dn = winsdb_dn(msg, ldb, rec->name);
if (msg->dn == NULL) goto failed;
ret |= ldb_msg_add_fmt(msg, "type", "0x%02X", rec->name->type);
if (rec->name->name && *rec->name->name) {
ret |= ldb_msg_add_fmt(msg, "recordState", "%u", rec->state);
ret |= ldb_msg_add_fmt(msg, "nodeType", "%u", rec->node);
ret |= ldb_msg_add_fmt(msg, "isStatic", "%u", rec->is_static);
- ret |= ldb_msg_add_empty(msg, "expireTime", 0);
+ ret |= ldb_msg_add_empty(msg, "expireTime", 0, NULL);
if (!(rec->is_static && rec->state == WREPL_STATE_ACTIVE)) {
ret |= ldb_msg_add_string(msg, "expireTime", expire_time);
}
ret |= ldb_msg_add_fmt(msg, "versionID", "%llu", (long long)rec->version);
ret |= ldb_msg_add_string(msg, "winsOwner", rec->wins_owner);
- ret |= ldb_msg_add_empty(msg, "address", 0);
+ ret |= ldb_msg_add_empty(msg, "address", 0, NULL);
for (i=0;rec->addresses[i];i++) {
ret |= ldb_msg_add_winsdb_addr(msg, rec, "address", rec->addresses[i]);
}
- ret |= ldb_msg_add_empty(msg, "registeredBy", 0);
+ ret |= ldb_msg_add_empty(msg, "registeredBy", 0, NULL);
if (rec->registered_by) {
ret |= ldb_msg_add_string(msg, "registeredBy", rec->registered_by);
if (ret != 0) goto failed;
{
struct ldb_context *wins_db = h->ldb;
TALLOC_CTX *tmp_ctx = talloc_new(wins_db);
- const struct ldb_dn *dn;
+ struct ldb_dn *dn;
int trans;
int ret;
trans = ldb_transaction_start(wins_db);
if (trans != LDB_SUCCESS) goto failed;
- dn = winsdb_dn(tmp_ctx, rec->name);
+ dn = winsdb_dn(tmp_ctx, wins_db, rec->name);
if (dn == NULL) goto failed;
ret = ldb_delete(wins_db, dn);
if (trans != LDB_SUCCESS) goto failed;
/* check if we have a special @MODULES record already */
- dn = ldb_dn_explode(tmp_ctx, "@MODULES");
+ dn = ldb_dn_new(tmp_ctx, h->ldb, "@MODULES");
if (!dn) goto failed;
/* find the record in the WINS database */
talloc_free(h->ldb);
h->ldb = NULL;
- if (lp_parm_bool(-1,"winsdb", "nosync", False)) {
+ if (lp_parm_bool(global_loadparm, NULL,"winsdb", "nosync", false)) {
flags |= LDB_FLG_NOSYNC;
}
- h->ldb = ldb_wrap_connect(h, lock_path(h, lp_wins_url()),
+ h->ldb = ldb_wrap_connect(h, global_loadparm, lock_path(h, global_loadparm, lp_wins_url(global_loadparm)),
NULL, NULL, flags, NULL);
if (!h->ldb) goto failed;
h = talloc(mem_ctx, struct winsdb_handle);
if (!h) return NULL;
- if (lp_parm_bool(-1,"winsdb", "nosync", False)) {
+ if (lp_parm_bool(global_loadparm, NULL,"winsdb", "nosync", false)) {
flags |= LDB_FLG_NOSYNC;
}
- h->ldb = ldb_wrap_connect(h, lock_path(h, lp_wins_url()),
+ h->ldb = ldb_wrap_connect(h, global_loadparm, lock_path(h, global_loadparm, lp_wins_url(global_loadparm)),
NULL, NULL, flags, NULL);
if (!h->ldb) goto failed;
h->caller = caller;
- owner = lp_parm_string(-1, "winsdb", "local_owner");
+ owner = lp_parm_string(global_loadparm, NULL, "winsdb", "local_owner");
if (!owner) {
owner = iface_n_ip(0);
}