summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-09-18 18:49:06 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:38:16 -0500
commit16aff2a184f7fab64d718b356056070e305e99e9 (patch)
treec1c3dd59cb0e9c54c0ce95bf9165d353206ebd8e /source4/lib/ldb/common
parent46a8d809376cab59c579c654b0de5105727a9585 (diff)
downloadsamba-16aff2a184f7fab64d718b356056070e305e99e9.tar.gz
samba-16aff2a184f7fab64d718b356056070e305e99e9.tar.bz2
samba-16aff2a184f7fab64d718b356056070e305e99e9.zip
r10305: start implementing better error handling
changed the prioivate modules API error string are now not spread over all modules but are kept in a single place. This allows a better control of memory and error reporting. (This used to be commit 3fc676ac1d6f59d08bedbbd9377986154cf84ce4)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c34
-rw-r--r--source4/lib/ldb/common/ldb_modules.c9
2 files changed, 34 insertions, 9 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 57fb5a81da..a00c2481d8 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -106,6 +106,14 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
return LDB_ERR_SUCCESS;
}
+static void ldb_reset_err_string(struct ldb_context *ldb)
+{
+ if (ldb->err_string) {
+ talloc_free(ldb->err_string);
+ ldb->err_string = NULL;
+ }
+}
+
/*
start a transaction
*/
@@ -136,6 +144,8 @@ int ldb_search(struct ldb_context *ldb,
const char *expression,
const char * const *attrs, struct ldb_message ***res)
{
+ ldb_reset_err_string(ldb);
+
return ldb->modules->ops->search(ldb->modules, base, scope, expression, attrs, res);
}
@@ -153,6 +163,8 @@ int ldb_search_bytree(struct ldb_context *ldb,
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
{
+ ldb_reset_err_string(ldb);
+
return ldb->modules->ops->search_bytree(ldb->modules, base, scope, tree, attrs, res);
}
@@ -165,6 +177,7 @@ int ldb_add(struct ldb_context *ldb,
{
int status;
+ ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
if (status != LDB_ERR_SUCCESS) return status;
@@ -184,6 +197,8 @@ int ldb_modify(struct ldb_context *ldb,
{
int status;
+ ldb_reset_err_string(ldb);
+
status = ldb_msg_sanity_check(message);
if (status != LDB_ERR_SUCCESS) return status;
@@ -200,7 +215,11 @@ int ldb_modify(struct ldb_context *ldb,
*/
int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
{
- int status = ldb_start_trans(ldb);
+ int status;
+
+ ldb_reset_err_string(ldb);
+
+ status = ldb_start_trans(ldb);
if (status != LDB_ERR_SUCCESS) return status;
status = ldb->modules->ops->delete_record(ldb->modules, dn);
@@ -212,7 +231,11 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
*/
int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
- int status = ldb_start_trans(ldb);
+ int status;
+
+ ldb_reset_err_string(ldb);
+
+ status = ldb_start_trans(ldb);
if (status != LDB_ERR_SUCCESS) return status;
status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
@@ -224,10 +247,11 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
*/
const char *ldb_errstring(struct ldb_context *ldb)
{
- if (ldb->modules == NULL) {
- return "ldb not connected";
+ if (ldb->err_string) {
+ return ldb->err_string;
}
- return ldb->modules->ops->errstring(ldb->modules);
+
+ return NULL;
}
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 29bc8264e9..e1f5b83083 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -322,11 +322,12 @@ int ldb_next_end_trans(struct ldb_module *module, int status)
return module->next->ops->end_transaction(module->next, status);
}
-const char *ldb_next_errstring(struct ldb_module *module)
+void ldb_set_errstring(struct ldb_module *module, char *err_string)
{
- if (!module->next) {
- return NULL;
+ if (module->ldb->err_string) {
+ talloc_free(module->ldb->err_string);
}
- return module->next->ops->errstring(module->next);
+
+ module->ldb->err_string = err_string;
}