r15761: Fix-as-you-go ...
authorSimo Sorce <idra@samba.org>
Sat, 20 May 2006 19:37:21 +0000 (19:37 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:08:15 +0000 (14:08 -0500)
Testing various async paths and uncovering bugs
(This used to be commit 099d873ea596ece18efe63b06bc64e7f97a96f82)

source4/dsdb/samdb/ldb_modules/password_hash.c
source4/lib/ldb/common/ldb_msg.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/modules/operational.c

index b7f4aff67aab9734a1b9e1b2aee5df1f65794e65..617962b909d2c57aaa2ee4c2d02490624406b864 100644 (file)
@@ -1672,11 +1672,11 @@ static int ph_async_wait(struct ldb_async_handle *handle) {
 
        switch (ac->step) {
        case PH_ADD_SEARCH_DOM:
-               if (ac->dom_req->async.handle->status != LDB_ASYNC_DONE) {
+               if (ac->dom_req->async.handle->state != LDB_ASYNC_DONE) {
                        ret = ldb_async_wait(ac->dom_req->async.handle, LDB_WAIT_NONE);
-                       if (ret != LDB_SUCCESS) goto error;
+                       if (ret != LDB_SUCCESS) goto done;
 
-                       if (ac->dom_req->async.handle->status != LDB_ASYNC_DONE) {
+                       if (ac->dom_req->async.handle->state != LDB_ASYNC_DONE) {
                                return LDB_SUCCESS;
                        }
                }
@@ -1685,22 +1685,22 @@ static int ph_async_wait(struct ldb_async_handle *handle) {
                return password_hash_add_async_do_add(handle);
 
        case PH_ADD_DO_ADD:
-               if (ac->down_req->async.handle->status != LDB_ASYNC_DONE) {
+               if (ac->down_req->async.handle->state != LDB_ASYNC_DONE) {
                        ret = ldb_async_wait(ac->down_req->async.handle, LDB_WAIT_NONE);
-                       if (ret != LDB_SUCCESS) goto error;
+                       if (ret != LDB_SUCCESS) goto done;
 
-                       if (ac->down_req->async.handle->status != LDB_ASYNC_DONE) {
+                       if (ac->down_req->async.handle->state != LDB_ASYNC_DONE) {
                                return LDB_SUCCESS;
                        }
                }
                return LDB_SUCCESS;
                
        case PH_MOD_DO_REQ:
-               if (ac->down_req->async.handle->status != LDB_ASYNC_DONE) {
+               if (ac->down_req->async.handle->state != LDB_ASYNC_DONE) {
                        ret = ldb_async_wait(ac->down_req->async.handle, LDB_WAIT_NONE);
-                       if (ret != LDB_SUCCESS) goto error;
+                       if (ret != LDB_SUCCESS) goto done;
 
-                       if (ac->down_req->async.handle->status != LDB_ASYNC_DONE) {
+                       if (ac->down_req->async.handle->state != LDB_ASYNC_DONE) {
                                return LDB_SUCCESS;
                        }
                }
@@ -1709,11 +1709,11 @@ static int ph_async_wait(struct ldb_async_handle *handle) {
                return password_hash_mod_async_search_self(handle);
                
        case PH_MOD_SEARCH_SELF:
-               if (ac->search_req->async.handle->status != LDB_ASYNC_DONE) {
+               if (ac->search_req->async.handle->state != LDB_ASYNC_DONE) {
                        ret = ldb_async_wait(ac->search_req->async.handle, LDB_WAIT_NONE);
-                       if (ret != LDB_SUCCESS) goto error;
+                       if (ret != LDB_SUCCESS) goto done;
 
-                       if (ac->search_req->async.handle->status != LDB_ASYNC_DONE) {
+                       if (ac->search_req->async.handle->state != LDB_ASYNC_DONE) {
                                return LDB_SUCCESS;
                        }
                }
@@ -1722,11 +1722,11 @@ static int ph_async_wait(struct ldb_async_handle *handle) {
                return password_hash_mod_async_search_dom(handle);
                
        case PH_MOD_SEARCH_DOM:
-               if (ac->dom_req->async.handle->status != LDB_ASYNC_DONE) {
+               if (ac->dom_req->async.handle->state != LDB_ASYNC_DONE) {
                        ret = ldb_async_wait(ac->dom_req->async.handle, LDB_WAIT_NONE);
-                       if (ret != LDB_SUCCESS) goto error;
+                       if (ret != LDB_SUCCESS) goto done;
 
-                       if (ac->dom_req->async.handle->status != LDB_ASYNC_DONE) {
+                       if (ac->dom_req->async.handle->state != LDB_ASYNC_DONE) {
                                return LDB_SUCCESS;
                        }
                }
@@ -1735,22 +1735,25 @@ static int ph_async_wait(struct ldb_async_handle *handle) {
                return password_hash_mod_async_do_mod(handle);
 
        case PH_MOD_DO_MOD:
-               if (ac->mod_req->async.handle->status != LDB_ASYNC_DONE) {
+               if (ac->mod_req->async.handle->state != LDB_ASYNC_DONE) {
                        ret = ldb_async_wait(ac->mod_req->async.handle, LDB_WAIT_NONE);
-                       if (ret != LDB_SUCCESS) goto error;
+                       if (ret != LDB_SUCCESS) goto done;
 
-                       if (ac->mod_req->async.handle->status != LDB_ASYNC_DONE) {
+                       if (ac->mod_req->async.handle->state != LDB_ASYNC_DONE) {
                                return LDB_SUCCESS;
                        }
                }
-               return LDB_SUCCESS;
+
+               break;
                
        default:
                ret = LDB_ERR_OPERATIONS_ERROR;
-               goto error;
+               goto done;
        }
 
-error:
+       ret = LDB_SUCCESS;
+
+done:
        handle->state = LDB_ASYNC_DONE;
        handle->status = ret;
        return ret;
index b09f2ce6eda7b773b130a40a010ae73f5a4c6d21..bae17e7046d5a42d75c307b14eb3aee282f110eb 100644 (file)
@@ -734,7 +734,7 @@ int ldb_msg_check_string_attribute(const struct ldb_message *msg, const char *na
                return 0;
 
        val.data = discard_const(value);
-       val.length = strlen(value) + 1;
+       val.length = strlen(value);
 
        if (ldb_msg_find_val(el, &val))
                return 1;
index 866b062d06c90c2e28d611a60d432263aee84217..9f0613feaadaa4ab1beb48e76fa86f43e81f2220 100644 (file)
@@ -619,17 +619,17 @@ struct ldb_async_handle {
 struct ldb_search {
        const struct ldb_dn *base;
        enum ldb_scope scope;
-       struct ldb_parse_tree *tree;
+       const struct ldb_parse_tree *tree;
        const char * const *attrs;
        struct ldb_result *res;
 };
 
 struct ldb_add {
-       struct ldb_message *message;
+       const struct ldb_message *message;
 };
 
 struct  ldb_modify {
-       struct ldb_message *message;
+       const struct ldb_message *message;
 };
 
 struct ldb_delete {
@@ -647,7 +647,7 @@ struct ldb_register_control {
 
 struct ldb_request {
 
-       int operation;
+       enum ldb_request_type operation;
 
        union {
                struct ldb_search search;
index 070f91e762aee1a4c6d77973b567a217853674eb..d796e93e5441c6716c018b34305ae55baf7ddfa8 100644 (file)
@@ -522,8 +522,10 @@ static int operational_add_async(struct ldb_module *module, struct ldb_request *
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       *down_req = *req;
+
        /* we have to copy the message as the caller might have it as a const */
-       msg = ldb_msg_copy_shallow(down_req, req->op.add.message);
+       down_req->op.mod.message = msg = ldb_msg_copy_shallow(down_req, req->op.mod.message);
        if (msg == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -543,15 +545,6 @@ static int operational_add_async(struct ldb_module *module, struct ldb_request *
                }
        }
 
-       down_req->op.add.message = msg;
-       
-       down_req->controls = req->controls;
-       down_req->creds = req->creds;
-
-       down_req->async.context = req->async.context;
-       down_req->async.callback = req->async.callback;
-       down_req->async.timeout = req->async.timeout;
-
        /* go on with the call chain */
        ret = ldb_next_request(module, down_req);
 
@@ -583,8 +576,10 @@ static int operational_modify_async(struct ldb_module *module, struct ldb_reques
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       *down_req = *req;
+
        /* we have to copy the message as the caller might have it as a const */
-       msg = ldb_msg_copy_shallow(down_req, req->op.mod.message);
+       down_req->op.mod.message = msg = ldb_msg_copy_shallow(down_req, req->op.mod.message);
        if (msg == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -600,16 +595,7 @@ static int operational_modify_async(struct ldb_module *module, struct ldb_reques
                talloc_free(down_req);
                return -1;
        }
-
-       down_req->op.mod.message = msg;
        
-       down_req->controls = req->controls;
-       down_req->creds = req->creds;
-
-       down_req->async.context = req->async.context;
-       down_req->async.callback = req->async.callback;
-       down_req->async.timeout = req->async.timeout;
-
        /* go on with the call chain */
        ret = ldb_next_request(module, down_req);