summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools
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
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')
-rw-r--r--source4/lib/ldb/tools/ldbedit.c9
-rw-r--r--source4/lib/ldb/tools/ldbutil.c68
-rw-r--r--source4/lib/ldb/tools/ldbutil.h5
3 files changed, 81 insertions, 1 deletions
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index d26f4d1b21..74e3037fb7 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -300,6 +300,7 @@ int main(int argc, const char **argv)
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
const char * const * attrs = NULL;
TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ struct ldb_control **req_ctrls;
ldb = ldb_init(mem_ctx, NULL);
@@ -325,7 +326,13 @@ int main(int argc, const char **argv)
}
}
- ret = ldb_search(ldb, ldb, &result, basedn, options->scope, attrs, "%s", expression);
+ req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls);
+ if (options->controls != NULL && req_ctrls== NULL) {
+ printf("parsing controls failed: %s\n", ldb_errstring(ldb));
+ return -1;
+ }
+
+ ret = ldb_search_ctrl(ldb, ldb, &result, basedn, options->scope, attrs, req_ctrls, "%s", expression);
if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
exit(1);
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;
+}
diff --git a/source4/lib/ldb/tools/ldbutil.h b/source4/lib/ldb/tools/ldbutil.h
index 7747dbec64..f8d3f3a210 100644
--- a/source4/lib/ldb/tools/ldbutil.h
+++ b/source4/lib/ldb/tools/ldbutil.h
@@ -39,3 +39,8 @@ int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
int ldb_modify_ctrl(struct ldb_context *ldb,
const struct ldb_message *message,
struct ldb_control **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, ...);