util_tdb: make the _byblob fetch/store functions public again.
[samba.git] / source3 / include / util_tdb.h
1 /* 
2    Unix SMB/CIFS implementation.
3    tdb utility functions
4    Copyright (C) Andrew Tridgell 1999
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __TDBUTIL_H__
21 #define __TDBUTIL_H__
22
23 #include "tdb.h"
24
25 #include "talloc.h" /* for tdb_wrap_open() */
26 #include "nt_status.h" /* for map_nt_error_from_tdb() */
27
28 /* single node of a list returned by tdb_search_keys */
29 typedef struct keys_node 
30 {
31         struct keys_node *prev, *next;
32         TDB_DATA node_key;
33 } TDB_LIST_NODE;
34
35 struct tdb_wrap {
36         struct tdb_context *tdb;
37         const char *name;
38         struct tdb_wrap *next, *prev;
39 };
40
41 struct tdb_validation_status {
42         bool tdb_error;
43         bool bad_freelist;
44         bool bad_entry;
45         bool unknown_key;
46         bool success;
47 };
48
49 typedef int (*tdb_validate_data_func)(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state);
50
51 TDB_DATA make_tdb_data(const uint8 *dptr, size_t dsize);
52 TDB_DATA string_tdb_data(const char *string);
53 TDB_DATA string_term_tdb_data(const char *string);
54
55 TDB_LIST_NODE *tdb_search_keys(struct tdb_context*, const char*);
56 void tdb_search_list_free(TDB_LIST_NODE*);
57
58 int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key,
59                                 unsigned int timeout);
60 int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval);
61 int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
62                                    int timeout);
63 void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval);
64 int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
65                                         unsigned int timeout);
66 void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval);
67
68 int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key);
69 int32 tdb_fetch_int32(struct tdb_context *tdb, const char *keystr);
70 bool tdb_store_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 value);
71 bool tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32 value);
72 int tdb_store_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, int32 v);
73 int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32 v);
74 bool tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 *value);
75 bool tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32 *value);
76 int32 tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int32 *oldval, int32 change_val);
77 bool tdb_change_uint32_atomic(TDB_CONTEXT *tdb, const char *keystr,
78                               uint32 *oldval, uint32 change_val);
79
80 int tdb_wipe(TDB_CONTEXT *tdb);
81
82 int tdb_store_bystring(struct tdb_context *tdb, const char *keystr, TDB_DATA data, int flags);
83 int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr,
84                              TDB_DATA data, int flags);
85 TDB_DATA tdb_fetch_bystring(struct tdb_context *tdb, const char *keystr);
86 int tdb_delete_bystring(struct tdb_context *tdb, const char *keystr);
87 int tdb_trans_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf,
88                     int flag);
89 int tdb_trans_delete(struct tdb_context *tdb, TDB_DATA key);
90
91 int tdb_unpack(const uint8 *buf, int bufsize, const char *fmt, ...);
92 size_t tdb_pack(uint8 *buf, int bufsize, const char *fmt, ...);
93 bool tdb_pack_append(TALLOC_CTX *mem_ctx, uint8 **buf, size_t *len,
94                      const char *fmt, ...);
95
96 struct tdb_context *tdb_open_log(const char *name, int hash_size,
97                                  int tdb_flags, int open_flags, mode_t mode);
98
99 struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
100                                const char *name, int hash_size, int tdb_flags,
101                                int open_flags, mode_t mode);
102
103 NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err);
104
105 int tdb_validate(struct tdb_context *tdb, tdb_validate_data_func validate_fn);
106 int tdb_validate_open(const char *tdb_path, tdb_validate_data_func validate_fn);
107 int tdb_validate_and_backup(const char *tdb_path,
108                             tdb_validate_data_func validate_fn);
109
110 #endif /* __TDBUTIL_H__ */