r16036: Add a couple of new functions to corretly deal with timeouts.
authorSimo Sorce <idra@samba.org>
Sun, 4 Jun 2006 05:28:13 +0000 (05:28 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:08:52 +0000 (14:08 -0500)
Check timeouts are correctly verified.
Some minor fixed and removal of unused code.
(This used to be commit b52e5d6a0cb1a32e62759eaa49ce3e4cc804cc92)

19 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/include/ldb.h
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/modules/asq.c
source4/lib/ldb/modules/objectclass.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/sort.c
source4/lib/ldb/tools/ldbsearch.c
source4/torture/ldap/schema.c

index 1f2d406a2864b7f280a35507f1cbc5eca5599bed..71f7a2dc7ea28d995a67e3d80afe8297f44354f8 100644 (file)
@@ -172,7 +172,6 @@ struct extended_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        const char * const *attrs;
        BOOL remove_guid;
@@ -236,7 +235,6 @@ static int extended_search_async(struct ldb_module *module, struct ldb_request *
        ac->module = module;
        ac->up_context = req->async.context;
        ac->up_callback = req->async.callback;
-       ac->timeout = req->async.timeout;
        ac->attrs = req->op.search.attrs;
        ac->remove_guid = False;
        ac->remove_sid = False;
@@ -289,7 +287,7 @@ static int extended_search_async(struct ldb_module *module, struct ldb_request *
 
        down_req->async.context = ac;
        down_req->async.callback = extended_async_callback;
-       down_req->async.timeout = req->async.timeout;
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
 
        /* perform the search */
        ret = ldb_next_request(module, down_req);
index 4e09faf269d0422dee721af1eaf4f572a0137365..1b5b896b3fdba8a826edecb85f4dcd9732fc1582 100644 (file)
@@ -103,7 +103,6 @@ struct kludge_acl_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        enum user_is user_type;
 };
@@ -160,7 +159,6 @@ static int kludge_acl_search_async(struct ldb_module *module, struct ldb_request
        ac->module = module;
        ac->up_context = req->async.context;
        ac->up_callback = req->async.callback;
-       ac->timeout = req->async.timeout;
        ac->user_type = what_is_user(module);
 
        down_req = talloc_zero(req, struct ldb_request);
@@ -178,7 +176,7 @@ static int kludge_acl_search_async(struct ldb_module *module, struct ldb_request
 
        down_req->async.context = ac;
        down_req->async.callback = kludge_acl_async_callback;
-       down_req->async.timeout = req->async.timeout;
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
 
        /* perform the search */
        ret = ldb_next_request(module, down_req);
@@ -193,7 +191,8 @@ static int kludge_acl_search_async(struct ldb_module *module, struct ldb_request
 }
 
 /* ANY change type */
-static int kludge_acl_change(struct ldb_module *module, struct ldb_request *req){
+static int kludge_acl_change(struct ldb_module *module, struct ldb_request *req)
+{
        enum user_is user_type = what_is_user(module);
        switch (user_type) {
        case SYSTEM:
index 643f8c17fdf40961c096475ede3a2f9f606a35f4..3f6a95199779454eeccb711e0f1ee00228216bf0 100644 (file)
@@ -99,6 +99,8 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
                return ret;
        }
        
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
+
        /* go on with the call chain */
        ret = ldb_next_request(module, down_req);
 
index a04fb52cd21eb2592751e0ac61d44a5f33e23941..8a400fbc63b22467428e6a0e91600a16196519c5 100644 (file)
@@ -510,6 +510,7 @@ static int build_domain_data_request(struct ph_async_context *ac,
        ac->dom_req->async.context = ac;
        ac->dom_req->async.callback = get_domain_data_callback;
        ac->dom_req->async.timeout = ac->orig_req->async.timeout;
+       ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->dom_req);
 
        return LDB_SUCCESS;
 }
@@ -634,7 +635,7 @@ static int password_hash_add_do_add(struct ldb_async_handle *h) {
        if (ac->down_req->op.add.message == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       
+
        /* Some operations below require kerberos contexts */
        if (smb_krb5_init_context(ac->down_req, &smb_krb5_context) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
@@ -685,6 +686,8 @@ static int password_hash_add_do_add(struct ldb_async_handle *h) {
 
        ac->step = PH_ADD_DO_ADD;
 
+       ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->down_req);
+
        /* perform the operation */
        return ldb_next_request(ac->module, ac->down_req);
 }
@@ -777,6 +780,8 @@ static int password_hash_modify(struct ldb_module *module, struct ldb_request *r
 
        ac->step = PH_MOD_DO_REQ;
 
+       ldb_set_timeout_from_prev_req(module->ldb, req, ac->down_req);
+
        return ldb_next_request(module, ac->down_req);
 }
 
@@ -848,7 +853,7 @@ static int password_hash_mod_search_self(struct ldb_async_handle *h) {
        ac->search_req->controls = NULL;
        ac->search_req->async.context = ac;
        ac->search_req->async.callback = get_self_callback;
-       ac->search_req->async.timeout = ac->orig_req->async.timeout;
+       ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->search_req);
 
        ac->step = PH_MOD_SEARCH_SELF;
 
@@ -1001,6 +1006,8 @@ static int password_hash_mod_do_mod(struct ldb_async_handle *h) {
 
        ac->step = PH_MOD_DO_MOD;
 
+       ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->mod_req);
+
        /* perform the search */
        return ldb_next_request(ac->module, ac->mod_req);
 }
index 46b34a469ba492fd09082ce1e5b07cd95cb75d09..e96da829eb908c8178443fe0f4e9100ec6ea14d7 100644 (file)
@@ -125,7 +125,6 @@ struct rootdse_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        const char * const * attrs;
 };
@@ -176,7 +175,6 @@ static int rootdse_search(struct ldb_module *module, struct ldb_request *req)
        ac->module = module;
        ac->up_context = req->async.context;
        ac->up_callback = req->async.callback;
-       ac->timeout = req->async.timeout;
        ac->attrs = req->op.search.attrs;
 
        down_req = talloc_zero(req, struct ldb_request);
@@ -199,7 +197,7 @@ static int rootdse_search(struct ldb_module *module, struct ldb_request *req)
 
        down_req->async.context = ac;
        down_req->async.callback = rootdse_async_callback;
-       down_req->async.timeout = req->async.timeout;
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
 
        /* perform the search */
        ret = ldb_next_request(module, down_req);
index 01972016ae61637efe8c27696106a38ee07184e9..eaa7aa034af71f3510749e3e1533ee700ec33bfd 100644 (file)
@@ -845,7 +845,9 @@ static int samldb_add(struct ldb_module *module, struct ldb_request *req)
        *down_req = *req;
        
        down_req->op.add.message = talloc_steal(down_req, msg2);
-       
+
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
+
        /* go on with the call chain */
        ret = ldb_next_request(module, down_req);
 
index 126ad37d9bda327c54aea2db2a0a7a57a81235a0..b6c22437bddfc6d40485ed4dc4a22445a8fd1e6a 100644 (file)
@@ -140,6 +140,9 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
                return LDB_ERR_OTHER;
        }
 
+       /* TODO: get timeout from options if available there */
+       ldb->default_timeout = 300; /* set default to 5 minutes */
+
        return LDB_SUCCESS;
 }
 
@@ -252,24 +255,41 @@ int ldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type typ
        return handle->module->ops->async_wait(handle, type);
 }
 
-
-/*
-  check for an error return from an op 
-  if an op fails, but has not setup an error string, then setup one now
-*/
-static int ldb_op_finish(struct ldb_context *ldb, int status)
+/* set the specified timeout or, if timeout is 0 set the default timeout */
+/* timeout == -1 means no timeout */
+int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout)
 {
-       if (status == LDB_SUCCESS) {
-               return ldb_transaction_commit(ldb);
+       if (req == NULL) return LDB_ERR_OPERATIONS_ERROR;
+       
+       if (timeout != 0) {
+               req->async.timeout = timeout;
+       } else {
+               req->async.timeout = ldb->default_timeout;
        }
-       if (ldb->err_string == NULL) {
-               /* no error string was setup by the backend */
-               ldb_set_errstring(ldb, 
-                                 talloc_asprintf(ldb, "%s (%d)", 
-                                                 ldb_strerror(status), status));
+       req->async.starttime = time(NULL);
+
+       return LDB_SUCCESS;
+}
+
+/* calculates the new timeout based on the previous starttime and timeout */
+int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq)
+{
+       time_t now;
+
+       if (newreq == NULL) return LDB_ERR_OPERATIONS_ERROR;
+
+       now = time(NULL);
+
+       if (oldreq == NULL)
+               return ldb_set_timeout(ldb, newreq, 0);
+
+       if ((now - oldreq->async.starttime) > oldreq->async.timeout) {
+               return LDB_ERR_TIME_LIMIT_EXCEEDED;
        }
-       ldb_transaction_cancel(ldb);
-       return status;
+       newreq->async.starttime = oldreq->async.starttime;
+       newreq->async.timeout = oldreq->async.timeout - (now - oldreq->async.starttime);
+
+       return LDB_SUCCESS;
 }
 
 /*
@@ -424,7 +444,7 @@ int ldb_search(struct ldb_context *ldb,
        req->controls = NULL;
        req->async.context = res;
        req->async.callback = ldb_search_callback;
-       req->async.timeout = 600; /* 10 minutes */
+       ldb_set_timeout(ldb, req, 0); /* use default timeout */
 
        ret = ldb_request(ldb, req);
        
@@ -461,7 +481,10 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_reque
        }
 
        if (close_transaction) {
-               return ldb_op_finish(ldb, ret);
+               if (ret == LDB_SUCCESS) {
+                       return ldb_transaction_commit(ldb);
+               }
+               ldb_transaction_cancel(ldb);
        }
 
        if (ldb->err_string == NULL) {
@@ -499,7 +522,7 @@ int ldb_add(struct ldb_context *ldb,
        req->controls = NULL;
        req->async.context = NULL;
        req->async.callback = NULL;
-       req->async.timeout = 600; /* 10 minutes */
+       ldb_set_timeout(ldb, req, 0); /* use default timeout */
 
        /* do request and autostart a transaction */
        ret = ldb_autotransaction_request(ldb, req);
@@ -531,7 +554,7 @@ int ldb_modify(struct ldb_context *ldb,
        req->controls = NULL;
        req->async.context = NULL;
        req->async.callback = NULL;
-       req->async.timeout = 600; /* 10 minutes */
+       ldb_set_timeout(ldb, req, 0); /* use default timeout */
 
        /* do request and autostart a transaction */
        ret = ldb_autotransaction_request(ldb, req);
@@ -560,7 +583,7 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
        req->controls = NULL;
        req->async.context = NULL;
        req->async.callback = NULL;
-       req->async.timeout = 600; /* 10 minutes */
+       ldb_set_timeout(ldb, req, 0); /* use default timeout */
 
        /* do request and autostart a transaction */
        ret = ldb_autotransaction_request(ldb, req);
@@ -589,7 +612,7 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
        req->controls = NULL;
        req->async.context = NULL;
        req->async.callback = NULL;
-       req->async.timeout = 600; /* 10 minutes */
+       ldb_set_timeout(ldb, req, 0); /* use default timeout */
 
        /* do request and autostart a transaction */
        ret = ldb_autotransaction_request(ldb, req);
index 56eed3ab24d5c8629db126354e06e53e043f5451..644f74385f9308c33dfc8142c344ce6eaefda948 100644 (file)
@@ -658,6 +658,7 @@ struct ldb_request {
                int (*callback)(struct ldb_context *, void *, struct ldb_async_result *);
 
                int timeout;
+               time_t starttime;
                struct ldb_async_handle *handle;
        } async;
 };
@@ -666,6 +667,9 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
 
 int ldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type);
 
+int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout);
+int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq);
+
 /**
   Initialise ldbs' global information
 
index d8f9aa417de0bd1656847d1c55c5d475937ece19..14f04036978b24bc8bbfa6041d14daf653c3ca1f 100644 (file)
@@ -113,6 +113,8 @@ struct ldb_context {
 
        int transaction_active;
 
+       int default_timeout;
+
        /* a backend supplied highestCommittedUSN function */
        uint64_t (*sequence_number)(struct ldb_context *);
 };
