From d812957a3162d37ec355b2e2673f3e7297626da7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 28 Oct 2005 03:43:39 +0000 Subject: r11353: a bit of an improvement to the ldb_tdb error handling (This used to be commit 896704f5c139c8bce30dfc898bb3a12be10035ed) --- source4/lib/ldb/common/ldb.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'source4/lib/ldb/common/ldb.c') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index abd2c03aa3..791e66ea51 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -222,6 +222,24 @@ int ldb_search_bytree(struct ldb_context *ldb, return module->ops->search_bytree(module, base, scope, tree, attrs, res); } +/* + 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) +{ + if (status == LDB_SUCCESS) { + return ldb_transaction_commit(ldb); + } + if (ldb->err_string == NULL) { + /* no error string was setup by the backend */ + ldb_set_errstring(ldb->modules, + talloc_asprintf(ldb, "ldb error %d", status)); + } + ldb_transaction_cancel(ldb); + return status; +} + /* add a record to the database. Will fail if a record with the given class and key already exists @@ -244,11 +262,7 @@ int ldb_add(struct ldb_context *ldb, if (status != LDB_SUCCESS) return status; status = module->ops->add_record(module, message); - if (status != LDB_SUCCESS) { - ldb_transaction_cancel(ldb); - return status; - } - return ldb_transaction_commit(ldb); + return ldb_op_finish(ldb, status); } return module->ops->add_record(module, message); @@ -275,11 +289,7 @@ int ldb_modify(struct ldb_context *ldb, if (status != LDB_SUCCESS) return status; status = module->ops->modify_record(module, message); - if (status != LDB_SUCCESS) { - ldb_transaction_cancel(ldb); - return status; - } - return ldb_transaction_commit(ldb); + return ldb_op_finish(ldb, status); } return module->ops->modify_record(module, message); @@ -303,11 +313,7 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn) if (status != LDB_SUCCESS) return status; status = module->ops->delete_record(module, dn); - if (status != LDB_SUCCESS) { - ldb_transaction_cancel(ldb); - return status; - } - return ldb_transaction_commit(ldb); + return ldb_op_finish(ldb, status); } return module->ops->delete_record(module, dn); @@ -330,11 +336,7 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct if (status != LDB_SUCCESS) return status; status = module->ops->rename_record(module, olddn, newdn); - if (status != LDB_SUCCESS) { - ldb_transaction_cancel(ldb); - return status; - } - return ldb_transaction_commit(ldb); + return ldb_op_finish(ldb, status); } return module->ops->rename_record(module, olddn, newdn); -- cgit