diff options
author | Simo Sorce <idra@samba.org> | 2006-06-04 05:28:13 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:08:52 -0500 |
commit | ca5accf224dc3ef998235603797b519866b57b1c (patch) | |
tree | 3d2790afbc47076c2b12611d5c1e5b20683b36c5 | |
parent | b31c685ec293ef65bc33a474fc5a1d83545d4749 (diff) | |
download | samba-ca5accf224dc3ef998235603797b519866b57b1c.tar.gz samba-ca5accf224dc3ef998235603797b519866b57b1c.tar.bz2 samba-ca5accf224dc3ef998235603797b519866b57b1c.zip |
r16036: Add a couple of new functions to corretly deal with timeouts.
Check timeouts are correctly verified.
Some minor fixed and removal of unused code.
(This used to be commit b52e5d6a0cb1a32e62759eaa49ce3e4cc804cc92)
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/extended_dn.c | 4 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/kludge_acl.c | 7 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/objectguid.c | 2 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/password_hash.c | 11 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/rootdse.c | 4 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/samldb.c | 4 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 65 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 4 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb_private.h | 2 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 32 | ||||
-rw-r--r-- | source4/lib/ldb/modules/asq.c | 26 | ||||
-rw-r--r-- | source4/lib/ldb/modules/objectclass.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/modules/operational.c | 8 | ||||
-rw-r--r-- | source4/lib/ldb/modules/paged_results.c | 9 | ||||
-rw-r--r-- | source4/lib/ldb/modules/rdn_name.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/modules/sort.c | 38 | ||||
-rw-r--r-- | source4/lib/ldb/tools/ldbsearch.c | 2 | ||||
-rw-r--r-- | source4/torture/ldap/schema.c | 2 |
19 files changed, 126 insertions, 106 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn.c b/source4/dsdb/samdb/ldb_modules/extended_dn.c index 1f2d406a28..71f7a2dc7e 100644 --- a/source4/dsdb/samdb/ldb_modules/extended_dn.c +++ b/source4/dsdb/samdb/ldb_modules/extended_dn.c @@ -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); diff --git a/source4/dsdb/samdb/ldb_modules/kludge_acl.c b/source4/dsdb/samdb/ldb_modules/kludge_acl.c index 4e09faf269..1b5b896b3f 100644 --- a/source4/dsdb/samdb/ldb_modules/kludge_acl.c +++ b/source4/dsdb/samdb/ldb_modules/kludge_acl.c @@ -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: diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c index 643f8c17fd..3f6a951997 100644 --- a/source4/dsdb/samdb/ldb_modules/objectguid.c +++ b/source4/dsdb/samdb/ldb_modules/objectguid.c @@ -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); diff --git a/source4/dsdb/samdb/ldb_modules/password_hash.c b/source4/dsdb/samdb/ldb_modules/password_hash.c index a04fb52cd2..8a400fbc63 100644 --- a/source4/dsdb/samdb/ldb_modules/password_hash.c +++ b/source4/dsdb/samdb/ldb_modules/password_hash.c @@ -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); } diff --git a/source4/dsdb/samdb/ldb_modules/rootdse.c b/source4/dsdb/samdb/ldb_modules/rootdse.c index 46b34a469b..e96da829eb 100644 --- a/source4/dsdb/samdb/ldb_modules/rootdse.c +++ b/source4/dsdb/samdb/ldb_modules/rootdse.c @@ -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); diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c index 01972016ae..eaa7aa034a 100644 --- a/source4/dsdb/samdb/ldb_modules/samldb.c +++ b/source4/dsdb/samdb/ldb_modules/samldb.c @@ -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); diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 126ad37d9b..b6c22437bd 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -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); diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 56eed3ab24..644f74385f 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -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 diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index d8f9aa417d..14f0403697 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -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 *); }; diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 003c6c011e..4fc34ccdcf 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -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) { diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 5748c2ecd7..4132fa6c15 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -46,13 +46,13 @@ 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) { diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 396a2346df..75ef4a487e 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -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; diff --git a/source4/lib/ldb/modules/objectclass.c b/source4/lib/ldb/modules/objectclass.c index 4423f82aed..6c50ba19c8 100644 --- a/source4/lib/ldb/modules/objectclass.c +++ b/source4/lib/ldb/modules/objectclass.c @@ -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); diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index 4b1daba30f..b404e94580 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -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); diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 6d864375c6..bdfaea6d51 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -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); diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index d6eb0ef13e..7aedc260ad 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -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; diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 2f9d7dfc96..23f4f36478 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -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; } @@ -144,33 +141,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); diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 854360b723..2c8108c9ad 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -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; diff --git a/source4/torture/ldap/schema.c b/source4/torture/ldap/schema.c index 51ff6f301f..8144782e60 100644 --- a/source4/torture/ldap/schema.c +++ b/source4/torture/ldap/schema.c @@ -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; |