index 003c6c011e00075f49e80c39285760c3c121382e..4fc34ccdcface3b24180204dc59133a96444ab77 100644 (file)
@@ -143,7 +143,7 @@ static void ildb_request_timeout(struct event_context *ev, struct timed_event *t
                DLIST_REMOVE(ac->req->conn->pending, ac->req);
        }
 
-       handle->status = LDB_ERR_OPERATIONS_ERROR;
+       handle->status = LDB_ERR_TIME_LIMIT_EXCEEDED;
 
        return;
 }
@@ -759,7 +759,7 @@ static int ildb_init(struct ldb_module *module)
        req->controls = NULL;
        req->async.context = ildb;
        req->async.callback = ildb_rootdse_callback;
-       req->async.timeout = 60;
+       ldb_set_timeout(module->ldb, req, 60);
 
        ret = ildb_search(module, req);
        if (ret != LDB_SUCCESS) {
index 5748c2ecd7bb63070264a6724a65cd9b0b9a8a65..4132fa6c1574cb168d195c8368d8f49d6b3cb961 100644 (file)
 
 struct lldb_private {
        LDAP *ldap;
-       int timeout;
 };
 
 struct lldb_async_context {
        struct ldb_module *module;
        int msgid;
        int timeout;
+       time_t starttime;
        void *context;
        int (*callback)(struct ldb_context *, void *, struct ldb_async_result *);
 };
@@ -65,7 +65,7 @@ static int lldb_ldap_to_ldb(int err) {
 static struct ldb_async_handle *init_handle(struct lldb_private *lldb, struct ldb_module *module,
                                            void *context,
                                            int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                                           int timeout)
+                                           int timeout, time_t starttime)
 {
        struct lldb_async_context *ac;
        struct ldb_async_handle *h;
@@ -94,6 +94,7 @@ static struct ldb_async_handle *init_handle(struct lldb_private *lldb, struct ld
        ac->context = context;
        ac->callback = callback;
        ac->timeout = timeout;
+       ac->starttime = starttime;
        ac->msgid = 0;
 
        return h;
@@ -248,7 +249,7 @@ static int lldb_search(struct ldb_module *module, struct ldb_request *req)
                ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls are not yet supported by ldb_ldap backend!\n");
        }
 
-       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout, req->async.starttime);
        if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -316,7 +317,7 @@ static int lldb_add(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout, req->async.starttime);
        if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -361,7 +362,7 @@ static int lldb_modify(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout, req->async.starttime);
        if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -405,7 +406,7 @@ static int lldb_delete(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout, req->async.starttime);
        if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -443,7 +444,7 @@ static int lldb_rename(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
-       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout);
+       req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout, req->async.starttime);
        if (req->async.handle == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -661,6 +662,12 @@ static int lldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
 
        switch(type) {
        case LDB_WAIT_NONE:
+
+               if ((ac->timeout != -1) &&
+                   ((ac->starttime + timeout) > time(NULL))) {
+                       return LDB_ERR_TIME_LIMIT_EXCEEDED;
+               }
+
                timeout.tv_sec = 0;
                timeout.tv_usec = 0;
 
@@ -676,13 +683,19 @@ static int lldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
                return lldb_parse_result(handle, result);
 
        case LDB_WAIT_ALL:
-               timeout.tv_sec = ac->timeout;
                timeout.tv_usec = 0;
                ret = LDB_ERR_OPERATIONS_ERROR;
 
                while (handle->status == LDB_SUCCESS && handle->state != LDB_ASYNC_DONE) {
 
-                       lret = ldap_result(lldb->ldap, ac->msgid, 0, &timeout, &result);
+                       if (ac->timeout == -1) {
+                               lret = ldap_result(lldb->ldap, ac->msgid, 0, NULL, &result);
+                       } else {
+                               timeout.tv_sec = ac->timeout - (time(NULL) - ac->starttime);
+                               if (timeout.tv_sec <= 0)
+                                       return LDB_ERR_TIME_LIMIT_EXCEEDED;
+                               lret = ldap_result(lldb->ldap, ac->msgid, 0, &timeout, &result);
+                       }
                        if (lret == -1) {
                                return LDB_ERR_OPERATIONS_ERROR;
                        }
@@ -773,7 +786,6 @@ static int lldb_connect(struct ldb_context *ldb,
        }
 
        lldb->ldap = NULL;
-       lldb->timeout = 120; /* TODO: get timeout from options ? */
 
        ret = ldap_initialize(&lldb->ldap, url);
        if (ret != LDAP_SUCCESS) {
index 396a2346df8686c2fae871f9110b506532f4150d..75ef4a487eae2e08761ba2bf00bdaa191cff36bf 100644 (file)
@@ -48,7 +48,6 @@ struct asq_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        const char * const *req_attrs;
        char *req_attribute;
@@ -66,8 +65,7 @@ struct asq_async_context {
 
 static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *module,
                                            void *context,
-                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                                           int timeout)
+                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *))
 {
        struct asq_async_context *ac;
        struct ldb_async_handle *h;
@@ -95,7 +93,6 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo
        ac->module = module;
        ac->up_context = context;
        ac->up_callback = callback;
-       ac->timeout = timeout;
 
        return h;
 }
@@ -233,7 +230,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_PROTOCOL_ERROR;
        }
 
-       h = init_handle(req, module, req->async.context, req->async.callback, req->async.timeout);
+       h = init_handle(req, module, req->async.context, req->async.callback);
        if (!h) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -271,7 +268,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req)
 
        ac->base_req->async.context = ac;
        ac->base_req->async.callback = asq_base_callback;
