658c48734106b5e2da6f888e3b48f8a00b02ee51
[obnox/samba/samba-obnox.git] / lib / dbwrap / dbwrap_ntdb.c
1 /*
2    Unix SMB/CIFS implementation.
3    Database interface wrapper around ntdb
4    Copyright (C) Volker Lendecke 2005-2007
5    Copyright (C) Rusty Russell 2012
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "dbwrap/dbwrap.h"
23 #include "dbwrap/dbwrap_private.h"
24 #include "dbwrap/dbwrap_ntdb.h"
25 #include "system/filesys.h"
26 #include "lib/util/util_ntdb.h"
27 #include "ccan/str/str.h"
28
29 struct db_ntdb_ctx {
30         struct ntdb_context *ntdb;
31
32         struct {
33                 dev_t dev;
34                 ino_t ino;
35         } id;
36 };
37
38 static int tdb_store_flag_to_ntdb(int tdb_flag)
39 {
40         switch (tdb_flag) {
41         /* In fact, any value defaults to TDB_REPLACE in tdb! */
42         case 0:
43         case TDB_REPLACE:
44                 return NTDB_REPLACE;
45         case TDB_INSERT:
46                 return NTDB_INSERT;
47         case TDB_MODIFY:
48                 return NTDB_MODIFY;
49         default:
50                 smb_panic("unknown tdb_flag");
51         }
52 }
53
54 static NTSTATUS db_ntdb_store(struct db_record *rec, NTDB_DATA data, int flag)
55 {
56         int ntdb_flag = tdb_store_flag_to_ntdb(flag);
57         struct db_ntdb_ctx *ctx = talloc_get_type_abort(rec->private_data,
58                                                         struct db_ntdb_ctx);
59
60         /*
61          * This has a bug: We need to replace rec->value for correct
62          * operation, but right now brlock and locking don't use the value
63          * anymore after it was stored.
64          */
65
66         if (ntdb_store(ctx->ntdb, rec->key, data, ntdb_flag) == NTDB_SUCCESS) {
67                 return NT_STATUS_OK;
68         }
69         return NT_STATUS_UNSUCCESSFUL;
70 }
71
72 static NTSTATUS db_ntdb_delete(struct db_record *rec)
73 {
74         enum NTDB_ERROR err;
75         struct db_ntdb_ctx *ctx = talloc_get_type_abort(rec->private_data,
76                                                        struct db_ntdb_ctx);
77
78         err = ntdb_delete(ctx->ntdb, rec->key);
79         if (err == NTDB_SUCCESS) {
80                 return NT_STATUS_OK;
81         }
82
83         if (err == NTDB_ERR_NOEXIST) {
84                 return NT_STATUS_NOT_FOUND;
85         }
86
87         return NT_STATUS_UNSUCCESSFUL;
88 }
89
90 static void db_ntdb_log_key(const char *prefix, NTDB_DATA key)
91 {
92         size_t len;
93         char *keystr;
94
95         if (DEBUGLEVEL < 10) {
96                 return;
97         }
98         len = key.dsize;
99         if (DEBUGLEVEL == 10) {
100                 /*
101                  * Only fully spam at debuglevel > 10
102                  */
103                 len = MIN(10, key.dsize);
104         }
105         keystr = hex_encode_talloc(talloc_tos(), (unsigned char *)(key.dptr),
106                                    len);
107         DEBUG(10, ("%s key %s\n", prefix, keystr));
108         TALLOC_FREE(keystr);
109 }
110
111 static int db_ntdb_record_destr(struct db_record* data)
112 {
113         struct db_ntdb_ctx *ctx =
114                 talloc_get_type_abort(data->private_data, struct db_ntdb_ctx);
115
116         db_ntdb_log_key("Unlocking", data->key);
117         ntdb_chainunlock(ctx->ntdb, data->key);
118         return 0;
119 }
120
121 struct ntdb_fetch_locked_state {
122         TALLOC_CTX *mem_ctx;
123         struct db_record *result;
124 };
125
126 static enum NTDB_ERROR db_ntdb_fetchlock_parse(NTDB_DATA key, NTDB_DATA data,
127                                                struct ntdb_fetch_locked_state *state)
128 {
129         struct db_record *result;
130
131         result = (struct db_record *)talloc_size(
132                 state->mem_ctx,
133                 sizeof(struct db_record) + key.dsize + data.dsize);
134
135         if (result == NULL) {
136                 return NTDB_ERR_OOM;
137         }
138         state->result = result;
139
140         result->key.dsize = key.dsize;
141         result->key.dptr = ((uint8_t *)result) + sizeof(struct db_record);
142         memcpy(result->key.dptr, key.dptr, key.dsize);
143
144         result->value.dsize = data.dsize;
145
146         if (data.dsize > 0) {
147                 result->value.dptr = result->key.dptr+key.dsize;
148                 memcpy(result->value.dptr, data.dptr, data.dsize);
149         }
150         else {
151                 result->value.dptr = NULL;
152         }
153
154         return NTDB_SUCCESS;
155 }
156
157 static struct db_record *db_ntdb_fetch_locked_internal(
158         struct db_context *db, TALLOC_CTX *mem_ctx, NTDB_DATA key)
159 {
160         struct db_ntdb_ctx *ctx = talloc_get_type_abort(db->private_data,
161                                                         struct db_ntdb_ctx);
162         struct ntdb_fetch_locked_state state;
163         enum NTDB_ERROR err;
164         NTDB_DATA null = { NULL, 0 };
165
166         state.mem_ctx = mem_ctx;
167         state.result = NULL;
168
169         err = ntdb_parse_record(ctx->ntdb, key, db_ntdb_fetchlock_parse,
170                                 &state);
171         if (err != NTDB_SUCCESS && err != NTDB_ERR_NOEXIST) {
172                 ntdb_chainunlock(ctx->ntdb, key);
173                 return NULL;
174         }
175
176         if (state.result == NULL) {
177                 db_ntdb_fetchlock_parse(key, null, &state);
178         }
179
180         if (state.result == NULL) {
181                 ntdb_chainunlock(ctx->ntdb, key);
182                 return NULL;
183         }
184
185         talloc_set_destructor(state.result, db_ntdb_record_destr);
186
187         state.result->private_data = talloc_reference(state.result, ctx);
188         state.result->store = db_ntdb_store;
189         state.result->delete_rec = db_ntdb_delete;
190
191         DEBUG(10, ("Allocated locked data 0x%p\n", state.result));
192
193         return state.result;
194 }
195
196 static struct db_record *db_ntdb_fetch_locked(
197         struct db_context *db, TALLOC_CTX *mem_ctx, NTDB_DATA key)
198 {
199         struct db_ntdb_ctx *ctx = talloc_get_type_abort(db->private_data,
200                                                        struct db_ntdb_ctx);
201
202         db_ntdb_log_key("Locking", key);
203         if (ntdb_chainlock(ctx->ntdb, key) != 0) {
204                 DEBUG(3, ("ntdb_chainlock failed\n"));
205                 return NULL;
206         }
207         return db_ntdb_fetch_locked_internal(db, mem_ctx, key);
208 }
209
210 /* Proxy which sets waitflag to false so we never block. */
211 static int lock_nonblock(int fd, int rw, off_t off, off_t len, bool waitflag,
212                          void *_orig)
213 {
214         struct ntdb_attribute_flock *orig = _orig;
215
216         return orig->lock(fd, rw, off, len, false, orig->data);
217 }
218
219 static enum NTDB_ERROR enable_nonblock(struct ntdb_context *ntdb,
220                                        union ntdb_attribute *orig)
221 {
222         union ntdb_attribute locking;
223         enum NTDB_ERROR ecode;
224
225         orig->base.attr = NTDB_ATTRIBUTE_FLOCK;
226         ecode = ntdb_get_attribute(ntdb, orig);
227         if (ecode != NTDB_SUCCESS) {
228                 return ecode;
229         }
230
231         /* Replace locking function with our own. */
232         locking = *orig;
233         locking.flock.data = orig;
234         locking.flock.lock = lock_nonblock;
235
236         return ntdb_set_attribute(ntdb, &locking);
237 }
238
239 static void disable_nonblock(struct ntdb_context *ntdb)
240 {
241         ntdb_unset_attribute(ntdb, NTDB_ATTRIBUTE_FLOCK);
242 }
243
244 static enum NTDB_ERROR ntdb_chainlock_nonblock(struct ntdb_context *ntdb,
245                                                NTDB_DATA key)
246 {
247         union ntdb_attribute orig;
248         enum NTDB_ERROR ecode;
249
250         ecode = enable_nonblock(ntdb, &orig);
251         if (!ecode) {
252                 ecode = ntdb_chainlock(ntdb, key);
253                 disable_nonblock(ntdb);
254         }
255         return ecode;
256 }
257
258 static struct db_record *db_ntdb_try_fetch_locked(
259         struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key)
260 {
261         struct db_ntdb_ctx *ctx = talloc_get_type_abort(db->private_data,
262                                                        struct db_ntdb_ctx);
263
264         db_ntdb_log_key("Trying to lock", key);
265         if (ntdb_chainlock_nonblock(ctx->ntdb, key) != 0) {
266                 DEBUG(3, ("ntdb_chainlock_nonblock failed\n"));
267                 return NULL;
268         }
269         return db_ntdb_fetch_locked_internal(db, mem_ctx, key);
270 }
271
272 static struct flock flock_struct;
273
274 /* Return a value which is none of v1, v2 or v3. */
275 static inline short int invalid_value(short int v1, short int v2, short int v3)
276 {
277         short int try = (v1+v2+v3)^((v1+v2+v3) << 16);
278         while (try == v1 || try == v2 || try == v3)
279                 try++;
280         return try;
281 }
282
283 /* We invalidate in as many ways as we can, so the OS rejects it */
284 static void invalidate_flock_struct(int signum)
285 {
286         flock_struct.l_type = invalid_value(F_RDLCK, F_WRLCK, F_UNLCK);
287         flock_struct.l_whence = invalid_value(SEEK_SET, SEEK_CUR, SEEK_END);
288         flock_struct.l_start = -1;
289         /* A large negative. */
290         flock_struct.l_len = (((off_t)1 << (sizeof(off_t)*CHAR_BIT - 1)) + 1);
291 }
292
293 static int timeout_lock(int fd, int rw, off_t off, off_t len, bool waitflag,
294                         void *_timeout)
295 {
296         int ret, saved_errno;
297         unsigned int timeout = *(unsigned int *)_timeout;
298
299         flock_struct.l_type = rw;
300         flock_struct.l_whence = SEEK_SET;
301         flock_struct.l_start = off;
302         flock_struct.l_len = len;
303
304         CatchSignal(SIGALRM, invalidate_flock_struct);
305         alarm(timeout);
306
307         for (;;) {
308                 if (waitflag)
309                         ret = fcntl(fd, F_SETLKW, &flock_struct);
310                 else
311                         ret = fcntl(fd, F_SETLK, &flock_struct);
312
313                 if (ret == 0)
314                         break;
315
316                 /* Not signalled?  Something else went wrong. */
317                 if (flock_struct.l_len == len) {
318                         if (errno == EAGAIN || errno == EINTR)
319                                 continue;
320                         saved_errno = errno;
321                         break;
322                 } else {
323                         saved_errno = EINTR;
324                         break;
325                 }
326         }
327
328         alarm(0);
329         if (ret != 0) {
330                 errno = saved_errno;
331         }
332         return ret;
333 }
334
335 static int ntdb_chainlock_timeout(struct ntdb_context *ntdb,
336                                   NTDB_DATA key,
337                                   unsigned int timeout)
338 {
339         union ntdb_attribute locking;
340         enum NTDB_ERROR ecode;
341
342         locking.base.attr = NTDB_ATTRIBUTE_FLOCK;
343         ecode = ntdb_get_attribute(ntdb, &locking);
344         if (ecode != NTDB_SUCCESS) {
345                 return -1;
346         }
347
348         /* Replace locking function with our own. */
349         locking.flock.data = &timeout;
350         locking.flock.lock = timeout_lock;
351
352         ecode = ntdb_set_attribute(ntdb, &locking);
353         if (ecode != NTDB_SUCCESS) {
354                 return -1;
355         }
356
357         ecode = ntdb_chainlock(ntdb, key);
358
359         ntdb_unset_attribute(ntdb, NTDB_ATTRIBUTE_FLOCK);
360         return ecode == NTDB_SUCCESS ? 0 : -1;
361 }
362
363 static struct db_record *db_ntdb_fetch_locked_timeout(
364         struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key,
365         unsigned int timeout)
366 {
367         struct db_ntdb_ctx *ctx = talloc_get_type_abort(db->private_data,
368                                                        struct db_ntdb_ctx);
369
370         db_ntdb_log_key("Trying to lock", key);
371         if (ntdb_chainlock_timeout(ctx->ntdb, key, timeout) != 0) {
372                 DEBUG(3, ("ntdb_chainlock_timeout failed\n"));
373                 return NULL;
374         }
375         return db_ntdb_fetch_locked_internal(db, mem_ctx, key);
376 }
377
378
379 static int db_ntdb_exists(struct db_context *db, TDB_DATA key)
380 {
381         struct db_ntdb_ctx *ctx = talloc_get_type_abort(
382                 db->private_data, struct db_ntdb_ctx);
383         return ntdb_exists(ctx->ntdb, key);
384 }
385
386 static int db_ntdb_wipe(struct db_context *db)
387 {
388         struct db_ntdb_ctx *ctx = talloc_get_type_abort(
389                 db->private_data, struct db_ntdb_ctx);
390         if (ntdb_wipe_all(ctx->ntdb) != NTDB_SUCCESS) {
391                 return -1;
392         }
393         return 0;
394 }
395
396 static int db_ntdb_check(struct db_context *db)
397 {
398         struct db_ntdb_ctx *ctx = talloc_get_type_abort(
399                 db->private_data, struct db_ntdb_ctx);
400         if (ntdb_check(ctx->ntdb, NULL, NULL) != NTDB_SUCCESS) {
401                 return -1;
402         }
403         return 0;
404 }
405
406 struct db_ntdb_parse_state {
407         void (*parser)(TDB_DATA key, TDB_DATA data,
408                        void *private_data);
409         void *private_data;
410 };
411
412 /*
413  * ntdb_parse_record expects a parser returning enum NTDB_ERROR,
414  * mixing up ntdb and parser errors. Wrap around that by always
415  * returning NTDB_SUCCESS and have dbwrap_parse_record expect a parser
416  * returning void.
417  */
418
419 static enum NTDB_ERROR db_ntdb_parser(NTDB_DATA key, NTDB_DATA data,
420                                       struct db_ntdb_parse_state *state)
421 {
422         state->parser(key, data, state->private_data);
423         return TDB_SUCCESS;
424 }
425
426 static NTSTATUS db_ntdb_parse(struct db_context *db, TDB_DATA key,
427                               void (*parser)(TDB_DATA key, TDB_DATA data,
428                                              void *private_data),
429                               void *private_data)
430 {
431         struct db_ntdb_ctx *ctx = talloc_get_type_abort(
432                 db->private_data, struct db_ntdb_ctx);
433         struct db_ntdb_parse_state state;
434         enum NTDB_ERROR err;
435
436         state.parser = parser;
437         state.private_data = private_data;
438
439         err = ntdb_parse_record(ctx->ntdb, key, db_ntdb_parser, &state);
440         return map_nt_error_from_ntdb(err);
441 }
442
443 struct db_ntdb_traverse_ctx {
444         struct db_context *db;
445         int (*f)(struct db_record *rec, void *private_data);
446         void *private_data;
447 };
448
449 static int db_ntdb_traverse_func(struct ntdb_context *ntdb,
450                                  NTDB_DATA kbuf, NTDB_DATA dbuf,
451                                  struct db_ntdb_traverse_ctx *ctx)
452 {
453         struct db_record rec;
454
455         rec.key = kbuf;
456         rec.value = dbuf;
457         rec.store = db_ntdb_store;
458         rec.delete_rec = db_ntdb_delete;
459         rec.private_data = ctx->db->private_data;
460         rec.db = ctx->db;
461
462         return ctx->f(&rec, ctx->private_data);
463 }
464
465 static int db_ntdb_traverse(struct db_context *db,
466                             int (*f)(struct db_record *rec, void *private_data),
467                             void *private_data)
468 {
469         struct db_ntdb_ctx *db_ctx =
470                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
471         struct db_ntdb_traverse_ctx ctx;
472         int64_t ret;
473
474         ctx.db = db;
475         ctx.f = f;
476         ctx.private_data = private_data;
477         ret = ntdb_traverse(db_ctx->ntdb, db_ntdb_traverse_func, &ctx);
478
479         if (ret < 0) {
480                 return -1;
481         }
482
483         /* Make sure we don't truncate! */
484         if ((int)ret != ret) {
485                 ret = INT_MAX;
486         }
487         return ret;
488 }
489
490 static NTSTATUS db_ntdb_store_deny(struct db_record *rec, NTDB_DATA data, int flag)
491 {
492         return NT_STATUS_MEDIA_WRITE_PROTECTED;
493 }
494
495 static NTSTATUS db_ntdb_delete_deny(struct db_record *rec)
496 {
497         return NT_STATUS_MEDIA_WRITE_PROTECTED;
498 }
499
500 static int db_ntdb_traverse_read_func(struct ntdb_context *ntdb,
501                                       NTDB_DATA kbuf, NTDB_DATA dbuf,
502                                       struct db_ntdb_traverse_ctx *ctx)
503 {
504         struct db_record rec;
505
506         rec.key = kbuf;
507         rec.value = dbuf;
508         rec.store = db_ntdb_store_deny;
509         rec.delete_rec = db_ntdb_delete_deny;
510         rec.private_data = ctx->db->private_data;
511         rec.db = ctx->db;
512
513         return ctx->f(&rec, ctx->private_data);
514 }
515
516 static int db_ntdb_traverse_read(struct db_context *db,
517                                  int (*f)(struct db_record *rec,
518                                           void *private_data),
519                                  void *private_data)
520 {
521         struct db_ntdb_ctx *db_ctx =
522                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
523         struct db_ntdb_traverse_ctx ctx;
524         int64_t ret;
525
526         ctx.db = db;
527         ctx.f = f;
528         ctx.private_data = private_data;
529
530         /* This is a bit of paranoia to check that f() isn't altering
531          * database. */
532         if (ntdb_get_flags(db_ctx->ntdb) & NTDB_RDONLY) {
533                 ret = ntdb_traverse(db_ctx->ntdb, db_ntdb_traverse_read_func,
534                                     &ctx);
535         } else {
536                 ntdb_add_flag(db_ctx->ntdb, NTDB_RDONLY);
537                 ret = ntdb_traverse(db_ctx->ntdb, db_ntdb_traverse_read_func,
538                                     &ctx);
539                 ntdb_remove_flag(db_ctx->ntdb, NTDB_RDONLY);
540         }
541
542         if (ret < 0) {
543                 return -1;
544         }
545
546         /* Make sure we don't truncate! */
547         if ((int)ret != ret) {
548                 ret = INT_MAX;
549         }
550         return ret;
551 }
552
553 static int db_ntdb_get_seqnum(struct db_context *db)
554
555 {
556         struct db_ntdb_ctx *db_ctx =
557                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
558         return ntdb_get_seqnum(db_ctx->ntdb);
559 }
560
561 static int db_ntdb_transaction_start(struct db_context *db)
562 {
563         struct db_ntdb_ctx *db_ctx =
564                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
565         return ntdb_transaction_start(db_ctx->ntdb) == NTDB_SUCCESS ? 0 : -1;
566 }
567
568 static NTSTATUS db_ntdb_transaction_start_nonblock(struct db_context *db)
569 {
570         union ntdb_attribute orig;
571         enum NTDB_ERROR ecode;
572         struct db_ntdb_ctx *db_ctx =
573                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
574
575         ecode = enable_nonblock(db_ctx->ntdb, &orig);
576         if (!ecode) {
577                 ecode = ntdb_transaction_start(db_ctx->ntdb);
578                 disable_nonblock(db_ctx->ntdb);
579         }
580         return map_nt_error_from_ntdb(ecode);
581 }
582
583 static int db_ntdb_transaction_commit(struct db_context *db)
584 {
585         struct db_ntdb_ctx *db_ctx =
586                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
587         return ntdb_transaction_commit(db_ctx->ntdb) == NTDB_SUCCESS ? 0 : -1;
588 }
589
590 static int db_ntdb_transaction_cancel(struct db_context *db)
591 {
592         struct db_ntdb_ctx *db_ctx =
593                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
594         ntdb_transaction_cancel(db_ctx->ntdb);
595         return 0;
596 }
597
598 static void db_ntdb_id(struct db_context *db, const uint8_t **id, size_t *idlen)
599 {
600         struct db_ntdb_ctx *db_ctx =
601                 talloc_get_type_abort(db->private_data, struct db_ntdb_ctx);
602         *id = (uint8_t *)&db_ctx->id;
603         *idlen = sizeof(db_ctx->id);
604 }
605
606 /* Don't ask this to open a .tdb file: dbwrap_local_open will catch that. */
607 struct db_context *db_open_ntdb(TALLOC_CTX *mem_ctx,
608                                 struct loadparm_context *lp_ctx,
609                                 const char *ntdbname,
610                                 int hash_size, int ntdb_flags,
611                                 int open_flags, mode_t mode,
612                                 enum dbwrap_lock_order lock_order)
613 {
614         struct db_context *result = NULL;
615         struct db_ntdb_ctx *db_ntdb;
616         struct stat st;
617         union ntdb_attribute hattr;
618
619         if ((ntdb_flags & NTDB_INTERNAL) && !ntdbname) {
620                 ntdbname = "unnamed";
621         }
622
623         /* Extra paranoia. */
624         if (strends(ntdbname, ".tdb")) {
625                 DEBUG(0, ("can't try to open %s with ntdb!", ntdbname));
626                 return NULL;
627         }
628
629         /* We only use this if hsize is non-zero. */
630         hattr.base.attr = NTDB_ATTRIBUTE_HASHSIZE;
631         hattr.base.next = NULL;
632         hattr.hashsize.size = hash_size;
633
634         result = talloc_zero(mem_ctx, struct db_context);
635         if (result == NULL) {
636                 DEBUG(0, ("talloc failed\n"));
637                 goto fail;
638         }
639
640         result->private_data = db_ntdb = talloc(result, struct db_ntdb_ctx);
641         if (db_ntdb == NULL) {
642                 DEBUG(0, ("talloc failed\n"));
643                 goto fail;
644         }
645         result->lock_order = lock_order;
646
647         db_ntdb->ntdb = ntdb_new(db_ntdb, ntdbname, ntdb_flags,
648                                  open_flags, mode,
649                                  hash_size ? &hattr : NULL, lp_ctx);
650         if (db_ntdb->ntdb == NULL) {
651                 DEBUG(3, ("Could not open ntdb %s: %s\n",
652                           ntdbname, strerror(errno)));
653                 goto fail;
654         }
655
656         ZERO_STRUCT(db_ntdb->id);
657
658         if (fstat(ntdb_fd(db_ntdb->ntdb), &st) == -1) {
659                 DEBUG(3, ("fstat failed: %s\n", strerror(errno)));
660                 goto fail;
661         }
662         db_ntdb->id.dev = st.st_dev;
663         db_ntdb->id.ino = st.st_ino;
664
665         result->fetch_locked = db_ntdb_fetch_locked;
666         result->fetch_locked_timeout = db_ntdb_fetch_locked_timeout;
667         result->try_fetch_locked = db_ntdb_try_fetch_locked;
668         result->traverse = db_ntdb_traverse;
669         result->traverse_read = db_ntdb_traverse_read;
670         result->parse_record = db_ntdb_parse;
671         result->get_seqnum = db_ntdb_get_seqnum;
672         result->persistent = ((ntdb_flags & NTDB_CLEAR_IF_FIRST) == 0);
673         result->transaction_start = db_ntdb_transaction_start;
674         result->transaction_start_nonblock = db_ntdb_transaction_start_nonblock;
675         result->transaction_commit = db_ntdb_transaction_commit;
676         result->transaction_cancel = db_ntdb_transaction_cancel;
677         result->exists = db_ntdb_exists;
678         result->wipe = db_ntdb_wipe;
679         result->id = db_ntdb_id;
680         result->check = db_ntdb_check;
681         result->stored_callback = NULL;
682         result->name = ntdb_name(db_ntdb->ntdb);
683         result->hash_size = hash_size;
684         return result;
685
686  fail:
687         if (result != NULL) {
688                 TALLOC_FREE(result);
689         }
690         return NULL;
691 }