]> git.samba.org - metze/samba/wip.git/blobdiff - source4/lib/ldb/common/ldb_attributes.c
Fix the mess with ldb includes.
[metze/samba/wip.git] / source4 / lib / ldb / common / ldb_attributes.c
index 81aab52a0898f3b5b567018bd8658ef9d4517fbb..4d688a4d7e56bf8bb33b940fbd4b3783e24ff0a1 100644 (file)
@@ -28,7 +28,7 @@
   message matching logic generic
 */
 
-#include "ldb_includes.h"
+#include "ldb_private.h"
 
 /*
   add a attribute to the ldb_schema
@@ -51,6 +51,10 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
        int i, n;
        struct ldb_schema_attribute *a;
 
+       if (!syntax) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
        n = ldb->schema.num_attributes + 1;
 
        a = talloc_realloc(ldb, ldb->schema.attributes,
@@ -62,11 +66,24 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
        ldb->schema.attributes = a;
 
        for (i = 0; i < ldb->schema.num_attributes; i++) {
-               if (ldb_attr_cmp(attribute, a[i].name) < 0) {
+               int cmp = ldb_attr_cmp(attribute, a[i].name);
+               if (cmp == 0) {
+                       /* silently ignore attempts to overwrite fixed attributes */
+                       if (a[i].flags & LDB_ATTR_FLAG_FIXED) {
+                               return 0;
+                       }
+                       if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) {
+                               talloc_free(discard_const_p(char, a[i].name));
+                       }
+                       /* To cancel out increment below */
+                       ldb->schema.num_attributes--;
+                       break;
+               } else if (cmp < 0) {
                        memmove(a+i+1, a+i, sizeof(*a) * (ldb->schema.num_attributes-i));
                        break;
                }
        }
+       ldb->schema.num_attributes++;
 
        a[i].name       = attribute;
        a[i].flags      = flags;
@@ -80,7 +97,6 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
                }
        }
 
-       ldb->schema.num_attributes++;
        return 0;
 }
 
@@ -145,7 +161,7 @@ void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name)
        int i;
 
        a = ldb_schema_attribute_by_name(ldb, name);
-       if (a == NULL) {
+       if (a == NULL || a->name == NULL) {
                return;
        }
 
@@ -209,3 +225,50 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb)
        return LDB_SUCCESS;
 }
 
+
+/*
+  add a extended dn syntax to the ldb_schema
+*/
+int ldb_dn_extended_add_syntax(struct ldb_context *ldb, 
+                              unsigned flags,
+                              const struct ldb_dn_extended_syntax *syntax)
+{
+       int n;
+       struct ldb_dn_extended_syntax *a;
+
+       if (!syntax) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       n = ldb->schema.num_dn_extended_syntax + 1;
+
+       a = talloc_realloc(ldb, ldb->schema.dn_extended_syntax,
+                          struct ldb_dn_extended_syntax, n);
+
+       if (!a) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       a[ldb->schema.num_dn_extended_syntax] = *syntax;
+       ldb->schema.dn_extended_syntax = a;
+
+       ldb->schema.num_dn_extended_syntax = n;
+
+       return LDB_SUCCESS;
+}
+
+/*
+  return the extended dn syntax for a given name
+*/
+const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_context *ldb,
+                                                                   const char *name)
+{
+       int i;
+       for (i=0; i < ldb->schema.num_dn_extended_syntax; i++) {
+               if (ldb_attr_cmp(ldb->schema.dn_extended_syntax[i].name, name) == 0) {
+                       return &ldb->schema.dn_extended_syntax[i];
+               }
+       }
+       return NULL;
+}
+