-       ac->base_req->async.timeout = req->async.timeout;
+       ldb_set_timeout_from_prev_req(module->ldb, req, ac->base_req);
 
        ac->step = ASQ_SEARCH_BASE;
 
@@ -324,7 +321,7 @@ static int asq_async_requests(struct ldb_async_handle *handle) {
 
                ac->reqs[i]->async.context = ac;
                ac->reqs[i]->async.callback = asq_reqs_callback;
-               ac->reqs[i]->async.timeout = ac->base_req->async.timeout;
+               ldb_set_timeout_from_prev_req(ac->module->ldb, ac->base_req, ac->reqs[i]);
        }
 
        ac->step = ASQ_SEARCH_MULTI;
@@ -436,14 +433,19 @@ static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_t
 
 static int asq_init(struct ldb_module *module)
 {
-       struct ldb_request request;
+       struct ldb_request *req;
        int ret;
 
-       request.operation = LDB_REQ_REGISTER;
-       request.op.reg.oid = LDB_CONTROL_ASQ_OID;
-       request.controls = NULL;
+       req = talloc_zero(module, struct ldb_request);
+       if (req == NULL) {
+               ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Out of memory!\n");
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       req->operation = LDB_REQ_REGISTER;
+       req->op.reg.oid = LDB_CONTROL_ASQ_OID;
 
-       ret = ldb_request(module->ldb, &request);
+       ret = ldb_request(module->ldb, req);
        if (ret != LDB_SUCCESS) {
                ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Unable to register control with rootdse!\n");
                return LDB_ERR_OTHER;
index 4423f82aedb8c1b213d66bff15eb693f80aa8993..6c50ba19c832b32b294872caa02565bdc6c527eb 100644 (file)
@@ -124,6 +124,7 @@ static int objectclass_add(struct ldb_module *module, struct ldb_request *req)
 
        ac->down_req->async.context = NULL;
        ac->down_req->async.callback = NULL;
+       ldb_set_timeout_from_prev_req(module->ldb, req, ac->down_req);
 
        ac->step = OC_DO_REQ;
 
@@ -171,6 +172,7 @@ static int objectclass_modify(struct ldb_module *module, struct ldb_request *req
 
        ac->down_req->async.context = NULL;
        ac->down_req->async.callback = NULL;
+       ldb_set_timeout_from_prev_req(module->ldb, req, ac->down_req);
 
        ac->step = OC_DO_REQ;
 
@@ -230,7 +232,7 @@ static int objectclass_search_self(struct ldb_async_handle *h) {
        ac->search_req->controls = NULL;
        ac->search_req->async.context = ac;
        ac->search_req->async.callback = get_self_callback;
-       ac->search_req->async.timeout = ac->orig_req->async.timeout;
+       ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->search_req);
 
        ac->step = OC_SEARCH_SELF;
 
@@ -270,7 +272,7 @@ static int objectclass_do_mod(struct ldb_async_handle *h) {
        ac->mod_req->controls = NULL;
        ac->mod_req->async.context = ac;
        ac->mod_req->async.callback = NULL;
-       ac->mod_req->async.timeout = ac->orig_req->async.timeout;
+       ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->mod_req);
        
        /* use a new message structure */
        ac->mod_req->op.mod.message = msg = ldb_msg_new(ac->mod_req);
index 4b1daba30fb21fe765f453768f36db4b5507bde2..b404e94580e3531058152f6b74bb367fcd5ca119 100644 (file)
@@ -231,7 +231,6 @@ struct operational_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        const char * const *attrs;
 };
@@ -279,7 +278,6 @@ static int operational_search(struct ldb_module *module, struct ldb_request *req
        ac->module = module;
        ac->up_context = req->async.context;
        ac->up_callback = req->async.callback;
-       ac->timeout = req->async.timeout;
        ac->attrs = req->op.search.attrs;
 
        down_req = talloc_zero(req, struct ldb_request);
@@ -329,7 +327,7 @@ static int operational_search(struct ldb_module *module, struct ldb_request *req
 
        down_req->async.context = ac;
        down_req->async.callback = operational_async_callback;
-       down_req->async.timeout = req->async.timeout;
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
 
        /* perform the search */
        ret = ldb_next_request(module, down_req);
@@ -385,6 +383,8 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req)
                }
        }
 
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
+
        /* go on with the call chain */
        ret = ldb_next_request(module, down_req);
 
@@ -436,6 +436,8 @@ static int operational_modify(struct ldb_module *module, struct ldb_request *req
                return -1;
        }
        
+       ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
+
        /* go on with the call chain */
        ret = ldb_next_request(module, down_req);
 
index 6d864375c6bac1dfe8440fc352fba9a8aa9a80c8..bdfaea6d51533bc82b312c7bf59fa1c1eb5bc1dd 100644 (file)
@@ -126,7 +126,6 @@ struct paged_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        int size;
 
@@ -135,8 +134,7 @@ struct paged_async_context {
 
 static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *module,
                                            void *context,
-                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                                           int timeout)
+                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *))
 {
        struct paged_async_context *ac;
        struct ldb_async_handle *h;
@@ -164,7 +162,6 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo
        ac->module = module;
        ac->up_context = context;
        ac->up_callback = callback;
-       ac->timeout = timeout;
 
        return h;
 }
