mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
s4-ldb: honor controls on search in ldbedit
This commit is contained in:
parent
cf37c29cd0
commit
6a22d8938c
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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, ...);
|
||||
|
Loading…
Reference in New Issue
Block a user