summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/dsdb/samdb/ldb_modules/extended_dn.c19
-rw-r--r--source4/dsdb/samdb/ldb_modules/proxy.c36
-rw-r--r--source4/ldap_server/ldap_backend.c22
-rw-r--r--source4/lib/ldb/common/ldb.c169
-rw-r--r--source4/lib/ldb/modules/paged_results.c21
-rw-r--r--source4/lib/ldb/modules/sort.c19
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c35
7 files changed, 186 insertions, 135 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn.c b/source4/dsdb/samdb/ldb_modules/extended_dn.c
index 25a8dd1d36..20d08ccf42 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn.c
@@ -271,19 +271,26 @@ static int extended_request(struct ldb_module *module, struct ldb_request *req)
static int extended_init(struct ldb_module *module)
{
- struct ldb_request request;
+ struct ldb_request *req;
int ret;
- request.operation = LDB_REQ_REGISTER;
- request.op.reg.oid = LDB_CONTROL_EXTENDED_DN_OID;
- request.controls = NULL;
+ req = talloc(module, struct ldb_request);
+ if (req == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
- ret = ldb_request(module->ldb, &request);
+ req->operation = LDB_REQ_REGISTER;
+ req->op.reg.oid = LDB_CONTROL_EXTENDED_DN_OID;
+ req->controls = NULL;
+
+ ret = ldb_request(module->ldb, req);
if (ret != LDB_SUCCESS) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "extended_dn: Unable to register control with rootdse!\n");
- return LDB_ERR_OTHER;
+ talloc_free(req);
+ return LDB_ERR_OPERATIONS_ERROR;
}
+ talloc_free(req);
return ldb_next_init(module);
}
diff --git a/source4/dsdb/samdb/ldb_modules/proxy.c b/source4/dsdb/samdb/ldb_modules/proxy.c
index 85b40b62d1..9f9a8c229e 100644
--- a/source4/dsdb/samdb/ldb_modules/proxy.c
+++ b/source4/dsdb/samdb/ldb_modules/proxy.c
@@ -249,7 +249,7 @@ static void proxy_convert_record(struct ldb_module *module, struct ldb_message *
static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *req)
{
struct proxy_data *proxy = talloc_get_type(module->private_data, struct proxy_data);
- struct ldb_request newreq;
+ struct ldb_request *newreq;
struct ldb_dn *base;
int ret, i;
@@ -268,43 +268,47 @@ static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *re
goto passthru;
}
- newreq.op.search.tree = proxy_convert_tree(module, req->op.search.tree);
+ newreq = talloc(module, struct ldb_request);
+ if (newreq == NULL) {
+ return -1;
+ }
+
+ newreq->op.search.tree = proxy_convert_tree(module, req->op.search.tree);
/* convert the basedn of this search */
base = ldb_dn_copy(proxy, req->op.search.base);
if (base == NULL) {
+ talloc_free(newreq);
goto failed;
}
base->comp_num -= proxy->newdn->comp_num;
- base = ldb_dn_compose(proxy, newreq.op.search.base, proxy->olddn);
+ base = ldb_dn_compose(proxy, newreq->op.search.base, proxy->olddn);
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "proxying: '%s' with dn '%s' \n",
- ldb_filter_from_tree(proxy, newreq.op.search.tree), ldb_dn_linearize(proxy, newreq.op.search.base));
+ ldb_filter_from_tree(proxy, newreq->op.search.tree), ldb_dn_linearize(proxy, newreq->op.search.base));
for (i = 0; req->op.search.attrs && req->op.search.attrs[i]; i++) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "attr: '%s'\n", req->op.search.attrs[i]);
}
- newreq.op.search.base = base;
- newreq.op.search.scope = req->op.search.scope;
- newreq.op.search.attrs = req->op.search.attrs;
- newreq.op.search.res = req->op.search.res;
- newreq.controls = req->controls;
- ret = ldb_request(proxy->upstream, &newreq);
+ newreq->op.search.base = base;
+ newreq->op.search.scope = req->op.search.scope;
+ newreq->op.search.attrs = req->op.search.attrs;
+ newreq->op.search.res = req->op.search.res;
+ newreq->controls = req->controls;
+ ret = ldb_request(proxy->upstream, newreq);
if (ret != LDB_SUCCESS) {
ldb_set_errstring(module->ldb, talloc_strdup(module, ldb_errstring(proxy->upstream)));
+ talloc_free(newreq);
return -1;
}
- for (i = 0; i < newreq.op.search.res->count; i++) {
- struct ldb_ldif ldif;
+ for (i = 0; i < newreq->op.search.res->count; i++) {
printf("# record %d\n", i+1);
- proxy_convert_record(module, newreq.op.search.res->msgs[i]);
-
- ldif.changetype = LDB_CHANGETYPE_NONE;
- ldif.msg = newreq.op.search.res->msgs[i];
+ proxy_convert_record(module, newreq->op.search.res->msgs[i]);
}
+ talloc_free(newreq);
return ret;
failed:
diff --git a/source4/ldap_server/ldap_backend.c b/source4/ldap_server/ldap_backend.c
index 713d99a2ea..b9f002f157 100644
--- a/source4/ldap_server/ldap_backend.c
+++ b/source4/ldap_server/ldap_backend.c
@@ -118,7 +118,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
struct ldb_context *samdb = talloc_get_type(call->conn->ldb, struct ldb_context);
struct ldb_dn *basedn;
struct ldb_result *res = NULL;
- struct ldb_request lreq;
+ struct ldb_request *lreq;
enum ldb_scope scope = LDB_SCOPE_DEFAULT;
const char **attrs = NULL;
const char *errstr = NULL;
@@ -172,19 +172,21 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
DEBUG(5,("ldb_request dn=%s filter=%s\n",
req->basedn, ldb_filter_from_tree(call, req->tree)));
- ZERO_STRUCT(lreq);
- lreq.operation = LDB_REQ_SEARCH;
- lreq.op.search.base = basedn;
- lreq.op.search.scope = scope;
- lreq.op.search.tree = req->tree;
- lreq.op.search.attrs = attrs;
+ lreq = talloc(local_ctx, struct ldb_request);
+ NT_STATUS_HAVE_NO_MEMORY(local_ctx);
+
+ lreq->operation = LDB_REQ_SEARCH;
+ lreq->op.search.base = basedn;
+ lreq->op.search.scope = scope;
+ lreq->op.search.tree = req->tree;
+ lreq->op.search.attrs = attrs;
- lreq.controls = call->request->controls;
+ lreq->controls = call->request->controls;
- ldb_ret = ldb_request(samdb, &lreq);
+ ldb_ret = ldb_request(samdb, lreq);
/* Ensure we don't keep the search results around for too long */
- res = talloc_steal(local_ctx, lreq.op.search.res);
+ res = talloc_steal(local_ctx, lreq->op.search.res);
if (ldb_ret == LDB_SUCCESS) {
for (i = 0; i < res->count; i++) {
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index ed3351dc5e..9acf74535b 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -257,57 +257,35 @@ static int ldb_op_finish(struct ldb_context *ldb, int status)
/*
start an ldb request
autostarts a transacion if none active and the operation is not a search
+ NOTE: the request must be a talloc context.
returns LDB_ERR_* on errors.
*/
-int ldb_request(struct ldb_context *ldb, struct ldb_request *request)
+int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
{
int status, started_transaction=0;
- struct ldb_request *r;
ldb_reset_err_string(ldb);
- /* to allow ldb modules to assume they can use the request ptr
- as a talloc context for the request, we have to copy the
- structure here */
- r = talloc(ldb, struct ldb_request);
- if (r == NULL) {
- ldb_oom(ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
- *r = *request;
-
- if (r->operation == LDB_REQ_SEARCH) {
- r->op.search.res = NULL;
+ if (req->operation == LDB_REQ_SEARCH) {
+ req->op.search.res = NULL;
}
/* start a transaction if needed */
if ((!ldb->transaction_active) &&
- (request->operation == LDB_REQ_ADD ||
- request->operation == LDB_REQ_MODIFY ||
- request->operation == LDB_REQ_DELETE ||
- request->operation == LDB_REQ_RENAME)) {
+ (req->operation == LDB_REQ_ADD ||
+ req->operation == LDB_REQ_MODIFY ||
+ req->operation == LDB_REQ_DELETE ||
+ req->operation == LDB_REQ_RENAME)) {
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) {
- talloc_free(r);
+ talloc_free(req);
return status;
}
started_transaction = 1;
}
/* call the first module in the chain */
- status = ldb->modules->ops->request(ldb->modules, r);
-
- /* the search call is the only one that returns something
- other than a status code. We steal the results into
- the context of the ldb before freeing the request */
- if (status == LDB_SUCCESS && request->operation == LDB_REQ_SEARCH) {
- request->op.search.res = talloc_steal(ldb, r->op.search.res);
- }
- if (status == LDB_SUCCESS && request->operation == LDB_ASYNC_SEARCH) {
- request->async.handle = r->async.handle;
- }
- talloc_free(r);
+ status = ldb->modules->ops->request(ldb->modules, req);
if (started_transaction) {
return ldb_op_finish(ldb, status);
@@ -331,31 +309,36 @@ int ldb_search(struct ldb_context *ldb,
const char * const *attrs,
struct ldb_result **res)
{
- struct ldb_request request;
- struct ldb_parse_tree *tree;
+ struct ldb_request *req;
int ret;
(*res) = NULL;
- tree = ldb_parse_tree(ldb, expression);
- if (tree == NULL) {
- ldb_set_errstring(ldb, talloc_strdup(ldb, "Unable to parse search expression"));
- return -1;
+ req = talloc(ldb, struct ldb_request);
+ if (req == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!"));
+ return LDB_ERR_OPERATIONS_ERROR;
}
- request.operation = LDB_REQ_SEARCH;
- request.op.search.base = base;
- request.op.search.scope = scope;
- request.op.search.tree = tree;
- request.op.search.attrs = attrs;
- request.controls = NULL;
+ req->operation = LDB_REQ_SEARCH;
+ req->op.search.base = base;
+ req->op.search.scope = scope;
- ret = ldb_request(ldb, &request);
+ req->op.search.tree = ldb_parse_tree(req, expression);
+ if (req->op.search.tree == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Unable to parse search expression"));
+ talloc_free(req);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
- (*res) = request.op.search.res;
+ req->op.search.attrs = attrs;
+ req->controls = NULL;
- talloc_free(tree);
+ ret = ldb_request(ldb, req);
+ (*res) = talloc_steal(ldb, req->op.search.res);
+
+ talloc_free(req);
return ret;
}
@@ -366,17 +349,26 @@ int ldb_search(struct ldb_context *ldb,
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
- struct ldb_request request;
- int status;
+ struct ldb_request *req;
+ int ret;
+
+ ret = ldb_msg_sanity_check(message);
+ if (ret != LDB_SUCCESS) return ret;
+
+ req = talloc(ldb, struct ldb_request);
+ if (req == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
- status = ldb_msg_sanity_check(message);
- if (status != LDB_SUCCESS) return status;
+ req->operation = LDB_REQ_ADD;
+ req->op.add.message = message;
+ req->controls = NULL;
- request.operation = LDB_REQ_ADD;
- request.op.add.message = message;
- request.controls = NULL;
+ ret = ldb_request(ldb, req);
- return ldb_request(ldb, &request);
+ talloc_free(req);
+ return ret;
}
/*
@@ -385,17 +377,26 @@ int ldb_add(struct ldb_context *ldb,
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
- struct ldb_request request;
- int status;
+ struct ldb_request *req;
+ int ret;
+
+ ret = ldb_msg_sanity_check(message);
+ if (ret != LDB_SUCCESS) return ret;
+
+ req = talloc(ldb, struct ldb_request);
+ if (req == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
- status = ldb_msg_sanity_check(message);
- if (status != LDB_SUCCESS) return status;
+ req->operation = LDB_REQ_MODIFY;
+ req->op.add.message = message;
+ req->controls = NULL;
- request.operation = LDB_REQ_MODIFY;
- request.op.mod.message = message;
- request.controls = NULL;
+ ret = ldb_request(ldb, req);
- return ldb_request(ldb, &request);
+ talloc_free(req);
+ return ret;
}
@@ -404,13 +405,23 @@ int ldb_modify(struct ldb_context *ldb,
*/
int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
{
- struct ldb_request request;
+ struct ldb_request *req;
+ int ret;
+
+ req = talloc(ldb, struct ldb_request);
+ if (req == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ req->operation = LDB_REQ_DELETE;
+ req->op.del.dn = dn;
+ req->controls = NULL;
- request.operation = LDB_REQ_DELETE;
- request.op.del.dn = dn;
- request.controls = NULL;
+ ret = ldb_request(ldb, req);
- return ldb_request(ldb, &request);
+ talloc_free(req);
+ return ret;
}
/*
@@ -418,14 +429,24 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
*/
int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
- struct ldb_request request;
+ struct ldb_request *req;
+ int ret;
- request.operation = LDB_REQ_RENAME;
- request.op.rename.olddn = olddn;
- request.op.rename.newdn = newdn;
- request.controls = NULL;
+ req = talloc(ldb, struct ldb_request);
+ if (req == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ req->operation = LDB_REQ_RENAME;
+ req->op.rename.olddn = olddn;
+ req->op.rename.newdn = newdn;
+ req->controls = NULL;
- return ldb_request(ldb, &request);
+ ret = ldb_request(ldb, req);
+
+ talloc_free(req);
+ return ret;
}
diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c
index 9d6a50e27f..fd0cc7c90b 100644
--- a/source4/lib/ldb/modules/paged_results.c
+++ b/source4/lib/ldb/modules/paged_results.c
@@ -249,29 +249,36 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req)
static int paged_request_init(struct ldb_module *module)
{
- struct ldb_request request;
- int ret;
struct private_data *data;
+ struct ldb_request *req;
+ int ret;
data = talloc(module, struct private_data);
if (data == NULL) {
return LDB_ERR_OTHER;
}
-
+
data->next_free_id = 1;
data->store = NULL;
module->private_data = data;
- request.operation = LDB_REQ_REGISTER;
- request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID;
- request.controls = NULL;
+ req = talloc(module, struct ldb_request);
+ if (req == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ req->operation = LDB_REQ_REGISTER;
+ req->op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID;
+ req->controls = NULL;
- ret = ldb_request(module->ldb, &request);
+ ret = ldb_request(module->ldb, req);
if (ret != LDB_SUCCESS) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n");
+ talloc_free(req);
return LDB_ERR_OTHER;
}
+ talloc_free(req);
return ldb_next_init(module);
}
diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c
index 82b589c749..08047c21f5 100644
--- a/source4/lib/ldb/modules/sort.c
+++ b/source4/lib/ldb/modules/sort.c
@@ -395,6 +395,8 @@ static int server_sort_search_async(struct ldb_module *module, struct ldb_contro
ac->reverse = sort_ctrls[0]->reverse;
ac->req = talloc(req, struct ldb_request);
+ if (!ac->req)
+ return LDB_ERR_OPERATIONS_ERROR;
ac->req->operation = req->operation;
ac->req->op.search.base = req->op.search.base;
@@ -548,19 +550,26 @@ static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_asyn
static int server_sort_init(struct ldb_module *module)
{
- struct ldb_request request;
+ struct ldb_request *req;
int ret;
- request.operation = LDB_REQ_REGISTER;
- request.op.reg.oid = LDB_CONTROL_SERVER_SORT_OID;
- request.controls = NULL;
+ req = talloc(module, struct ldb_request);
+ if (req == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ req->operation = LDB_REQ_REGISTER;
+ req->op.reg.oid = LDB_CONTROL_SERVER_SORT_OID;
+ req->controls = NULL;
- ret = ldb_request(module->ldb, &request);
+ ret = ldb_request(module->ldb, req);
if (ret != LDB_SUCCESS) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n");
+ talloc_free(req);
return LDB_ERR_OTHER;
}
+ talloc_free(req);
return ldb_next_init(module);
}
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index fbf32c0777..77f54fee65 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -68,33 +68,34 @@ static int do_search(struct ldb_context *ldb,
int loop = 0;
int total = 0;
int refs = 0;
- struct ldb_request req;
+ struct ldb_request *req;
struct ldb_result *result = NULL;
- req.operation = LDB_REQ_SEARCH;
- req.op.search.base = basedn;
- req.op.search.scope = options->scope;
- req.op.search.tree = ldb_parse_tree(ldb, expression);
- if (req.op.search.tree == NULL) return -1;
- req.op.search.attrs = attrs;
- req.op.search.res = NULL;
- req.controls = parse_controls(ldb, options->controls);
- if (options->controls != NULL && req.controls == NULL) return -1;
- req.creds = NULL;
+ req = talloc(ldb, struct ldb_request);
+ req->operation = LDB_REQ_SEARCH;
+ req->op.search.base = basedn;
+ req->op.search.scope = options->scope;
+ req->op.search.tree = ldb_parse_tree(ldb, expression);
+ if (req->op.search.tree == NULL) return -1;
+ req->op.search.attrs = attrs;
+ req->op.search.res = NULL;
+ req->controls = parse_controls(ldb, options->controls);
+ if (options->controls != NULL && req->controls == NULL) return -1;
+ req->creds = NULL;
do {
loop = 0;
- ret = ldb_request(ldb, &req);
+ ret = ldb_request(ldb, req);
if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
- if (req.op.search.res && req.op.search.res->controls) {
- handle_controls_reply(req.op.search.res->controls, req.controls);
+ if (req->op.search.res && req->op.search.res->controls) {
+ handle_controls_reply(req->op.search.res->controls, req->controls);
}
return -1;
}
- result = req.op.search.res;
+ result = req->op.search.res;
if (options->sorted) {
ldb_qsort(result->msgs, result->count, sizeof(struct ldb_message *),
@@ -127,7 +128,7 @@ static int do_search(struct ldb_context *ldb,
}
if (result->controls) {
- if (handle_controls_reply(result->controls, req.controls) == 1)
+ if (handle_controls_reply(result->controls, req->controls) == 1)
loop = 1;
}
@@ -139,7 +140,7 @@ static int do_search(struct ldb_context *ldb,
}
}
- req.op.search.res = NULL;
+ req->op.search.res = NULL;
} while(loop);