diff options
author | Volker Lendecke <vlendec@samba.org> | 2006-12-05 06:25:12 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:16:21 -0500 |
commit | 1710dd1fe248ff82613e50ebb97be079e4f31bf4 (patch) | |
tree | 7e57a2e3717f0c8895ed45fe146af777a3963918 /source3/lib | |
parent | 490e3205bcf0866f6089a2b3964ad34d92d4c807 (diff) | |
download | samba-1710dd1fe248ff82613e50ebb97be079e4f31bf4.tar.gz samba-1710dd1fe248ff82613e50ebb97be079e4f31bf4.tar.bz2 samba-1710dd1fe248ff82613e50ebb97be079e4f31bf4.zip |
r20036: Merge ldb_search_exp_fmt -- Thanks simo
(This used to be commit fa6fa1268b33334d17869d0f096cf7600e88f993)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/ldb/common/ldb.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/source3/lib/ldb/common/ldb.c b/source3/lib/ldb/common/ldb.c index 9e0ee6ebca..512ad84efa 100644 --- a/source3/lib/ldb/common/ldb.c +++ b/source3/lib/ldb/common/ldb.c @@ -795,6 +795,45 @@ 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; + + res = NULL; + *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; + } else { + talloc_free(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 */ |