ldb_tdb: Add/remove a GUID index of the DN during ltdb_index_add_all()/ltdb_index_del...
authorAndrew Bartlett <abartlet@samba.org>
Fri, 11 Aug 2017 00:25:42 +0000 (12:25 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:21 +0000 (21:20 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c
lib/ldb/ldb_tdb/ldb_tdb.h

index 9b5853f6c344666f512856d0fe5a5309eca9203d..916d39ce8bbae08607861c438713f2d331c02c36 100644 (file)
@@ -44,6 +44,10 @@ struct ltdb_idxptr {
        int error;
 };
 
+static int ltdb_write_index_dn_guid(struct ldb_module *module,
+                                   const struct ldb_message *msg,
+                                   int add);
+
 /* we put a @IDXVERSION attribute on index entries. This
    allows us to tell if it was written by an older version
 */
@@ -1387,23 +1391,28 @@ static int ltdb_index_add_all(struct ldb_module *module,
        struct ldb_message_element *elements = msg->elements;
        unsigned int i;
        const char *dn_str;
+       int ret;
 
-       if (ldb_dn_is_special(msg->dn)) {
-               return LDB_SUCCESS;
-       }
+       if (ldb_dn_is_special(msg->dn)) {
+               return LDB_SUCCESS;
+       }
 
        dn_str = ldb_dn_get_linearized(msg->dn);
        if (dn_str == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       ret = ltdb_write_index_dn_guid(module, msg, 1);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
        if (!ltdb->cache->attribute_indexes) {
                /* no indexed fields */
                return LDB_SUCCESS;
        }
 
        for (i = 0; i < msg->num_elements; i++) {
-               int ret;
                if (!ltdb_is_indexed(module, ltdb, elements[i].name)) {
                        continue;
                }
@@ -1495,6 +1504,25 @@ static int ltdb_index_onelevel(struct ldb_module *module,
        return ret;
 }
 
+/*
+  insert a one level index for a message
+*/
+static int ltdb_write_index_dn_guid(struct ldb_module *module,
+                                   const struct ldb_message *msg,
+                                   int add)
+{
+       struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module),
+                                                   struct ltdb_private);
+
+       /* We index for DN only if using a GUID index */
+       if (ltdb->cache->GUID_index_attribute == NULL) {
+               return LDB_SUCCESS;
+       }
+
+       return ltdb_modify_index_dn(module, ltdb, msg, msg->dn,
+                                   LTDB_IDXDN, add);
+}
+
 /*
   add the index entries for a new element in a record
   The caller guarantees that these element values are not yet indexed
@@ -1671,6 +1699,11 @@ int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg)
                return ret;
        }
 
+       ret = ltdb_write_index_dn_guid(module, msg, 0);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
        if (!ltdb->cache->attribute_indexes) {
                /* no indexed fields */
                return LDB_SUCCESS;
index 796b61dccf4bde3676100d42f2307a9d1343434e..8cf583febf04b119d1bf821eb038d19b80889807 100644 (file)
@@ -62,6 +62,7 @@ struct ltdb_context {
 #define LTDB_IDXVERSION "@IDXVERSION"
 #define LTDB_IDXATTR    "@IDXATTR"
 #define LTDB_IDXONE     "@IDXONE"
+#define LTDB_IDXDN     "@IDXDN"
 #define LTDB_BASEINFO   "@BASEINFO"
 #define LTDB_OPTIONS    "@OPTIONS"
 #define LTDB_ATTRIBUTES "@ATTRIBUTES"