summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-10-14 12:51:36 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:42:31 -0500
commita76ffb574c3b8885892b62f093786c8b52127054 (patch)
treed55bd4ab941b448918bc1cd5fc490cd827e80820
parent6f0f39cab1e39467bd02ebc04cab24bea5feef33 (diff)
downloadsamba-a76ffb574c3b8885892b62f093786c8b52127054.tar.gz
samba-a76ffb574c3b8885892b62f093786c8b52127054.tar.bz2
samba-a76ffb574c3b8885892b62f093786c8b52127054.zip
r11029:
(This used to be commit 49e61d011c702ae51982d45025ad35e44a6c39d6)
-rw-r--r--source4/nbt_server/wins/winsdb.c112
1 files changed, 96 insertions, 16 deletions
diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c
index ff6dc70226..7633a70143 100644
--- a/source4/nbt_server/wins/winsdb.c
+++ b/source4/nbt_server/wins/winsdb.c
@@ -77,19 +77,27 @@ failed:
}
/*
- allocate a new version id for a record
+ return a DN for a nbt_name
*/
-static uint64_t winsdb_allocate_version(struct wins_server *winssrv)
+static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct nbt_name *name)
{
- winssrv->max_version++;
- if (!winsdb_save_version(winssrv)) {
- return 0;
+ struct ldb_dn *dn;
+
+ dn = ldb_dn_string_compose(mem_ctx, NULL, "type=%02x", name->type);
+ if (dn && name->name && *name->name) {
+ dn = ldb_dn_string_compose(mem_ctx, dn, "name=%s", name->name);
+ }
+ if (dn && name->scope && *name->scope) {
+ dn = ldb_dn_string_compose(mem_ctx, dn, "scope=%s", name->scope);
}
- return winssrv->max_version;
+ return dn;
}
/*
- remove a version id
+ decode the winsdb_addr("address") attribute:
+ "172.31.1.1" or
+ "172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z"
+ are valid records
*/
static BOOL winsdb_remove_version(struct wins_server *winssrv, uint64_t version)
{
@@ -101,22 +109,94 @@ static BOOL winsdb_remove_version(struct wins_server *winssrv, uint64_t version)
return True;
}
-
/*
- return a DN for a nbt_name
+ encode the winsdb_addr("address") attribute like this:
+ "172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z"
*/
-static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct nbt_name *name)
+static int ldb_msg_add_winsdb_addr(struct ldb_context *ldb, struct ldb_message *msg,
+ const char *attr_name, struct winsdb_addr *addr)
{
- struct ldb_dn *dn;
+ struct ldb_val val;
+ const char *str;
dn = ldb_dn_string_compose(mem_ctx, NULL, "type=%02x", name->type);
- if (dn && name->name && *name->name) {
- dn = ldb_dn_string_compose(mem_ctx, dn, "name=%s", name->name);
+
+ addresses[len]->address = talloc_strdup(addresses[len], address);
+ if (!addresses[len]->address) {
+ talloc_free(addresses);
+ return NULL;
}
- if (dn && name->scope && *name->scope) {
- dn = ldb_dn_string_compose(mem_ctx, dn, "scope=%s", name->scope);
+
+ addresses[len]->wins_owner = talloc_strdup(addresses[len], wins_owner);
+ if (!addresses[len]->wins_owner) {
+ talloc_free(addresses);
+ return NULL;
}
- return dn;
+
+ addresses[len]->expire_time = expire_time;
+
+ addresses[len+1] = NULL;
+
+ return addresses;
+}
+
+void winsdb_addr_list_remove(struct winsdb_addr **addresses, const char *address)
+{
+ size_t i;
+
+ for (i=0; addresses[i]; i++) {
+ if (strcmp(addresses[i]->address, address) == 0) {
+ break;
+ }
+ }
+ if (!addresses[i]) return;
+
+ for (; addresses[i]; i++) {
+ addresses[i] = addresses[i+1];
+ }
+
+ return;
+}
+
+struct winsdb_addr *winsdb_addr_list_check(struct winsdb_addr **addresses, const char *address)
+{
+ size_t i;
+
+ for (i=0; addresses[i]; i++) {
+ if (strcmp(addresses[i]->address, address) == 0) {
+ return addresses[i];
+ }
+ }
+
+ return NULL;
+}
+
+size_t winsdb_addr_list_length(struct winsdb_addr **addresses)
+{
+ size_t i;
+ for (i=0; addresses[i]; i++);
+ return i;
+}
+
+const char **winsdb_addr_string_list(TALLOC_CTX *mem_ctx, struct winsdb_addr **addresses)
+{
+ size_t len = winsdb_addr_list_length(addresses);
+ const char **str_list;
+ size_t i;
+
+ str_list = talloc_array(mem_ctx, const char *, len + 1);
+ if (!str_list) return NULL;
+
+ for (i=0; i < len; i++) {
+ str_list[i] = talloc_strdup(str_list, addresses[i]->address);
+ if (!str_list[i]) {
+ talloc_free(str_list);
+ return NULL;
+ }
+ }
+
+ str_list[len] = NULL;
+ return str_list;
}
/*