summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-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++) {