ldb_tdb: Load the syntax of the GUID index attr during ltdb_cache_load()
[samba.git] / lib / ldb / ldb_tdb / ldb_tdb.h
index 35218000eb4bb6a5334b9a6701b22ec92a960d52..17d9e6612ccf9af8bc58fcf9f573d20b8dbd0e84 100644 (file)
@@ -18,9 +18,9 @@ struct ltdb_private {
 
        struct ltdb_cache {
                struct ldb_message *indexlist;
-               struct ldb_message *attributes;
                bool one_level_indexes;
                bool attribute_indexes;
+               const char *GUID_index_attribute;
        } *cache;
 
        int in_transaction;
@@ -33,6 +33,10 @@ struct ltdb_private {
 
        bool warn_unindexed;
        bool warn_reindex;
+
+       bool read_only;
+
+       const struct ldb_schema_syntax *GUID_index_syntax;
 };
 
 struct ltdb_context {
@@ -48,6 +52,9 @@ struct ltdb_context {
        enum ldb_scope scope;
        const char * const *attrs;
        struct tevent_timer *timeout_event;
+
+       /* error handling */
+       int error;
 };
 
 /* special record types */
@@ -57,6 +64,9 @@ struct ltdb_context {
 #define LTDB_IDXVERSION "@IDXVERSION"
 #define LTDB_IDXATTR    "@IDXATTR"
 #define LTDB_IDXONE     "@IDXONE"
+#define LTDB_IDXDN     "@IDXDN"
+#define LTDB_IDXGUID    "@IDXGUID"
+#define LTDB_IDX_DN_GUID "@IDX_DN_GUID"
 #define LTDB_BASEINFO   "@BASEINFO"
 #define LTDB_OPTIONS    "@OPTIONS"
 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
@@ -68,6 +78,10 @@ struct ltdb_context {
 #define LTDB_MOD_TIMESTAMP "whenChanged"
 #define LTDB_OBJECTCLASS "objectClass"
 
+/* DB keys */
+#define LTDB_GUID_KEY_PREFIX "GUID="
+#define LTDB_GUID_SIZE 16
+
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c  */
 
 int ltdb_cache_reload(struct ldb_module *module);
@@ -80,13 +94,21 @@ int ltdb_check_at_attributes_values(const struct ldb_val *value);
 struct ldb_parse_tree;
 
 int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
-int ltdb_index_add_new(struct ldb_module *module, const struct ldb_message *msg);
+int ltdb_index_add_new(struct ldb_module *module,
+                      struct ltdb_private *ltdb,
+                      const struct ldb_message *msg);
 int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg);
-int ltdb_index_del_element(struct ldb_module *module, struct ldb_dn *dn,
+int ltdb_index_del_element(struct ldb_module *module,
+                          struct ltdb_private *ltdb,
+                          const struct ldb_message *msg,
                           struct ldb_message_element *el);
-int ltdb_index_add_element(struct ldb_module *module, struct ldb_dn *dn, 
+int ltdb_index_add_element(struct ldb_module *module,
+                          struct ltdb_private *ltdb,
+                          const struct ldb_message *msg,
                           struct ldb_message_element *el);
-int ltdb_index_del_value(struct ldb_module *module, struct ldb_dn *dn,
+int ltdb_index_del_value(struct ldb_module *module,
+                        struct ltdb_private *ltdb,
+                        const struct ldb_message *msg,
                         struct ldb_message_element *el, unsigned int v_idx);
 int ltdb_reindex(struct ldb_module *module);
 int ltdb_index_transaction_start(struct ldb_module *module);
@@ -98,23 +120,32 @@ int ltdb_index_transaction_cancel(struct ldb_module *module);
 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, 
                      const struct ldb_val *val);
 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
-int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg);
-int ltdb_add_attr_results(struct ldb_module *module,
-                         TALLOC_CTX *mem_ctx, 
-                         struct ldb_message *msg,
-                         const char * const attrs[], 
-                         unsigned int *count, 
-                         struct ldb_message ***res);
-int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs);
+int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
+                   unsigned int unpack_flags);
+int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn);
+int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
+                   struct TDB_DATA tdb_key,
+                   struct ldb_message *msg,
+                   unsigned int unpack_flags);
+int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
+                     const struct ldb_message *msg, const char * const *attrs,
+                     struct ldb_message **filtered_msg);
 int ltdb_search(struct ltdb_context *ctx);
 
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c  */
 int ltdb_lock_read(struct ldb_module *module);
 int ltdb_unlock_read(struct ldb_module *module);
-TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
+/* 
+ * Determine if this key could hold a record.  We allow the new GUID
+ * index, the old DN index and a possible future ID=
+ */
+bool ltdb_key_is_record(TDB_DATA key);
+TDB_DATA ltdb_key_dn(struct ldb_module *module, struct ldb_dn *dn);
+TDB_DATA ltdb_key_msg(struct ldb_module *module, const struct ldb_message *msg);
 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
-int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn);
+int ltdb_delete_noindex(struct ldb_module *module,
+                       const struct ldb_message *msg);
 int ltdb_err_map(enum TDB_ERROR tdb_code);
 
 struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,