diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-07-06 05:08:30 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2006-07-06 05:08:30 +0000 |
commit | 6fd3971d88c8fa4cbcaa42cf32841236ceae3943 (patch) | |
tree | 59c8981f24b9fe9d254b7394e2f67faf88797a94 | |
parent | 2e928decf83126d8ceb9473e7e8b47611711b57d (diff) | |
download | samba-6fd3971d88c8fa4cbcaa42cf32841236ceae3943.tar.gz samba-6fd3971d88c8fa4cbcaa42cf32841236ceae3943.tar.xz samba-6fd3971d88c8fa4cbcaa42cf32841236ceae3943.zip |
r16825: Make ldb_sainity_check() set an error string. This makes it much
easier to chase down what modules or application code gets wrong.
Ensure not to leave memory allocated on failure in ldb_search()
Andrew Bartlett
-rw-r--r-- | source/lib/ldb/common/ldb.c | 23 | ||||
-rw-r--r-- | source/lib/ldb/common/ldb_msg.c | 11 | ||||
-rw-r--r-- | source/lib/ldb/include/ldb.h | 3 | ||||
-rw-r--r-- | source/lib/ldb/modules/objectclass.c | 2 |
4 files changed, 26 insertions, 13 deletions
diff --git a/source/lib/ldb/common/ldb.c b/source/lib/ldb/common/ldb.c index 5228eeb6b3b..c059646629d 100644 --- a/source/lib/ldb/common/ldb.c +++ b/source/lib/ldb/common/ldb.c @@ -527,11 +527,8 @@ int ldb_search(struct ldb_context *ldb, struct ldb_request *req; int ret; - *res = talloc_zero(ldb, struct ldb_result); - if (! *res) { - return LDB_ERR_OPERATIONS_ERROR; - } - + *res = NULL; + req = talloc(ldb, struct ldb_request); if (req == NULL) { ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); @@ -549,6 +546,12 @@ int ldb_search(struct ldb_context *ldb, return LDB_ERR_OPERATIONS_ERROR; } + *res = talloc_zero(ldb, struct ldb_result); + if (! *res) { + talloc_free(req); + return LDB_ERR_OPERATIONS_ERROR; + } + req->op.search.attrs = attrs; req->controls = NULL; req->async.context = res; @@ -581,9 +584,11 @@ int ldb_add(struct ldb_context *ldb, struct ldb_request *req; int ret; - ret = ldb_msg_sanity_check(message); - if (ret != LDB_SUCCESS) return ret; - + ret = ldb_msg_sanity_check(ldb, message); + if (ret != LDB_SUCCESS) { + return ret; + } + req = talloc(ldb, struct ldb_request); if (req == NULL) { ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!")); @@ -613,7 +618,7 @@ int ldb_modify(struct ldb_context *ldb, struct ldb_request *req; int ret; - ret = ldb_msg_sanity_check(message); + ret = ldb_msg_sanity_check(ldb, message); if (ret != LDB_SUCCESS) return ret; req = talloc(ldb, struct ldb_request); diff --git a/source/lib/ldb/common/ldb_msg.c b/source/lib/ldb/common/ldb_msg.c index bae17e7046d..797d050975c 100644 --- a/source/lib/ldb/common/ldb_msg.c +++ b/source/lib/ldb/common/ldb_msg.c @@ -550,18 +550,20 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, return mod; } -int ldb_msg_sanity_check(const struct ldb_message *msg) +int ldb_msg_sanity_check(struct ldb_context *ldb, + const struct ldb_message *msg) { int i, j; /* 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!")); return LDB_ERR_INVALID_DN_SYNTAX; } if (msg->dn->comp_num == 0) { /* root dse has empty dn */ - /* TODO: return also an error string */ + ldb_set_errstring(ldb, talloc_strdup(ldb, "DN on new ldb message is '' (not permitted)!")); return LDB_ERR_ENTRY_ALREADY_EXISTS; } @@ -569,8 +571,13 @@ int ldb_msg_sanity_check(const struct ldb_message *msg) for (i = 0; i < msg->num_elements; i++) { for (j = 0; j < msg->elements[i].num_values; j++) { if (msg->elements[i].values[j].length == 0) { + 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))); + talloc_free(mem_ctx); return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } } diff --git a/source/lib/ldb/include/ldb.h b/source/lib/ldb/include/ldb.h index b684b03ef42..2f0464b9532 100644 --- a/source/lib/ldb/include/ldb.h +++ b/source/lib/ldb/include/ldb.h @@ -1207,7 +1207,8 @@ int ldb_msg_check_string_attribute(const struct ldb_message *msg, LDB_ERR_INVALID_ATTRIBUTE_SYNTAX) if there is a problem with a message. */ -int ldb_msg_sanity_check(const struct ldb_message *msg); +int ldb_msg_sanity_check(struct ldb_context *ldb, + const struct ldb_message *msg); /** Duplicate an ldb_val structure diff --git a/source/lib/ldb/modules/objectclass.c b/source/lib/ldb/modules/objectclass.c index efe93be3d41..473d5a3e6fa 100644 --- a/source/lib/ldb/modules/objectclass.c +++ b/source/lib/ldb/modules/objectclass.c @@ -412,7 +412,7 @@ static int objectclass_do_mod(struct ldb_async_handle *h) { } } - ret = ldb_msg_sanity_check(msg); + ret = ldb_msg_sanity_check(ac->module->ldb, msg); if (ret != LDB_SUCCESS) { talloc_free(mem_ctx); return ret; |