2 Unix SMB/CIFS implementation.
6 Copyright (C) Rusty Russell 2012
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.
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.
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/>.
22 #ifndef _____LIB_UTIL_UTIL_NTDB_H__
23 #define _____LIB_UTIL_UTIL_NTDB_H__
27 struct loadparm_context;
30 /* You only need this on databases with NTDB_CLEAR_IF_FIRST */
31 int ntdb_reopen(struct ntdb_context *ntdb);
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);
38 * This is like TDB_CLEAR_IF_FIRST, for use with ntdb_new.
40 * It's a bad idea for new code.
42 #define NTDB_CLEAR_IF_FIRST 1048576
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
50 Any extra ntdb attributes can be handed through attr; usually it's
51 NULL, ntdb_new provides logging and allocator attributes.
53 The destructor for the struct ntdb_context will do ntdb_close()
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);
62 /****************************************************************************
63 Lock a chain by string.
64 ****************************************************************************/
65 enum NTDB_ERROR ntdb_lock_bystring(struct ntdb_context *ntdb,
68 /****************************************************************************
69 Unlock a chain by string.
70 ****************************************************************************/
71 void ntdb_unlock_bystring(struct ntdb_context *ntdb, const char *keyval);
73 /****************************************************************************
74 Delete an entry using a null terminated string key.
75 ****************************************************************************/
76 enum NTDB_ERROR ntdb_delete_bystring(struct ntdb_context *ntdb,
79 /****************************************************************************
80 Store a buffer by a null terminated string key. Return 0 on success, -ve
82 ****************************************************************************/
83 enum NTDB_ERROR ntdb_store_bystring(struct ntdb_context *ntdb,
85 NTDB_DATA data, int nflags);
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,
97 /****************************************************************************
98 Turn a nul-terminated string into an NTDB_DATA.
99 ****************************************************************************/
100 static inline NTDB_DATA string_term_ntdb_data(const char *string)
102 return ntdb_mkdata(string, string ? strlen(string) + 1 : 0);
105 #endif /* _____LIB_UTIL_UTIL_NTDB_H__ */