r20032: Add ldb_search_exp_fmt()
authorSimo Sorce <idra@samba.org>
Tue, 5 Dec 2006 02:48:58 +0000 (02:48 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:28:50 +0000 (14:28 -0500)
This functions adds support of a memory context to hook the results to
and a printf style exp_fmt partameter to easily build expressions at once.

source/lib/ldb/common/ldb.c

index c05f8313f1dcb5d674bfbfd6cf435b50236c1e00..733f0bc29a45d8a5885137a336bc082a8d930df5 100644 (file)
@@ -794,6 +794,42 @@ done:
        return ret;
 }
 
+/*
+ a useful search function where you can easily define the expression and that
+ takes a memory context where results are allocated
+*/
+
+int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_result **result,
+                        struct ldb_dn *base, enum ldb_scope scope, const char * const *attrs,
+                        const char *exp_fmt, ...)
+{
+       struct ldb_result **res;
+       char *expression;
+       va_list ap;
+       int ret;
+
+       *result = NULL;
+
+       va_start(ap, exp_fmt);
+       expression = talloc_vasprintf(mem_ctx, exp_fmt, ap);
+       va_end(ap);
+
+       if ( ! expression) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ret = ldb_search(ldb, base, scope, expression, attrs, res);
+
+       if (ret == LDB_SUCCESS) {
+               talloc_steal(mem_ctx, res);
+               result = res;
+       }
+
+       talloc_free(expression);
+
+       return ret;
+}
+
 /*
   add a record to the database. Will fail if a record with the given class and key
   already exists