summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-02-28 04:37:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:52:08 -0500
commitaf99fe6b011b70a1770ab9b70fd7e0cac20b1ac0 (patch)
treeac00d451c0c861343b3e2199c389471657c1e36f /source4/lib
parent4d4f7a054e78d5cb56a2d054c8cb2bee6bea0b22 (diff)
downloadsamba-af99fe6b011b70a1770ab9b70fd7e0cac20b1ac0.tar.gz
samba-af99fe6b011b70a1770ab9b70fd7e0cac20b1ac0.tar.bz2
samba-af99fe6b011b70a1770ab9b70fd7e0cac20b1ac0.zip
r13743: Generic fixes and improvements
(This used to be commit c5eb27e5f7b23e5aa7e0fb1e11abfc760b499e85)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c139
1 files changed, 80 insertions, 59 deletions
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index de32c10ba4..a5f4ab67fd 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -24,10 +24,22 @@
*/
/*
- This is a ldb backend for the internal ldap client library in
- Samba4. By using this backend we are independent of a system ldap
- library
-*/
+ * Name: ldb_ildap
+ *
+ * Component: ldb ildap backend
+ *
+ * Description: This is a ldb backend for the internal ldap
+ * client library in Samba4. By using this backend we are
+ * independent of a system ldap library
+ *
+ * Author: Andrew Tridgell
+ *
+ * Modifications:
+ *
+ * - description: make the module use asyncronous calls
+ * date: Feb 2006
+ * author: Simo Sorce
+ */
#include "includes.h"
@@ -141,7 +153,7 @@ static void ildb_async_callback(struct ldap_request *req)
{
struct ldb_async_handle *handle = talloc_get_type(req->async.private_data, struct ldb_async_handle);
struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context);
- struct ildb_private *ildb = ac->module->private_data;
+ struct ildb_private *ildb = talloc_get_type(ac->module->private_data, struct ildb_private);
NTSTATUS status;
int i;
@@ -166,6 +178,10 @@ static void ildb_async_callback(struct ldap_request *req)
}
status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult);
handle->status = ildb_map_error(ildb, status);
+ if (ac->callback && handle->status == LDB_SUCCESS) {
+ /* FIXME: build a corresponding ares to pass on */
+ handle->status = ac->callback(ac->module->ldb, ac->context, NULL);
+ }
handle->state = LDB_ASYNC_DONE;
break;
@@ -176,6 +192,10 @@ static void ildb_async_callback(struct ldap_request *req)
}
status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult);
handle->status = ildb_map_error(ildb, status);
+ if (ac->callback && handle->status == LDB_SUCCESS) {
+ /* FIXME: build a corresponding ares to pass on */
+ handle->status = ac->callback(ac->module->ldb, ac->context, NULL);
+ }
handle->state = LDB_ASYNC_DONE;
break;
@@ -186,6 +206,10 @@ static void ildb_async_callback(struct ldap_request *req)
}
status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult);
handle->status = ildb_map_error(ildb, status);
+ if (ac->callback && handle->status == LDB_SUCCESS) {
+ /* FIXME: build a corresponding ares to pass on */
+ handle->status = ac->callback(ac->module->ldb, ac->context, NULL);
+ }
handle->state = LDB_ASYNC_DONE;
break;
@@ -196,6 +220,10 @@ static void ildb_async_callback(struct ldap_request *req)
}
status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult);
handle->status = ildb_map_error(ildb, status);
+ if (ac->callback && handle->status == LDB_SUCCESS) {
+ /* FIXME: build a corresponding ares to pass on */
+ handle->status = ac->callback(ac->module->ldb, ac->context, NULL);
+ }
handle->state = LDB_ASYNC_DONE;
break;
@@ -302,7 +330,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg
int timeout,
struct ldb_async_handle **handle)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ildb_async_context *ildb_ac;
struct ldb_async_handle *h;
struct ldap_request *req;
@@ -362,7 +390,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas
int timeout,
struct ldb_async_handle **handle)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldap_message *msg;
int n;
@@ -422,12 +450,6 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas
return ildb_request_send(module, msg, context, callback, timeout, handle);
}
-struct ildb_sync_context {
- struct ldb_result *res;
- int status;
- int done;
-};
-
static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares)
{
struct ldb_result *res;
@@ -476,12 +498,10 @@ static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, str
res->refs[n + 1] = NULL;
}
- if (ares->type == LDB_REPLY_DONE) {
- if (ares->controls) {
- res->controls = talloc_steal(res, ares->controls);
- if (! res->controls) {
- goto error;
- }
+ if (ares->controls) {
+ res->controls = talloc_steal(res, ares->controls);
+ if (! res->controls) {
+ goto error;
}
}
@@ -504,7 +524,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
struct ldb_control **control_req,
struct ldb_result **res)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_async_handle *handle;
int ret;
@@ -531,7 +551,7 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l
int timeout,
struct ldb_async_handle **handle)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldap_message *msg;
struct ldap_mod **mods;
int i,n;
@@ -578,7 +598,7 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l
static int ildb_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_async_handle *handle;
int ret;
@@ -600,7 +620,7 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message
int timeout,
struct ldb_async_handle **handle)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldap_message *msg;
struct ldap_mod **mods;
int i,n;
@@ -647,7 +667,7 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message
static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_async_handle *handle;
int ret;
@@ -669,7 +689,7 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
int timeout,
struct ldb_async_handle **handle)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldap_message *msg;
*handle = NULL;
@@ -697,7 +717,7 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_async_handle *handle;
int ret;
@@ -720,7 +740,7 @@ static int ildb_rename_async(struct ldb_module *module,
int timeout,
struct ldb_async_handle **handle)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldap_message *msg;
*handle = NULL;
@@ -766,7 +786,7 @@ static int ildb_rename_async(struct ldb_module *module,
static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
- struct ildb_private *ildb = module->private_data;
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_async_handle *handle;
int ret;
@@ -878,36 +898,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req)
}
}
-/*
- fetch the rootDSE for later use
-*/
-static int ildb_init_2(struct ldb_module *module)
-{
- struct ildb_private *ildb = module->private_data;
- struct ldb_result *res = NULL;
- struct ldb_dn *empty_dn = ldb_dn_new(ildb);
- int ret;
- ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE,
- ldb_parse_tree(empty_dn, "dn=dc=rootDSE"),
- NULL, NULL, &res);
- if (ret == LDB_SUCCESS && res->count == 1) {
- ildb->rootDSE = talloc_steal(ildb, res->msgs[0]);
- }
- if (ret == LDB_SUCCESS) talloc_free(res);
- talloc_free(empty_dn);
-
- return LDB_SUCCESS;
-}
-
-static const struct ldb_module_ops ildb_ops = {
- .name = "ldap",
- .request = ildb_request,
- .start_transaction = ildb_start_trans,
- .end_transaction = ildb_end_trans,
- .del_transaction = ildb_del_trans,
- .second_stage_init = ildb_init_2
-};
-
static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type)
{
@@ -917,6 +907,8 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
return LDB_ERR_OPERATIONS_ERROR;
}
+ handle->state = LDB_ASYNC_INIT;
+
switch(type) {
case LDB_WAIT_NONE:
if (event_loop_once(ac->req->conn->event.event_ctx) != 0) {
@@ -924,7 +916,6 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
}
break;
case LDB_WAIT_ONCE:
- handle->state = LDB_ASYNC_INIT;
while (handle->status == LDB_SUCCESS && handle->state == LDB_ASYNC_INIT) {
if (event_loop_once(ac->req->conn->event.event_ctx) != 0) {
return LDB_ERR_OTHER;
@@ -946,6 +937,36 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
}
/*
+ fetch the rootDSE for later use
+*/
+static int ildb_init_2(struct ldb_module *module)
+{
+ struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
+ struct ldb_result *res = NULL;
+ struct ldb_dn *empty_dn = ldb_dn_new(ildb);
+ int ret;
+ ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE,
+ ldb_parse_tree(empty_dn, "dn=dc=rootDSE"),
+ NULL, NULL, &res);
+ if (ret == LDB_SUCCESS && res->count == 1) {
+ ildb->rootDSE = talloc_steal(ildb, res->msgs[0]);
+ }
+ if (ret == LDB_SUCCESS) talloc_free(res);
+ talloc_free(empty_dn);
+
+ return LDB_SUCCESS;
+}
+
+static const struct ldb_module_ops ildb_ops = {
+ .name = "ldap",
+ .request = ildb_request,
+ .start_transaction = ildb_start_trans,
+ .end_transaction = ildb_end_trans,
+ .del_transaction = ildb_del_trans,
+ .second_stage_init = ildb_init_2
+};
+
+/*
connect to the database
*/
int ildb_connect(struct ldb_context *ldb, const char *url,