1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-03 12:58:35 +03:00

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)
This commit is contained in:
Stefan Metzmacher 2005-10-14 12:47:57 +00:00 committed by Gerald (Jerry) Carter
parent d49e67f06f
commit bab5662021
3 changed files with 36 additions and 33 deletions

View File

@ -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);
}

View File

@ -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;
};

View File

@ -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;
}