@@ -267,7 +264,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_PROTOCOL_ERROR;
        }
 
-       h = init_handle(req, module, req->async.context, req->async.callback, req->async.timeout);
+       h = init_handle(req, module, req->async.context, req->async.callback);
        if (!h) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -304,7 +301,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req)
 
                ac->store->req->async.context = ac;
                ac->store->req->async.callback = paged_search_async_callback;
-               ac->store->req->async.timeout = req->async.timeout;
+               ldb_set_timeout_from_prev_req(module->ldb, req, ac->store->req);
 
                ret = ldb_next_request(module, ac->store->req);
 
index d6eb0ef13e94078fd6859b6afba1d9cce274f93e..7aedc260ad62f9f71156fc1f36c2cf654722d1a4 100644 (file)
@@ -226,7 +226,7 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       ac->mod_req->async.timeout = ac->orig_req->async.timeout;
+       ldb_set_timeout_from_prev_req(h->module->ldb, ac->orig_req, ac->mod_req);
 
        ac->step = RENAME_MODIFY;
 
index 2f9d7dfc96f8bd0e6318d1df9f750079ae5405ca..23f4f3647842436fa6fac9a18b1b75a42c08ec3f 100644 (file)
@@ -47,7 +47,6 @@ struct sort_async_context {
        struct ldb_module *module;
        void *up_context;
        int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *);
