svn commit: samba r16825 - in branches/SAMBA_4_0/source/lib/ldb:
common include modules
abartlet at samba.org
abartlet at samba.org
Thu Jul 6 05:08:30 GMT 2006
Author: abartlet
Date: 2006-07-06 05:08:30 +0000 (Thu, 06 Jul 2006)
New Revision: 16825
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16825
Log:
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
Modified:
branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c
branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
branches/SAMBA_4_0/source/lib/ldb/modules/objectclass.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c 2006-07-05 20:49:50 UTC (rev 16824)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c 2006-07-06 05:08:30 UTC (rev 16825)
@@ -527,11 +527,8 @@
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 @@
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 @@
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 @@
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);
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c 2006-07-05 20:49:50 UTC (rev 16824)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c 2006-07-06 05:08:30 UTC (rev 16825)
@@ -550,18 +550,20 @@
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 @@
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;
}
}
Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h 2006-07-05 20:49:50 UTC (rev 16824)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h 2006-07-06 05:08:30 UTC (rev 16825)
@@ -1207,7 +1207,8 @@
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
Modified: branches/SAMBA_4_0/source/lib/ldb/modules/objectclass.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/modules/objectclass.c 2006-07-05 20:49:50 UTC (rev 16824)
+++ branches/SAMBA_4_0/source/lib/ldb/modules/objectclass.c 2006-07-06 05:08:30 UTC (rev 16825)
@@ -412,7 +412,7 @@
}
}
- 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;
More information about the samba-cvs
mailing list