1NTDB(3) System Administration tools NTDB(3)
2
3
4
6 ntdb - A not-so trivial keyword/data database system
7
9 #include <ntdb.h>
10
12 If you have previously used the tdb library from Samba, much of this
13 will seem familiar, but there are some API changes which a compiler
14 will warn you about if you simply replace ´tdb´ with ´ntdb´ in your
15 code! The on-disk format for ntdb is incompatible with tdb.
16
17 tdb´s API was based on gdbm, and ntdb continues this tradition, with
18 enhancements. A differences guide is available in the text file
19 lib/ntdb/doc/TDB_porting.txt in the SAMBA source tree.
20
22 The complete API is documented in the ntdb.h header, which is kept
23 up-to-date and recommended reading.
24
25 Normal usage is to call ntdb_open() to create or open an ntdb file.
26 ntdb_store() is used to add records, ntdb_fetch() is used to fetch
27 them. Traversals are supported via callback (ntdb_traverse()) or
28 iteration (ntdb_firstkey() and ntdb_nextkey()). Transactions are
29 supported for batching updates or reads atomically, using
30 ntdb_transaction_start() and ntdb_transaction_commit().
31
32 Use With Talloc
33 ntdb_open() takes an optional linked list of attributes: in particular
34 you can specify an alternate allocator (such as talloc):
35
36 #include <talloc.h>
37 #include <ntdb.h>
38
39 static void *my_alloc(const void *owner, size_t len, void *priv)
40 {
41 return talloc_size(owner, len);
42 }
43
44 static void *my_expand(void *old, size_t newlen, void *priv)
45 {
46 return talloc_realloc_size(NULL, old, newlen);
47 }
48
49 static void my_free(void *old, void *priv)
50 {
51 talloc_free(old);
52 }
53
54 /* This opens an ntdb file as a talloc object with given parent. */
55 struct ntdb_context *ntdb_open_talloc(const void *parent,
56 const char *filename)
57 {
58 struct ntdb_context *ntdb;
59 union ntdb_attribute alloc;
60
61 alloc.base.attr = NTDB_ATTRIBUTE_ALLOCATOR;
62 alloc.base.next = NULL;
63 alloc.alloc.alloc = my_alloc;
64 alloc.alloc.expand = my_expand;
65 alloc.alloc.free = my_free;
66
67 ntdb = ntdb_open(filename, NTDB_DEFAULT, O_RDWR|O_CREAT, 0600,
68 &alloc);
69 if (ntdb) {
70 talloc_steal(parent, ntdb);
71 talloc_set_name(ntdb, "%s", filename);
72 }
73 return ntdb;
74 }
75
77 http://tdb.samba.org/
78
80 The original tdb software was created by Andrew Tridgell, and is now
81 developed by the Samba Team as an Open Source project similar to the
82 way the Linux kernel is developed. ntdb was derived from tdb, but
83 mostly rewritten by Rusty Russell.
84
86 Copyright (C) Rusty Russell 2013, IBM Corporation
87
88 This program is free software; you can redistribute it and/or modify it
89 under the terms of the GNU Lesser General Public License as published
90 by the Free Software Foundation; either version 3 of the License, or
91 (at your option) any later version.
92
93 This program is distributed in the hope that it will be useful, but
94 WITHOUT ANY WARRANTY; without even the implied warranty of
95 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96 General Public License for more details.
97
98 You should have received a copy of the GNU General Public License along
99 with this program; if not, see http://www.gnu.org/licenses/.
100
101
102
103Samba 4.1 06/19/2018 NTDB(3)