util: util_ntdb.c gains bystring functions.
[kai/samba-autobuild/.git] / lib / util / util_ntdb.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    tdb utility functions
5
6    Copyright (C) Rusty Russell 2012
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _____LIB_UTIL_UTIL_NTDB_H__
23 #define _____LIB_UTIL_UTIL_NTDB_H__
24 #include <ntdb.h>
25 #include <talloc.h>
26
27 struct loadparm_context;
28 union ntdb_attribute;
29
30 /* You only need this on databases with NTDB_CLEAR_IF_FIRST */
31 int ntdb_reopen(struct ntdb_context *ntdb);
32
33 /* You only need to do this if you have NTDB_CLEAR_IF_FIRST databases, and
34  * the parent will go away before this child. */
35 int ntdb_reopen_all(void);
36
37 /*
38  * This is like TDB_CLEAR_IF_FIRST, for use with ntdb_new.
39  *
40  * It's a bad idea for new code.
41  */
42 #define NTDB_CLEAR_IF_FIRST 1048576
43
44 /***************************************************************
45  Open an NTDB using talloc: it will be allocated off the context, and
46  all NTDB_DATA.dptr are allocated as children of the ntdb context.
47  Sets up a logging function for you, and uses lp_ctx to decide whether
48  to disable mmap.
49
50  Any extra ntdb attributes can be handed through attr; usually it's
51  NULL, ntdb_new provides logging and allocator attributes.
52
53  The destructor for the struct ntdb_context will do ntdb_close()
54  for you.
55 ****************************************************************/
56 struct ntdb_context *ntdb_new(TALLOC_CTX *ctx,
57                               const char *name, int ntdb_flags,
58                               int open_flags, mode_t mode,
59                               union ntdb_attribute *attr,
60                               struct loadparm_context *lp_ctx);
61
62 /****************************************************************************
63  Lock a chain by string.
64 ****************************************************************************/
65 enum NTDB_ERROR ntdb_lock_bystring(struct ntdb_context *ntdb,
66                                    const char *keyval);
67
68 /****************************************************************************
69  Unlock a chain by string.
70 ****************************************************************************/
71 void ntdb_unlock_bystring(struct ntdb_context *ntdb, const char *keyval);
72
73 /****************************************************************************
74  Delete an entry using a null terminated string key.
75 ****************************************************************************/
76 enum NTDB_ERROR ntdb_delete_bystring(struct ntdb_context *ntdb,
77                                      const char *keystr);
78
79 /****************************************************************************
80  Store a buffer by a null terminated string key.  Return 0 on success, -ve
81  on failure.
82 ****************************************************************************/
83 enum NTDB_ERROR ntdb_store_bystring(struct ntdb_context *ntdb,
84                                     const char *keystr,
85                                     NTDB_DATA data, int nflags);
86
87 /****************************************************************************
88  Fetch a buffer using a null terminated string key.  Don't forget to call
89  free() on the result dptr (unless the ntdb is from ntdb_new, in which case
90  it will be a child of ntdb).
91 ****************************************************************************/
92 enum NTDB_ERROR ntdb_fetch_bystring(struct ntdb_context *ntdb,
93                                     const char *keystr,
94                                     NTDB_DATA *data);
95
96
97 /****************************************************************************
98  Turn a nul-terminated string into an NTDB_DATA.
99 ****************************************************************************/
100 static inline NTDB_DATA string_term_ntdb_data(const char *string)
101 {
102         return ntdb_mkdata(string, string ? strlen(string) + 1 : 0);
103 }
104
105 #endif /* _____LIB_UTIL_UTIL_NTDB_H__ */