ldb_tdb: Add a function to get the GUID key for a DN
authorAndrew Bartlett <abartlet@samba.org>
Fri, 11 Aug 2017 06:09:01 +0000 (18:09 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:22 +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 5da3be2b3e1144b41788d8178633d91168b9b7ba..6675ad0f05d96879d8088386989b7acd34deee1b 100644 (file)
@@ -47,6 +47,10 @@ struct ltdb_idxptr {
 static int ltdb_write_index_dn_guid(struct ldb_module *module,
                                    const struct ldb_message *msg,
                                    int add);
+static int ltdb_index_dn_base_dn(struct ldb_module *module,
+                                struct ltdb_private *ltdb,
+                                struct ldb_dn *base_dn,
+                                struct dn_list *dn_list);
 
 /* we put a @IDXVERSION attribute on index entries. This
    allows us to tell if it was written by an older version
@@ -266,6 +270,42 @@ normal_index:
        return LDB_SUCCESS;
 }
 
+int ltdb_key_dn_from_idx(struct ldb_module *module,
+                        struct ltdb_private *ltdb,
+                        TALLOC_CTX *mem_ctx,
+                        struct ldb_dn *dn,
+                        TDB_DATA *tdb_key)
+{
+       struct ldb_context *ldb = ldb_module_get_ctx(module);
+       int ret;
+       struct dn_list *list = talloc(mem_ctx, struct dn_list);
+       if (list == NULL) {
+               ldb_oom(ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ret = ltdb_index_dn_base_dn(module, ltdb, dn, list);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       if (list->count == 0) {
+               return LDB_ERR_NO_SUCH_OBJECT;
+       }
+       if (list->count > 1) {
+               return LDB_ERR_CONSTRAINT_VIOLATION;
+       }
+
+       *tdb_key = ltdb_guid_to_key(module, ltdb,
+                                   mem_ctx, &list->dn[0]);
+       if (tdb_key->dptr == NULL) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       return LDB_SUCCESS;
+}
+
+
 
 /*
   save a dn_list into a full @IDX style record
index 367a00f9cce5e12e851bbb511f738264707d8b6d..ce62bc010ba6489d4d02d74d0c319cdc0fef384e 100644 (file)
@@ -114,6 +114,11 @@ int ltdb_reindex(struct ldb_module *module);
 int ltdb_index_transaction_start(struct ldb_module *module);
 int ltdb_index_transaction_commit(struct ldb_module *module);
 int ltdb_index_transaction_cancel(struct ldb_module *module);
+int ltdb_key_dn_from_idx(struct ldb_module *module,
+                        struct ltdb_private *ltdb,
+                        TALLOC_CTX *mem_ctx,
+                        struct ldb_dn *dn,
+                        TDB_DATA *tdb_key);
 
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c  */