summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb')
-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
4 files changed, 141 insertions, 103 deletions
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);