2 Unix SMB/CIFS implementation.
3 Database interface wrapper around tdb
4 Copyright (C) Volker Lendecke 2005-2007
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.
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.
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/>.
26 #include "libcli/util/ntstatus.h"
32 enum dbwrap_lock_order
{
33 DBWRAP_LOCK_ORDER_NONE
= 0, /* Don't check lock orders for this db. */
34 DBWRAP_LOCK_ORDER_1
= 1,
35 DBWRAP_LOCK_ORDER_2
= 2,
36 DBWRAP_LOCK_ORDER_3
= 3,
37 DBWRAP_LOCK_ORDER_4
= 4
40 #define DBWRAP_FLAG_NONE 0x0000000000000000ULL
41 #define DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS 0x0000000000000001ULL
43 enum dbwrap_req_state
{
45 * We are creating the request
49 * The request is queued and waiting to be dispatched
53 * We are waiting to receive the reply
55 DBWRAP_REQ_DISPATCHED
,
57 * The request is finished
61 * The request errored out
66 /* The following definitions come from lib/dbwrap.c */
68 TDB_DATA
dbwrap_record_get_key(const struct db_record
*rec
);
69 TDB_DATA
dbwrap_record_get_value(const struct db_record
*rec
);
70 NTSTATUS
dbwrap_record_store(struct db_record
*rec
, TDB_DATA data
, int flags
);
71 NTSTATUS
dbwrap_record_storev(struct db_record
*rec
,
72 const TDB_DATA
*dbufs
, int num_dbufs
, int flags
);
73 NTSTATUS
dbwrap_record_delete(struct db_record
*rec
);
76 * @brief Adds TDB records from one db_context to another
78 * @param to Destination db_context
79 * @param from Source db_context
80 * @param flags (TDB_INSERT or TDB_REPLACE)
82 * @return NT_STATUS_OK on success or NT_STATUS_INTERNAL_DB_CORRUPTION
85 dbwrap_merge_dbs(struct db_context
*to
, struct db_context
*from
, int flags
);
87 struct db_record
*dbwrap_fetch_locked(struct db_context
*db
,
90 struct db_context
*dbwrap_record_get_db(struct db_record
*rec
);
92 void dbwrap_lock_order_lock(const char *db_name
,
93 enum dbwrap_lock_order lock_order
);
94 void dbwrap_lock_order_unlock(const char *db_name
,
95 enum dbwrap_lock_order lock_order
);
97 NTSTATUS
dbwrap_do_locked(struct db_context
*db
, TDB_DATA key
,
98 void (*fn
)(struct db_record
*rec
,
103 NTSTATUS
dbwrap_delete(struct db_context
*db
, TDB_DATA key
);
104 NTSTATUS
dbwrap_store(struct db_context
*db
, TDB_DATA key
,
105 TDB_DATA data
, int flags
);
106 NTSTATUS
dbwrap_fetch(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
107 TDB_DATA key
, TDB_DATA
*value
);
108 bool dbwrap_exists(struct db_context
*db
, TDB_DATA key
);
109 NTSTATUS
dbwrap_traverse(struct db_context
*db
,
110 int (*f
)(struct db_record
*, void*),
113 NTSTATUS
dbwrap_traverse_read(struct db_context
*db
,
114 int (*f
)(struct db_record
*, void*),
117 NTSTATUS
dbwrap_parse_record(struct db_context
*db
, TDB_DATA key
,
118 void (*parser
)(TDB_DATA key
, TDB_DATA data
,
122 * Async implementation of dbwrap_parse_record
124 * @param[in] mem_ctx talloc memory context to use.
126 * @param[in] ev tevent context to use
128 * @param[in] db Database to query
130 * @param[in] key Record key, the function makes a copy of this
132 * @param[in] parser Parser callback function
134 * @param[in] private_data Private data for the callback function
136 * @param[out] req_state Pointer to a enum dbwrap_req_state variable
138 * @note req_state is updated in the send function. To determine the final
139 * result of the request the caller should therefore not rely on req_state. The
140 * primary use case is to give the caller an indication whether the request is
141 * already sent to ctdb (DBWRAP_REQ_DISPATCHED) or if it's still stuck in the
142 * sendqueue (DBWRAP_REQ_QUEUED).
144 struct tevent_req
*dbwrap_parse_record_send(
146 struct tevent_context
*ev
,
147 struct db_context
*db
,
149 void (*parser
)(TDB_DATA key
, TDB_DATA data
, void *private_data
),
151 enum dbwrap_req_state
*req_state
);
152 NTSTATUS
dbwrap_parse_record_recv(struct tevent_req
*req
);
153 int dbwrap_wipe(struct db_context
*db
);
154 int dbwrap_check(struct db_context
*db
);
155 int dbwrap_get_seqnum(struct db_context
*db
);
156 /* Returns 0 if unknown. */
157 int dbwrap_transaction_start(struct db_context
*db
);
158 NTSTATUS
dbwrap_transaction_start_nonblock(struct db_context
*db
);
159 int dbwrap_transaction_commit(struct db_context
*db
);
160 int dbwrap_transaction_cancel(struct db_context
*db
);
161 size_t dbwrap_db_id(struct db_context
*db
, uint8_t *id
, size_t idlen
);
162 bool dbwrap_is_persistent(struct db_context
*db
);
163 const char *dbwrap_name(struct db_context
*db
);
165 /* The following definitions come from lib/dbwrap_util.c */
167 NTSTATUS
dbwrap_purge(struct db_context
*db
, TDB_DATA key
);
168 NTSTATUS
dbwrap_purge_bystring(struct db_context
*db
, const char *key
);
169 NTSTATUS
dbwrap_delete_bystring(struct db_context
*db
, const char *key
);
170 NTSTATUS
dbwrap_store_bystring(struct db_context
*db
, const char *key
,
171 TDB_DATA data
, int flags
);
172 NTSTATUS
dbwrap_fetch_bystring(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
173 const char *key
, TDB_DATA
*value
);
175 NTSTATUS
dbwrap_fetch_int32(struct db_context
*db
, TDB_DATA key
,
177 NTSTATUS
dbwrap_fetch_int32_bystring(struct db_context
*db
, const char *keystr
,
179 NTSTATUS
dbwrap_store_int32_bystring(struct db_context
*db
, const char *keystr
,
181 NTSTATUS
dbwrap_fetch_uint32_bystring(struct db_context
*db
,
182 const char *keystr
, uint32_t *val
);
183 NTSTATUS
dbwrap_store_uint32_bystring(struct db_context
*db
,
184 const char *keystr
, uint32_t v
);
185 NTSTATUS
dbwrap_change_uint32_atomic_bystring(struct db_context
*db
,
188 uint32_t change_val
);
189 NTSTATUS
dbwrap_trans_change_uint32_atomic_bystring(struct db_context
*db
,
192 uint32_t change_val
);
193 NTSTATUS
dbwrap_change_int32_atomic(struct db_context
*db
,
197 NTSTATUS
dbwrap_change_int32_atomic_bystring(struct db_context
*db
,
201 NTSTATUS
dbwrap_trans_change_int32_atomic_bystring(struct db_context
*db
,
205 NTSTATUS
dbwrap_trans_store(struct db_context
*db
, TDB_DATA key
, TDB_DATA dbuf
,
207 NTSTATUS
dbwrap_trans_delete(struct db_context
*db
, TDB_DATA key
);
208 NTSTATUS
dbwrap_trans_store_int32_bystring(struct db_context
*db
,
211 NTSTATUS
dbwrap_trans_store_uint32_bystring(struct db_context
*db
,
214 NTSTATUS
dbwrap_trans_store_bystring(struct db_context
*db
, const char *key
,
215 TDB_DATA data
, int flags
);
216 NTSTATUS
dbwrap_trans_delete_bystring(struct db_context
*db
, const char *key
);
217 NTSTATUS
dbwrap_trans_do(struct db_context
*db
,
218 NTSTATUS (*action
)(struct db_context
*, void *),
220 NTSTATUS
dbwrap_trans_traverse(struct db_context
*db
,
221 int (*f
)(struct db_record
*, void*),
224 NTSTATUS
dbwrap_delete_bystring_upper(struct db_context
*db
, const char *key
);
225 NTSTATUS
dbwrap_store_bystring_upper(struct db_context
*db
, const char *key
,
226 TDB_DATA data
, int flags
);
227 NTSTATUS
dbwrap_fetch_bystring_upper(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
228 const char *key
, TDB_DATA
*value
);
230 size_t dbwrap_marshall(struct db_context
*db
, uint8_t *buf
, size_t bufsize
);
231 NTSTATUS
dbwrap_parse_marshall_buf(const uint8_t *buf
, size_t buflen
,
232 bool (*fn
)(TDB_DATA key
, TDB_DATA value
,
235 NTSTATUS
dbwrap_unmarshall(struct db_context
*db
, const uint8_t *buf
,
238 NTSTATUS
dbwrap_merge_dbufs(TDB_DATA
*buf
, TALLOC_CTX
*mem_ctx
,
239 const TDB_DATA
*dbufs
, int num_dbufs
);
243 * This opens a tdb file
245 struct db_context
*dbwrap_local_open(TALLOC_CTX
*mem_ctx
,
247 int hash_size
, int tdb_flags
,
248 int open_flags
, mode_t mode
,
249 enum dbwrap_lock_order lock_order
,
250 uint64_t dbwrap_flags
);
252 #endif /* __DBWRAP_H__ */