The branch, master has been updated via fea02ce ldb:ldb_autotransaction_request - error string shouldn't be set here via 21d053d ldb:pyldb.c - py_ldb_* modification calls - error string shouldn't be set here via 96a9f82 s4:ldap_backend.c/"map_ldb_error" - handle errors similar to "PyErr_SetLdbError" via 7599d59 ldb:ldb.c/"ldb_wait" - make "ldb_wait" always return an error string via 500d1ba ldb:ldb.c/"ldb_wait" - change "ldb_wait" slightly in order to introduce error messages via 8cab94e ldb:ldb.c/"ldb_request" - make "ldb_request" always return an error string via f2a3125 ldb:ldb.c - "ldb_set_errstring" can be implemented by using "ldb_asprintf_errstring" via 0f41868 ldb:ldb_autotransaction_request - fix a typo in a comment from 4549862 gensec: trim header includes back to what is actually required
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit fea02ce1771ddb2ee09a442a86def72a01b9582e Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 11:45:32 2011 +0200 ldb:ldb_autotransaction_request - error string shouldn't be set here A generic error string should be set independently of the access mechanism to an LDB operation. Hence it should be handled in "ldb_wait" and "ldb_request" Signed-off-by: Andrew Tridgell <tri...@samba.org> Autobuild-User: Andrew Tridgell <tri...@samba.org> Autobuild-Date: Tue Oct 11 10:15:18 CEST 2011 on sn-devel-104 commit 21d053d120cbc665ed8c0afe82598220a608f2af Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Tue Sep 20 17:41:10 2011 +0200 ldb:pyldb.c - py_ldb_* modification calls - error string shouldn't be set here As discussed with Jelmer, we shouldn't be setting a generic LDB error string only for the Python bindings alone. This should be done in "ldb_request" and "ldb_wait" - the common place for all possible LDB access mechanisms. Signed-off-by: Andrew Tridgell <tri...@samba.org> commit 96a9f823edd9c9387d6708fa8c3a4dc5de75127d Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 11:59:06 2011 +0200 s4:ldap_backend.c/"map_ldb_error" - handle errors similar to "PyErr_SetLdbError" If the call was done using an error string ("add_err_string"), then use that one without an additional "ldb_strerror()" for the definitive LDAP output. Otherwise generate one using "ldb_strerror()". This omits redundancies in the error string generation (twice the same information by "ldb_strerror()"). Signed-off-by: Andrew Tridgell <tri...@samba.org> commit 7599d59d1afd0814c14953a830ba4a618187e95e Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 12:54:08 2011 +0200 ldb:ldb.c/"ldb_wait" - make "ldb_wait" always return an error string Signed-off-by: Andrew Tridgell <tri...@samba.org> commit 500d1ba546ff3a677f0a48edc233daeed4d1fe41 Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 12:38:46 2011 +0200 ldb:ldb.c/"ldb_wait" - change "ldb_wait" slightly in order to introduce error messages In this occasion remove a redundant check for "LDB_ASYNC_DONE": if (handle->state == LDB_ASYNC_DONE || if (handle->state == LDB_ASYNC_DONE) handle->status != LDB_SUCCESS) { return handle->status; return handle->status; == if (handle->status != LDB_SUCCESS) } return handle->status; ... ... return LDB_SUCCESS; return LDB_SUCCESS; Signed-off-by: Andrew Tridgell <tri...@samba.org> commit 8cab94e827df1ecbb03cd91467be41feece8c6e5 Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 12:35:20 2011 +0200 ldb:ldb.c/"ldb_request" - make "ldb_request" always return an error string Signed-off-by: Andrew Tridgell <tri...@samba.org> commit f2a3125dcb081d8771bbcd09607592fa9cbef028 Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 13:43:29 2011 +0200 ldb:ldb.c - "ldb_set_errstring" can be implemented by using "ldb_asprintf_errstring" Signed-off-by: Andrew Tridgell <tri...@samba.org> commit 0f41868691ebee9c996bb4dcd44a95833349848b Author: Matthias Dieter Wallnöfer <m...@samba.org> Date: Wed Sep 21 11:38:59 2011 +0200 ldb:ldb_autotransaction_request - fix a typo in a comment Signed-off-by: Andrew Tridgell <tri...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/ldb/common/ldb.c | 91 ++++++++++++++++++++++++++--------- lib/ldb/pyldb.c | 18 +------- source4/ldap_server/ldap_backend.c | 8 +-- 3 files changed, 70 insertions(+), 47 deletions(-) Changeset truncated at 500 lines: diff --git a/lib/ldb/common/ldb.c b/lib/ldb/common/ldb.c index a4c04ce..cd6172a 100644 --- a/lib/ldb/common/ldb.c +++ b/lib/ldb/common/ldb.c @@ -269,28 +269,25 @@ int ldb_connect(struct ldb_context *ldb, const char *url, void ldb_set_errstring(struct ldb_context *ldb, const char *err_string) { - if (ldb->err_string) { - talloc_free(ldb->err_string); - } - ldb->err_string = talloc_strdup(ldb, err_string); - if (ldb->flags & LDB_FLG_ENABLE_TRACING) { - ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_set_errstring: %s", ldb->err_string); - } + ldb_asprintf_errstring(ldb, "%s", err_string); } void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) { va_list ap; - char *old_string = NULL; if (ldb->err_string) { - old_string = ldb->err_string; + talloc_free(ldb->err_string); } va_start(ap, format); ldb->err_string = talloc_vasprintf(ldb, format, ap); va_end(ap); - talloc_free(old_string); + + if (ldb->flags & LDB_FLG_ENABLE_TRACING) { + ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_asprintf/set_errstring: %s", + ldb->err_string); + } } void ldb_reset_err_string(struct ldb_context *ldb) @@ -546,7 +543,7 @@ int ldb_transaction_cancel_noerr(struct ldb_context *ldb) } -/* autostarts a transacion if none active */ +/* autostarts a transaction if none active */ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req) { @@ -567,11 +564,6 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, } ldb_transaction_cancel(ldb); - if (ldb->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret); - } - return ret; } @@ -581,26 +573,41 @@ int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type) int ret; if (!handle) { - return LDB_ERR_UNAVAILABLE; + return ldb_error(handle->ldb, LDB_ERR_UNAVAILABLE, NULL); } if (handle->state == LDB_ASYNC_DONE) { + if ((handle->status != LDB_SUCCESS) && + (handle->ldb->err_string == NULL)) { + /* if no error string was setup by the backend */ + ldb_asprintf_errstring(handle->ldb, "ldb_wait: %s (%d)", + ldb_strerror(handle->status), + handle->status); + } return handle->status; } ev = ldb_get_event_context(handle->ldb); if (NULL == ev) { - return LDB_ERR_OPERATIONS_ERROR; + return ldb_oom(handle->ldb); } switch (type) { case LDB_WAIT_NONE: ret = tevent_loop_once(ev); if (ret != 0) { - return LDB_ERR_OPERATIONS_ERROR; + return ldb_operr(handle->ldb); } - if (handle->state == LDB_ASYNC_DONE || - handle->status != LDB_SUCCESS) { + if (handle->status != LDB_SUCCESS) { + if (handle->ldb->err_string == NULL) { + /* + * if no error string was setup by the backend + */ + ldb_asprintf_errstring(handle->ldb, + "ldb_wait: %s (%d)", + ldb_strerror(handle->status), + handle->status); + } return handle->status; } break; @@ -609,13 +616,35 @@ int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type) while (handle->state != LDB_ASYNC_DONE) { ret = tevent_loop_once(ev); if (ret != 0) { - return LDB_ERR_OPERATIONS_ERROR; + return ldb_operr(handle->ldb); } if (handle->status != LDB_SUCCESS) { + if (handle->ldb->err_string == NULL) { + /* + * if no error string was setup by the + * backend + */ + ldb_asprintf_errstring(handle->ldb, + "ldb_wait: %s (%d)", + ldb_strerror(handle->status), + handle->status); + } return handle->status; } } - return handle->status; + if (handle->status != LDB_SUCCESS) { + if (handle->ldb->err_string == NULL) { + /* + * if no error string was setup by the backend + */ + ldb_asprintf_errstring(handle->ldb, + "ldb_wait: %s (%d)", + ldb_strerror(handle->status), + handle->status); + } + return handle->status; + } + break; } return LDB_SUCCESS; @@ -851,11 +880,15 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req) discard_const(&req->op.add.message)); if (ret != LDB_SUCCESS) { ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; + return ret; } FIRST_OP(ldb, add); ret = ldb_msg_check_element_flags(ldb, req->op.add.message); if (ret != LDB_SUCCESS) { + /* + * "ldb_msg_check_element_flags" generates an error + * string + */ return ret; } ret = module->ops->add(module, req); @@ -869,6 +902,10 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req) FIRST_OP(ldb, modify); ret = ldb_msg_check_element_flags(ldb, req->op.mod.message); if (ret != LDB_SUCCESS) { + /* + * "ldb_msg_check_element_flags" generates an error + * string + */ return ret; } ret = module->ops->modify(module, req); @@ -906,6 +943,12 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req) break; } + if ((ret != LDB_SUCCESS) && (ldb->err_string == NULL)) { + /* if no error string was setup by the backend */ + ldb_asprintf_errstring(ldb, "ldb_request: %s (%d)", + ldb_strerror(ret), ret); + } + return ret; } diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index dbdfe77..673cee2 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -995,17 +995,13 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args, PyObject *kwar ret = ldb_request(ldb_ctx, req); if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); + ret = ldb_wait(req->handle, LDB_WAIT_ALL); } if (ret == LDB_SUCCESS) { ret = ldb_transaction_commit(ldb_ctx); } else { ldb_transaction_cancel(ldb_ctx); - if (ldb_ctx->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret); - } } talloc_free(mem_ctx); @@ -1152,10 +1148,6 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args, PyObject *kwargs) ret = ldb_transaction_commit(ldb_ctx); } else { ldb_transaction_cancel(ldb_ctx); - if (ldb_ctx->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret); - } } talloc_free(mem_ctx); @@ -1227,10 +1219,6 @@ static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args, PyObject *kwar ret = ldb_transaction_commit(ldb_ctx); } else { ldb_transaction_cancel(ldb_ctx); - if (ldb_ctx->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret); - } } talloc_free(mem_ctx); @@ -1310,10 +1298,6 @@ static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args, PyObject *kwar ret = ldb_transaction_commit(ldb_ctx); } else { ldb_transaction_cancel(ldb_ctx); - if (ldb_ctx->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret); - } } talloc_free(mem_ctx); diff --git a/source4/ldap_server/ldap_backend.c b/source4/ldap_server/ldap_backend.c index 57f81ea..afeb350 100644 --- a/source4/ldap_server/ldap_backend.c +++ b/source4/ldap_server/ldap_backend.c @@ -169,12 +169,8 @@ static int map_ldb_error(TALLOC_CTX *mem_ctx, int ldb_err, } *errstring = talloc_asprintf(mem_ctx, "%08X: %s", W_ERROR_V(err), - ldb_strerror(ldb_err)); - if (add_err_string != NULL) { - *errstring = talloc_asprintf(mem_ctx, "%s - %s", *errstring, - add_err_string); - } - + add_err_string != NULL ? add_err_string : ldb_strerror(ldb_err)); + /* result is 1:1 for now */ return ldb_err; } -- Samba Shared Repository