summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-10-14 12:53:50 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:42:33 -0500
commite148b33f4b006f1c075cb88232cb42571d685f3d (patch)
treebdda21030677cdddb50ec5182a7f5c9417f8ae44
parent8bb5bcb6745661692f1116da67368a58910ce111 (diff)
downloadsamba-e148b33f4b006f1c075cb88232cb42571d685f3d.tar.gz
samba-e148b33f4b006f1c075cb88232cb42571d685f3d.tar.bz2
samba-e148b33f4b006f1c075cb88232cb42571d685f3d.zip
r11034: r10344@SERNOX: metze | 2005-09-20 11:35:54 +0200
create winsdb_record() and winsdb_message() as public functions so that they can be used in the wrepl_server/ metze (This used to be commit b8b48c8aa5f741ad020d0a4debac665f8b2953ab)
-rw-r--r--source4/include/structs.h2
-rw-r--r--source4/nbt_server/wins/winsdb.c55
2 files changed, 36 insertions, 21 deletions
diff --git a/source4/include/structs.h b/source4/include/structs.h
index faa2637f6f..a037168da1 100644
--- a/source4/include/structs.h
+++ b/source4/include/structs.h
@@ -276,6 +276,8 @@ struct wreplsrv_service;
struct wreplsrv_in_connection;
struct wreplsrv_in_call;
+struct winsdb_record;
+
struct wrepl_packet;
struct wrepl_associate;
struct wrepl_associate_stop;
diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c
index 7633a70143..0b7d16b532 100644
--- a/source4/nbt_server/wins/winsdb.c
+++ b/source4/nbt_server/wins/winsdb.c
@@ -401,9 +401,7 @@ struct winsdb_record *winsdb_load(struct wins_server *winssrv,
struct ldb_message **res = NULL;
int ret;
struct winsdb_record *rec;
- struct ldb_message_element *el;
TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
- int i;
/* find the record in the WINS database */
ret = ldb_search(winssrv->wins_db, winsdb_dn(tmp_ctx, name), LDB_SCOPE_BASE,
@@ -413,7 +411,34 @@ struct winsdb_record *winsdb_load(struct wins_server *winssrv,
}
if (ret != 1) goto failed;
- rec = talloc(tmp_ctx, struct winsdb_record);
+ rec = winsdb_record(res[0], tmp_ctx);
+ if (rec == NULL) goto failed;
+ rec->name = name;
+
+ /* see if it has already expired */
+ if (rec->state == WINS_REC_ACTIVE &&
+ rec->expire_time <= time(NULL)) {
+ DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
+ nbt_name_string(tmp_ctx, rec->name), timestring(tmp_ctx, rec->expire_time)));
+ rec->state = WINS_REC_RELEASED;
+ }
+
+ talloc_steal(mem_ctx, rec);
+ talloc_free(tmp_ctx);
+ return rec;
+
+failed:
+ talloc_free(tmp_ctx);
+ return NULL;
+}
+
+struct winsdb_record *winsdb_record(struct ldb_message *msg, TALLOC_CTX *mem_ctx)
+{
+ struct winsdb_record *rec;
+ struct ldb_message_element *el;
+ uint32_t i;
+
+ rec = talloc(mem_ctx, struct winsdb_record);
if (rec == NULL) goto failed;
/* parse it into a more convenient winsdb_record structure */
@@ -428,7 +453,7 @@ struct winsdb_record *winsdb_load(struct wins_server *winssrv,
if (!rec->wins_owner) rec->wins_owner = WINSDB_OWNER_LOCAL;
- el = ldb_msg_find_element(res[0], "address");
+ el = ldb_msg_find_element(msg, "address");
if (el == NULL) goto failed;
rec->addresses = talloc_array(rec, struct winsdb_addr *, el->num_values+1);
@@ -440,29 +465,17 @@ struct winsdb_record *winsdb_load(struct wins_server *winssrv,
}
rec->addresses[i] = NULL;
- /* see if it has already expired */
- if (rec->state == WINS_REC_ACTIVE &&
- rec->expire_time <= time(NULL)) {
- DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
- nbt_name_string(tmp_ctx, rec->name), timestring(tmp_ctx, rec->expire_time)));
- rec->state = WINS_REC_RELEASED;
- }
-
- talloc_steal(mem_ctx, rec);
- talloc_free(tmp_ctx);
return rec;
-
failed:
- talloc_free(tmp_ctx);
+ talloc_free(rec);
return NULL;
}
-
/*
form a ldb_message from a winsdb_record
*/
-static struct ldb_message *winsdb_message(struct wins_server *winssrv,
- struct winsdb_record *rec, TALLOC_CTX *mem_ctx)
+struct ldb_message *winsdb_message(struct ldb_context *ldb,
+ struct winsdb_record *rec, TALLOC_CTX *mem_ctx)
{
int i, ret=0;
struct ldb_message *msg = ldb_msg_new(mem_ctx);
@@ -506,7 +519,7 @@ uint8_t winsdb_add(struct wins_server *winssrv, struct winsdb_record *rec)
rec->version = winsdb_allocate_version(winssrv);
if (rec->version == 0) goto failed;
- msg = winsdb_message(winssrv, rec, tmp_ctx);
+ msg = winsdb_message(winssrv->wins_db, rec, tmp_ctx);
if (msg == NULL) goto failed;
ret = ldb_add(ldb, msg);
if (ret != 0) goto failed;
@@ -543,7 +556,7 @@ uint8_t winsdb_modify(struct wins_server *winssrv, struct winsdb_record *rec)
if (rec->version == 0) goto failed;
rec->wins_owner = WINSDB_OWNER_LOCAL;
- msg = winsdb_message(winssrv, rec, tmp_ctx);
+ msg = winsdb_message(winssrv->wins_db, rec, tmp_ctx);
if (msg == NULL) goto failed;
for (i=0;i<msg->num_elements;i++) {