diff options
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 64 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_debug.c | 1 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 10 |
4 files changed, 44 insertions, 33 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 9420318fa9..ce42a36a59 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -174,12 +174,25 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co return LDB_SUCCESS; } -void ldb_set_errstring(struct ldb_context *ldb, char *err_string) +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_steal(ldb, err_string); + ldb->err_string = talloc_strdup(ldb, err_string); +} + +void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) +{ + va_list ap; + + if (ldb->err_string) { + talloc_free(ldb->err_string); + } + + va_start(ap, format); + ldb->err_string = talloc_vasprintf(ldb, format, ap); + va_end(ap); } void ldb_reset_err_string(struct ldb_context *ldb) @@ -194,8 +207,7 @@ void ldb_reset_err_string(struct ldb_context *ldb) module = ldb->modules; \ while (module && module->ops->op == NULL) module = module->next; \ if (module == NULL) { \ - ldb_set_errstring(ldb, \ - talloc_asprintf(ldb, "unable to find module or backend to handle operation: " #op)); \ + ldb_asprintf_errstring(ldb, "unable to find module or backend to handle operation: " #op); \ return LDB_ERR_OPERATIONS_ERROR; \ } \ } while (0) @@ -215,10 +227,10 @@ static int ldb_transaction_start_internal(struct ldb_context *ldb) if (status != LDB_SUCCESS) { if (ldb->err_string == NULL) { /* no error string was setup by the backend */ - ldb_set_errstring(ldb, - talloc_asprintf(ldb, "ldb transaction start: %s (%d)", - ldb_strerror(status), - status)); + ldb_asprintf_errstring(ldb, + "ldb transaction start: %s (%d)", + ldb_strerror(status), + status); } } return status; @@ -239,10 +251,10 @@ static int ldb_transaction_commit_internal(struct ldb_context *ldb) if (status != LDB_SUCCESS) { if (ldb->err_string == NULL) { /* no error string was setup by the backend */ - ldb_set_errstring(ldb, - talloc_asprintf(ldb, "ldb transaction commit: %s (%d)", - ldb_strerror(status), - status)); + ldb_asprintf_errstring(ldb, + "ldb transaction commit: %s (%d)", + ldb_strerror(status), + status); } } return status; @@ -261,10 +273,10 @@ static int ldb_transaction_cancel_internal(struct ldb_context *ldb) if (status != LDB_SUCCESS) { if (ldb->err_string == NULL) { /* no error string was setup by the backend */ - ldb_set_errstring(ldb, - talloc_asprintf(ldb, "ldb transaction cancel: %s (%d)", - ldb_strerror(status), - status)); + ldb_asprintf_errstring(ldb, + "ldb transaction cancel: %s (%d)", + ldb_strerror(status), + status); } } return status; @@ -345,9 +357,7 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_reque if (ldb->err_string == NULL) { /* no error string was setup by the backend */ - ldb_set_errstring(ldb, - talloc_asprintf(ldb, "%s (%d)", - ldb_strerror(ret), ret)); + ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret); } return ret; @@ -460,7 +470,7 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld int n; if (!context) { - ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context in callback")); + ldb_set_errstring(ldb, "NULL Context in callback"); return LDB_ERR_OPERATIONS_ERROR; } @@ -533,7 +543,7 @@ int ldb_search(struct ldb_context *ldb, req = talloc(ldb, struct ldb_request); if (req == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -543,7 +553,7 @@ int ldb_search(struct ldb_context *ldb, req->op.search.tree = ldb_parse_tree(req, expression); if (req->op.search.tree == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Unable to parse search expression")); + ldb_set_errstring(ldb, "Unable to parse search expression"); talloc_free(req); return LDB_ERR_OPERATIONS_ERROR; } @@ -593,7 +603,7 @@ int ldb_add(struct ldb_context *ldb, req = talloc(ldb, struct ldb_request); if (req == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -625,7 +635,7 @@ int ldb_modify(struct ldb_context *ldb, req = talloc(ldb, struct ldb_request); if (req == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); + ldb_set_errstring(ldb, "Out of Memory!"); return LDB_ERR_OPERATIONS_ERROR; } @@ -654,7 +664,7 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn) req = talloc(ldb, struct ldb_request); if (req == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); + ldb_set_errstring(ldb, "Out of Memory!"); return LDB_ERR_OPERATIONS_ERROR; } @@ -682,7 +692,7 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct req = talloc(ldb, struct ldb_request); if (req == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); + ldb_set_errstring(ldb, "Out of Memory!"); return LDB_ERR_OPERATIONS_ERROR; } @@ -712,7 +722,7 @@ int ldb_sequence_number(struct ldb_context *ldb, uint64_t *seq_num) req = talloc(ldb, struct ldb_request); if (req == NULL) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } diff --git a/source4/lib/ldb/common/ldb_debug.c b/source4/lib/ldb/common/ldb_debug.c index c4718c7f52..2548a5495a 100644 --- a/source4/lib/ldb/common/ldb_debug.c +++ b/source4/lib/ldb/common/ldb_debug.c @@ -100,5 +100,6 @@ void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, ldb_set_errstring(ldb, msg); ldb_debug(ldb, level, "%s", msg); } + talloc_free(msg); } diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index d38c873c3b..e863a2beb5 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -369,7 +369,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) module = module->next; \ while (module && module->ops->op == NULL) module = module->next; \ if (module == NULL) { \ - ldb_set_errstring(ldb, talloc_strdup(ldb, "Unable to find backend operation for " #op )); \ + ldb_asprintf_errstring(ldb, "Unable to find backend operation for " #op ); \ return LDB_ERR_OPERATIONS_ERROR; \ } \ } while (0) diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 2fe9e39e68..b0dc74bdb5 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -571,12 +571,12 @@ int ldb_msg_sanity_check(struct ldb_context *ldb, /* basic check on DN */ if (msg->dn == NULL) { /* TODO: return also an error string */ - ldb_set_errstring(ldb, talloc_strdup(ldb, "ldb message lacks a DN!")); + ldb_set_errstring(ldb, "ldb message lacks a DN!"); return LDB_ERR_INVALID_DN_SYNTAX; } if (msg->dn->comp_num == 0) { /* root dse has empty dn */ - ldb_set_errstring(ldb, talloc_strdup(ldb, "DN on new ldb message is '' (not permitted)!")); + ldb_set_errstring(ldb, "DN on new ldb message is '' (not permitted)!"); return LDB_ERR_ENTRY_ALREADY_EXISTS; } @@ -587,9 +587,9 @@ int ldb_msg_sanity_check(struct ldb_context *ldb, TALLOC_CTX *mem_ctx = talloc_new(ldb); /* an attribute cannot be empty */ /* TODO: return also an error string */ - ldb_set_errstring(ldb, talloc_asprintf(mem_ctx, "Element %s has empty attribute in ldb message (%s)!", - msg->elements[i].name, - ldb_dn_linearize(mem_ctx, msg->dn))); + ldb_asprintf_errstring(ldb, "Element %s has empty attribute in ldb message (%s)!", + msg->elements[i].name, + ldb_dn_linearize(mem_ctx, msg->dn)); talloc_free(mem_ctx); return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } |