ntdb.3.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?xml version="1.0"?>
  2. <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  3. <refentry>
  4. <refmeta>
  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>
  10. </refmeta>
  11. <refnamediv>
  12. <refname>ntdb</refname>
  13. <refpurpose>A not-so trivial keyword/data database system</refpurpose>
  14. </refnamediv>
  15. <refsynopsisdiv>
  16. <synopsis>#include &lt;ntdb.h&gt;</synopsis>
  17. </refsynopsisdiv>
  18. <refsect1><title>DESCRIPTION</title>
  19. <para>
  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.
  25. </para>
  26. <para>
  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
  30. SAMBA source tree.
  31. </para>
  32. </refsect1>
  33. <refsect1><title>NTDB API OVERVIEW</title>
  34. <para>
  35. The complete API is documented in the ntdb.h header, which is
  36. kept up-to-date and recommended reading.
  37. </para>
  38. <para>
  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().
  46. </para>
  47. <refsect2><title>Use With Talloc</title>
  48. <para>
  49. ntdb_open() takes an optional linked list of attributes:
  50. in particular you can specify an alternate allocator (such as
  51. talloc):
  52. </para>
  53. <programlisting>
  54. #include &lt;talloc.h&gt;
  55. #include &lt;ntdb.h&gt;
  56. static void *my_alloc(const void *owner, size_t len, void *priv)
  57. {
  58. return talloc_size(owner, len);
  59. }
  60. static void *my_expand(void *old, size_t newlen, void *priv)
  61. {
  62. return talloc_realloc_size(NULL, old, newlen);
  63. }
  64. static void my_free(void *old, void *priv)
  65. {
  66. talloc_free(old);
  67. }
  68. /* This opens an ntdb file as a talloc object with given parent. */
  69. struct ntdb_context *ntdb_open_talloc(const void *parent,
  70. const char *filename)
  71. {
  72. struct ntdb_context *ntdb;
  73. union ntdb_attribute alloc;
  74. alloc.base.attr = NTDB_ATTRIBUTE_ALLOCATOR;
  75. alloc.base.next = NULL;
  76. alloc.alloc.alloc = my_alloc;
  77. alloc.alloc.expand = my_expand;
  78. alloc.alloc.free = my_free;
  79. ntdb = ntdb_open(filename, NTDB_DEFAULT, O_RDWR|O_CREAT, 0600,
  80. &amp;alloc);
  81. if (ntdb) {
  82. talloc_steal(parent, ntdb);
  83. talloc_set_name(ntdb, "%s", filename);
  84. }
  85. return ntdb;
  86. }
  87. </programlisting>
  88. </refsect2>
  89. </refsect1>
  90. <refsect1><title>SEE ALSO</title>
  91. <para>
  92. <ulink url="http://tdb.samba.org/"/>
  93. </para>
  94. </refsect1>
  95. <refsect1><title>AUTHOR</title>
  96. <para> The original tdb software was created by Andrew Tridgell, and
  97. is now developed by the
  98. Samba Team as an Open Source project similar to the way the
  99. Linux kernel is developed. ntdb was derived from tdb, but mostly
  100. rewritten by Rusty Russell.
  101. </para>
  102. </refsect1>
  103. <refsect1><title>COPYRIGHT/LICENSE</title>
  104. <para>
  105. Copyright (C) Rusty Russell 2013, IBM Corporation
  106. </para>
  107. <para>
  108. This program is free software; you can redistribute it and/or modify
  109. it under the terms of the GNU Lesser General Public License as
  110. published by the Free Software Foundation; either version 3 of the
  111. License, or (at your option) any later version.
  112. </para>
  113. <para>
  114. This program is distributed in the hope that it will be useful, but
  115. WITHOUT ANY WARRANTY; without even the implied warranty of
  116. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  117. General Public License for more details.
  118. </para>
  119. <para>
  120. You should have received a copy of the GNU General Public License
  121. along with this program; if not, see http://www.gnu.org/licenses/.
  122. </para>
  123. </refsect1>
  124. </refentry>