r15927: Optimize ldb module traverse while keeping the API intact.
authorSimo Sorce <idra@samba.org>
Mon, 29 May 2006 01:30:02 +0000 (01:30 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:08:41 +0000 (14:08 -0500)
I was sick of jumping inot each module for each request,
even the ones not handle by that module.
(This used to be commit 7d65105e885a28584e8555453b90232c43a92bf7)

21 files changed:
source4/dsdb/samdb/ldb_modules/extended_dn.c
source4/dsdb/samdb/ldb_modules/kludge_acl.c
source4/dsdb/samdb/ldb_modules/objectguid.c
source4/dsdb/samdb/ldb_modules/password_hash.c
source4/dsdb/samdb/ldb_modules/rootdse.c
source4/dsdb/samdb/ldb_modules/samldb.c
source4/lib/ldb/common/ldb.c
source4/lib/ldb/common/ldb_modules.c
source4/lib/ldb/include/ldb_private.h
source4/lib/ldb/ldb_ildap/ldb_ildap.c
source4/lib/ldb/ldb_ldap/ldb_ldap.c
source4/lib/ldb/ldb_tdb/ldb_search.c
source4/lib/ldb/ldb_tdb/ldb_tdb.c
source4/lib/ldb/ldb_tdb/ldb_tdb.h
source4/lib/ldb/modules/asq.c
source4/lib/ldb/modules/operational.c
source4/lib/ldb/modules/paged_results.c
source4/lib/ldb/modules/rdn_name.c
source4/lib/ldb/modules/skel.c
source4/lib/ldb/modules/sort.c
source4/nbt_server/wins/wins_ldb.c

index e421f7d13c2dbcf67e563d2f9875b9f52c4bbf22..520ffde32db3ac1abc98733857e8e83260da8a5d 100644 (file)
@@ -290,8 +290,9 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-static int extended_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
+static int extended_search_async(struct ldb_module *module, struct ldb_request *req)
 {
+       struct ldb_control *control;
        struct ldb_extended_dn_control *extended_ctrl;
        struct ldb_control **saved_controls;
        struct extended_async_context *ac;
@@ -299,6 +300,13 @@ static int extended_search_async(struct ldb_module *module, struct ldb_control *
        char **new_attrs;
        int ret;
 
+       /* check if there's an extended dn control */
+       control = get_control_from_list(req->controls, LDB_CONTROL_EXTENDED_DN_OID);
+       if (control == NULL) {
+               /* not found go on */
+               return ldb_next_request(module, req);
+       }
+
        extended_ctrl = talloc_get_type(control->data, struct ldb_extended_dn_control);
        if (!extended_ctrl) {
                return LDB_ERR_PROTOCOL_ERROR;
@@ -397,9 +405,6 @@ static int extended_request(struct ldb_module *module, struct ldb_request *req)
        case LDB_REQ_SEARCH:
                return extended_search(module, control, req);
 
-       case LDB_ASYNC_SEARCH:
-               return extended_search_async(module, control, req);
-
        default:
                return LDB_ERR_OPERATIONS_ERROR;
 
@@ -433,6 +438,7 @@ static int extended_init(struct ldb_module *module)
 
 static const struct ldb_module_ops extended_dn_ops = {
        .name              = "extended_dn",
+       .search            = extended_search_async,
        .request           = extended_request,
        .init_context      = extended_init
 };
index 88e1831d14e6eab2d2bdcdad9b86ef684fbe6923..d6929bd732b0c26f6d3f96572b9e27ac371f787f 100644 (file)
@@ -266,21 +266,14 @@ static int kludge_acl_request(struct ldb_module *module, struct ldb_request *req
        switch (req->operation) {
 
        case LDB_REQ_ADD:
-       case LDB_ASYNC_ADD:
        case LDB_REQ_MODIFY:
-       case LDB_ASYNC_MODIFY:
        case LDB_REQ_DELETE:
-       case LDB_ASYNC_DELETE:
        case LDB_REQ_RENAME:
-       case LDB_ASYNC_RENAME:
                return kludge_acl_change(module, req);
 
        case LDB_REQ_SEARCH:
                return kludge_acl_search(module, req);
 
-       case LDB_ASYNC_SEARCH:
-               return kludge_acl_search_async(module, req);
-
        case LDB_REQ_REGISTER:
                return ldb_next_request(module, req);
 
@@ -354,6 +347,11 @@ done:
 
 static const struct ldb_module_ops kludge_acl_ops = {
        .name              = "kludge_acl",
+       .search            = kludge_acl_search_async,
+       .add               = kludge_acl_change,
+       .modify            = kludge_acl_change,
+       .del               = kludge_acl_change,
+       .rename            = kludge_acl_change,
        .request           = kludge_acl_request,
        .start_transaction = kludge_acl_start_trans,
        .end_transaction   = kludge_acl_end_trans,
index 96457447fb261a68e5746757f77b65e882d2b898..5ac32603391688678faa18a6fa5465315b7a958d 100644 (file)
@@ -174,9 +174,6 @@ static int objectguid_request(struct ldb_module *module, struct ldb_request *req
        case LDB_REQ_ADD:
                return objectguid_add(module, req);
 
-       case LDB_ASYNC_ADD:
-               return objectguid_add_async(module, req);
-
        default:
                return ldb_next_request(module, req);
 
@@ -185,6 +182,7 @@ static int objectguid_request(struct ldb_module *module, struct ldb_request *req
 
 static const struct ldb_module_ops objectguid_ops = {
        .name          = "objectguid",
+       .add           = objectguid_add_async,
        .request       = objectguid_request
 };
 
index 67cb01b9d8f2df67c7d0cf371159326687e61caa..0be0fff0ff1e6c9c4acfb9b65e7f6a6c53ffc39f 100644 (file)
@@ -1842,12 +1842,6 @@ static int password_hash_request(struct ldb_module *module, struct ldb_request *
        case LDB_REQ_MODIFY:
                return password_hash_modify(module, req);
 
-       case LDB_ASYNC_ADD:
-               return password_hash_add_async(module, req);
-
-       case LDB_ASYNC_MODIFY:
-               return password_hash_modify_async(module, req);
-
        default:
                return ldb_next_request(module, req);
 
@@ -1856,6 +1850,8 @@ static int password_hash_request(struct ldb_module *module, struct ldb_request *
 
 static const struct ldb_module_ops password_hash_ops = {
        .name          = "password_hash",
+       .add           = password_hash_add_async,
+       .modify        = password_hash_modify_async,
        .request       = password_hash_request,
        .async_wait    = password_hash_async_wait
 };
index 84622357f8b140ca5323f7a4004b3d62c355c493..892a98db12d2e38dda75d13a2fa04a5844eda924 100644 (file)
@@ -278,9 +278,6 @@ static int rootdse_request(struct ldb_module *module, struct ldb_request *req)
        case LDB_REQ_SEARCH:
                return rootdse_search_bytree(module, req);
 
-       case LDB_ASYNC_SEARCH:
-               return rootdse_search_async(module, req);
-               
        case LDB_REQ_REGISTER:
                return rootdse_register_control(module, req);
 
@@ -309,6 +306,7 @@ static int rootdse_init(struct ldb_module *module)
 static const struct ldb_module_ops rootdse_ops = {
        .name                   = "rootdse",
        .init_context           = rootdse_init,
+       .search                 = rootdse_search_async,
        .request                = rootdse_request
 };
 
index 9bf322f3844ed6123f4fc153dcb650ca32b230e1..368fd161d4b7c6d6e96b04e5ac4f80cf3a8a1ff9 100644 (file)
@@ -915,9 +915,6 @@ static int samldb_request(struct ldb_module *module, struct ldb_request *req)
        case LDB_REQ_ADD:
                return samldb_add(module, req);
 
-       case LDB_ASYNC_ADD:
-               return samldb_add_async(module, req);
-
        default:
                return ldb_next_request(module, req);
 
@@ -933,6 +930,7 @@ static int samldb_init(struct ldb_module *module)
 static const struct ldb_module_ops samldb_ops = {
        .name          = "samldb",
        .init_context  = samldb_init,
+       .add           = samldb_add_async,
        .request       = samldb_request
 };
 
index 3d5f816fe8771e43ddb5ba8c32e64fe01ed0e648..f3480014561813a68076266d953570eca9ce1e33 100644 (file)
@@ -280,7 +280,8 @@ static int ldb_op_finish(struct ldb_context *ldb, int status)
 */
 int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
 {
-       int status, started_transaction=0;
+       struct ldb_module *module;
+       int ret, started_transaction=0;
 
        ldb_reset_err_string(ldb);
 
@@ -288,28 +289,52 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
                req->op.search.res = NULL;
        }
 
-       /* start a transaction if not async and not search */
+       /* start a transaction if SYNC and not search */
        if ((!ldb->transaction_active) &&
            (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(req);
-                       return status;
+               ret = ldb_transaction_start(ldb);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
                }
                started_transaction = 1;
        }
 
        /* call the first module in the chain */
-       status = ldb->modules->ops->request(ldb->modules, req);
+       switch (req->operation) {
+       case LDB_ASYNC_SEARCH:
+               FIRST_OP(ldb, search);
+               ret = module->ops->search(module, req);
+               break;
+       case LDB_ASYNC_ADD:
+               FIRST_OP(ldb, add);
+               ret = module->ops->add(module, req);
+               break;
+       case LDB_ASYNC_MODIFY:
+               FIRST_OP(ldb, modify);
+               ret = module->ops->modify(module, req);
+               break;
+       case LDB_ASYNC_DELETE:
+               FIRST_OP(ldb, del);
+               ret = module->ops->del(module, req);
+               break;
+       case LDB_ASYNC_RENAME:
+               FIRST_OP(ldb, rename);
+               ret = module->ops->rename(module, req);
+               break;
+       default:
+               FIRST_OP(ldb, request);
+               ret = module->ops->request(module, req);
+               break;
+       }
 
        if (started_transaction) {
-               return ldb_op_finish(ldb, status);
+               return ldb_op_finish(ldb, ret);
        }
 
-       return status;
+       return ret;
 }
 
 /*
@@ -453,7 +478,6 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_reque
        }
 
        ret = ldb_request(ldb, req);
-
        if (ret == LDB_SUCCESS) {
                ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
        }
index bc27d1ed1b527150f9fddb7b242036292aa5511e..4ce404d0963b0d6e1523ad7e57160dd5786f43c7 100644 (file)
@@ -347,10 +347,29 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
 /*
    helper functions to call the next module in chain
 */
+
 int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
 {
-       FIND_OP(module, request);
-       return module->ops->request(module, request);
+       switch (request->operation) {
+       case LDB_ASYNC_SEARCH:
+               FIND_OP(module, search);
+               return module->ops->search(module, request);
+       case LDB_ASYNC_ADD:
+               FIND_OP(module, add);
+               return module->ops->add(module, request);
+       case LDB_ASYNC_MODIFY:
+               FIND_OP(module, modify);
+               return module->ops->modify(module, request);
+       case LDB_ASYNC_DELETE:
+               FIND_OP(module, del);
+               return module->ops->del(module, request);
+       case LDB_ASYNC_RENAME:
+               FIND_OP(module, rename);
+               return module->ops->rename(module, request);
+       default:
+               FIND_OP(module, request);
+               return module->ops->request(module, request);
+       }
 }
 
 int ldb_next_init(struct ldb_module *module)
index 0ea6c4e9dec828eeec34a9c3cb5ef228eb080f09..d8f9aa417de0bd1656847d1c55c5d475937ece19 100644 (file)
@@ -57,7 +57,12 @@ struct ldb_module {
 struct ldb_module_ops {
        const char *name;
        int (*init_context) (struct ldb_module *);
-       int (*request)(struct ldb_module *, struct ldb_request *);
+       int (*search)(struct ldb_module *, struct ldb_request *); /* search */
+       int (*add)(struct ldb_module *, struct ldb_request *); /* add */
+       int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */
+       int (*del)(struct ldb_module *, struct ldb_request *); /* delete */
+       int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */
+       int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */
        int (*start_transaction)(struct ldb_module *);
        int (*end_transaction)(struct ldb_module *);
        int (*del_transaction)(struct ldb_module *);
index 0fa7af25ec2c65a9df4be24fc8183492b4a20735..1454b565e0cea157058b5dc48909478ff913e6dd 100644 (file)
@@ -385,27 +385,20 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg
 /*
   search for matching records using an asynchronous function
  */
-static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *base,
-                             enum ldb_scope scope, struct ldb_parse_tree *tree,
-                             const char * const *attrs,
-                             struct ldb_control **control_req,
-                             void *context,
-                             int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                             int timeout,
-                             struct ldb_async_handle **handle)
+static int ildb_search_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
        struct ldap_message *msg;
        int n;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
-       if (!callback || !context) {
+       if (!req->async.callback || !req->async.context) {
                ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context"));
                return LDB_ERR_OPERATIONS_ERROR;
        }
        
-       if (tree == NULL) {
+       if (req->op.search.tree == NULL) {
                ldb_set_errstring(module->ldb, talloc_asprintf(module, "Invalid expression parse tree"));
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -418,7 +411,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas
 
        msg->type = LDAP_TAG_SearchRequest;
 
-       if (base == NULL) {
+       if (req->op.search.base == NULL) {
                if (ildb->rootDSE != NULL) {
                        msg->r.SearchRequest.basedn =
                                talloc_strdup(msg, ldb_msg_find_string(ildb->rootDSE, "defaultNamingContext", ""));
@@ -426,7 +419,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas
                        msg->r.SearchRequest.basedn = talloc_strdup(msg, "");
                }
        } else {
-               msg->r.SearchRequest.basedn  = ldb_dn_linearize(msg, base);
+               msg->r.SearchRequest.basedn  = ldb_dn_linearize(msg, req->op.search.base);
        }
        if (msg->r.SearchRequest.basedn == NULL) {
                ldb_set_errstring(module->ldb, talloc_asprintf(module, "Unable to determine baseDN"));
@@ -434,24 +427,24 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       if (scope == LDB_SCOPE_DEFAULT) {
+       if (req->op.search.scope == LDB_SCOPE_DEFAULT) {
                msg->r.SearchRequest.scope = LDB_SCOPE_SUBTREE;
        } else {
-               msg->r.SearchRequest.scope = scope;
+               msg->r.SearchRequest.scope = req->op.search.scope;
        }
        
        msg->r.SearchRequest.deref  = LDAP_DEREFERENCE_NEVER;
        msg->r.SearchRequest.timelimit = 0;
        msg->r.SearchRequest.sizelimit = 0;
        msg->r.SearchRequest.attributesonly = 0;
-       msg->r.SearchRequest.tree = tree;
+       msg->r.SearchRequest.tree = req->op.search.tree;
        
-       for (n = 0; attrs && attrs[n]; n++) /* noop */ ;
+       for (n = 0; req->op.search.attrs && req->op.search.attrs[n]; n++) /* noop */ ;
        msg->r.SearchRequest.num_attributes = n;
-       msg->r.SearchRequest.attributes = discard_const(attrs);
-       msg->controls = control_req;
+       msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs);
+       msg->controls = req->controls;
 
-       return ildb_request_send(module, msg, context, callback, timeout, handle);
+       return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle));
 }
 
 static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares)
@@ -529,7 +522,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
                              struct ldb_result **res)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
        *res = talloc_zero(ildb, struct ldb_result);
@@ -537,12 +530,26 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = ildb_search_async(module, base, scope, tree, attrs, control_req,
-                               res, &ildb_search_sync_callback, ildb->ldap->timeout, &handle);
+       req = talloc_zero(ildb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_SEARCH;
+       req->op.search.base = base;
+       req->op.search.scope = scope;
+       req->op.search.tree = tree;
+       req->op.search.attrs = attrs;
+       req->controls = control_req;
+       req->async.context = (void *)res;
+       req->async.callback = ildb_search_sync_callback;
+       req->async.timeout = ildb->ldap->timeout;
+
+       ret = ildb_search_async(module, req);
 
        if (ret == LDB_SUCCESS) {
-               ret = ldb_async_wait(handle, LDB_WAIT_ALL);
-               talloc_free(handle);
+               ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
+               talloc_free(req);
        }
 
        if (ret != LDB_SUCCESS) {
@@ -555,21 +562,17 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
 /*
   add a record
 */
-static int ildb_add_async(struct ldb_module *module, const struct ldb_message *ldb_msg,
-                         void *context,
-                         int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                         int timeout,
-                         struct ldb_async_handle **handle)
+static int ildb_add_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
        struct ldap_message *msg;
        struct ldap_mod **mods;
        int i,n;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
        /* ignore ltdb specials */
-       if (ldb_dn_is_special(ldb_msg->dn)) {
+       if (ldb_dn_is_special(req->op.add.message->dn)) {
                return LDB_SUCCESS;
        }
 
@@ -580,13 +583,13 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l
 
        msg->type = LDAP_TAG_AddRequest;
 
-       msg->r.AddRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn);
+       msg->r.AddRequest.dn = ldb_dn_linearize(msg, req->op.add.message->dn);
        if (msg->r.AddRequest.dn == NULL) {
                talloc_free(msg);
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       mods = ildb_msg_to_mods(msg, &n, ldb_msg, 0);
+       mods = ildb_msg_to_mods(msg, &n, req->op.add.message, 0);
        if (mods == NULL) {
                talloc_free(msg);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -603,45 +606,54 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l
                msg->r.AddRequest.attributes[i] = mods[i]->attrib;
        }
 
-       return ildb_request_send(module, msg, context, callback, timeout, handle);
+       return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle));
 }
 
 static int ildb_add(struct ldb_module *module, const struct ldb_message *msg)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ildb_add_async(module, msg,
-                               NULL, NULL, ildb->ldap->timeout, &handle);
+       req = talloc_zero(ildb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_ADD;
+       req->op.add.message = msg;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = ildb->ldap->timeout;
+
+       ret = ildb_add_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
 /*
   modify a record
 */
-static int ildb_modify_async(struct ldb_module *module, const struct ldb_message *ldb_msg,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            int timeout,
-                            struct ldb_async_handle **handle)
+static int ildb_modify_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
        struct ldap_message *msg;
        struct ldap_mod **mods;
        int i,n;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
        /* ignore ltdb specials */
-       if (ldb_dn_is_special(ldb_msg->dn)) {
+       if (ldb_dn_is_special(req->op.mod.message->dn)) {
                return LDB_SUCCESS;
        }
 
@@ -652,13 +664,13 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message
 
        msg->type = LDAP_TAG_ModifyRequest;
 
-       msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn);
+       msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, req->op.mod.message->dn);
        if (msg->r.ModifyRequest.dn == NULL) {
                talloc_free(msg);
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       mods = ildb_msg_to_mods(msg, &n, ldb_msg, 1);
+       mods = ildb_msg_to_mods(msg, &n, req->op.mod.message, 1);
        if (mods == NULL) {
                talloc_free(msg);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -675,43 +687,56 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message
                msg->r.ModifyRequest.mods[i] = *mods[i];
        }
 
-       return ildb_request_send(module, msg, context, callback, timeout, handle);
+       return ildb_request_send(module, msg,
+                               req->async.context,
+                               req->async.callback,
+                               req->async.timeout,
+                               &(req->async.handle));
 }
 
 static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ildb_modify_async(module, msg,
-                               NULL, NULL, ildb->ldap->timeout, &handle);
+       req = talloc_zero(ildb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_MODIFY;
+       req->op.mod.message = msg;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = ildb->ldap->timeout;
+
+       ret = ildb_modify_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
 /*
   delete a record
 */
-static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            int timeout,
-                            struct ldb_async_handle **handle)
+static int ildb_delete_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
        struct ldap_message *msg;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
        /* ignore ltdb specials */
-       if (ldb_dn_is_special(dn)) {
+       if (ldb_dn_is_special(req->op.del.dn)) {
                return LDB_SUCCESS;
        }
 
@@ -722,50 +747,62 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
 
        msg->type = LDAP_TAG_DelRequest;
        
-       msg->r.DelRequest.dn = ldb_dn_linearize(msg, dn);
+       msg->r.DelRequest.dn = ldb_dn_linearize(msg, req->op.del.dn);
        if (msg->r.DelRequest.dn == NULL) {
                talloc_free(msg);
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       return ildb_request_send(module, msg, context, callback, timeout, handle);
+       return ildb_request_send(module, msg,
+                               req->async.context,
+                               req->async.callback,
+                               req->async.timeout,
+                               &(req->async.handle));
 }
 
 static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ildb_delete_async(module, dn,
-                               NULL, NULL, ildb->ldap->timeout, &handle);
+       req = talloc_zero(ildb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
 
-       if (ret != LDB_SUCCESS)
+       req->operation = LDB_ASYNC_DELETE;
+       req->op.del.dn = dn;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = ildb->ldap->timeout;
+
+       ret = ildb_delete_async(module, req);
+
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
 /*
   rename a record
 */
-static int ildb_rename_async(struct ldb_module *module,
-                            const struct ldb_dn *olddn, const struct ldb_dn *newdn,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            int timeout,
-                            struct ldb_async_handle **handle)
+static int ildb_rename_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
        struct ldap_message *msg;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
        /* ignore ltdb specials */
-       if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) {
+       if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) {
                return LDB_SUCCESS;
        }
 
@@ -775,7 +812,7 @@ static int ildb_rename_async(struct ldb_module *module,
        }
 
        msg->type = LDAP_TAG_ModifyDNRequest;
-       msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, olddn);
+       msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, req->op.rename.olddn);
        if (msg->r.ModifyDNRequest.dn == NULL) {
                talloc_free(msg);
                return LDB_ERR_INVALID_DN_SYNTAX;
@@ -783,8 +820,8 @@ static int ildb_rename_async(struct ldb_module *module,
 
        msg->r.ModifyDNRequest.newrdn = 
                talloc_asprintf(msg, "%s=%s",
-                               newdn->components[0].name,
-                               ldb_dn_escape_value(msg, newdn->components[0].value));
+                               req->op.rename.newdn->components[0].name,
+                               ldb_dn_escape_value(msg, req->op.rename.newdn->components[0].value));
        if (msg->r.ModifyDNRequest.newrdn == NULL) {
                talloc_free(msg);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -792,7 +829,7 @@ static int ildb_rename_async(struct ldb_module *module,
 
        msg->r.ModifyDNRequest.newsuperior =
                ldb_dn_linearize(msg,
-                                ldb_dn_get_parent(msg, newdn));
+                                ldb_dn_get_parent(msg, req->op.rename.newdn));
        if (msg->r.ModifyDNRequest.newsuperior == NULL) {
                talloc_free(msg);
                return LDB_ERR_INVALID_DN_SYNTAX;
@@ -800,24 +837,42 @@ static int ildb_rename_async(struct ldb_module *module,
 
        msg->r.ModifyDNRequest.deleteolddn = True;
 
-       return ildb_request_send(module, msg, context, callback, timeout, handle);
+       return ildb_request_send(module, msg,
+                               req->async.context,
+                               req->async.callback,
+                               req->async.timeout,
+                               &(req->async.handle));
 }
 
 static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
 {
        struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ildb_rename_async(module, olddn, newdn,
-                               NULL, NULL, ildb->ldap->timeout, &handle);
+       req = talloc_zero(ildb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_RENAME;
+       req->op.rename.olddn = olddn;
+       req->op.rename.newdn = newdn;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = ildb->ldap->timeout;
 
-       if (ret != LDB_SUCCESS)
+       ret = ildb_rename_async(module, req);
+
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
@@ -869,51 +924,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req)
                                        req->op.rename.olddn,
                                        req->op.rename.newdn);
 
-       case LDB_ASYNC_SEARCH:
-               return ildb_search_async(module,
-                                       req->op.search.base,
-                                       req->op.search.scope, 
-                                       req->op.search.tree, 
-                                       req->op.search.attrs,
-                                       req->controls,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_ADD:
-               return ildb_add_async(module,
-                                       req->op.add.message,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_MODIFY:
-               return ildb_modify_async(module,
-                                       req->op.mod.message,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_DELETE:
-               return ildb_delete_async(module,
-                                       req->op.del.dn,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_RENAME:
-               return ildb_rename_async(module,
-                                       req->op.rename.olddn,
-                                       req->op.rename.newdn,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
        default:
                return -1;
 
@@ -977,6 +987,11 @@ static int ildb_init(struct ldb_module *module)
 
 static const struct ldb_module_ops ildb_ops = {
        .name              = "ldap",
+       .search            = ildb_search_async,
+       .add               = ildb_add_async,
+       .modify            = ildb_modify_async,
+       .del               = ildb_delete_async,
+       .rename            = ildb_rename_async,
        .request           = ildb_request,
        .start_transaction = ildb_start_trans,
        .end_transaction   = ildb_end_trans,
index c53db1f90c7885a0e04b26d119665e73ed1d10a0..f372e5fd04a3cccf1ce904c1c2de72c9cd32e34b 100644 (file)
@@ -224,14 +224,7 @@ static int lldb_add_msg_attr(struct ldb_context *ldb,
 /*
   search for matching records
 */
-static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *base,
-                             enum ldb_scope scope, struct ldb_parse_tree *tree,
-                             const char * const *attrs,
-                             struct ldb_control **control_req,
-                             void *context,
-                             int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                             int timeout,
-                             struct ldb_async_handle **handle)
+static int lldb_search_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
        struct lldb_async_context *lldb_ac;
@@ -241,44 +234,41 @@ static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *bas
        char *expression;
        int ret;
 
-       if (!callback || !context) {
+       if (!req->async.callback || !req->async.context) {
                ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context"));
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       if (tree == NULL) {
+       if (req->op.search.tree == NULL) {
                ldb_set_errstring(module->ldb, talloc_asprintf(module, "Invalid expression parse tree"));
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       if (control_req != NULL) {
+       if (req->controls != NULL) {
                ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls are not yet supported by ldb_ldap backend!\n");
        }
 
-       *handle = init_handle(lldb, module, context, callback, timeout);
-       if (*handle == NULL) {
-               talloc_free(*handle);
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context);
+       lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context);
 
-       search_base = ldb_dn_linearize(lldb_ac, base);
-       if (base == NULL) {
+       search_base = ldb_dn_linearize(lldb_ac, req->op.search.base);
+       if (req->op.search.base == NULL) {
                search_base = talloc_strdup(lldb_ac, "");
        }
        if (search_base == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       expression = ldb_filter_from_tree(lldb_ac, tree);
+       expression = ldb_filter_from_tree(lldb_ac, req->op.search.tree);
        if (expression == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       switch (scope) {
+       switch (req->op.search.scope) {
        case LDB_SCOPE_BASE:
                ldap_scope = LDAP_SCOPE_BASE;
                break;
@@ -290,12 +280,12 @@ static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *bas
                break;
        }
 
-       tv.tv_sec = timeout;
+       tv.tv_sec = req->async.timeout;
        tv.tv_usec = 0;
 
        ret = ldap_search_ext(lldb->ldap, search_base, ldap_scope, 
                            expression, 
-                           discard_const_p(char *, attrs), 
+                           discard_const_p(char *, req->op.search.attrs), 
                            0,
                            NULL,
                            NULL,
@@ -305,8 +295,6 @@ static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *bas
 
        if (ret != LDAP_SUCCESS) {
                ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret)));
-               talloc_free(*handle);
-               *handle = NULL;
        }
 
        return lldb_ldap_to_ldb(ret);
@@ -389,7 +377,7 @@ static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
                              struct ldb_result **res)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
        *res = talloc_zero(lldb, struct ldb_result);
@@ -397,12 +385,26 @@ static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = lldb_search_async(module, base, scope, tree, attrs, control_req,
-                               res, &lldb_search_sync_callback, lldb->timeout, &handle);
+       req = talloc_zero(lldb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_SEARCH;
+       req->op.search.base = base;
+       req->op.search.scope = scope;
+       req->op.search.tree = tree;
+       req->op.search.attrs = attrs;
+       req->controls = control_req;
+       req->async.context = (void *)res;
+       req->async.callback = lldb_search_sync_callback;
+       req->async.timeout = lldb->timeout;
+
+       ret = lldb_search_async(module, req);
 
        if (ret == LDB_SUCCESS) {
-               ret = ldb_async_wait(handle, LDB_WAIT_ALL);
-               talloc_free(handle);
+               ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
+               talloc_free(req);
        }
 
        if (ret != LDB_SUCCESS) {
@@ -415,11 +417,7 @@ static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba
 /*
   add a record
 */
-static int lldb_add_async(struct ldb_module *module, const struct ldb_message *msg,
-                         void *context,
-                         int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                         int timeout,
-                         struct ldb_async_handle **handle)
+static int lldb_add_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
        struct lldb_async_context *lldb_ac;
@@ -428,26 +426,24 @@ static int lldb_add_async(struct ldb_module *module, const struct ldb_message *m
        int ret;
 
        /* ltdb specials should not reach this point */
-       if (ldb_dn_is_special(msg->dn)) {
+       if (ldb_dn_is_special(req->op.add.message->dn)) {
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       *handle = init_handle(lldb, module, context, callback, timeout);
-       if (*handle == NULL) {
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context);
+       lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context);
 
-       mods = lldb_msg_to_mods(lldb_ac, msg, 0);
+       mods = lldb_msg_to_mods(lldb_ac, req->op.add.message, 0);
        if (mods == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       dn = ldb_dn_linearize(lldb_ac, msg->dn);
+       dn = ldb_dn_linearize(lldb_ac, req->op.add.message->dn);
        if (dn == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
@@ -458,7 +454,6 @@ static int lldb_add_async(struct ldb_module *module, const struct ldb_message *m
 
        if (ret != LDAP_SUCCESS) {
                ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret)));
-               talloc_free(*handle);
        }
 
        return lldb_ldap_to_ldb(ret);
@@ -467,22 +462,31 @@ static int lldb_add_async(struct ldb_module *module, const struct ldb_message *m
 static int lldb_add(struct ldb_module *module, const struct ldb_message *msg)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       /* ldap does not understand ltdb specials */
-       if (ldb_dn_is_special(msg->dn)) {
-               return LDB_SUCCESS;
+       req = talloc_zero(lldb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = lldb_add_async(module, msg, NULL, NULL, lldb->timeout, &handle);
+       req->operation = LDB_ASYNC_ADD;
+       req->op.add.message = msg;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = lldb->timeout;
+
+       ret = lldb_add_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
@@ -490,11 +494,7 @@ static int lldb_add(struct ldb_module *module, const struct ldb_message *msg)
 /*
   modify a record
 */
-static int lldb_modify_async(struct ldb_module *module, const struct ldb_message *msg,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            int timeout,
-                            struct ldb_async_handle **handle)
+static int lldb_modify_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
        struct lldb_async_context *lldb_ac;
@@ -503,26 +503,24 @@ static int lldb_modify_async(struct ldb_module *module, const struct ldb_message
        int ret;
 
        /* ltdb specials should not reach this point */
-       if (ldb_dn_is_special(msg->dn)) {
+       if (ldb_dn_is_special(req->op.mod.message->dn)) {
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       *handle = init_handle(lldb, module, context, callback, timeout);
-       if (*handle == NULL) {
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context);
+       lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context);
 
-       mods = lldb_msg_to_mods(lldb_ac, msg, 1);
+       mods = lldb_msg_to_mods(lldb_ac, req->op.mod.message, 1);
        if (mods == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       dn = ldb_dn_linearize(lldb_ac, msg->dn);
+       dn = ldb_dn_linearize(lldb_ac, req->op.mod.message->dn);
        if (dn == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
@@ -533,7 +531,6 @@ static int lldb_modify_async(struct ldb_module *module, const struct ldb_message
 
        if (ret != LDAP_SUCCESS) {
                ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret)));
-               talloc_free(*handle);
        }
 
        return lldb_ldap_to_ldb(ret);
@@ -542,33 +539,38 @@ static int lldb_modify_async(struct ldb_module *module, const struct ldb_message
 static int lldb_modify(struct ldb_module *module, const struct ldb_message *msg)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       /* ldap does not understand ltdb specials */
-       if (ldb_dn_is_special(msg->dn)) {
-               return LDB_SUCCESS;
+       req = talloc_zero(lldb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = lldb_modify_async(module, msg, NULL, NULL, lldb->timeout, &handle);
+       req->operation = LDB_ASYNC_MODIFY;
+       req->op.mod.message = msg;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = lldb->timeout;
+
+       ret = lldb_modify_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
 /*
   delete a record
 */
-static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            int timeout,
-                            struct ldb_async_handle **handle)
+static int lldb_delete_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
        struct lldb_async_context *lldb_ac;
@@ -576,18 +578,18 @@ static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
        int ret;
        
        /* ltdb specials should not reach this point */
-       if (ldb_dn_is_special(dn)) {
+       if (ldb_dn_is_special(req->op.del.dn)) {
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       *handle = init_handle(lldb, module, context, callback, timeout);
-       if (*handle == NULL) {
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context);
+       lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context);
 
-       dnstr = ldb_dn_linearize(lldb_ac, dn);
+       dnstr = ldb_dn_linearize(lldb_ac, req->op.del.dn);
 
        ret = ldap_delete_ext(lldb->ldap, dnstr,
                              NULL,
@@ -596,7 +598,6 @@ static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
 
        if (ret != LDAP_SUCCESS) {
                ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret)));
-               talloc_free(*handle);
        }
 
        return lldb_ldap_to_ldb(ret);
@@ -605,34 +606,38 @@ static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
 static int lldb_delete(struct ldb_module *module, const struct ldb_dn *dn)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       /* ignore ltdb specials */
-       if (ldb_dn_is_special(dn)) {
-               return LDB_SUCCESS;
+       req = talloc_zero(lldb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = lldb_delete_async(module, dn, NULL, NULL, lldb->timeout, &handle);
+       req->operation = LDB_ASYNC_DELETE;
+       req->op.del.dn = dn;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = lldb->timeout;
 
-       if (ret != LDB_SUCCESS)
+       ret = lldb_delete_async(module, req);
+
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
 /*
   rename a record
 */
-static int lldb_rename_async(struct ldb_module *module,
-                            const struct ldb_dn *olddn, const struct ldb_dn *newdn,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            int timeout,
-                            struct ldb_async_handle **handle)
+static int lldb_rename_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
        struct lldb_async_context *lldb_ac;
@@ -642,34 +647,31 @@ static int lldb_rename_async(struct ldb_module *module,
        int ret;
        
        /* ltdb specials should not reach this point */
-       if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) {
+       if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) {
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       *handle = init_handle(lldb, module, context, callback, timeout);
-       if (*handle == NULL) {
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context);
+       lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context);
 
-       old_dn = ldb_dn_linearize(lldb_ac, olddn);
+       old_dn = ldb_dn_linearize(lldb_ac, req->op.rename.olddn);
        if (old_dn == NULL) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
        newrdn = talloc_asprintf(lldb_ac, "%s=%s",
-                                     newdn->components[0].name,
-                                     ldb_dn_escape_value(lldb, newdn->components[0].value));
+                                req->op.rename.newdn->components[0].name,
+                                ldb_dn_escape_value(lldb, req->op.rename.newdn->components[0].value));
        if (!newrdn) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       parentdn = ldb_dn_linearize(lldb_ac, ldb_dn_get_parent(lldb_ac, newdn));
+       parentdn = ldb_dn_linearize(lldb_ac, ldb_dn_get_parent(lldb_ac, req->op.rename.newdn));
        if (!parentdn) {
-               talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
@@ -679,7 +681,6 @@ static int lldb_rename_async(struct ldb_module *module,
 
        if (ret != LDAP_SUCCESS) {
                ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret)));
-               talloc_free(*handle);
        }
 
        return lldb_ldap_to_ldb(ret);
@@ -688,22 +689,32 @@ static int lldb_rename_async(struct ldb_module *module,
 static int lldb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
 {
        struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private);
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       /* ignore ltdb specials */
-       if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) {
-               return LDB_SUCCESS;
+       req = talloc_zero(lldb, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = lldb_rename_async(module, olddn, newdn, NULL, NULL, lldb->timeout, &handle);
+       req->operation = LDB_ASYNC_RENAME;
+       req->op.rename.olddn = olddn;
+       req->op.rename.newdn = newdn;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+       req->async.timeout = lldb->timeout;
+
+       ret = lldb_rename_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
@@ -984,51 +995,6 @@ static int lldb_request(struct ldb_module *module, struct ldb_request *req)
                                        req->op.rename.olddn,
                                        req->op.rename.newdn);
 
-       case LDB_ASYNC_SEARCH:
-               return lldb_search_async(module,
-                                       req->op.search.base,
-                                       req->op.search.scope, 
-                                       req->op.search.tree, 
-                                       req->op.search.attrs,
-                                       req->controls,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_ADD:
-               return lldb_add_async(module,
-                                       req->op.add.message,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_MODIFY:
-               return lldb_modify_async(module,
-                                       req->op.mod.message,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_DELETE:
-               return lldb_delete_async(module,
-                                       req->op.del.dn,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_RENAME:
-               return lldb_rename_async(module,
-                                       req->op.rename.olddn,
-                                       req->op.rename.newdn,
-                                       req->async.context,
-                                       req->async.callback,
-                                       req->async.timeout,
-                                       &req->async.handle);
-
        default:
                return -1;
 
@@ -1037,6 +1003,11 @@ static int lldb_request(struct ldb_module *module, struct ldb_request *req)
 
 static const struct ldb_module_ops lldb_ops = {
        .name              = "ldap",
+       .search            = lldb_search_async,
+       .add               = lldb_add_async,
+       .modify            = lldb_modify_async,
+       .del               = lldb_delete_async,
+       .rename            = lldb_rename_async,
        .request           = lldb_request,
        .start_transaction = lldb_start_trans,
        .end_transaction   = lldb_end_trans,
index 0ab1442c2f768af68e7bce2f24c9864817fecae9..9b45697098b5ac43a09c8a43f63ff34049b2e1ae 100644 (file)
@@ -514,19 +514,14 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base,
-                     enum ldb_scope scope, struct ldb_parse_tree *tree,
-                     const char * const *attrs,
-                     void *context,
-                     int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                     struct ldb_async_handle **handle)
+int ltdb_search_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
        struct ltdb_async_context *ltdb_ac;
        int ret;
 
-       if ((base == NULL || base->comp_num == 0) &&
-           (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL))
+       if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) &&
+           (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL))
                return LDB_ERR_OPERATIONS_ERROR;
 
        if (ltdb_lock_read(module) != 0) {
@@ -538,32 +533,32 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       if (tree == NULL) {
+       if (req->op.search.tree == NULL) {
                ltdb_unlock_read(module);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       *handle = init_ltdb_handle(ltdb, module, context, callback);
-       if (*handle == NULL) {
+       req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback);
+       if (req->async.handle == NULL) {
                ltdb_unlock_read(module);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context);
+       ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context);
 
-       ltdb_ac->tree = tree;
-       ltdb_ac->scope = scope;
-       ltdb_ac->base = base;
-       ltdb_ac->attrs = attrs;
+       ltdb_ac->tree = req->op.search.tree;
+       ltdb_ac->scope = req->op.search.scope;
+       ltdb_ac->base = req->op.search.base;
+       ltdb_ac->attrs = req->op.search.attrs;
 
-       ret = ltdb_search_indexed(*handle);
+       ret = ltdb_search_indexed(req->async.handle);
        if (ret == -1) {
-               ret = ltdb_search_full(*handle);
+               ret = ltdb_search_full(req->async.handle);
        }
        if (ret != LDB_SUCCESS) {
                ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n"));
-               (*handle)->state = LDB_ASYNC_DONE;
-               (*handle)->status = ret;
+               req->async.handle->state = LDB_ASYNC_DONE;
+               req->async.handle->status = ret;
        }
 
        ltdb_unlock_read(module);
@@ -579,7 +574,7 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
                       enum ldb_scope scope, struct ldb_parse_tree *tree,
                       const char * const attrs[], struct ldb_result **res)
 {
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
        *res = talloc_zero(module, struct ldb_result);
@@ -587,13 +582,25 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ret = ltdb_search_async(module, base, scope, tree, attrs,
-                               res, &ltdb_search_sync_callback,
-                               &handle);
+       req = talloc_zero(module, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_SEARCH;
+       req->op.search.base = base;
+       req->op.search.scope = scope;
+       req->op.search.tree = tree;
+       req->op.search.attrs = attrs;
+       req->controls = NULL;
+       req->async.context = (void *)res;
+       req->async.callback = ltdb_search_sync_callback;
+
+       ret = ltdb_search_async(module, req);
 
        if (ret == LDB_SUCCESS) {
-               ret = ldb_async_wait(handle, LDB_WAIT_ALL);
-               talloc_free(handle);
+               ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
+               talloc_free(req);
        }
 
        if (ret != LDB_SUCCESS) {
index e0465afb30d6ae37b1e3712b83888c476e3abf49..e5b0ca066850912a27cfd06eea5247d1672dc38f 100644 (file)
@@ -259,24 +259,21 @@ done:
 /*
   add a record to the database
 */
-static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *msg,
-                         void *context,
-                         int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                         struct ldb_async_handle **handle)
+static int ltdb_add_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
        struct ltdb_async_context *ltdb_ac;
        int tret, ret = LDB_SUCCESS;
 
-       *handle = init_ltdb_handle(ltdb, module, context, callback);
-       if (*handle == NULL) {
+       req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context);
+       ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context);
 
-       tret = ltdb_check_special_dn(module, msg);
+       tret = ltdb_check_special_dn(module, req->op.add.message);
        if (tret != LDB_SUCCESS) {
-               (*handle)->status = tret;
+               req->async.handle->status = tret;
                goto done;
        }
        
@@ -285,37 +282,50 @@ static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *m
                goto done;
        }
 
-       tret = ltdb_store(module, msg, TDB_INSERT);
+       tret = ltdb_store(module, req->op.add.message, TDB_INSERT);
 
        if (tret != LDB_SUCCESS) {
-               (*handle)->status = tret;
+               req->async.handle->status = tret;
                goto done;
        }
 
-       ltdb_modified(module, msg->dn);
+       ltdb_modified(module, req->op.add.message->dn);
 
        if (ltdb_ac->callback) {
                ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
        }
 
 done:
-       (*handle)->state = LDB_ASYNC_DONE;
+       req->async.handle->state = LDB_ASYNC_DONE;
        return ret;
 }
 
 static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
 {
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ltdb_add_async(module, msg, NULL, NULL, &handle);
+       req = talloc_zero(module, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_ADD;
+       req->op.add.message = msg;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
 
-       if (ret != LDB_SUCCESS)
+       ret = ltdb_add_async(module, req);
+
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
@@ -347,27 +357,24 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn)
 /*
   delete a record from the database
 */
-static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            struct ldb_async_handle **handle)
+static int ltdb_delete_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
        struct ltdb_async_context *ltdb_ac;
        struct ldb_message *msg;
        int tret, ret = LDB_SUCCESS;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
        if (ltdb_cache_load(module) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       *handle = init_ltdb_handle(ltdb, module, context, callback);
-       if (*handle == NULL) {
+       req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context);
+       ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context);
 
        msg = talloc(ltdb_ac, struct ldb_message);
        if (msg == NULL) {
@@ -377,48 +384,61 @@ static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
 
        /* in case any attribute of the message was indexed, we need
           to fetch the old record */
-       tret = ltdb_search_dn1(module, dn, msg);
+       tret = ltdb_search_dn1(module, req->op.del.dn, msg);
        if (tret != 1) {
                /* not finding the old record is an error */
-               (*handle)->status = LDB_ERR_NO_SUCH_OBJECT;
+               req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT;
                goto done;
        }
 
-       tret = ltdb_delete_noindex(module, dn);
+       tret = ltdb_delete_noindex(module, req->op.del.dn);
        if (tret != LDB_SUCCESS) {
-               (*handle)->status = LDB_ERR_NO_SUCH_OBJECT;
+               req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT;
                goto done;
        }
 
        /* remove any indexed attributes */
        tret = ltdb_index_del(module, msg);
        if (tret != LDB_SUCCESS) {
-               (*handle)->status = LDB_ERR_NO_SUCH_OBJECT;
+               req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT;
                goto done;
        }
-       ltdb_modified(module, dn);
+       ltdb_modified(module, req->op.del.dn);
 
        if (ltdb_ac->callback)
                ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
 
 done:
-       (*handle)->state = LDB_ASYNC_DONE;
+       req->async.handle->state = LDB_ASYNC_DONE;
        return ret;
 }
 
 static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn)
 {
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ltdb_delete_async(module, dn, NULL, NULL, &handle);
+       req = talloc_zero(module, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_DELETE;
+       req->op.del.dn = dn;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+
+       ret = ltdb_delete_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
@@ -734,26 +754,23 @@ failed:
 /*
   modify a record
 */
-static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message *msg,
-                         void *context,
-                         int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                         struct ldb_async_handle **handle)
+static int ltdb_modify_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
        struct ltdb_async_context *ltdb_ac;
        int tret, ret = LDB_SUCCESS;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
-       *handle = init_ltdb_handle(ltdb, module, context, callback);
-       if (*handle == NULL) {
+       req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context);
+       ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context);
 
-       tret = ltdb_check_special_dn(module, msg);
+       tret = ltdb_check_special_dn(module, req->op.mod.message);
        if (tret != LDB_SUCCESS) {
-               (*handle)->status = tret;
+               req->async.handle->status = tret;
                goto done;
        }
        
@@ -762,63 +779,73 @@ static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message
                goto done;
        }
 
-       tret = ltdb_modify_internal(module, msg);
+       tret = ltdb_modify_internal(module, req->op.mod.message);
 
        if (tret != LDB_SUCCESS) {
-               (*handle)->status = tret;
+               req->async.handle->status = tret;
                goto done;
        }
 
-       ltdb_modified(module, msg->dn);
+       ltdb_modified(module, req->op.mod.message->dn);
 
        if (ltdb_ac->callback)
                ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
 
 done:
-       (*handle)->state = LDB_ASYNC_DONE;
+       req->async.handle->state = LDB_ASYNC_DONE;
        return ret;
 }
 
 static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg)
 {
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ltdb_modify_async(module, msg, NULL, NULL, &handle);
+       req = talloc_zero(module, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_ASYNC_MODIFY;
+       req->op.mod.message = msg;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+
+       ret = ltdb_modify_async(module, req);
 
-       if (ret != LDB_SUCCESS)
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
 /*
   rename a record
 */
-static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn,
-                            void *context,
-                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                            struct ldb_async_handle **handle)
+static int ltdb_rename_async(struct ldb_module *module, struct ldb_request *req)
 {
        struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
        struct ltdb_async_context *ltdb_ac;
        struct ldb_message *msg;
        int tret, ret = LDB_SUCCESS;
 
-       *handle = NULL;
+       req->async.handle = NULL;
 
        if (ltdb_cache_load(module) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       *handle = init_ltdb_handle(ltdb, module, context, callback);
-       if (*handle == NULL) {
+       req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback);
+       if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context);
+       ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context);
 
        msg = talloc(ltdb_ac, struct ldb_message);
        if (msg == NULL) {
@@ -828,14 +855,14 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old
 
        /* in case any attribute of the message was indexed, we need
           to fetch the old record */
-       tret = ltdb_search_dn1(module, olddn, msg);
+       tret = ltdb_search_dn1(module, req->op.rename.olddn, msg);
        if (tret != 1) {
                /* not finding the old record is an error */
-               (*handle)->status = LDB_ERR_NO_SUCH_OBJECT;
+               req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT;
                goto done;
        }
 
-       msg->dn = ldb_dn_copy(msg, newdn);
+       msg->dn = ldb_dn_copy(msg, req->op.rename.newdn);
        if (!msg->dn) {
                ret = LDB_ERR_OPERATIONS_ERROR;
                goto done;
@@ -847,9 +874,9 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old
                goto done;
        }
 
-       tret = ltdb_delete(module, olddn);
+       tret = ltdb_delete(module, req->op.rename.olddn);
        if (tret != LDB_SUCCESS) {
-               ltdb_delete(module, newdn);
+               ltdb_delete(module, req->op.rename.newdn);
                ret = LDB_ERR_OPERATIONS_ERROR;
                goto done;
        }
@@ -858,23 +885,37 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old
                ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
 
 done:
-       (*handle)->state = LDB_ASYNC_DONE;
+       req->async.handle->state = LDB_ASYNC_DONE;
        return ret;
 }
 
 static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
 {
-       struct ldb_async_handle *handle;
+       struct ldb_request *req;
        int ret;
 
-       ret = ltdb_rename_async(module, olddn, newdn, NULL, NULL, &handle);
+       req = talloc_zero(module, struct ldb_request);
+       if (! req) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
 
-       if (ret != LDB_SUCCESS)
+       req->operation = LDB_ASYNC_RENAME;
+       req->op.rename.olddn = olddn;
+       req->op.rename.newdn = newdn;
+       req->controls = NULL;
+       req->async.context = NULL;
+       req->async.callback = NULL;
+
+       ret = ltdb_rename_async(module, req);
+
+       if (ret != LDB_SUCCESS) {
+               talloc_free(req);
                return ret;
+       }
 
-       ret = ldb_async_wait(handle, LDB_WAIT_ALL);
+       ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
 
-       talloc_free(handle);
+       talloc_free(req);
        return ret;
 }
 
@@ -952,45 +993,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req)
                                        req->op.rename.olddn,
                                        req->op.rename.newdn);
 
-       case LDB_ASYNC_SEARCH:
-               return ltdb_search_async(module,
-                                       req->op.search.base,
-                                       req->op.search.scope, 
-                                       req->op.search.tree, 
-                                       req->op.search.attrs,
-                                       req->async.context,
-                                       req->async.callback,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_ADD:
-               return ltdb_add_async(module,
-                                       req->op.add.message,
-                                       req->async.context,
-                                       req->async.callback,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_MODIFY:
-               return ltdb_modify_async(module,
-                                       req->op.mod.message,
-                                       req->async.context,
-                                       req->async.callback,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_DELETE:
-               return ltdb_delete_async(module,
-                                       req->op.del.dn,
-                                       req->async.context,
-                                       req->async.callback,
-                                       &req->async.handle);
-
-       case LDB_ASYNC_RENAME:
-               return ltdb_rename_async(module,
-                                       req->op.rename.olddn,
-                                       req->op.rename.newdn,
-                                       req->async.context,
-                                       req->async.callback,
-                                       &req->async.handle);
-
        default:
                return LDB_ERR_OPERATIONS_ERROR;
 
@@ -1024,6 +1026,11 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb)
 
 static const struct ldb_module_ops ltdb_ops = {
        .name              = "tdb",
+       .search            = ltdb_search_async,
+       .add               = ltdb_add_async,
+       .modify            = ltdb_modify_async,
+       .del               = ltdb_delete_async,
+       .rename            = ltdb_rename_async,
        .request           = ltdb_request,
        .start_transaction = ltdb_start_trans,
        .end_transaction   = ltdb_end_trans,
index 196103ad6b8fe4400cf252d8ac5ab685a6533575..ad9e5c10c63b90d895974016bddcbeae8cd0398d 100644 (file)
@@ -100,12 +100,7 @@ int ltdb_add_attr_results(struct ldb_module *module,
                          unsigned int *count, 
                          struct ldb_message ***res);
 int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs);
-int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base,
-                     enum ldb_scope scope, struct ldb_parse_tree *tree,
-                     const char * const *attrs,
-                     void *context,
-                     int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                     struct ldb_async_handle **handle);
+int ltdb_search_async(struct ldb_module *module, struct ldb_request *req);
 int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
                       enum ldb_scope scope, struct ldb_parse_tree *tree,
                       const char * const attrs[], struct ldb_result **res);
index de5a0e34b75f8f1c31e901abff8e73685cad201e..3a29d3f2664349d15d86379cc98ccd170dc88656 100644 (file)
@@ -77,7 +77,7 @@ static int build_response(struct ldb_result *res, int result)
 }
 
 /* search */
-static int asq_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
+static int asq_search_sync(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
 {
        struct ldb_asq_control *asq_ctrl;
        struct ldb_request *base_req;
@@ -352,14 +352,22 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-static int asq_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
+static int asq_search(struct ldb_module *module, struct ldb_request *req)
 {
+       struct ldb_control *control;
        struct ldb_asq_control *asq_ctrl;
        struct asq_async_context *ac;
        struct ldb_async_handle *h;
        char **base_attrs;
        int ret;
 
+       /* check if there's a paged request control */
+       control = get_control_from_list(req->controls, LDB_CONTROL_ASQ_OID);
+       if (control == NULL) {
+               /* not found go on */
+               return ldb_next_request(module, req);
+       }
+
        req->async.handle = NULL;
 
        if (!req->async.callback || !req->async.context) {
@@ -590,11 +598,8 @@ static int asq(struct ldb_module *module, struct ldb_request *req)
        switch (req->operation) {
 
        case LDB_REQ_SEARCH:
-               return asq_search(module, control, req);
+               return asq_search_sync(module, control, req);
        
-       case LDB_ASYNC_SEARCH:
-               return asq_search_async(module, control, req);
-
        default:
                return LDB_ERR_PROTOCOL_ERROR;
 
@@ -622,6 +627,7 @@ static int asq_init(struct ldb_module *module)
 
 static const struct ldb_module_ops asq_ops = {
        .name              = "asq",
+       .search            = asq_search,
        .request           = asq,
        .async_wait        = asq_async_wait,
        .init_context      = asq_init
index d796e93e5441c6716c018b34305ae55baf7ddfa8..b47adf06529caf3ed296c26a74731ff1d4728bf0 100644 (file)
@@ -295,7 +295,7 @@ static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_
 /*
   hook add record ops
 */
-static int operational_add(struct ldb_module *module, struct ldb_request *req)
+static int operational_add_sync(struct ldb_module *module, struct ldb_request *req)
 {
        const struct ldb_message *msg = req->op.add.message;
        time_t t = time(NULL);
@@ -341,7 +341,7 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req)
 /*
   hook modify record ops
 */
-static int operational_modify(struct ldb_module *module, struct ldb_request *req)
+static int operational_modify_sync(struct ldb_module *module, struct ldb_request *req)
 {
        const struct ldb_message *msg = req->op.mod.message;
        time_t t = time(NULL);
@@ -421,7 +421,7 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-static int operational_search_async(struct ldb_module *module, struct ldb_request *req)
+static int operational_search(struct ldb_module *module, struct ldb_request *req)
 {
        struct operational_async_context *ac;
        struct ldb_request *down_req;
@@ -506,7 +506,7 @@ static int operational_search_async(struct ldb_module *module, struct ldb_reques
 /*
   hook add record ops
 */
-static int operational_add_async(struct ldb_module *module, struct ldb_request *req)
+static int operational_add(struct ldb_module *module, struct ldb_request *req)
 {
        struct ldb_request *down_req;
        struct ldb_message *msg;
@@ -560,7 +560,7 @@ static int operational_add_async(struct ldb_module *module, struct ldb_request *
 /*
   hook modify record ops
 */
-static int operational_modify_async(struct ldb_module *module, struct ldb_request *req)
+static int operational_modify(struct ldb_module *module, struct ldb_request *req)
 {
        struct ldb_request *down_req;
        struct ldb_message *msg;
@@ -617,19 +617,10 @@ static int operational_request(struct ldb_module *module, struct ldb_request *re
                return operational_search_bytree(module, req);
 
        case LDB_REQ_ADD:
-               return operational_add(module, req);
+               return operational_add_sync(module, req);
 
        case LDB_REQ_MODIFY:
-               return operational_modify(module, req);
-
-       case LDB_ASYNC_SEARCH:
-               return operational_search_async(module, req);
-
-       case LDB_ASYNC_ADD:
-               return operational_add_async(module, req);
-
-       case LDB_ASYNC_MODIFY:
-               return operational_modify_async(module, req);
+               return operational_modify_sync(module, req);
 
        default:
                return ldb_next_request(module, req);
@@ -650,6 +641,9 @@ static int operational_init(struct ldb_module *ctx)
 
 static const struct ldb_module_ops operational_ops = {
        .name              = "operational",
+       .search            = operational_search,
+       .add               = operational_add,
+       .modify            = operational_modify,
        .request           = operational_request,
        .init_context      = operational_init
 };
index 1b002716a537e953a0e42f7eaf6951d6d0b4548d..fab1ca5ac100596a170cc204e1a9e2325e8c064a 100644 (file)
@@ -123,7 +123,7 @@ static struct results_store *new_store(struct private_data *priv)
 }
 
 /* search */
-static int paged_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
+static int paged_search_sync(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
 {
        struct private_data *private_data = talloc_get_type(module->private_data, struct private_data);
        struct results_store *current = NULL;
@@ -364,15 +364,25 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-static int paged_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
+static int paged_search(struct ldb_module *module, struct ldb_request *req)
 {
-       struct private_data *private_data = talloc_get_type(module->private_data, struct private_data);
+       struct ldb_control *control;
+       struct private_data *private_data;
        struct ldb_paged_control *paged_ctrl;
        struct ldb_control **saved_controls;
        struct paged_async_context *ac;
        struct ldb_async_handle *h;
        int ret;
 
+       /* check if there's a paged request control */
+       control = get_control_from_list(req->controls, LDB_CONTROL_PAGED_RESULTS_OID);
+       if (control == NULL) {
+               /* not found go on */
+               return ldb_next_request(module, req);
+       }
+
+       private_data = talloc_get_type(module->private_data, struct private_data);
+
        req->async.handle = NULL;
 
        if (!req->async.callback || !req->async.context) {
@@ -463,7 +473,7 @@ static int paged_search_async(struct ldb_module *module, struct ldb_control *con
 
 }
 
-static int paged_async_results(struct ldb_async_handle *handle)
+static int paged_results(struct ldb_async_handle *handle)
 {
        struct paged_async_context *ac;
        struct ldb_paged_control *paged;
@@ -590,7 +600,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait
        if (ac->store->req->async.handle->state == LDB_ASYNC_DONE) {
                /* if lower level is finished we do not need to call it anymore */
                /* return all we have until size == 0 or we empty storage */
-               ret = paged_async_results(handle);
+               ret = paged_results(handle);
 
                /* we are done, if num_entries is zero free the storage
                 * as that mean we delivered the last batch */
@@ -611,7 +621,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait
                        }
                }
 
-               ret = paged_async_results(handle);
+               ret = paged_results(handle);
 
                /* we are done, if num_entries is zero free the storage
                 * as that mean we delivered the last batch */
@@ -634,7 +644,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait
        if (ac->store->num_entries >= ac->size ||
            ac->store->req->async.handle->state == LDB_ASYNC_DONE) {
 
-               ret = paged_async_results(handle);
+               ret = paged_results(handle);
 
                /* we are done, if num_entries is zero free the storage
                 * as that mean we delivered the last batch */
@@ -660,10 +670,7 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req)
        switch (req->operation) {
 
        case LDB_REQ_SEARCH:
-               return paged_search(module, control, req);
-
-       case LDB_ASYNC_SEARCH:
-               return paged_search_async(module, control, req);
+               return paged_search_sync(module, control, req);
 
        default:
                return LDB_ERR_PROTOCOL_ERROR;
@@ -707,7 +714,8 @@ static int paged_request_init(struct ldb_module *module)
 }
 
 static const struct ldb_module_ops paged_ops = {
-       .name                   = "paged_results",
+       .name           = "paged_results",
+       .search         = paged_search,
        .request        = paged_request,
        .async_wait     = paged_async_wait,
        .init_context   = paged_request_init
index 7ce6c296916391da71677d9b1c4fc4b4adc96f02..2004002e38158b62af8e7e426c7f4f46ffab9c20 100644 (file)
@@ -310,7 +310,7 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) {
        ac->step = RENAME_MODIFY;
 
        /* do the mod call */
-       return ldb_next_request(h->module, ac->mod_req);
+       return ldb_request(h->module->ldb, ac->mod_req);
 }
 
 static int rename_async_wait(struct ldb_async_handle *handle)
@@ -409,12 +409,6 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req)
        case LDB_REQ_ADD:
                return rdn_name_add_sync(module, req);
 
-       case LDB_ASYNC_ADD:
-               return rdn_name_add(module, req);
-
-       case LDB_ASYNC_RENAME:
-               return rdn_name_rename(module, req);
-
        default:
                return ldb_next_request(module, req);
 
@@ -423,6 +417,8 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req)
 
 static const struct ldb_module_ops rdn_name_ops = {
        .name              = "rdn_name",
+       .add               = rdn_name_add,
+       .rename            = rdn_name_rename,
        .request           = rdn_name_request,
        .async_wait        = rdn_name_async_wait
 };
index 2f3c2e8b57acd872468ad542d67d63c6c517dcc5..2adef580b1c05993ecf6a178a94f926476b7d486 100644 (file)
@@ -97,28 +97,7 @@ static int skel_destructor(struct ldb_module *ctx)
 
 static int skel_request(struct ldb_module *module, struct ldb_request *req)
 {
-       switch (req->operation) {
-
-       case LDB_REQ_SEARCH:
-               return skel_search(module, req);
-
-       case LDB_REQ_ADD:
-               return skel_add(module, req);
-
-       case LDB_REQ_MODIFY:
-               return skel_modify(module, req);
-
-       case LDB_REQ_DELETE:
-               return skel_delete(module, req);
-
-       case LDB_REQ_RENAME:
-               return skel_rename(module,
-                                  req);
-
-       default:
-               return ldb_next_request(module, req);
-
-       }
+       return ldb_next_request(module, req);
 }
 
 static int skel_init(struct ldb_module *ctx)
@@ -141,6 +120,11 @@ static int skel_init(struct ldb_module *ctx)
 static const struct ldb_module_ops skel_ops = {
        .name              = "skel",
        .init_context      = skel_init,
+       .search            = skel_search,
+       .add               = skel_add,
+       .modify            = skel_modify,
+       .del               = skel_delete,
+       .rename            = skel_rename,
        .request           = skel_request,
        .start_transaction = skel_start_trans,
        .end_transaction   = skel_end_trans,
index 3e1bbe92bde9cf08d510456a891adbce8f1652e6..9f03100dd00fafe822ef36c439d130ea6e09d6ac 100644 (file)
@@ -340,14 +340,22 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-static int server_sort_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req)
+static int server_sort_search_async(struct ldb_module *module, struct ldb_request *req)
 {
+       struct ldb_control *control;
        struct ldb_server_sort_control **sort_ctrls;
        struct ldb_control **saved_controls;
        struct sort_async_context *ac;
        struct ldb_async_handle *h;
        int ret;
 
+       /* check if there's a paged request control */
+       control = get_control_from_list(req->controls, LDB_CONTROL_SERVER_SORT_OID);
+       if (control == NULL) {
+               /* not found go on */
+               return ldb_next_request(module, req);
+       }
+
        req->async.handle = NULL;
 
        if (!req->async.callback || !req->async.context) {
@@ -543,9 +551,6 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req)
        case LDB_REQ_SEARCH:
                return server_sort_search(module, control, req);
 
-       case LDB_ASYNC_SEARCH:
-               return server_sort_search_async(module, control, req);
-
        default:
                return LDB_ERR_PROTOCOL_ERROR;
 
@@ -579,6 +584,7 @@ static int server_sort_init(struct ldb_module *module)
 
 static const struct ldb_module_ops server_sort_ops = {
        .name              = "server_sort",
+       .search            = server_sort_search_async,
        .request           = server_sort,
        .async_wait        = server_sort_async_wait,
        .init_context      = server_sort_init
index 6fcf67570285f3d624b14f08bb8de878b23ab29d..5c45a64413d33d8f2e60b570fb13da81ea07b148 100644 (file)
 #include "system/network.h"
 #include "netif/netif.h"
 
-/* add_record: do things with the sambaPassword attribute */
-static int wins_ldb_verify(struct ldb_module *module, struct ldb_request *req, const struct ldb_message *msg)
+static int wins_ldb_verify(struct ldb_module *module, struct ldb_request *req)
 {
        struct winsdb_handle *h = talloc_get_type(ldb_get_opaque(module->ldb, "winsdb_handle"),
                                                  struct winsdb_handle);
+       const struct ldb_message *msg;
        char *error = NULL;
 
+       switch (req->operation) {
+       case LDB_REQ_ADD:
+       case LDB_ASYNC_ADD:
+               msg = req->op.add.message;
+               break;
+               
+       case LDB_REQ_MODIFY:
+       case LDB_ASYNC_MODIFY:
+               msg = req->op.mod.message;
+               break;
+
+       default:
+               return ldb_next_request(module, req);
+       }
+
        /* do not manipulate our control entries */
        if (ldb_dn_is_special(msg->dn)) {
                return ldb_next_request(module, req);
@@ -73,26 +88,13 @@ static int wins_ldb_verify(struct ldb_module *module, struct ldb_request *req, c
 
 static int wins_ldb_request(struct ldb_module *module, struct ldb_request *req)
 {
-       const struct ldb_message *msg;
-
        switch (req->operation) {
        case LDB_REQ_ADD:
-       case LDB_ASYNC_ADD:
-
-               msg = req->op.add.message;
-               break;
-               
        case LDB_REQ_MODIFY:
-       case LDB_ASYNC_MODIFY:
-
-               msg = req->op.mod.message;
-               break;
-
+               return wins_ldb_verify(module, req);
        default:
                return ldb_next_request(module, req);
        }
-
-       return wins_ldb_verify(module, req, msg);
 }
        
 
@@ -127,6 +129,8 @@ failed:
 
 static const struct ldb_module_ops wins_ldb_ops = {
        .name          = "wins_ldb",
+       .add           = wins_ldb_verify,
+       .modify        = wins_ldb_verify,
        .request       = wins_ldb_request,
        .init_context  = wins_ldb_init
 };