diff options
author | Simo Sorce <idra@samba.org> | 2006-12-05 02:48:58 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:28:50 -0500 |
commit | 5e583a96d4da28daac71efd44002480bb3f0fe17 (patch) | |
tree | 83413bb9b8fd4364401fd1ab9573a7401ef4f2ae /source4/lib/ldb/common/ldb.c | |
parent | 1027451d529ce521cbc9a74a605ae40afd850a43 (diff) | |
download | samba-5e583a96d4da28daac71efd44002480bb3f0fe17.tar.gz samba-5e583a96d4da28daac71efd44002480bb3f0fe17.tar.bz2 samba-5e583a96d4da28daac71efd44002480bb3f0fe17.zip |
r20032: Add ldb_search_exp_fmt()
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.
(This used to be commit 2a2e181e4bc382d69056cebace9a4ae9897bdfbc)
Diffstat (limited to 'source4/lib/ldb/common/ldb.c')
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index c05f8313f1..733f0bc29a 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -795,6 +795,42 @@ done: } /* + 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 */ |