2 #include "system/filesys.h"
3 #include "system/time.h"
5 #include "ldb_module.h"
8 typedef int (*ldb_kv_traverse_fn)(struct ltdb_private *ltdb,
9 struct ldb_val key, struct ldb_val data,
13 int (*store)(struct ltdb_private *ltdb, struct ldb_val key, struct ldb_val data, int flags);
14 int (*delete)(struct ltdb_private *ltdb, struct ldb_val key);
15 int (*iterate)(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, void *ctx);
16 int (*update_in_iterate)(struct ltdb_private *ltdb, struct ldb_val key,
17 struct ldb_val key2, struct ldb_val data, void *ctx);
18 int (*fetch_and_parse)(struct ltdb_private *ltdb, 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 ltdb_private *);
25 int (*prepare_write)(struct ltdb_private *);
26 int (*abort_write)(struct ltdb_private *);
27 int (*finish_write)(struct ltdb_private *);
28 int (*error)(struct ltdb_private *ltdb);
29 const char * (*errorstr)(struct ltdb_private *ltdb);
30 const char * (*name)(struct ltdb_private *ltdb);
31 bool (*has_changed)(struct ltdb_private *ltdb);
32 bool (*transaction_active)(struct ltdb_private *ltdb);
35 /* this private structure is used by the ltdb backend in the
38 const struct kv_db_ops *kv_ops;
40 unsigned int connect_flags;
42 unsigned long long sequence_number;
44 /* the low level tdb seqnum - used to avoid loading BASEINFO when
49 struct ldb_message *indexlist;
50 bool one_level_indexes;
51 bool attribute_indexes;
52 const char *GUID_index_attribute;
53 const char *GUID_index_dn_component;
59 bool disallow_dn_filter;
60 struct ltdb_idxptr *idxptr;
71 const struct ldb_schema_syntax *GUID_index_syntax;
74 * Maximum index key length. If non zero keys longer than this length
75 * will be truncated for non unique indexes. Keys for unique indexes
76 * greater than this length will be rejected.
78 unsigned max_key_length;
82 struct ldb_module *module;
83 struct ldb_request *req;
85 bool request_terminated;
86 struct ltdb_req_spy *spy;
89 const struct ldb_parse_tree *tree;
92 const char * const *attrs;
93 struct tevent_timer *timeout_event;
99 struct ltdb_reindex_context {
100 struct ldb_module *module;
106 /* special record types */
107 #define LTDB_INDEX "@INDEX"
108 #define LTDB_INDEXLIST "@INDEXLIST"
109 #define LTDB_IDX "@IDX"
110 #define LTDB_IDXVERSION "@IDXVERSION"
111 #define LTDB_IDXATTR "@IDXATTR"
112 #define LTDB_IDXONE "@IDXONE"
113 #define LTDB_IDXDN "@IDXDN"
114 #define LTDB_IDXGUID "@IDXGUID"
115 #define LTDB_IDX_DN_GUID "@IDX_DN_GUID"
116 #define LTDB_BASEINFO "@BASEINFO"
117 #define LTDB_OPTIONS "@OPTIONS"
118 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
120 /* special attribute types */
121 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
122 #define LTDB_CHECK_BASE "checkBaseOnSearch"
123 #define LTDB_DISALLOW_DN_FILTER "disallowDNFilter"
124 #define LTDB_MOD_TIMESTAMP "whenChanged"
125 #define LTDB_OBJECTCLASS "objectClass"
128 #define LTDB_GUID_KEY_PREFIX "GUID="
129 #define LTDB_GUID_SIZE 16
130 #define LTDB_GUID_KEY_SIZE (LTDB_GUID_SIZE + sizeof(LTDB_GUID_KEY_PREFIX) - 1)
132 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */
134 int ltdb_cache_reload(struct ldb_module *module);
135 int ltdb_cache_load(struct ldb_module *module);
136 int ltdb_increase_sequence_number(struct ldb_module *module);
137 int ltdb_check_at_attributes_values(const struct ldb_val *value);
139 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */
141 struct ldb_parse_tree;
143 int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
144 int ltdb_index_add_new(struct ldb_module *module,
145 struct ltdb_private *ltdb,
146 const struct ldb_message *msg);
147 int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg);
148 int ltdb_index_del_element(struct ldb_module *module,
149 struct ltdb_private *ltdb,
150 const struct ldb_message *msg,
151 struct ldb_message_element *el);
152 int ltdb_index_add_element(struct ldb_module *module,
153 struct ltdb_private *ltdb,
154 const struct ldb_message *msg,
155 struct ldb_message_element *el);
156 int ltdb_index_del_value(struct ldb_module *module,
157 struct ltdb_private *ltdb,
158 const struct ldb_message *msg,
159 struct ldb_message_element *el, unsigned int v_idx);
160 int ltdb_reindex(struct ldb_module *module);
161 int ltdb_index_transaction_start(struct ldb_module *module);
162 int ltdb_index_transaction_commit(struct ldb_module *module);
163 int ltdb_index_transaction_cancel(struct ldb_module *module);
164 int ltdb_key_dn_from_idx(struct ldb_module *module,
165 struct ltdb_private *ltdb,
170 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
172 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
173 const struct ldb_val *val);
174 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
175 int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
176 unsigned int unpack_flags);
177 int ltdb_search_base(struct ldb_module *module,
180 struct ldb_dn **ret_dn);
181 int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
182 struct TDB_DATA tdb_key,
183 struct ldb_message *msg,
184 unsigned int unpack_flags);
185 int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
186 const struct ldb_message *msg, const char * const *attrs,
187 struct ldb_message **filtered_msg);
188 int ltdb_search(struct ltdb_context *ctx);
190 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
192 * Determine if this key could hold a record. We allow the new GUID
193 * index, the old DN index and a possible future ID=
195 bool ltdb_key_is_record(TDB_DATA key);
196 TDB_DATA ltdb_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx,
198 TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
199 const struct ldb_message *msg);
200 int ltdb_guid_to_key(struct ldb_module *module,
201 struct ltdb_private *ltdb,
202 const struct ldb_val *GUID_val,
204 int ltdb_idx_to_key(struct ldb_module *module,
205 struct ltdb_private *ltdb,
207 const struct ldb_val *idx_val,
209 TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
210 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
211 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
212 int ltdb_delete_noindex(struct ldb_module *module,
213 const struct ldb_message *msg);
214 int ltdb_err_map(enum TDB_ERROR tdb_code);
216 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
217 const char *path, int hash_size, int tdb_flags,
218 int open_flags, mode_t mode,
219 struct ldb_context *ldb);
220 int init_store(struct ltdb_private *ltdb, const char *name,
221 struct ldb_context *ldb, const char *options[],
222 struct ldb_module **_module);
224 int ltdb_connect(struct ldb_context *ldb, const char *url,
225 unsigned int flags, const char *options[],
226 struct ldb_module **_module);