s3: smbd: Move check_fsp_open() and check_fsp() to smb1_reply.c
[Samba.git] / lib / dbwrap / dbwrap.h
blobcfae403b178a6f4d8b5996a737010b468416defb
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);
74 struct db_record *dbwrap_fetch_locked(struct db_context *db,
75 TALLOC_CTX *mem_ctx,
76 TDB_DATA key);
77 struct db_context *dbwrap_record_get_db(struct db_record *rec);
79 void dbwrap_lock_order_lock(const char *db_name,
80 enum dbwrap_lock_order lock_order);
81 void dbwrap_lock_order_unlock(const char *db_name,
82 enum dbwrap_lock_order lock_order);
84 NTSTATUS dbwrap_do_locked(struct db_context *db, TDB_DATA key,
85 void (*fn)(struct db_record *rec,
86 TDB_DATA value,
87 void *private_data),
88 void *private_data);
90 NTSTATUS dbwrap_delete(struct db_context *db, TDB_DATA key);
91 NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key,
92 TDB_DATA data, int flags);
93 NTSTATUS dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
94 TDB_DATA key, TDB_DATA *value);
95 bool dbwrap_exists(struct db_context *db, TDB_DATA key);
96 NTSTATUS dbwrap_traverse(struct db_context *db,
97 int (*f)(struct db_record*, void*),
98 void *private_data,
99 int *count);
100 NTSTATUS dbwrap_traverse_read(struct db_context *db,
101 int (*f)(struct db_record*, void*),
102 void *private_data,
103 int *count);
104 NTSTATUS dbwrap_parse_record(struct db_context *db, TDB_DATA key,
105 void (*parser)(TDB_DATA key, TDB_DATA data,
106 void *private_data),
107 void *private_data);
109 * Async implementation of dbwrap_parse_record
111 * @param[in] mem_ctx talloc memory context to use.
113 * @param[in] ev tevent context to use
115 * @param[in] db Database to query
117 * @param[in] key Record key, the function makes a copy of this
119 * @param[in] parser Parser callback function
121 * @param[in] private_data Private data for the callback function
123 * @param[out] req_state Pointer to a enum dbwrap_req_state variable
125 * @note req_state is updated in the send function. To determine the final
126 * result of the request the caller should therefor not rely on req_state. The
127 * primary use case is to give the caller an indication whether the request is
128 * already sent to ctdb (DBWRAP_REQ_DISPATCHED) or if it's still stuck in the
129 * sendqueue (DBWRAP_REQ_QUEUED).
131 struct tevent_req *dbwrap_parse_record_send(
132 TALLOC_CTX *mem_ctx,
133 struct tevent_context *ev,
134 struct db_context *db,
135 TDB_DATA key,
136 void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data),
137 void *private_data,
138 enum dbwrap_req_state *req_state);
139 NTSTATUS dbwrap_parse_record_recv(struct tevent_req *req);
140 int dbwrap_wipe(struct db_context *db);
141 int dbwrap_check(struct db_context *db);
142 int dbwrap_get_seqnum(struct db_context *db);
143 /* Returns 0 if unknown. */
144 int dbwrap_transaction_start(struct db_context *db);
145 NTSTATUS dbwrap_transaction_start_nonblock(struct db_context *db);
146 int dbwrap_transaction_commit(struct db_context *db);
147 int dbwrap_transaction_cancel(struct db_context *db);
148 size_t dbwrap_db_id(struct db_context *db, uint8_t *id, size_t idlen);
149 bool dbwrap_is_persistent(struct db_context *db);
150 const char *dbwrap_name(struct db_context *db);
152 /* The following definitions come from lib/dbwrap_util.c */
154 NTSTATUS dbwrap_purge(struct db_context *db, TDB_DATA key);
155 NTSTATUS dbwrap_purge_bystring(struct db_context *db, const char *key);
156 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
157 NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
158 TDB_DATA data, int flags);
159 NTSTATUS dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
160 const char *key, TDB_DATA *value);
162 NTSTATUS dbwrap_fetch_int32(struct db_context *db, TDB_DATA key,
163 int32_t *result);
164 NTSTATUS dbwrap_fetch_int32_bystring(struct db_context *db, const char *keystr,
165 int32_t *result);
166 NTSTATUS dbwrap_store_int32_bystring(struct db_context *db, const char *keystr,
167 int32_t v);
168 NTSTATUS dbwrap_fetch_uint32_bystring(struct db_context *db,
169 const char *keystr, uint32_t *val);
170 NTSTATUS dbwrap_store_uint32_bystring(struct db_context *db,
171 const char *keystr, uint32_t v);
172 NTSTATUS dbwrap_change_uint32_atomic_bystring(struct db_context *db,
173 const char *keystr,
174 uint32_t *oldval,
175 uint32_t change_val);
176 NTSTATUS dbwrap_trans_change_uint32_atomic_bystring(struct db_context *db,
177 const char *keystr,
178 uint32_t *oldval,
179 uint32_t change_val);
180 NTSTATUS dbwrap_change_int32_atomic(struct db_context *db,
181 TDB_DATA key,
182 int32_t *oldval,
183 int32_t change_val);
184 NTSTATUS dbwrap_change_int32_atomic_bystring(struct db_context *db,
185 const char *keystr,
186 int32_t *oldval,
187 int32_t change_val);
188 NTSTATUS dbwrap_trans_change_int32_atomic_bystring(struct db_context *db,
189 const char *keystr,
190 int32_t *oldval,
191 int32_t change_val);
192 NTSTATUS dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf,
193 int flag);
194 NTSTATUS dbwrap_trans_delete(struct db_context *db, TDB_DATA key);
195 NTSTATUS dbwrap_trans_store_int32_bystring(struct db_context *db,
196 const char *keystr,
197 int32_t v);
198 NTSTATUS dbwrap_trans_store_uint32_bystring(struct db_context *db,
199 const char *keystr,
200 uint32_t v);
201 NTSTATUS dbwrap_trans_store_bystring(struct db_context *db, const char *key,
202 TDB_DATA data, int flags);
203 NTSTATUS dbwrap_trans_delete_bystring(struct db_context *db, const char *key);
204 NTSTATUS dbwrap_trans_do(struct db_context *db,
205 NTSTATUS (*action)(struct db_context *, void *),
206 void *private_data);
207 NTSTATUS dbwrap_trans_traverse(struct db_context *db,
208 int (*f)(struct db_record*, void*),
209 void *private_data);
211 NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key);
212 NTSTATUS dbwrap_store_bystring_upper(struct db_context *db, const char *key,
213 TDB_DATA data, int flags);
214 NTSTATUS dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
215 const char *key, TDB_DATA *value);
217 size_t dbwrap_marshall(struct db_context *db, uint8_t *buf, size_t bufsize);
218 NTSTATUS dbwrap_parse_marshall_buf(const uint8_t *buf, size_t buflen,
219 bool (*fn)(TDB_DATA key, TDB_DATA value,
220 void *private_data),
221 void *private_data);
222 NTSTATUS dbwrap_unmarshall(struct db_context *db, const uint8_t *buf,
223 size_t buflen);
225 NTSTATUS dbwrap_merge_dbufs(TDB_DATA *buf, TALLOC_CTX *mem_ctx,
226 const TDB_DATA *dbufs, int num_dbufs);
230 * This opens a tdb file
232 struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
233 const char *name,
234 int hash_size, int tdb_flags,
235 int open_flags, mode_t mode,
236 enum dbwrap_lock_order lock_order,
237 uint64_t dbwrap_flags);
239 #endif /* __DBWRAP_H__ */