From ccb94436642c8254049e251d954e05605c66f591 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 Aug 2017 18:09:01 +1200 Subject: [PATCH] ldb_tdb: Add a function to get the GUID key for a DN Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/ldb_tdb/ldb_index.c | 40 ++++++++++++++++++++++++++++++++++++++++ lib/ldb/ldb_tdb/ldb_tdb.h | 5 +++++ 2 files changed, 45 insertions(+) diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 5da3be2b3e1..6675ad0f05d 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -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 diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 367a00f9cce..ce62bc010ba 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -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 */ -- 2.11.4.GIT