summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c23
-rw-r--r--source4/lib/ldb/common/ldb_msg.c11
2 files changed, 23 insertions, 11 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 5228eeb6b3..c059646629 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/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/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index bae17e7046..797d050975 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/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;
}
}