-       int timeout;
 
        char *attributeName;
        char *orderingRule;
@@ -66,8 +65,7 @@ struct sort_async_context {
 
 static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *module,
                                            void *context,
-                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *),
-                                           int timeout)
+                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *))
 {
        struct sort_async_context *ac;
        struct ldb_async_handle *h;
@@ -95,7 +93,6 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo
        ac->module = module;
        ac->up_context = context;
        ac->up_callback = callback;
-       ac->timeout = timeout;
 
        return h;
 }
@@ -143,33 +140,6 @@ static int build_response(void *mem_ctx, struct ldb_control ***ctrls, int result
 }
 
 static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque)
-{
-       struct opaque *data = (struct opaque *)opaque;
-       struct ldb_message_element *el1, *el2;
-
-       if (data->result != 0) {
-               /* an error occurred previously,
-                * let's exit the sorting by returning always 0 */
-               return 0;
-       }
-
-       el1 = ldb_msg_find_element(*msg1, data->attribute);
-       el2 = ldb_msg_find_element(*msg2, data->attribute);
-
-       if (!el1 || !el2) {
-               /* the attribute was not found return and
-                * set an error */
-               data->result = 53;
-               return 0;
-       }
-
-       if (data->reverse)
-               return data->h->comparison_fn(data->ldb, data, &el2->values[0], &el1->values[0]);
-
-       return data->h->comparison_fn(data->ldb, data, &el1->values[0], &el2->values[0]);
-}
-
-static int sort_compare_async(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque)
 {
        struct sort_async_context *ac = talloc_get_type(opaque, struct sort_async_context);
        struct ldb_message_element *el1, *el2;
@@ -279,7 +249,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req
                return LDB_ERR_OPERATIONS_ERROR;
        }
        
