2 #include "system/filesys.h"
3 #include "system/time.h"
5 #include "ldb_module.h"
8 typedef int (*ldb_kv_traverse_fn)(struct ldb_kv_private *ldb_kv,
9 struct ldb_val key, struct ldb_val data,
13 int (*store)(struct ldb_kv_private *ldb_kv, struct ldb_val key, struct ldb_val data, int flags);
14 int (*delete)(struct ldb_kv_private *ldb_kv, struct ldb_val key);
15 int (*iterate)(struct ldb_kv_private *ldb_kv, ldb_kv_traverse_fn fn, void *ctx);
16 int (*update_in_iterate)(struct ldb_kv_private *ldb_kv, struct ldb_val key,
17 struct ldb_val key2, struct ldb_val data, void *ctx);
18 int (*fetch_and_parse)(struct ldb_kv_private *ldb_kv, struct ldb_val key,
19 int (*parser)(struct ldb_val key, struct ldb_val data,
22 int (*lock_read)(struct ldb_module *);
23 int (*unlock_read)(struct ldb_module *);
24 int (*begin_write)(struct ldb_kv_private *);
25 int (*prepare_write)(struct ldb_kv_private *);
26 int (*abort_write)(struct ldb_kv_private *);
27 int (*finish_write)(struct ldb_kv_private *);
28 int (*error)(struct ldb_kv_private *ldb_kv);
29 const char * (*errorstr)(struct ldb_kv_private *ldb_kv);
30 const char * (*name)(struct ldb_kv_private *ldb_kv);
31 bool (*has_changed)(struct ldb_kv_private *ldb_kv);
32 bool (*transaction_active)(struct ldb_kv_private *ldb_kv);
35 /* this private structure is used by the key value backends in the
37 struct ldb_kv_private {
38 const struct kv_db_ops *kv_ops;
39 struct ldb_module *module;
41 struct lmdb_private *lmdb_private;
42 unsigned int connect_flags;
44 unsigned long long sequence_number;
46 /* the low level tdb seqnum - used to avoid loading BASEINFO when
51 struct ldb_message *indexlist;
52 bool one_level_indexes;
53 bool attribute_indexes;
54 const char *GUID_index_attribute;
55 const char *GUID_index_dn_component;
60 bool disallow_dn_filter;
61 struct ltdb_idxptr *idxptr;
72 const struct ldb_schema_syntax *GUID_index_syntax;
75 * Maximum index key length. If non zero keys longer than this length
76 * will be truncated for non unique indexes. Keys for unique indexes
77 * greater than this length will be rejected.
79 unsigned max_key_length;
82 * To allow testing that ensures the DB does not fall back
85 bool disable_full_db_scan;
88 * The PID that opened this database so we don't work in a
94 struct ldb_kv_context {
95 struct ldb_module *module;
96 struct ldb_request *req;
98 bool request_terminated;
99 struct ldb_kv_req_spy *spy;
102 const struct ldb_parse_tree *tree;
104 enum ldb_scope scope;
105 const char * const *attrs;
106 struct tevent_timer *timeout_event;
112 struct ldb_kv_reindex_context {
113 struct ldb_module *module;
119 /* special record types */
120 #define LTDB_INDEX "@INDEX"
121 #define LTDB_INDEXLIST "@INDEXLIST"
122 #define LTDB_IDX "@IDX"
123 #define LTDB_IDXVERSION "@IDXVERSION"
124 #define LTDB_IDXATTR "@IDXATTR"
125 #define LTDB_IDXONE "@IDXONE"
126 #define LTDB_IDXDN "@IDXDN"
127 #define LTDB_IDXGUID "@IDXGUID"
128 #define LTDB_IDX_DN_GUID "@IDX_DN_GUID"
131 * This will be used to indicate when a new, yet to be developed
132 * sub-database version of the indicies are in use, to ensure we do
133 * not load future databases unintentionally.
136 #define LTDB_IDX_LMDB_SUBDB "@IDX_LMDB_SUBDB"
138 #define LTDB_BASEINFO "@BASEINFO"
139 #define LTDB_OPTIONS "@OPTIONS"
140 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
142 /* special attribute types */
143 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
144 #define LTDB_CHECK_BASE "checkBaseOnSearch"
145 #define LTDB_DISALLOW_DN_FILTER "disallowDNFilter"
146 #define LTDB_MOD_TIMESTAMP "whenChanged"
147 #define LTDB_OBJECTCLASS "objectClass"
150 #define LTDB_GUID_KEY_PREFIX "GUID="
151 #define LTDB_GUID_SIZE 16
152 #define LTDB_GUID_KEY_SIZE (LTDB_GUID_SIZE + sizeof(LTDB_GUID_KEY_PREFIX) - 1)
154 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */
156 int ldb_kv_cache_reload(struct ldb_module *module);
157 int ldb_kv_cache_load(struct ldb_module *module);
158 int ldb_kv_increase_sequence_number(struct ldb_module *module);
159 int ldb_kv_check_at_attributes_values(const struct ldb_val *value);
161 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */
163 struct ldb_parse_tree;
165 int ldb_kv_search_indexed(struct ldb_kv_context *ctx, uint32_t *);
166 int ldb_kv_index_add_new(struct ldb_module *module,
167 struct ldb_kv_private *ldb_kv,
168 const struct ldb_message *msg);
169 int ldb_kv_index_delete(struct ldb_module *module,
170 const struct ldb_message *msg);
171 int ldb_kv_index_del_element(struct ldb_module *module,
172 struct ldb_kv_private *ldb_kv,
173 const struct ldb_message *msg,
174 struct ldb_message_element *el);
175 int ldb_kv_index_add_element(struct ldb_module *module,
176 struct ldb_kv_private *ldb_kv,
177 const struct ldb_message *msg,
178 struct ldb_message_element *el);
179 int ldb_kv_index_del_value(struct ldb_module *module,
180 struct ldb_kv_private *ldb_kv,
181 const struct ldb_message *msg,
182 struct ldb_message_element *el,
184 int ldb_kv_reindex(struct ldb_module *module);
185 int ldb_kv_index_transaction_start(struct ldb_module *module);
186 int ldb_kv_index_transaction_commit(struct ldb_module *module);
187 int ldb_kv_index_transaction_cancel(struct ldb_module *module);
188 int ldb_kv_key_dn_from_idx(struct ldb_module *module,
189 struct ldb_kv_private *ldb_kv,
194 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
196 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
197 const struct ldb_val *val);
198 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
199 int ldb_kv_search_dn1(struct ldb_module *module,
201 struct ldb_message *msg,
202 unsigned int unpack_flags);
203 int ldb_kv_search_base(struct ldb_module *module,
206 struct ldb_dn **ret_dn);
207 int ldb_kv_search_key(struct ldb_module *module,
208 struct ldb_kv_private *ldb_kv,
209 struct TDB_DATA tdb_key,
210 struct ldb_message *msg,
211 unsigned int unpack_flags);
212 int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx,
213 const struct ldb_message *msg,
214 const char *const *attrs,
215 struct ldb_message **filtered_msg);
216 int ldb_kv_search(struct ldb_kv_context *ctx);
218 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
220 * Determine if this key could hold a record. We allow the new GUID
221 * index, the old DN index and a possible future ID=
223 bool ldb_kv_key_is_record(TDB_DATA key);
224 TDB_DATA ldb_kv_key_dn(struct ldb_module *module,
227 TDB_DATA ldb_kv_key_msg(struct ldb_module *module,
229 const struct ldb_message *msg);
230 int ldb_kv_guid_to_key(struct ldb_module *module,
231 struct ldb_kv_private *ldb_kv,
232 const struct ldb_val *GUID_val,
234 int ldb_kv_idx_to_key(struct ldb_module *module,
235 struct ldb_kv_private *ldb_kv,
237 const struct ldb_val *idx_val,
239 TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
240 int ldb_kv_store(struct ldb_module *module,
241 const struct ldb_message *msg,
243 int ldb_kv_modify_internal(struct ldb_module *module,
244 const struct ldb_message *msg,
245 struct ldb_request *req);
246 int ldb_kv_delete_noindex(struct ldb_module *module,
247 const struct ldb_message *msg);
248 int ltdb_err_map(enum TDB_ERROR tdb_code);
250 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
251 const char *path, int hash_size, int tdb_flags,
252 int open_flags, mode_t mode,
253 struct ldb_context *ldb);
254 int ldb_kv_init_store(struct ldb_kv_private *ldb_kv,
256 struct ldb_context *ldb,
257 const char *options[],
258 struct ldb_module **_module);
260 int ltdb_connect(struct ldb_context *ldb, const char *url,
261 unsigned int flags, const char *options[],
262 struct ldb_module **_module);