2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5 <refentrytitle>ntdb</refentrytitle>
6 <manvolnum>3</manvolnum>
7 <refmiscinfo class="source">Samba</refmiscinfo>
8 <refmiscinfo class="manual">System Administration tools</refmiscinfo>
9 <refmiscinfo class="version">4.1</refmiscinfo>
12 <refname>ntdb</refname>
13 <refpurpose>A not-so trivial keyword/data database system</refpurpose>
16 <synopsis>#include <ntdb.h></synopsis>
18 <refsect1><title>DESCRIPTION</title>
20 If you have previously used the tdb library from Samba, much of
21 this will seem familiar, but there are some API changes which a
22 compiler will warn you about if you simply replace 'tdb' with
23 'ntdb' in your code! The on-disk format for ntdb is
24 incompatible with tdb.
27 tdb's API was based on gdbm, and ntdb continues this tradition,
28 with enhancements. A differences guide is available in the text
29 file <filename>lib/ntdb/doc/TDB_porting.txt</filename> in the
33 <refsect1><title>NTDB API OVERVIEW</title>
35 The complete API is documented in the ntdb.h header, which is
36 kept up-to-date and recommended reading.
39 Normal usage is to call ntdb_open() to create or open an ntdb
40 file. ntdb_store() is used to add records, ntdb_fetch() is used
41 to fetch them. Traversals are supported via callback
42 (ntdb_traverse()) or iteration (ntdb_firstkey() and
43 ntdb_nextkey()). Transactions are supported for batching
44 updates or reads atomically, using ntdb_transaction_start() and
45 ntdb_transaction_commit().
47 <refsect2><title>Use With Talloc</title>
49 ntdb_open() takes an optional linked list of attributes:
50 in particular you can specify an alternate allocator (such as
54 #include <talloc.h>
55 #include <ntdb.h>
57 static void *my_alloc(const void *owner, size_t len, void *priv)
59 return talloc_size(owner, len);
62 static void *my_expand(void *old, size_t newlen, void *priv)
64 return talloc_realloc_size(NULL, old, newlen);
67 static void my_free(void *old, void *priv)
72 /* This opens an ntdb file as a talloc object with given parent. */
73 struct ntdb_context *ntdb_open_talloc(const void *parent,
76 struct ntdb_context *ntdb;
77 union ntdb_attribute alloc;
79 alloc.base.attr = NTDB_ATTRIBUTE_ALLOCATOR;
80 alloc.base.next = NULL;
81 alloc.alloc.alloc = my_alloc;
82 alloc.alloc.expand = my_expand;
83 alloc.alloc.free = my_free;
85 ntdb = ntdb_open(filename, NTDB_DEFAULT, O_RDWR|O_CREAT, 0600,
88 talloc_steal(parent, ntdb);
89 talloc_set_name(ntdb, "%s", filename);
96 <refsect1><title>SEE ALSO</title>
98 <ulink url="http://tdb.samba.org/"/>
102 <refsect1><title>AUTHOR</title>
103 <para> The original tdb software was created by Andrew Tridgell, and
104 is now developed by the
105 Samba Team as an Open Source project similar to the way the
106 Linux kernel is developed. ntdb was derived from tdb, but mostly
107 rewritten by Rusty Russell.
111 <refsect1><title>COPYRIGHT/LICENSE</title>
113 Copyright (C) Rusty Russell 2013, IBM Corporation
116 This program is free software; you can redistribute it and/or modify
117 it under the terms of the GNU Lesser General Public License as
118 published by the Free Software Foundation; either version 3 of the
119 License, or (at your option) any later version.
122 This program is distributed in the hope that it will be useful, but
123 WITHOUT ANY WARRANTY; without even the implied warranty of
124 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
125 General Public License for more details.
128 You should have received a copy of the GNU General Public License
129 along with this program; if not, see http://www.gnu.org/licenses/.