From 0391b1cb3a1527aed5beefbdda67a6ce5062bbab Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 30 Dec 2005 20:08:52 +0000 Subject: r12617: create a winsdb_handle and pass that arround, so we later can hang the local owner address, on this handle too metze (This used to be commit 49ba4cc11144671cafcbe2967954bfd786ea6e76) --- source4/nbt_server/config.mk | 1 + source4/nbt_server/wins/winsdb.c | 36 ++++++++++++++++++++++++--------- source4/nbt_server/wins/winsdb.h | 9 ++++++++- source4/wrepl_server/wrepl_in_call.c | 2 +- source4/wrepl_server/wrepl_scavenging.c | 6 +++--- source4/wrepl_server/wrepl_server.c | 5 +++-- source4/wrepl_server/wrepl_server.h | 2 +- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/source4/nbt_server/config.mk b/source4/nbt_server/config.mk index a8aab7b2ad..60c338d0fc 100644 --- a/source4/nbt_server/config.mk +++ b/source4/nbt_server/config.mk @@ -5,6 +5,7 @@ [SUBSYSTEM::WINSDB] OBJ_FILES = \ wins/winsdb.o +PRIVATE_PROTO_HEADER = wins/winsdb_proto.h REQUIRED_SUBSYSTEMS = \ LIBLDB # End SUBSYSTEM WINSDB diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c index 5fcad32903..42a6f19d84 100644 --- a/source4/nbt_server/wins/winsdb.c +++ b/source4/nbt_server/wins/winsdb.c @@ -32,13 +32,14 @@ /* return the new maxVersion and save it */ -static uint64_t winsdb_allocate_version(struct ldb_context *wins_db) +static uint64_t winsdb_allocate_version(struct winsdb_handle *h) { int trans; int ret; struct ldb_dn *dn; struct ldb_result *res = NULL; struct ldb_message *msg = NULL; + struct ldb_context *wins_db = h->ldb; TALLOC_CTX *tmp_ctx = talloc_new(wins_db); uint64_t maxVersion = 0; @@ -366,7 +367,7 @@ const char **winsdb_addr_string_list(TALLOC_CTX *mem_ctx, struct winsdb_addr **a /* load a WINS entry from the database */ -NTSTATUS winsdb_lookup(struct ldb_context *wins_db, +NTSTATUS winsdb_lookup(struct winsdb_handle *h, struct nbt_name *name, TALLOC_CTX *mem_ctx, struct winsdb_record **_rec) @@ -375,6 +376,7 @@ NTSTATUS winsdb_lookup(struct ldb_context *wins_db, struct ldb_result *res = NULL; int ret; struct winsdb_record *rec; + struct ldb_context *wins_db = h->ldb; TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); /* find the record in the WINS database */ @@ -578,9 +580,10 @@ failed: /* save a WINS record into the database */ -uint8_t winsdb_add(struct ldb_context *wins_db, struct winsdb_record *rec, uint32_t flags) +uint8_t winsdb_add(struct winsdb_handle *h, struct winsdb_record *rec, uint32_t flags) { struct ldb_message *msg; + struct ldb_context *wins_db = h->ldb; TALLOC_CTX *tmp_ctx = talloc_new(wins_db); int trans = -1; int ret = 0; @@ -589,7 +592,7 @@ uint8_t winsdb_add(struct ldb_context *wins_db, struct winsdb_record *rec, uint3 if (trans != LDB_SUCCESS) goto failed; if (flags & WINSDB_FLAG_ALLOC_VERSION) { - rec->version = winsdb_allocate_version(wins_db); + rec->version = winsdb_allocate_version(h); if (rec->version == 0) goto failed; } if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) { @@ -617,9 +620,10 @@ failed: /* modify a WINS record in the database */ -uint8_t winsdb_modify(struct ldb_context *wins_db, struct winsdb_record *rec, uint32_t flags) +uint8_t winsdb_modify(struct winsdb_handle *h, struct winsdb_record *rec, uint32_t flags) { struct ldb_message *msg; + struct ldb_context *wins_db = h->ldb; TALLOC_CTX *tmp_ctx = talloc_new(wins_db); int trans; int ret; @@ -629,7 +633,7 @@ uint8_t winsdb_modify(struct ldb_context *wins_db, struct winsdb_record *rec, ui if (trans != LDB_SUCCESS) goto failed; if (flags & WINSDB_FLAG_ALLOC_VERSION) { - rec->version = winsdb_allocate_version(wins_db); + rec->version = winsdb_allocate_version(h); if (rec->version == 0) goto failed; } if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) { @@ -662,8 +666,9 @@ failed: /* delete a WINS record from the database */ -uint8_t winsdb_delete(struct ldb_context *wins_db, struct winsdb_record *rec) +uint8_t winsdb_delete(struct winsdb_handle *h, struct winsdb_record *rec) { + struct ldb_context *wins_db = h->ldb; TALLOC_CTX *tmp_ctx = talloc_new(wins_db); const struct ldb_dn *dn; int trans; @@ -690,8 +695,19 @@ failed: return NBT_RCODE_SVR; } -struct ldb_context *winsdb_connect(TALLOC_CTX *mem_ctx) +struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx) { - return ldb_wrap_connect(mem_ctx, lock_path(mem_ctx, lp_wins_url()), - system_session(mem_ctx), NULL, 0, NULL); + struct winsdb_handle *h = NULL; + + h = talloc(mem_ctx, struct winsdb_handle); + if (!h) return NULL; + + h->ldb = ldb_wrap_connect(h, lock_path(h, lp_wins_url()), + system_session(h), NULL, 0, NULL); + if (!h->ldb) goto failed; + + return h; +failed: + talloc_free(h); + return NULL; } diff --git a/source4/nbt_server/wins/winsdb.h b/source4/nbt_server/wins/winsdb.h index 2cf3b56c74..f890a10148 100644 --- a/source4/nbt_server/wins/winsdb.h +++ b/source4/nbt_server/wins/winsdb.h @@ -50,9 +50,14 @@ struct winsdb_record { const char *registered_by; }; +struct winsdb_handle { + /* wins server database handle */ + struct ldb_context *ldb; +}; + struct wins_server { /* wins server database handle */ - struct ldb_context *wins_db; + struct winsdb_handle *wins_db; /* some configuration */ struct { @@ -70,3 +75,5 @@ struct wins_server { uint32_t tombstone_interval; } config; }; + +#include "nbt_server/wins/winsdb_proto.h" diff --git a/source4/wrepl_server/wrepl_in_call.c b/source4/wrepl_server/wrepl_in_call.c index ebcd4f5d83..a2637d1b39 100644 --- a/source4/wrepl_server/wrepl_in_call.c +++ b/source4/wrepl_server/wrepl_in_call.c @@ -244,7 +244,7 @@ static NTSTATUS wreplsrv_in_send_request(struct wreplsrv_in_call *call) (long long)owner_in->min_version, (long long)owner_in->max_version); NT_STATUS_HAVE_NO_MEMORY(filter); - ret = ldb_search(service->wins_db, 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; talloc_steal(call, res); if (res->count == 0) { diff --git a/source4/wrepl_server/wrepl_scavenging.c b/source4/wrepl_server/wrepl_scavenging.c index e450b66ed8..bc25354e3c 100644 --- a/source4/wrepl_server/wrepl_scavenging.c +++ b/source4/wrepl_server/wrepl_scavenging.c @@ -53,7 +53,7 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi "(expireTime<=%s)(!(isStatic=1)))", WINSDB_OWNER_LOCAL, now_timestr); NT_STATUS_HAVE_NO_MEMORY(filter); - ret = ldb_search(service->wins_db, 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; talloc_steal(tmp_mem, res); @@ -161,7 +161,7 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s "(!(recordState=%u))(expireTime<=%s)(!(isStatic=1)))", WINSDB_OWNER_LOCAL, WREPL_STATE_ACTIVE, now_timestr); NT_STATUS_HAVE_NO_MEMORY(filter); - ret = ldb_search(service->wins_db, 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; talloc_steal(tmp_mem, res); @@ -264,7 +264,7 @@ static NTSTATUS wreplsrv_scavenging_replica_active_records(struct wreplsrv_servi "(recordState=%u)(expireTime<=%s)(!(isStatic=1)))", WINSDB_OWNER_LOCAL, WREPL_STATE_ACTIVE, now_timestr); NT_STATUS_HAVE_NO_MEMORY(filter); - ret = ldb_search(service->wins_db, 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; talloc_steal(tmp_mem, res); diff --git a/source4/wrepl_server/wrepl_server.c b/source4/wrepl_server/wrepl_server.c index 5f182cd513..2682ca6721 100644 --- a/source4/wrepl_server/wrepl_server.c +++ b/source4/wrepl_server/wrepl_server.c @@ -172,7 +172,7 @@ BOOL wreplsrv_is_our_address(struct wreplsrv_service *service, const char *addre uint64_t wreplsrv_local_max_version(struct wreplsrv_service *service) { int ret; - struct ldb_context *ldb = service->wins_db; + struct ldb_context *ldb = service->wins_db->ldb; struct ldb_dn *dn; struct ldb_result *res = NULL; TALLOC_CTX *tmp_ctx = talloc_new(service); @@ -306,6 +306,7 @@ static NTSTATUS wreplsrv_load_table(struct wreplsrv_service *service) int ret; NTSTATUS status; TALLOC_CTX *tmp_ctx = talloc_new(service); + struct ldb_context *ldb = service->wins_db->ldb; int i; const char *wins_owner; uint64_t version; @@ -316,7 +317,7 @@ static NTSTATUS wreplsrv_load_table(struct wreplsrv_service *service) }; /* find the record in the WINS database */ - ret = ldb_search(service->wins_db, NULL, LDB_SCOPE_SUBTREE, + ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, "(objectClass=winsRecord)", attrs, &res); status = NT_STATUS_INTERNAL_DB_CORRUPTION; if (ret != LDB_SUCCESS) goto failed; diff --git a/source4/wrepl_server/wrepl_server.h b/source4/wrepl_server/wrepl_server.h index fabba09389..48378fe152 100644 --- a/source4/wrepl_server/wrepl_server.h +++ b/source4/wrepl_server/wrepl_server.h @@ -213,7 +213,7 @@ struct wreplsrv_service { struct timeval startup_time; /* the winsdb handle */ - struct ldb_context *wins_db; + struct winsdb_handle *wins_db; /* some configuration */ struct { -- cgit