]> git.samba.org - kamenim/samba.git/commitdiff
r10304: check for basic ldb_message sanity and return appropriate
authorSimo Sorce <idra@samba.org>
Sun, 18 Sep 2005 10:47:03 +0000 (10:47 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:15 +0000 (13:38 -0500)
LDB_ERR_ value
(This used to be commit 610f5646f0816820ac9342e81d46d139e26cc918)

source4/lib/ldb/common/ldb.c
source4/lib/ldb/common/ldb_msg.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/include/ldb_private.h

index ae71f087131e832adbc089a4b16ba79fb8b057e7..57fb5a81da7b09f4ff75c0b1ec76cb5db247edbb 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "includes.h"
 #include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
 #include "ldb/include/ldb_private.h"
 
 /* 
@@ -89,20 +90,20 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
 #endif
        else {
                ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to find backend for '%s'\n", url);
-               return -1;
+               return LDB_ERR_OTHER;
        }
 
-       if (ret != 0) {
+       if (ret != LDB_ERR_SUCCESS) {
                ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
                return ret;
        }
 
-       if (ldb_load_modules(ldb, options) != 0) {
+       if (ldb_load_modules(ldb, options) != LDB_ERR_SUCCESS) {
                ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for '%s'\n", url);
-               return -1;
+               return LDB_ERR_OTHER;
        }
 
-       return 0;
+       return LDB_ERR_SUCCESS;
 }
 
 /*
@@ -162,8 +163,14 @@ int ldb_search_bytree(struct ldb_context *ldb,
 int ldb_add(struct ldb_context *ldb, 
            const struct ldb_message *message)
 {
-       int status = ldb_start_trans(ldb);
-       if (status != 0) return status;
+       int status;
+
+
+       status = ldb_msg_sanity_check(message);
+       if (status != LDB_ERR_SUCCESS) return status;
+
+       status = ldb_start_trans(ldb);
+       if (status != LDB_ERR_SUCCESS) return status;
 
        status = ldb->modules->ops->add_record(ldb->modules, message);
        return ldb_end_trans(ldb, status);
@@ -175,8 +182,13 @@ int ldb_add(struct ldb_context *ldb,
 int ldb_modify(struct ldb_context *ldb, 
               const struct ldb_message *message)
 {
-       int status = ldb_start_trans(ldb);
-       if (status != 0) return status;
+       int status;
+
+       status = ldb_msg_sanity_check(message);
+       if (status != LDB_ERR_SUCCESS) return status;
+
+       status = ldb_start_trans(ldb);
+       if (status != LDB_ERR_SUCCESS) return status;
 
        status = ldb->modules->ops->modify_record(ldb->modules, message);
        return ldb_end_trans(ldb, status);
@@ -189,7 +201,7 @@ int ldb_modify(struct ldb_context *ldb,
 int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
 {
        int status = ldb_start_trans(ldb);
-       if (status != 0) return status;
+       if (status != LDB_ERR_SUCCESS) return status;
 
        status = ldb->modules->ops->delete_record(ldb->modules, dn);
        return ldb_end_trans(ldb, status);
@@ -201,7 +213,7 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
 int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
 {
        int status = ldb_start_trans(ldb);
-       if (status != 0) return status;
+       if (status != LDB_ERR_SUCCESS) return status;
 
        status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
        return ldb_end_trans(ldb, status);
@@ -227,13 +239,13 @@ int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value)
        struct ldb_opaque *o = talloc(ldb, struct ldb_opaque);
        if (o == NULL) {
                ldb_oom(ldb);
-               return -1;
+               return LDB_ERR_OTHER;
        }
        o->next = ldb->opaque;
        o->name = name;
        o->value = value;
        ldb->opaque = o;
-       return 0;
+       return LDB_ERR_SUCCESS;
 }
 
 /*
index f65c944eab9168b377f292037fef6886b8fbade1..2773237b3638a2e0ffa641b4e536aaa6fcf19e19 100644 (file)
@@ -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;
+}
index 66b0343891400079fc646a82b0f5ce957bd0429f..008327eb0550849476b57eb4c5adad2e8197d86e 100644 (file)
@@ -3,6 +3,7 @@
 
    Copyright (C) Andrew Tridgell  2004
    Copyright (C) Stefan Metzmacher  2004
+   Copyright (C) Simo Sorce  2005
 
      ** NOTE! The following LGPL license applies to the ldb
      ** library. This does NOT imply that all of Samba is released
@@ -451,6 +452,8 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
                                 struct ldb_message *msg1,
                                 struct ldb_message *msg2);
 
+int ldb_msg_sanity_check(const struct ldb_message *msg);
+
 struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v);
 
 /*
index e55a19c28c6754ff2517a6a50ce72f16edd539e4..96cd4589203ceae990bb14aab944e00c9522858d 100644 (file)
@@ -3,7 +3,7 @@
 
    Copyright (C) Andrew Tridgell    2004
    Copyright (C) Stefan Metzmacher  2004
-   Copyright (C) Simo Sorce         2004
+   Copyright (C) Simo Sorce         2004-2005
 
      ** NOTE! The following LGPL license applies to the ldb
      ** library. This does NOT imply that all of Samba is released