regedit: Print help on left side of screen instead of the right.
[Samba.git] / lib / util / util_ntdb.h
blob7531c42dee8bfe33b5fdf567583b737654168e5b
1 /*
2 Unix SMB/CIFS implementation.
4 tdb utility functions
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__
24 #include <ntdb.h>
25 #include <talloc.h>
26 #include "libcli/util/ntstatus.h"
28 struct loadparm_context;
29 union ntdb_attribute;
31 /* You only need this on databases with NTDB_CLEAR_IF_FIRST */
32 int ntdb_reopen(struct ntdb_context *ntdb);
34 /* You only need to do this if you have NTDB_CLEAR_IF_FIRST databases, and
35 * the parent will go away before this child. */
36 int ntdb_reopen_all(void);
39 * This is like TDB_CLEAR_IF_FIRST, for use with ntdb_new.
41 * It's a bad idea for new code.
43 #define NTDB_CLEAR_IF_FIRST 1048576
45 /***************************************************************
46 Open an NTDB using talloc: it will be allocated off the context, and
47 all NTDB_DATA.dptr are allocated as children of the ntdb context.
48 Sets up a logging function for you, and uses lp_ctx to decide whether
49 to disable mmap.
51 Any extra ntdb attributes can be handed through attr; usually it's
52 NULL, ntdb_new provides logging and allocator attributes.
54 The destructor for the struct ntdb_context will do ntdb_close()
55 for you.
56 ****************************************************************/
57 struct ntdb_context *ntdb_new(TALLOC_CTX *ctx,
58 const char *name, int ntdb_flags,
59 int open_flags, mode_t mode,
60 union ntdb_attribute *attr,
61 struct loadparm_context *lp_ctx);
63 /****************************************************************************
64 Lock a chain by string.
65 ****************************************************************************/
66 enum NTDB_ERROR ntdb_lock_bystring(struct ntdb_context *ntdb,
67 const char *keyval);
69 /****************************************************************************
70 Unlock a chain by string.
71 ****************************************************************************/
72 void ntdb_unlock_bystring(struct ntdb_context *ntdb, const char *keyval);
74 /****************************************************************************
75 Delete an entry using a null terminated string key.
76 ****************************************************************************/
77 enum NTDB_ERROR ntdb_delete_bystring(struct ntdb_context *ntdb,
78 const char *keystr);
80 /****************************************************************************
81 Store a buffer by a null terminated string key. Return 0 on success, -ve
82 on failure.
83 ****************************************************************************/
84 enum NTDB_ERROR ntdb_store_bystring(struct ntdb_context *ntdb,
85 const char *keystr,
86 NTDB_DATA data, int nflags);
88 /****************************************************************************
89 Fetch a buffer using a null terminated string key. Don't forget to call
90 free() on the result dptr (unless the ntdb is from ntdb_new, in which case
91 it will be a child of ntdb).
92 ****************************************************************************/
93 enum NTDB_ERROR ntdb_fetch_bystring(struct ntdb_context *ntdb,
94 const char *keystr,
95 NTDB_DATA *data);
98 /****************************************************************************
99 Fetch a int32_t value by a string key. *val is int32_t in native byte order.
100 ntdb must have been created with ntdb_new() (as it uses talloc_free).
101 ****************************************************************************/
102 enum NTDB_ERROR ntdb_fetch_int32(struct ntdb_context *ntdb,
103 const char *keystr, int32_t *val);
105 /****************************************************************************
106 Store a int32_t value by a string key. val is int32_t in native byte order.
107 ****************************************************************************/
108 enum NTDB_ERROR ntdb_store_int32(struct ntdb_context *ntdb,
109 const char *keystr, int32_t val);
112 /****************************************************************************
113 Atomic integer add; reads the old value into *oldval (if found), then stores
114 *oldval + addval back for next time. Uses chainlock to do this atomically.
116 Thus the first time this is ever called, oldval will be unchanged.
117 ****************************************************************************/
118 enum NTDB_ERROR ntdb_add_int32_atomic(struct ntdb_context *ntdb,
119 const char *keystr,
120 int32_t *oldval, int32_t addval);
122 /****************************************************************************
123 Turn a nul-terminated string into an NTDB_DATA.
124 ****************************************************************************/
125 static inline NTDB_DATA string_term_ntdb_data(const char *string)
127 return ntdb_mkdata(string, string ? strlen(string) + 1 : 0);
131 /****************************************************************************
132 Return an NTSTATUS from a NTDB_ERROR
133 ****************************************************************************/
134 NTSTATUS map_nt_error_from_ntdb(enum NTDB_ERROR err);
135 #endif /* _____LIB_UTIL_UTIL_NTDB_H__ */