summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools/ldbutil.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-11-04 20:05:59 +1100
committerAndrew Tridgell <tridge@samba.org>2010-11-04 20:35:44 +1100
commit6a22d8938c36de8e8a6e99eadca896bdb9802b1d (patch)
tree55a035b958660f9919e9b205449f187d17b5886f /source4/lib/ldb/tools/ldbutil.c
parentcf37c29cd009f9378ffa4d3ee54b38aef9fa066b (diff)
downloadsamba-6a22d8938c36de8e8a6e99eadca896bdb9802b1d.tar.gz
samba-6a22d8938c36de8e8a6e99eadca896bdb9802b1d.tar.bz2
samba-6a22d8938c36de8e8a6e99eadca896bdb9802b1d.zip
s4-ldb: honor controls on search in ldbedit
Diffstat (limited to 'source4/lib/ldb/tools/ldbutil.c')
-rw-r--r--source4/lib/ldb/tools/ldbutil.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/source4/lib/ldb/tools/ldbutil.c b/source4/lib/ldb/tools/ldbutil.c
index 5f7ea894df..c9130b12ba 100644
--- a/source4/lib/ldb/tools/ldbutil.c
+++ b/source4/lib/ldb/tools/ldbutil.c
@@ -147,3 +147,71 @@ int ldb_modify_ctrl(struct ldb_context *ldb,
talloc_free(req);
return ret;
}
+
+
+/*
+ ldb_search with controls
+*/
+int ldb_search_ctrl(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
+ struct ldb_result **result, struct ldb_dn *base,
+ enum ldb_scope scope, const char * const *attrs,
+ struct ldb_control **controls,
+ const char *exp_fmt, ...)
+{
+ struct ldb_request *req;
+ struct ldb_result *res;
+ char *expression;
+ va_list ap;
+ int ret;
+
+ expression = NULL;
+ *result = NULL;
+ req = NULL;
+
+ res = talloc_zero(mem_ctx, struct ldb_result);
+ if (!res) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ if (exp_fmt) {
+ va_start(ap, exp_fmt);
+ expression = talloc_vasprintf(mem_ctx, exp_fmt, ap);
+ va_end(ap);
+
+ if (!expression) {
+ talloc_free(res);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ }
+
+ ret = ldb_build_search_req(&req, ldb, mem_ctx,
+ base?base:ldb_get_default_basedn(ldb),
+ scope,
+ expression,
+ attrs,
+ controls,
+ res,
+ ldb_search_default_callback,
+ NULL);
+ ldb_req_set_location(req, "ldb_search_ctrl");
+
+ if (ret != LDB_SUCCESS) goto done;
+
+ ret = ldb_request(ldb, req);
+
+ if (ret == LDB_SUCCESS) {
+ ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+ }
+
+done:
+ if (ret != LDB_SUCCESS) {
+ talloc_free(res);
+ res = NULL;
+ }
+
+ talloc_free(expression);
+ talloc_free(req);
+
+ *result = res;
+ return ret;
+}