r12217: add my copyright
[kai/samba-autobuild/.git] / source4 / nbt_server / wins / winsdb.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    WINS database routines
5
6    Copyright (C) Andrew Tridgell        2005
7    Copyright (C) Stefan Metzmacher      2005
8       
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25 #include "nbt_server/nbt_server.h"
26 #include "nbt_server/wins/winsdb.h"
27 #include "lib/ldb/include/ldb.h"
28 #include "lib/ldb/include/ldb_errors.h"
29 #include "db_wrap.h"
30 #include "system/time.h"
31
32 /*
33   return the new maxVersion and save it
34 */
35 static uint64_t winsdb_allocate_version(struct ldb_context *wins_db)
36 {
37         int trans;
38         int ret;
39         struct ldb_dn *dn;
40         struct ldb_result *res = NULL;
41         struct ldb_message *msg = NULL;
42         TALLOC_CTX *tmp_ctx = talloc_new(wins_db);
43         uint64_t maxVersion = 0;
44
45         trans = ldb_transaction_start(wins_db);
46         if (trans != LDB_SUCCESS) goto failed;
47
48         dn = ldb_dn_explode(tmp_ctx, "CN=VERSION");
49         if (!dn) goto failed;
50
51         /* find the record in the WINS database */
52         ret = ldb_search(wins_db, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
53
54         if (ret != LDB_SUCCESS) goto failed;
55         if (res->count > 1) goto failed;
56
57         talloc_steal(tmp_ctx, res);
58
59         if (res->count == 1) {
60                 maxVersion = ldb_msg_find_uint64(res->msgs[0], "maxVersion", 0);
61         }
62         maxVersion++;
63
64         msg = ldb_msg_new(tmp_ctx);
65         if (!msg) goto failed;
66         msg->dn = dn;
67
68
69         ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE);
70         if (ret != 0) goto failed;
71         ret = ldb_msg_add_string(msg, "objectClass", "winsMaxVersion");
72         if (ret != 0) goto failed;
73         ret = ldb_msg_add_empty(msg, "maxVersion", LDB_FLAG_MOD_REPLACE);
74         if (ret != 0) goto failed;
75         ret = ldb_msg_add_fmt(msg, "maxVersion", "%llu", (long long)maxVersion);
76         if (ret != 0) goto failed;
77
78         ret = ldb_modify(wins_db, msg);
79         if (ret != 0) ret = ldb_add(wins_db, msg);
80         if (ret != 0) goto failed;
81
82         trans = ldb_transaction_commit(wins_db);
83         if (trans != LDB_SUCCESS) goto failed;
84
85         talloc_free(tmp_ctx);
86         return maxVersion;
87
88 failed:
89         if (trans == LDB_SUCCESS) ldb_transaction_cancel(wins_db);
90         talloc_free(tmp_ctx);
91         return 0;
92 }
93
94 /*
95   return a DN for a nbt_name
96 */
97 static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct nbt_name *name)
98 {
99         struct ldb_dn *dn;
100
101         dn = ldb_dn_string_compose(mem_ctx, NULL, "type=0x%02X", name->type);
102         if (dn && name->name && *name->name) {
103                 dn = ldb_dn_string_compose(mem_ctx, dn, "name=%s", name->name);
104         }
105         if (dn && name->scope && *name->scope) {
106                 dn = ldb_dn_string_compose(mem_ctx, dn, "scope=%s", name->scope);
107         }
108         return dn;
109 }
110
111 static NTSTATUS winsdb_nbt_name(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct nbt_name **_name)
112 {
113         NTSTATUS status;
114         struct nbt_name *name;
115         uint32_t cur = 0;
116
117         name = talloc(mem_ctx, struct nbt_name);
118         if (!name) {
119                 status = NT_STATUS_NO_MEMORY;
120                 goto failed;
121         }
122
123         if (dn->comp_num > 3) {
124                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
125                 goto failed;
126         }
127
128         if (dn->comp_num > cur && strcasecmp("scope", dn->components[cur].name) == 0) {
129                 name->scope     = talloc_steal(name, dn->components[cur].value.data);
130                 cur++;
131         } else {
132                 name->scope     = NULL;
133         }
134
135         if (dn->comp_num > cur && strcasecmp("name", dn->components[cur].name) == 0) {
136                 name->name      = talloc_steal(name, dn->components[cur].value.data);
137                 cur++;
138         } else {
139                 name->name      = talloc_strdup(name, "");
140                 if (!name->name) {
141                         status = NT_STATUS_NO_MEMORY;
142                         goto failed;
143                 }
144         }
145
146         if (dn->comp_num > cur && strcasecmp("type", dn->components[cur].name) == 0) {
147                 name->type      = strtoul((char *)dn->components[cur].value.data, NULL, 0);
148                 cur++;
149         } else {
150                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
151                 goto failed;
152         }
153
154         *_name = name;
155         return NT_STATUS_OK;
156 failed:
157         talloc_free(name);
158         return status;
159 }
160
161 /*
162  decode the winsdb_addr("address") attribute:
163  "172.31.1.1" or 
164  "172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z;"
165  are valid records
166 */
167 static NTSTATUS winsdb_addr_decode(struct winsdb_record *rec, struct ldb_val *val,
168                                    TALLOC_CTX *mem_ctx, struct winsdb_addr **_addr)
169 {
170         NTSTATUS status;
171         struct winsdb_addr *addr;
172         char *address;
173         char *wins_owner;
174         char *expire_time;
175         char *p;
176
177         addr = talloc(mem_ctx, struct winsdb_addr);
178         if (!addr) {
179                 status = NT_STATUS_NO_MEMORY;
180                 goto failed;
181         }
182
183         address = (char *)val->data;
184
185         p = strchr(address, ';');
186         if (!p) {
187                 /* support old entries, with only the address */
188                 addr->address           = talloc_steal(addr, val->data);
189                 addr->wins_owner        = talloc_reference(addr, rec->wins_owner);
190                 if (!addr->wins_owner) {
191                         status = NT_STATUS_NO_MEMORY;
192                         goto failed;
193                 }
194                 addr->expire_time       = rec->expire_time;
195                 *_addr = addr;
196                 return NT_STATUS_OK;
197         }
198
199         *p = '\0';p++;
200         addr->address = talloc_strdup(addr, address);
201         if (!addr->address) {
202                 status = NT_STATUS_NO_MEMORY;
203                 goto failed;
204         }
205
206         if (strncmp("winsOwner:", p, 10) != 0) {
207                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
208                 goto failed;
209         }
210         wins_owner = p + 10;
211         p = strchr(wins_owner, ';');
212         if (!p) {
213                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
214                 goto failed;
215         }
216
217         *p = '\0';p++;
218         addr->wins_owner = talloc_strdup(addr, wins_owner);
219         if (!addr->wins_owner) {
220                 status = NT_STATUS_NO_MEMORY;
221                 goto failed;
222         }
223
224         if (strncmp("expireTime:", p, 11) != 0) {
225                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
226                 goto failed;
227         }
228
229         expire_time = p + 11;
230         p = strchr(expire_time, ';');
231         if (!p) {
232                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
233                 goto failed;
234         }
235
236         *p = '\0';p++;
237         addr->expire_time = ldb_string_to_time(expire_time);
238
239         *_addr = addr;
240         return NT_STATUS_OK;
241 failed:
242         talloc_free(addr);
243         return status;
244 }
245
246 /*
247  encode the winsdb_addr("address") attribute like this:
248  "172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z;"
249 */
250 static int ldb_msg_add_winsdb_addr(struct ldb_message *msg, 
251                                    const char *attr_name, struct winsdb_addr *addr)
252 {
253         struct ldb_val val;
254         const char *str;
255
256         str = talloc_asprintf(msg, "%s;winsOwner:%s;expireTime:%s;",
257                               addr->address, addr->wins_owner,
258                               ldb_timestring(msg, addr->expire_time));
259         if (!str) return -1;
260
261         val.data = discard_const_p(uint8_t, str);
262         val.length = strlen(str);
263
264         return ldb_msg_add_value(msg, attr_name, &val);
265 }
266
267 struct winsdb_addr **winsdb_addr_list_make(TALLOC_CTX *mem_ctx)
268 {
269         struct winsdb_addr **addresses;
270
271         addresses = talloc_array(mem_ctx, struct winsdb_addr *, 1);
272         if (!addresses) return NULL;
273
274         addresses[0] = NULL;
275
276         return addresses;
277 }
278
279 struct winsdb_addr **winsdb_addr_list_add(struct winsdb_addr **addresses, const char *address,
280                                           const char *wins_owner, time_t expire_time)
281 {
282         size_t len = winsdb_addr_list_length(addresses);
283
284         addresses = talloc_realloc(addresses, addresses, struct winsdb_addr *, len + 2);
285         if (!addresses) return NULL;
286
287         addresses[len] = talloc(addresses, struct winsdb_addr);
288         if (!addresses[len]) {
289                 talloc_free(addresses);
290                 return NULL;
291         }
292
293         addresses[len]->address = talloc_strdup(addresses[len], address);
294         if (!addresses[len]->address) {
295                 talloc_free(addresses);
296                 return NULL;
297         }
298
299         addresses[len]->wins_owner = talloc_strdup(addresses[len], wins_owner);
300         if (!addresses[len]->wins_owner) {
301                 talloc_free(addresses);
302                 return NULL;
303         }
304
305         addresses[len]->expire_time = expire_time;
306
307         addresses[len+1] = NULL;
308
309         return addresses;
310 }
311
312 void winsdb_addr_list_remove(struct winsdb_addr **addresses, const char *address)
313 {
314         size_t i;
315
316         for (i=0; addresses[i]; i++) {
317                 if (strcmp(addresses[i]->address, address) == 0) {
318                         break;
319                 }
320         }
321         if (!addresses[i]) return;
322
323         for (; addresses[i]; i++) {
324                 addresses[i] = addresses[i+1];
325         }
326
327         return;
328 }
329
330 struct winsdb_addr *winsdb_addr_list_check(struct winsdb_addr **addresses, const char *address)
331 {
332         size_t i;
333
334         for (i=0; addresses[i]; i++) {
335                 if (strcmp(addresses[i]->address, address) == 0) {
336                         return addresses[i];
337                 }
338         }
339
340         return NULL;
341 }
342
343 size_t winsdb_addr_list_length(struct winsdb_addr **addresses)
344 {
345         size_t i;
346         for (i=0; addresses[i]; i++);
347         return i;
348 }
349
350 const char **winsdb_addr_string_list(TALLOC_CTX *mem_ctx, struct winsdb_addr **addresses)
351 {
352         size_t len = winsdb_addr_list_length(addresses);
353         const char **str_list;
354         size_t i;
355
356         str_list = talloc_array(mem_ctx, const char *, len + 1);
357         if (!str_list) return NULL;
358
359         for (i=0; i < len; i++) {
360                 str_list[i] = talloc_strdup(str_list, addresses[i]->address);
361                 if (!str_list[i]) {
362                         talloc_free(str_list);
363                         return NULL;
364                 }
365         }
366
367         str_list[len] = NULL;
368         return str_list;
369 }
370
371 /*
372   load a WINS entry from the database
373 */
374 NTSTATUS winsdb_lookup(struct ldb_context *wins_db, 
375                        struct nbt_name *name,
376                        TALLOC_CTX *mem_ctx,
377                        struct winsdb_record **_rec)
378 {
379         NTSTATUS status;
380         struct ldb_result *res = NULL;
381         int ret;
382         struct winsdb_record *rec;
383         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
384
385         /* find the record in the WINS database */
386         ret = ldb_search(wins_db, winsdb_dn(tmp_ctx, name), LDB_SCOPE_BASE, 
387                          NULL, NULL, &res);
388
389         if (ret != LDB_SUCCESS || res->count > 1) {
390                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
391                 goto failed;
392         } else if (res->count== 0) {
393                 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
394                 goto failed;
395         }
396
397         talloc_steal(tmp_ctx, res);
398
399         status = winsdb_record(res->msgs[0], tmp_ctx, &rec);
400         if (!NT_STATUS_IS_OK(status)) goto failed;
401
402         /* see if it has already expired */
403         if (rec->state == WREPL_STATE_ACTIVE &&
404             rec->expire_time <= time(NULL)) {
405                 DEBUG(5,("WINS: expiring name %s (expired at %s)\n", 
406                          nbt_name_string(tmp_ctx, rec->name), timestring(tmp_ctx, rec->expire_time)));
407                 rec->state = WREPL_STATE_RELEASED;
408         }
409
410         talloc_steal(mem_ctx, rec);
411         talloc_free(tmp_ctx);
412         *_rec = rec;
413         return NT_STATUS_OK;
414
415 failed:
416         talloc_free(tmp_ctx);
417         return status;
418 }
419
420 NTSTATUS winsdb_record(struct ldb_message *msg, TALLOC_CTX *mem_ctx, struct winsdb_record **_rec)
421 {
422         NTSTATUS status;
423         struct winsdb_record *rec;
424         struct ldb_message_element *el;
425         struct nbt_name *name;
426         uint32_t i, num_values;
427
428         rec = talloc(mem_ctx, struct winsdb_record);
429         if (rec == NULL) {
430                 status = NT_STATUS_NO_MEMORY;
431                 goto failed;
432         }
433
434         status = winsdb_nbt_name(rec, msg->dn, &name);
435         if (!NT_STATUS_IS_OK(status)) goto failed;
436
437         if (strlen(name->name) > 15) {
438                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
439                 goto failed;
440         }
441         if (name->scope && strlen(name->scope) > 238) {
442                 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
443                 goto failed;
444         }
445
446         /* parse it into a more convenient winsdb_record structure */
447         rec->name               = name;
448         rec->type               = ldb_msg_find_int(msg, "recordType", WREPL_TYPE_UNIQUE);
449         rec->state              = ldb_msg_find_int(msg, "recordState", WREPL_STATE_RELEASED);
450         rec->node               = ldb_msg_find_int(msg, "nodeType", WREPL_NODE_B);
451         rec->is_static          = ldb_msg_find_int(msg, "isStatic", 0);
452         rec->expire_time        = ldb_string_to_time(ldb_msg_find_string(msg, "expireTime", NULL));
453         rec->version            = ldb_msg_find_uint64(msg, "versionID", 0);
454         rec->wins_owner         = ldb_msg_find_string(msg, "winsOwner", NULL);
455         rec->registered_by      = ldb_msg_find_string(msg, "registeredBy", NULL);
456         talloc_steal(rec, rec->wins_owner);
457         talloc_steal(rec, rec->registered_by);
458
459         if (!rec->wins_owner) {
460                 rec->wins_owner = talloc_strdup(rec, WINSDB_OWNER_LOCAL);
461                 if (rec->wins_owner == NULL) {
462                         status = NT_STATUS_NO_MEMORY;
463                         goto failed;
464                 }
465         }
466
467         el = ldb_msg_find_element(msg, "address");
468         if (el) {
469                 num_values = el->num_values;
470         } else {
471                 num_values = 0;
472         }
473
474         if (rec->type == WREPL_TYPE_UNIQUE || rec->type == WREPL_TYPE_GROUP) {
475                 if (num_values != 1) {
476                         status = NT_STATUS_INTERNAL_DB_CORRUPTION;
477                         goto failed;
478                 }
479         }
480         if (rec->state == WREPL_STATE_ACTIVE) {
481                 if (num_values < 1) {
482                         status = NT_STATUS_INTERNAL_DB_CORRUPTION;
483                         goto failed;
484                 }
485         }
486
487         rec->addresses     = talloc_array(rec, struct winsdb_addr *, num_values+1);
488         if (rec->addresses == NULL) {
489                 status = NT_STATUS_NO_MEMORY;
490                 goto failed;
491         }
492
493         for (i=0;i<num_values;i++) {
494                 status = winsdb_addr_decode(rec, &el->values[i], rec->addresses, &rec->addresses[i]);
495                 if (!NT_STATUS_IS_OK(status)) goto failed;
496         }
497         rec->addresses[i] = NULL;
498
499         *_rec = rec;
500         return NT_STATUS_OK;
501 failed:
502         if (NT_STATUS_EQUAL(NT_STATUS_INTERNAL_DB_CORRUPTION, status)) {
503                 DEBUG(1,("winsdb_record: corrupted record: %s\n", ldb_dn_linearize(rec, msg->dn)));
504         }
505         talloc_free(rec);
506         return status;
507 }
508
509 /*
510   form a ldb_message from a winsdb_record
511 */
512 struct ldb_message *winsdb_message(struct ldb_context *ldb, 
513                                    struct winsdb_record *rec, TALLOC_CTX *mem_ctx)
514 {
515         int i, ret=0;
516         size_t addr_count;
517         struct ldb_message *msg = ldb_msg_new(mem_ctx);
518         if (msg == NULL) goto failed;
519
520         /* make sure we don't put in corrupted records */
521         addr_count = winsdb_addr_list_length(rec->addresses);
522         if (rec->state == WREPL_STATE_ACTIVE && addr_count == 0) {
523                 rec->state = WREPL_STATE_RELEASED;
524         }
525         if (rec->type == WREPL_TYPE_UNIQUE && addr_count > 1) {
526                 rec->type = WREPL_TYPE_MHOMED;
527         }
528
529         msg->dn = winsdb_dn(msg, rec->name);
530         if (msg->dn == NULL) goto failed;
531         ret |= ldb_msg_add_fmt(msg, "type", "0x%02X", rec->name->type);
532         if (rec->name->name && *rec->name->name) {
533                 ret |= ldb_msg_add_string(msg, "name", rec->name->name);
534         }
535         if (rec->name->scope && *rec->name->scope) {
536                 ret |= ldb_msg_add_string(msg, "scope", rec->name->scope);
537         }
538         ret |= ldb_msg_add_fmt(msg, "objectClass", "winsRecord");
539         ret |= ldb_msg_add_fmt(msg, "recordType", "%u", rec->type);
540         ret |= ldb_msg_add_fmt(msg, "recordState", "%u", rec->state);
541         ret |= ldb_msg_add_fmt(msg, "nodeType", "%u", rec->node);
542         ret |= ldb_msg_add_fmt(msg, "isStatic", "%u", rec->is_static);
543         ret |= ldb_msg_add_string(msg, "expireTime", 
544                                   ldb_timestring(msg, rec->expire_time));
545         ret |= ldb_msg_add_fmt(msg, "versionID", "%llu", (long long)rec->version);
546         ret |= ldb_msg_add_string(msg, "winsOwner", rec->wins_owner);
547         ret |= ldb_msg_add_empty(msg, "address", 0);
548         for (i=0;rec->addresses[i];i++) {
549                 ret |= ldb_msg_add_winsdb_addr(msg, "address", rec->addresses[i]);
550         }
551         ret |= ldb_msg_add_empty(msg, "registeredBy", 0);
552         if (rec->registered_by) {
553                 ret |= ldb_msg_add_string(msg, "registeredBy", rec->registered_by);
554                 if (ret != 0) goto failed;
555         }
556         return msg;
557
558 failed:
559         talloc_free(msg);
560         return NULL;
561 }
562
563 /*
564   save a WINS record into the database
565 */
566 uint8_t winsdb_add(struct ldb_context *wins_db, struct winsdb_record *rec, uint32_t flags)
567 {
568         struct ldb_message *msg;
569         TALLOC_CTX *tmp_ctx = talloc_new(wins_db);
570         int trans = -1;
571         int ret = 0;
572
573         trans = ldb_transaction_start(wins_db);
574         if (trans != LDB_SUCCESS) goto failed;
575
576         if (flags & WINSDB_FLAG_ALLOC_VERSION) {
577                 rec->version = winsdb_allocate_version(wins_db);
578                 if (rec->version == 0) goto failed;
579         }
580         if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) {
581                 rec->wins_owner = WINSDB_OWNER_LOCAL;
582         }
583
584         msg = winsdb_message(wins_db, rec, tmp_ctx);
585         if (msg == NULL) goto failed;
586         ret = ldb_add(wins_db, msg);
587         if (ret != 0) goto failed;
588
589         trans = ldb_transaction_commit(wins_db);
590         if (trans != LDB_SUCCESS) goto failed;
591
592         talloc_free(tmp_ctx);
593         return NBT_RCODE_OK;
594
595 failed:
596         if (trans == LDB_SUCCESS) ldb_transaction_cancel(wins_db);
597         talloc_free(tmp_ctx);
598         return NBT_RCODE_SVR;
599 }
600
601
602 /*
603   modify a WINS record in the database
604 */
605 uint8_t winsdb_modify(struct ldb_context *wins_db, struct winsdb_record *rec, uint32_t flags)
606 {
607         struct ldb_message *msg;
608         TALLOC_CTX *tmp_ctx = talloc_new(wins_db);
609         int trans;
610         int ret;
611         int i;
612
613         trans = ldb_transaction_start(wins_db);
614         if (trans != LDB_SUCCESS) goto failed;
615
616         if (flags & WINSDB_FLAG_ALLOC_VERSION) {
617                 rec->version = winsdb_allocate_version(wins_db);
618                 if (rec->version == 0) goto failed;
619         }
620         if (flags & WINSDB_FLAG_TAKE_OWNERSHIP) {
621                 rec->wins_owner = WINSDB_OWNER_LOCAL;
622         }
623
624         msg = winsdb_message(wins_db, rec, tmp_ctx);
625         if (msg == NULL) goto failed;
626
627         for (i=0;i<msg->num_elements;i++) {
628                 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
629         }
630
631         ret = ldb_modify(wins_db, msg);
632         if (ret != 0) goto failed;
633
634         trans = ldb_transaction_commit(wins_db);
635         if (trans != LDB_SUCCESS) goto failed;
636
637         talloc_free(tmp_ctx);
638         return NBT_RCODE_OK;
639
640 failed:
641         if (trans == LDB_SUCCESS) ldb_transaction_cancel(wins_db);
642         talloc_free(tmp_ctx);
643         return NBT_RCODE_SVR;
644 }
645
646
647 /*
648   delete a WINS record from the database
649 */
650 uint8_t winsdb_delete(struct ldb_context *wins_db, struct winsdb_record *rec)
651 {
652         TALLOC_CTX *tmp_ctx = talloc_new(wins_db);
653         const struct ldb_dn *dn;
654         int trans;
655         int ret;
656
657         trans = ldb_transaction_start(wins_db);
658         if (trans != LDB_SUCCESS) goto failed;
659
660         dn = winsdb_dn(tmp_ctx, rec->name);
661         if (dn == NULL) goto failed;
662
663         ret = ldb_delete(wins_db, dn);
664         if (ret != 0) goto failed;
665
666         trans = ldb_transaction_commit(wins_db);
667         if (trans != LDB_SUCCESS) goto failed;
668
669         talloc_free(tmp_ctx);
670         return NBT_RCODE_OK;
671
672 failed:
673         if (trans == LDB_SUCCESS) ldb_transaction_cancel(wins_db);
674         talloc_free(tmp_ctx);
675         return NBT_RCODE_SVR;
676 }
677
678 struct ldb_context *winsdb_connect(TALLOC_CTX *mem_ctx)
679 {
680         return ldb_wrap_connect(mem_ctx, lp_wins_url(), 0, NULL);
681 }