ldb_tdb: Add ltdb_search_key()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 10 Aug 2017 04:06:08 +0000 (16:06 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:20 +0000 (21:20 +0200)
This allows us to slowly split out the tdb key in the DB from being the DN

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_search.c
lib/ldb/ldb_tdb/ldb_tdb.h

index 4d3c38a0b08cbef73ebee12e6f8d04a447ae0287..bbceead56f016e7bb58af94b7ee1c03f7b7f8f5e 100644 (file)
@@ -200,25 +200,18 @@ static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
   return LDB_ERR_NO_SUCH_OBJECT on record-not-found
   and LDB_SUCCESS on success
 */
-int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
+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)
 {
-       void *data = ldb_module_get_private(module);
-       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
        int ret;
-       TDB_DATA tdb_key;
        struct ltdb_parse_data_unpack_ctx ctx = {
                .msg = msg,
                .module = module,
                .unpack_flags = unpack_flags
        };
 
-       /* form the key */
-       tdb_key = ltdb_key_dn(module, dn);
-       if (!tdb_key.dptr) {
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
        memset(msg, 0, sizeof(*msg));
 
        msg->num_elements = 0;
@@ -237,6 +230,34 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes
                return ret;
        }
 
+       return LDB_SUCCESS;
+}
+
+/*
+  search the database for a single simple dn, returning all attributes
+  in a single message
+
+  return LDB_ERR_NO_SUCH_OBJECT on record-not-found
+  and LDB_SUCCESS on success
+*/
+int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
+                   unsigned int unpack_flags)
+{
+       void *data = ldb_module_get_private(module);
+       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+       int ret;
+       TDB_DATA tdb_key;
+       /* form the key */
+       tdb_key = ltdb_key_dn(module, dn);
+       if (!tdb_key.dptr) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ret = ltdb_search_key(module, ltdb, tdb_key, msg, unpack_flags);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
        if ((unpack_flags & LDB_UNPACK_DATA_FLAG_NO_DN) == 0) {
                if (!msg->dn) {
                        msg->dn = ldb_dn_copy(msg, dn);
index 5d264bf13eaaa6ff08a838f4e00d80de0bafa34f..93cff6727102354c93e9ff45c3637cb6c79fac29 100644 (file)
@@ -104,6 +104,10 @@ int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
 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,
                    unsigned int unpack_flags);
+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);