1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-07 20:23:50 +03:00

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
This commit is contained in:
Andrew Bartlett
2006-07-06 05:08:30 +00:00
committed by Gerald (Jerry) Carter
parent a789aa468b
commit 0828739951
4 changed files with 26 additions and 13 deletions

View File

@@ -527,10 +527,7 @@ int ldb_search(struct ldb_context *ldb,
struct ldb_request *req; struct ldb_request *req;
int ret; int ret;
*res = talloc_zero(ldb, struct ldb_result); *res = NULL;
if (! *res) {
return LDB_ERR_OPERATIONS_ERROR;
}
req = talloc(ldb, struct ldb_request); req = talloc(ldb, struct ldb_request);
if (req == NULL) { if (req == NULL) {
@@ -549,6 +546,12 @@ int ldb_search(struct ldb_context *ldb,
return LDB_ERR_OPERATIONS_ERROR; 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->op.search.attrs = attrs;
req->controls = NULL; req->controls = NULL;
req->async.context = res; req->async.context = res;
@@ -581,8 +584,10 @@ int ldb_add(struct ldb_context *ldb,
struct ldb_request *req; struct ldb_request *req;
int ret; int ret;
ret = ldb_msg_sanity_check(message); ret = ldb_msg_sanity_check(ldb, message);
if (ret != LDB_SUCCESS) return ret; if (ret != LDB_SUCCESS) {
return ret;
}
req = talloc(ldb, struct ldb_request); req = talloc(ldb, struct ldb_request);
if (req == NULL) { if (req == NULL) {
@@ -613,7 +618,7 @@ int ldb_modify(struct ldb_context *ldb,
struct ldb_request *req; struct ldb_request *req;
int ret; int ret;
ret = ldb_msg_sanity_check(message); ret = ldb_msg_sanity_check(ldb, message);
if (ret != LDB_SUCCESS) return ret; if (ret != LDB_SUCCESS) return ret;
req = talloc(ldb, struct ldb_request); req = talloc(ldb, struct ldb_request);

View File

@@ -550,18 +550,20 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
return mod; 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; int i, j;
/* basic check on DN */ /* basic check on DN */
if (msg->dn == NULL) { if (msg->dn == NULL) {
/* TODO: return also an error string */ /* TODO: return also an error string */
ldb_set_errstring(ldb, talloc_strdup(ldb, "ldb message lacks a DN!"));
return LDB_ERR_INVALID_DN_SYNTAX; return LDB_ERR_INVALID_DN_SYNTAX;
} }
if (msg->dn->comp_num == 0) { if (msg->dn->comp_num == 0) {
/* root dse has empty dn */ /* 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; 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 (i = 0; i < msg->num_elements; i++) {
for (j = 0; j < msg->elements[i].num_values; j++) { for (j = 0; j < msg->elements[i].num_values; j++) {
if (msg->elements[i].values[j].length == 0) { if (msg->elements[i].values[j].length == 0) {
TALLOC_CTX *mem_ctx = talloc_new(ldb);
/* an attribute cannot be empty */ /* an attribute cannot be empty */
/* TODO: return also an error string */ /* 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; return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
} }
} }

View File

@@ -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 LDB_ERR_INVALID_ATTRIBUTE_SYNTAX) if there is a problem with a
message. 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 Duplicate an ldb_val structure

View File

@@ -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) { if (ret != LDB_SUCCESS) {
talloc_free(mem_ctx); talloc_free(mem_ctx);
return ret; return ret;