summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/ldb_msg.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-09-18 10:47:03 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:38:15 -0500
commit46a8d809376cab59c579c654b0de5105727a9585 (patch)
treedab315ccb06125c1e9a1c395b64a2f870baec9f5 /source4/lib/ldb/common/ldb_msg.c
parentbb8f5c93ee3369e112d99d4d3497dc803abdbf76 (diff)
downloadsamba-46a8d809376cab59c579c654b0de5105727a9585.tar.gz
samba-46a8d809376cab59c579c654b0de5105727a9585.tar.bz2
samba-46a8d809376cab59c579c654b0de5105727a9585.zip
r10304: check for basic ldb_message sanity and return appropriate
LDB_ERR_ value (This used to be commit 610f5646f0816820ac9342e81d46d139e26cc918)
Diffstat (limited to 'source4/lib/ldb/common/ldb_msg.c')
-rw-r--r--source4/lib/ldb/common/ldb_msg.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index f65c944eab..2773237b36 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
/*
@@ -499,3 +500,32 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
return mod;
}
+
+int ldb_msg_sanity_check(const struct ldb_message *msg)
+{
+ int i, j;
+
+ /* basic check on DN */
+ if (msg->dn == NULL) {
+ /* TODO: return also an error string */
+ return LDB_ERR_INVALID_DN_SYNTAX;
+ }
+ if (msg->dn->comp_num == 0) {
+ /* root dse has empty dn */
+ /* TODO: return also an error string */
+ return LDB_ERR_ENTRY_ALREADY_EXISTS;
+ }
+
+ /* basic syntax checks */
+ 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) {
+ /* an attribute cannot be empty */
+ /* TODO: return also an error string */
+ return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
+ }
+ }
+ }
+
+ return LDB_ERR_SUCCESS;
+}