s3:libads: no longer pass "GSS-SPNEGO" to ads_sasl_spnego_gensec_bind()
[Samba.git] / lib / dbwrap / dbwrap.h
blobabc5161be050f13cbce47c6a633ece685385edf8
1 /*
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/>.
20 #ifndef __DBWRAP_H__
21 #define __DBWRAP_H__
23 #include "replace.h"
24 #include <talloc.h>
25 #include <tevent.h>
26 #include "libcli/util/ntstatus.h"
27 #include "tdb.h"
29 struct db_record;
30 struct db_context;
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 {
44 /**
45 * We are creating the request
47 DBWRAP_REQ_INIT,
48 /**
49 * The request is queued and waiting to be dispatched
51 DBWRAP_REQ_QUEUED,
52 /**
53 * We are waiting to receive the reply
55 DBWRAP_REQ_DISPATCHED,
56 /**
57 * The request is finished
59 DBWRAP_REQ_DONE,
60 /**
61 * The request errored out
63 DBWRAP_REQ_ERROR
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);
75 /**
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
84 NTSTATUS
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,
88 TALLOC_CTX *mem_ctx,
89 TDB_DATA key);
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,
99 TDB_DATA value,
100 void *private_data),
101 void *private_data);
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*),
111 void *private_data,
112 int *count);
113 NTSTATUS dbwrap_traverse_read(struct db_context *db,
114 int (*f)(struct db_record*, void*),
115 void *private_data,
116 int *count);
117 NTSTATUS dbwrap_parse_record(struct db_context *db, TDB_DATA key,
118 void (*parser)(TDB_DATA key, TDB_DATA data,
119 void *private_data),
120 void *private_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(
145 TALLOC_CTX *mem_ctx,
146 struct tevent_context *ev,
147 struct db_context *db,
148 TDB_DATA key,
149 void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data),
150 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,
176 int32_t *result);
177 NTSTATUS dbwrap_fetch_int32_bystring(struct db_context *db, const char *keystr,
178 int32_t *result);
179 NTSTATUS dbwrap_store_int32_bystring(struct db_context *db, const char *keystr,
180 int32_t v);
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,
186 const char *keystr,
187 uint32_t *oldval,
188 uint32_t change_val);
189 NTSTATUS dbwrap_trans_change_uint32_atomic_bystring(struct db_context *db,
190 const char *keystr,
191 uint32_t *oldval,
192 uint32_t change_val);
193 NTSTATUS dbwrap_change_int32_atomic(struct db_context *db,
194 TDB_DATA key,
195 int32_t *oldval,
196 int32_t change_val);
197 NTSTATUS dbwrap_change_int32_atomic_bystring(struct db_context *db,
198 const char *keystr,
199 int32_t *oldval,
200 int32_t change_val);
201 NTSTATUS dbwrap_trans_change_int32_atomic_bystring(struct db_context *db,
202 const char *keystr,
203 int32_t *oldval,
204 int32_t change_val);
205 NTSTATUS dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf,
206 int flag);
207 NTSTATUS dbwrap_trans_delete(struct db_context *db, TDB_DATA key);
208 NTSTATUS dbwrap_trans_store_int32_bystring(struct db_context *db,
209 const char *keystr,
210 int32_t v);
211 NTSTATUS dbwrap_trans_store_uint32_bystring(struct db_context *db,
212 const char *keystr,
213 uint32_t v);
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 *),
219 void *private_data);
220 NTSTATUS dbwrap_trans_traverse(struct db_context *db,
221 int (*f)(struct db_record*, void*),
222 void *private_data);
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,
233 void *private_data),
234 void *private_data);
235 NTSTATUS dbwrap_unmarshall(struct db_context *db, const uint8_t *buf,
236 size_t buflen);
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,
246 const char *name,
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__ */