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, TDB_DATA key, TDB_DATA data, int flags);
14 int (*delete)(struct ltdb_private *ltdb, TDB_DATA key);
15 int (*iterate)(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, void *ctx);
16 int (*update_in_iterate)(struct ltdb_private *ltdb, TDB_DATA key,
17 TDB_DATA key2, TDB_DATA data, void *ctx);
18 int (*fetch_and_parse)(struct ltdb_private *ltdb, TDB_DATA key,
19 int (*parser)(TDB_DATA key, TDB_DATA 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);
34 /* this private structure is used by the ltdb backend in the
37 const struct kv_db_ops *kv_ops;
39 unsigned int connect_flags;
41 unsigned long long sequence_number;
43 /* the low level tdb seqnum - used to avoid loading BASEINFO when
48 struct ldb_message *indexlist;
49 bool one_level_indexes;
50 bool attribute_indexes;
51 const char *GUID_index_attribute;
52 const char *GUID_index_dn_component;
58 bool disallow_dn_filter;
59 struct ltdb_idxptr *idxptr;
70 const struct ldb_schema_syntax *GUID_index_syntax;
73 * Maximum index key length. If non zero keys longer than this length
74 * will be truncated for non unique indexes. Keys for unique indexes
75 * greater than this length will be rejected.
77 unsigned max_key_length;
81 struct ldb_module *module;
82 struct ldb_request *req;
84 bool request_terminated;
85 struct ltdb_req_spy *spy;
88 const struct ldb_parse_tree *tree;
91 const char * const *attrs;
92 struct tevent_timer *timeout_event;
98 struct ltdb_reindex_context {
99 struct ldb_module *module;
105 /* special record types */
106 #define LTDB_INDEX "@INDEX"
107 #define LTDB_INDEXLIST "@INDEXLIST"
108 #define LTDB_IDX "@IDX"
109 #define LTDB_IDXVERSION "@IDXVERSION"
110 #define LTDB_IDXATTR "@IDXATTR"
111 #define LTDB_IDXONE "@IDXONE"
112 #define LTDB_IDXDN "@IDXDN"
113 #define LTDB_IDXGUID "@IDXGUID"
114 #define LTDB_IDX_DN_GUID "@IDX_DN_GUID"
115 #define LTDB_BASEINFO "@BASEINFO"
116 #define LTDB_OPTIONS "@OPTIONS"
117 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
119 /* special attribute types */
120 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
121 #define LTDB_CHECK_BASE "checkBaseOnSearch"
122 #define LTDB_DISALLOW_DN_FILTER "disallowDNFilter"
123 #define LTDB_MOD_TIMESTAMP "whenChanged"
124 #define LTDB_OBJECTCLASS "objectClass"
127 #define LTDB_GUID_KEY_PREFIX "GUID="
128 #define LTDB_GUID_SIZE 16
129 #define LTDB_GUID_KEY_SIZE (LTDB_GUID_SIZE + sizeof(LTDB_GUID_KEY_PREFIX) - 1)
131 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */
133 int ltdb_cache_reload(struct ldb_module *module);
134 int ltdb_cache_load(struct ldb_module *module);
135 int ltdb_increase_sequence_number(struct ldb_module *module);
136 int ltdb_check_at_attributes_values(const struct ldb_val *value);
138 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */
140 struct ldb_parse_tree;
142 int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
143 int ltdb_index_add_new(struct ldb_module *module,
144 struct ltdb_private *ltdb,
145 const struct ldb_message *msg);
146 int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg);
147 int ltdb_index_del_element(struct ldb_module *module,
148 struct ltdb_private *ltdb,
149 const struct ldb_message *msg,
150 struct ldb_message_element *el);
151 int ltdb_index_add_element(struct ldb_module *module,
152 struct ltdb_private *ltdb,
153 const struct ldb_message *msg,
154 struct ldb_message_element *el);
155 int ltdb_index_del_value(struct ldb_module *module,
156 struct ltdb_private *ltdb,
157 const struct ldb_message *msg,
158 struct ldb_message_element *el, unsigned int v_idx);
159 int ltdb_reindex(struct ldb_module *module);
160 int ltdb_index_transaction_start(struct ldb_module *module);
161 int ltdb_index_transaction_commit(struct ldb_module *module);
162 int ltdb_index_transaction_cancel(struct ldb_module *module);
163 int ltdb_key_dn_from_idx(struct ldb_module *module,
164 struct ltdb_private *ltdb,
169 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
171 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
172 const struct ldb_val *val);
173 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
174 int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
175 unsigned int unpack_flags);
176 int ltdb_search_base(struct ldb_module *module,
179 struct ldb_dn **ret_dn);
180 int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
181 struct TDB_DATA tdb_key,
182 struct ldb_message *msg,
183 unsigned int unpack_flags);
184 int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
185 const struct ldb_message *msg, const char * const *attrs,
186 struct ldb_message **filtered_msg);
187 int ltdb_search(struct ltdb_context *ctx);
189 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
191 * Determine if this key could hold a record. We allow the new GUID
192 * index, the old DN index and a possible future ID=
194 bool ltdb_key_is_record(TDB_DATA key);
195 TDB_DATA ltdb_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx,
197 TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
198 const struct ldb_message *msg);
199 int ltdb_guid_to_key(struct ldb_module *module,
200 struct ltdb_private *ltdb,
201 const struct ldb_val *GUID_val,
203 int ltdb_idx_to_key(struct ldb_module *module,
204 struct ltdb_private *ltdb,
206 const struct ldb_val *idx_val,
208 TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
209 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
210 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
211 int ltdb_delete_noindex(struct ldb_module *module,
212 const struct ldb_message *msg);
213 int ltdb_err_map(enum TDB_ERROR tdb_code);
215 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
216 const char *path, int hash_size, int tdb_flags,
217 int open_flags, mode_t mode,
218 struct ldb_context *ldb);
219 int init_store(struct ltdb_private *ltdb, const char *name,
220 struct ldb_context *ldb, const char *options[],
221 struct ldb_module **_module);
223 int ltdb_connect(struct ldb_context *ldb, const char *url,
224 unsigned int flags, const char *options[],
225 struct ldb_module **_module);