summaryrefslogtreecommitdiff
path: root/source4/nbt_server/wins
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-10-14 12:47:57 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:42:15 -0500
commitbab5662021721794c4ac9abe3373d50a2b96b1d5 (patch)
tree86795830ab360ee78e394eb3c71311cbef867999 /source4/nbt_server/wins
parentd49e67f06f55054f23dbef609b4debb11c157ffa (diff)
downloadsamba-bab5662021721794c4ac9abe3373d50a2b96b1d5.tar.gz
samba-bab5662021721794c4ac9abe3373d50a2b96b1d5.tar.bz2
samba-bab5662021721794c4ac9abe3373d50a2b96b1d5.zip
r11022: r10309@SERNOX: metze | 2005-09-19 11:08:37 +0200
- add winsdb_connect() function, so that the winsdb can be opened by the wrepl_server/ code - remove maintaining of a min_version field, as it was implemented incorrect, and is maybe not needed at all - fix handling of max_version, (we started with 0, on each server start) metze (This used to be commit e6106e21a0b097ec45948a08f499e44d32db8d2a)
Diffstat (limited to 'source4/nbt_server/wins')
-rw-r--r--source4/nbt_server/wins/winsdb.c53
-rw-r--r--source4/nbt_server/wins/winsdb.h5
-rw-r--r--source4/nbt_server/wins/winsserver.c11
3 files changed, 36 insertions, 33 deletions
diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c
index e719ef0968..a3199155ab 100644
--- a/source4/nbt_server/wins/winsdb.c
+++ b/source4/nbt_server/wins/winsdb.c
@@ -29,37 +29,51 @@
#include "system/time.h"
/*
- save the min/max version IDs for the database
+ return the new maxVersion and save it
*/
-static BOOL winsdb_save_version(struct wins_server *winssrv)
+static uint64_t winsdb_allocate_version(struct wins_server *winssrv)
{
- int i, ret = 0;
+ int ret;
struct ldb_context *ldb = winssrv->wins_db;
- struct ldb_message *msg = ldb_msg_new(winssrv);
- if (msg == NULL) goto failed;
+ struct ldb_dn *dn;
+ struct ldb_message **res = NULL;
+ struct ldb_message *msg = NULL;
+ TALLOC_CTX *tmp_ctx = talloc_new(winssrv);
+ uint64_t maxVersion = 0;
- msg->dn = ldb_dn_explode(msg, "CN=VERSION");
- if (msg->dn == NULL) goto failed;
+ dn = ldb_dn_explode(tmp_ctx, "CN=VERSION");
+ if (!dn) goto failed;
ret |= ldb_msg_add_string(msg, "objectClass", "winsEntry");
ret |= ldb_msg_add_fmt(msg, "minVersion", "%llu", winssrv->min_version);
ret |= ldb_msg_add_fmt(msg, "maxVersion", "%llu", winssrv->max_version);
if (ret != 0) goto failed;
- for (i=0;i<msg->num_elements;i++) {
- msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
+ if (ret == 1) {
+ maxVersion = ldb_msg_find_uint64(res[0], "maxVersion", 0);
}
+ maxVersion++;
+
+ msg = ldb_msg_new(tmp_ctx);
+ if (!msg) goto failed;
+ msg->dn = dn;
+
+
+ ret = ldb_msg_add_empty(ldb, msg, "maxVersion", LDB_FLAG_MOD_REPLACE);
+ if (ret != 0) goto failed;
+ ret = ldb_msg_add_fmt(ldb, msg, "maxVersion", "%llu", maxVersion);
+ if (ret != 0) goto failed;
ret = ldb_modify(ldb, msg);
if (ret != 0) ret = ldb_add(ldb, msg);
if (ret != 0) goto failed;
- talloc_free(msg);
- return True;
+ talloc_free(tmp_ctx);
+ return maxVersion;
failed:
- talloc_free(msg);
- return False;
+ talloc_free(tmp_ctx);
+ return 0;
}
/*
@@ -312,16 +326,7 @@ failed:
return NBT_RCODE_SVR;
}
-
-/*
- connect to the WINS database
-*/
-NTSTATUS winsdb_init(struct wins_server *winssrv)
+struct ldb_context *winsdb_connect(TALLOC_CTX *mem_ctx)
{
- winssrv->wins_db = ldb_wrap_connect(winssrv, lp_wins_url(), 0, NULL);
- if (winssrv->wins_db == NULL) {
- return NT_STATUS_INTERNAL_DB_ERROR;
- }
-
- return NT_STATUS_OK;
+ return ldb_wrap_connect(mem_ctx, lp_wins_url(), 0, NULL);
}
diff --git a/source4/nbt_server/wins/winsdb.h b/source4/nbt_server/wins/winsdb.h
index 454bef3e3b..c6e3ac4c5c 100644
--- a/source4/nbt_server/wins/winsdb.h
+++ b/source4/nbt_server/wins/winsdb.h
@@ -44,9 +44,4 @@ struct wins_server {
uint32_t min_ttl;
uint32_t max_ttl;
-
- /* these are the minimum and maximum record version IDs in the
- database. They are needed for replication */
- uint64_t min_version;
- uint64_t max_version;
};
diff --git a/source4/nbt_server/wins/winsserver.c b/source4/nbt_server/wins/winsserver.c
index c9758b3162..a2f7fccad5 100644
--- a/source4/nbt_server/wins/winsserver.c
+++ b/source4/nbt_server/wins/winsserver.c
@@ -274,15 +274,18 @@ NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv)
return NT_STATUS_OK;
}
- nbtsrv->winssrv = talloc(nbtsrv, struct wins_server);
+ nbtsrv->winssrv = talloc_zero(nbtsrv, struct wins_server);
NT_STATUS_HAVE_NO_MEMORY(nbtsrv->winssrv);
nbtsrv->winssrv->max_ttl = lp_max_wins_ttl();
nbtsrv->winssrv->min_ttl = lp_min_wins_ttl();
- nbtsrv->winssrv->min_version = 0;
- nbtsrv->winssrv->max_version = 0;
+
+ nbtsrv->winssrv->wins_db = winsdb_connect(nbtsrv->winssrv);
+ if (!nbtsrv->winssrv->wins_db) {
+ return NT_STATUS_INTERNAL_DB_ERROR;
+ }
irpc_add_name(nbtsrv->task->msg_ctx, "wins_server");
- return winsdb_init(nbtsrv->winssrv);
+ return NT_STATUS_OK;
}