-       h = init_handle(req, module, req->async.context, req->async.callback, req->async.timeout);
+       h = init_handle(req, module, req->async.context, req->async.callback);
        if (!h) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -342,7 +312,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req
 
        ac->req->async.context = ac;
        ac->req->async.callback = server_sort_search_callback;
-       ac->req->async.timeout = req->async.timeout;
+       ldb_set_timeout_from_prev_req(module->ldb, req, ac->req);
 
        req->async.handle = h;
 
@@ -362,7 +332,7 @@ static int server_sort_results(struct ldb_async_handle *handle)
 
        ldb_qsort(ac->msgs, ac->num_msgs,
                  sizeof(struct ldb_message *),
-                 ac, (ldb_qsort_cmp_fn_t)sort_compare_async);
+                 ac, (ldb_qsort_cmp_fn_t)sort_compare);
 
        for (i = 0; i < ac->num_msgs; i++) {
                ares = talloc_zero(ac, struct ldb_async_result);
index 854360b72318ea8a6b29029b098fd4bf1c3880d6..2c8108c9aded33db9eed8e8e9026a0434f5ee78a 100644 (file)
@@ -226,7 +226,7 @@ static int do_search(struct ldb_context *ldb,
        req->controls = actx->req_ctrls;
        req->async.context = actx;
        req->async.callback = &search_callback;
-       req->async.timeout = 3600; /* TODO: make this settable by command line */
+       ldb_set_timeout(ldb, req, 0); /* TODO: make this settable by command line */
 
 again:
        actx->pending = 0;
index 51ff6f301f309f7644c0ff2f84738611e6f5296b..8144782e6017c219caf6f9d1bd8404ed634e1a53 100644 (file)
@@ -233,7 +233,7 @@ static BOOL test_create_schema_type(struct ldb_context *ldb, struct test_rootDSE
        req->controls = ctrl;
        req->async.context = actx;
        req->async.callback = test_schema_search_callback;
-       req->async.timeout = 3600;
+       ldb_set_timeout(ldb, req, 0);
 
        actx->count             = 0;
        actx->ctrl              = control;