The branch, master has been updated
       via  e2733d3 s4-dsdb clarify that failure to load the schema items from 
DRS is expected
       via  b206a36 move schema_fill_constructed() call to 
dsdb_setup_sorted_accessors()
       via  dee678a s4-dsdb Remove unused schema function
       via  0e9cf38 s4-dsdb: added SAMDB_INDEXING_VERSION to @INDEXLIST
       via  6853b3a s4-dsdb: fixed booling conversion to check value length
       via  cba88a2 ldb: fix the canonicalisation of booleans
       via  60b6b33 s4-dbcheck: enable dbcheck now that backlinks are fixed
       via  4ede333 s4-dsdb: add auto-normalisation of attributes
       via  2ba18d8 s4-dsdb: ensure rIDSetReferences is stored as an extended DN
       via  55b25e1 s4-dsdb: ensure we setup the dn_format field in schema 
attributes
       via  6ef36a0 s4-acl-test: use symbolic names for groupType
       via  ff58087 s4-pysamba: fixed double conversion of int32
       via  fd04a38 s4-dsdb: make extended_dn_in a bit more efficient
       via  4e4953d s4-samdb: support relative paths in SamDB() connect
       via  8ce8107 s4-dsdb: use dn_format shortcut to find DN format
       via  d994ef2 pysamdb: move normalise_int32() to common module
      from  68d79eb s3-rpc_server: Fix sending of packets over named pipe proxy.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e2733d362d97f0dca5b622e54d73ae0e0cc643f0
Author: Andrew Bartlett <[email protected]>
Date:   Tue Aug 9 13:10:21 2011 +1000

    s4-dsdb clarify that failure to load the schema items from DRS is expected
    
    This happens if we have a custom schema - we need to build up the schema 
until
    it loads, by converting more objects.
    
    Andrew Bartlett
    
    Autobuild-User: Andrew Bartlett <[email protected]>
    Autobuild-Date: Tue Aug  9 13:10:25 CEST 2011 on sn-devel-104

commit b206a365eade7fbd2defddbadf14ca293409ede3
Author: Andrew Bartlett <[email protected]>
Date:   Tue Aug 9 12:55:57 2011 +1000

    move schema_fill_constructed() call to dsdb_setup_sorted_accessors()

commit dee678a7be373bbe6497e60d9283dae4ca4793ec
Author: Andrew Bartlett <[email protected]>
Date:   Tue Aug 9 11:54:17 2011 +1000

    s4-dsdb Remove unused schema function

commit 0e9cf380eaae413b904503bc9676f965ef71ef16
Author: Andrew Tridgell <[email protected]>
Date:   Tue Aug 9 16:54:36 2011 +1000

    s4-dsdb: added SAMDB_INDEXING_VERSION to @INDEXLIST
    
    this can be used to force re-indexing of samdb when we change
    something that affects index comparison, in this case the
    canonicalisation of booleans
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>

commit 6853b3a805938ca6fdc69a35d9fdcefb1338101f
Author: Andrew Tridgell <[email protected]>
Date:   Tue Aug 9 16:50:51 2011 +1000

    s4-dsdb: fixed booling conversion to check value length
    
    this ensures we don't look past the end of the data
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>

commit cba88a2b623e47cf97885bd45387049da1105930
Author: Andrew Tridgell <[email protected]>
Date:   Tue Aug 9 16:41:16 2011 +1000

    ldb: fix the canonicalisation of booleans
    
    we were canonicalising "FALSE" to "FALS"
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>

commit 60b6b338f7921bc3c5895e0d0fdbe79305f1be0c
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 11:19:30 2011 +1000

    s4-dbcheck: enable dbcheck now that backlinks are fixed

commit 4ede333f468b36fb7435c9de1216da3b66bf0490
Author: Andrew Tridgell <[email protected]>
Date:   Tue Aug 9 14:41:20 2011 +1000

    s4-dsdb: add auto-normalisation of attributes
    
    this auto-normalises some attributes when they are added/modified. The
    list that we auto-normalise is currently:
    
    Boolean
    INT32
    INTEGER
    UTC_TIME
    
    This fixes a problem with groupType being stored in an unnormalised
    form
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>

commit 2ba18d89eb066cf52d8bbd18a28e494bb4247d9c
Author: Andrew Tridgell <[email protected]>
Date:   Tue Aug 9 13:18:08 2011 +1000

    s4-dsdb: ensure rIDSetReferences is stored as an extended DN
    
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 55b25e1e23882fb8eb476408790b12f03a5d65e8
Author: Andrew Tridgell <[email protected]>
Date:   Tue Aug 9 11:47:25 2011 +1000

    s4-dsdb: ensure we setup the dn_format field in schema attributes
    
    this ensures we setup dn_format when we do runtime schema changes
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>

commit 6ef36a0e6ad3363445e1250495873738e83b108a
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 14:03:58 2011 +1000

    s4-acl-test: use symbolic names for groupType
    
    clearer than magic numbers

commit ff58087a3f686bfcfa304c28179fb2b03c4a0a46
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 14:02:39 2011 +1000

    s4-pysamba: fixed double conversion of int32
    
    if the number is already negative, we shouldn't convert it

commit fd04a38d5063cd5b90970c7a89a1f12701833df7
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 13:10:22 2011 +1000

    s4-dsdb: make extended_dn_in a bit more efficient
    
    checking filter elements in the right order makes it a little faster

commit 4e4953dd48467cf96a17cc48ccf1139e175845fe
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 13:09:35 2011 +1000

    s4-samdb: support relative paths in SamDB() connect
    
    don't add the private path unless the database doesn't exist with the
    supplied path

commit 8ce8107a5bcd821585138fd6e7c690547b783bbf
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 11:28:12 2011 +1000

    s4-dsdb: use dn_format shortcut to find DN format
    
    this saves some string comparisons

commit d994ef20567c1368f6bdea163d12ed3837f79a03
Author: Andrew Tridgell <[email protected]>
Date:   Fri Aug 5 11:17:06 2011 +1000

    pysamdb: move normalise_int32() to common module
    
    this will be needed in quite a few places

-----------------------------------------------------------------------

Summary of changes:
 lib/ldb/common/attrib_handlers.c                   |    6 +-
 source4/dsdb/repl/replicated_objects.c             |    6 +-
 source4/dsdb/samdb/ldb_modules/extended_dn_in.c    |   26 ++++--
 source4/dsdb/samdb/ldb_modules/extended_dn_out.c   |    4 +-
 source4/dsdb/samdb/ldb_modules/extended_dn_store.c |    4 +-
 source4/dsdb/samdb/ldb_modules/objectclass_attrs.c |   47 +++++++++++
 source4/dsdb/samdb/ldb_modules/ridalloc.c          |   18 ++++-
 source4/dsdb/samdb/ldb_modules/util.c              |    2 +-
 source4/dsdb/schema/schema.h                       |    1 +
 source4/dsdb/schema/schema_inferiors.c             |   31 --------
 source4/dsdb/schema/schema_set.c                   |   81 ++++++++++++++------
 source4/dsdb/schema/schema_syntax.c                |   37 ++++++----
 source4/dsdb/tests/python/acl.py                   |   27 ++++---
 source4/scripting/python/samba/common.py           |    5 +
 source4/scripting/python/samba/samdb.py            |   12 +--
 source4/selftest/knownfail                         |    1 -
 16 files changed, 199 insertions(+), 109 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/ldb/common/attrib_handlers.c b/lib/ldb/common/attrib_handlers.c
index 2f4454c..73e1705 100644
--- a/lib/ldb/common/attrib_handlers.c
+++ b/lib/ldb/common/attrib_handlers.c
@@ -166,12 +166,12 @@ static int ldb_comparison_Integer(struct ldb_context 
*ldb, void *mem_ctx,
 static int ldb_canonicalise_Boolean(struct ldb_context *ldb, void *mem_ctx,
                             const struct ldb_val *in, struct ldb_val *out)
 {
-       if (strncasecmp((char *)in->data, "TRUE", in->length) == 0) {
+       if (in->length >= 4 && strncasecmp((char *)in->data, "TRUE", 
in->length) == 0) {
                out->data = (uint8_t *)talloc_strdup(mem_ctx, "TRUE");
                out->length = 4;
-       } else if (strncasecmp((char *)in->data, "FALSE", in->length) == 0) {
+       } else if (in->length >= 5 && strncasecmp((char *)in->data, "FALSE", 
in->length) == 0) {
                out->data = (uint8_t *)talloc_strdup(mem_ctx, "FALSE");
-               out->length = 4;
+               out->length = 5;
        } else {
                return -1;
        }
diff --git a/source4/dsdb/repl/replicated_objects.c 
b/source4/dsdb/repl/replicated_objects.c
index d11de92..f8c1517 100644
--- a/source4/dsdb/repl/replicated_objects.c
+++ b/source4/dsdb/repl/replicated_objects.c
@@ -122,8 +122,8 @@ WERROR dsdb_repl_make_working_schema(struct ldb_context 
*ldb,
                                                      ignore_attids,
                                                      tmp_ctx, &object);
                        if (!W_ERROR_IS_OK(werr)) {
-                               DEBUG(1,("Warning: Failed to convert schema 
object %s into ldb msg\n",
-                                        cur->object.identifier->dn));
+                               DEBUG(4,("debug: Failed to convert schema 
object %s into ldb msg, will try during next loop\n",
+                                         cur->object.identifier->dn));
 
                                failed_obj_count++;
                        } else {
@@ -136,7 +136,7 @@ WERROR dsdb_repl_make_working_schema(struct ldb_context 
*ldb,
                                                                       
working_schema,
                                                                       
object.msg);
                                if (!W_ERROR_IS_OK(werr)) {
-                                       DEBUG(1,("Warning: failed to convert 
object %s into a schema element: %s\n",
+                                       DEBUG(4,("debug: failed to convert 
object %s into a schema element, will try during next loop: %s\n",
                                                 
ldb_dn_get_linearized(object.msg->dn),
                                                 win_errstr(werr)));
                                        failed_obj_count++;
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_in.c 
b/source4/dsdb/samdb/ldb_modules/extended_dn_in.c
index 76a9518..760dd64 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn_in.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn_in.c
@@ -343,6 +343,11 @@ static int extended_dn_filter_callback(struct 
ldb_parse_tree *tree, void *privat
 
        filter_ctx = talloc_get_type_abort(private_context, struct 
extended_dn_filter_ctx);
 
+       if (filter_ctx->test_only && filter_ctx->matched) {
+               /* the tree already matched */
+               return LDB_SUCCESS;
+       }
+
        attribute = dsdb_attribute_by_lDAPDisplayName(filter_ctx->schema, 
tree->u.equality.attr);
        if (attribute == NULL) {
                return LDB_SUCCESS;
@@ -366,7 +371,19 @@ static int extended_dn_filter_callback(struct 
ldb_parse_tree *tree, void *privat
                return LDB_SUCCESS;
        }
 
+       guid_val = ldb_dn_get_extended_component(dn, "GUID");
+       sid_val  = ldb_dn_get_extended_component(dn, "SID");
+
+       if (!guid_val && !sid_val && (attribute->searchFlags & 
SEARCH_FLAG_ATTINDEX)) {
+               /* if it is indexed, then fixing the string DN will do
+                  no good here, as we will not find the attribute in
+                  the index. So for now fall through to a standard DN
+                  component comparison */
+               return LDB_SUCCESS;
+       }
+
        if (filter_ctx->test_only) {
+               /* we need to copy the tree */
                filter_ctx->matched = true;
                return LDB_SUCCESS;
        }
@@ -378,9 +395,6 @@ static int extended_dn_filter_callback(struct 
ldb_parse_tree *tree, void *privat
                return LDB_SUCCESS;
        }
 
-       guid_val = ldb_dn_get_extended_component(dn, "GUID");
-       sid_val  = ldb_dn_get_extended_component(dn, "SID");
-
        if (guid_val) {
                expression = talloc_asprintf(filter_ctx, "objectGUID=%s", 
ldb_binary_encode(filter_ctx, *guid_val));
                scope = LDB_SCOPE_SUBTREE;
@@ -389,12 +403,6 @@ static int extended_dn_filter_callback(struct 
ldb_parse_tree *tree, void *privat
                expression = talloc_asprintf(filter_ctx, "objectSID=%s", 
ldb_binary_encode(filter_ctx, *sid_val));
                scope = LDB_SCOPE_SUBTREE;
                base_dn = NULL;
-       } else if (attribute->searchFlags & SEARCH_FLAG_ATTINDEX) {
-               /* if it is indexed, then fixing the string DN will do
-                  no good here, as we will not find the attribute in
-                  the index. So for now fall through to a standard DN
-                  component comparison */
-               return LDB_SUCCESS;
        } else {
                /* fallback to searching using the string DN as the base DN */
                expression = "objectClass=*";
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c 
b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
index 3333a37..0f37bbe 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
@@ -76,7 +76,7 @@ static int extended_dn_out_dereference_setup_control(struct 
ldb_context *ldb, st
        }
 
        for (cur = schema->attributes; cur; cur = cur->next) {
-               if (dsdb_dn_oid_to_format(cur->syntax->ldap_oid) != 
DSDB_NORMAL_DN) {
+               if (cur->dn_format != DSDB_NORMAL_DN) {
                        continue;
                }
                dereference_control->dereference
@@ -508,7 +508,7 @@ static int extended_callback(struct ldb_request *req, 
struct ldb_reply *ares,
                }
 
                /* Look to see if this attributeSyntax is a DN */
-               if (dsdb_dn_oid_to_format(attribute->syntax->ldap_oid) == 
DSDB_INVALID_DN) {
+               if (attribute->dn_format == DSDB_INVALID_DN) {
                        continue;
                }
 
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_store.c 
b/source4/dsdb/samdb/ldb_modules/extended_dn_store.c
index c423520..57dc883 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn_store.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn_store.c
@@ -325,7 +325,7 @@ static int extended_dn_add(struct ldb_module *module, 
struct ldb_request *req)
                }
 
                /* We only setup an extended DN GUID on DN elements */
-               if (dsdb_dn_oid_to_format(schema_attr->syntax->ldap_oid) == 
DSDB_INVALID_DN) {
+               if (schema_attr->dn_format == DSDB_INVALID_DN) {
                        continue;
                }
 
@@ -400,7 +400,7 @@ static int extended_dn_modify(struct ldb_module *module, 
struct ldb_request *req
                }
 
                /* We only setup an extended DN GUID on these particular DN 
objects */
-               if (dsdb_dn_oid_to_format(schema_attr->syntax->ldap_oid) == 
DSDB_INVALID_DN) {
+               if (schema_attr->dn_format == DSDB_INVALID_DN) {
                        continue;
                }
 
diff --git a/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c 
b/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
index 4525cf3..9893ada 100644
--- a/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
+++ b/source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
@@ -88,6 +88,45 @@ static int oc_validate_dsheuristics(struct 
ldb_message_element *el)
        return LDB_SUCCESS;
 }
 
+/*
+  auto normalise values on input
+ */
+static int oc_auto_normalise(struct ldb_context *ldb, const struct 
dsdb_attribute *attr,
+                            struct ldb_message *msg, struct 
ldb_message_element *el)
+{
+       int i;
+       bool values_copied = false;
+
+       for (i=0; i<el->num_values; i++) {
+               struct ldb_val v;
+               int ret;
+               ret = attr->ldb_schema_attribute->syntax->canonicalise_fn(ldb, 
el->values, &el->values[i], &v);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+               if (data_blob_cmp(&v, &el->values[i]) == 0) {
+                       /* no need to replace it */
+                       talloc_free(v.data);
+                       continue;
+               }
+
+               /* we need to copy the values array on the first change */
+               if (!values_copied) {
+                       struct ldb_val *v2;
+                       v2 = talloc_array(msg->elements, struct ldb_val, 
el->num_values);
+                       if (v2 == NULL) {
+                               return ldb_oom(ldb);
+                       }
+                       memcpy(v2, el->values, sizeof(struct ldb_val) * 
el->num_values);
+                       el->values = v2;
+                       values_copied = true;
+               }
+
+               el->values[i] = v;
+       }
+       return LDB_SUCCESS;
+}
+
 static int attr_handler(struct oc_context *ac)
 {
        struct ldb_context *ldb;
@@ -174,6 +213,14 @@ static int attr_handler(struct oc_context *ac)
                        }
                }
 
+               /* auto normalise some attribute values */
+               if (attr->syntax->auto_normalise) {
+                       ret = oc_auto_normalise(ldb, attr, msg, 
&msg->elements[i]);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+
                /* Substitute the attribute name to match in case */
                msg->elements[i].name = attr->lDAPDisplayName;
        }
diff --git a/source4/dsdb/samdb/ldb_modules/ridalloc.c 
b/source4/dsdb/samdb/ldb_modules/ridalloc.c
index 28fade1..ed87f86 100644
--- a/source4/dsdb/samdb/ldb_modules/ridalloc.c
+++ b/source4/dsdb/samdb/ldb_modules/ridalloc.c
@@ -263,6 +263,8 @@ static int ridalloc_create_rid_set_ntds(struct ldb_module 
*module, TALLOC_CTX *m
                .next_rid       = 0,
                .used_pool      = 0,
        };
+       const char *no_attrs[] = { NULL };
+       struct ldb_result *res;
 
        /*
          steps:
@@ -339,7 +341,21 @@ static int ridalloc_create_rid_set_ntds(struct ldb_module 
*module, TALLOC_CTX *m
        msg = ldb_msg_new(tmp_ctx);
        msg->dn = machine_dn;
 
-       ret = ldb_msg_add_string(msg, "rIDSetReferences", 
ldb_dn_get_linearized(rid_set_dn));
+       /* we need the extended DN of the RID Set object for
+        * rIDSetReferences */
+       ret = dsdb_module_search_dn(module, msg, &res, rid_set_dn, no_attrs,
+                                   DSDB_FLAG_NEXT_MODULE | 
DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT, parent);
+       if (ret != LDB_SUCCESS) {
+               ldb_asprintf_errstring(ldb, "Failed to find extended DN of RID 
Set %s - %s",
+                                      ldb_dn_get_linearized(msg->dn),
+                                      ldb_errstring(ldb));
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+       rid_set_dn = res->msgs[0]->dn;
+
+
+       ret = ldb_msg_add_string(msg, "rIDSetReferences", 
ldb_dn_get_extended_linearized(msg, rid_set_dn, 1));
        if (ret != LDB_SUCCESS) {
                talloc_free(tmp_ctx);
                return ret;
diff --git a/source4/dsdb/samdb/ldb_modules/util.c 
b/source4/dsdb/samdb/ldb_modules/util.c
index ebb214d..dfb8600 100644
--- a/source4/dsdb/samdb/ldb_modules/util.c
+++ b/source4/dsdb/samdb/ldb_modules/util.c
@@ -751,7 +751,7 @@ int dsdb_module_reference_dn(struct ldb_module *module, 
TALLOC_CTX *mem_ctx, str
        attrs[1] = NULL;
 
        ret = dsdb_module_search_dn(module, mem_ctx, &res, base, attrs,
-                                   DSDB_FLAG_NEXT_MODULE, parent);
+                                   DSDB_FLAG_NEXT_MODULE | 
DSDB_SEARCH_SHOW_EXTENDED_DN, parent);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h
index 13cc31c..58cf82b 100644
--- a/source4/dsdb/schema/schema.h
+++ b/source4/dsdb/schema/schema.h
@@ -73,6 +73,7 @@ struct dsdb_syntax {
        WERROR (*validate_ldb)(const struct dsdb_syntax_ctx *ctx,
                               const struct dsdb_attribute *attr,
                               const struct ldb_message_element *in);
+       bool auto_normalise;
 };
 
 struct dsdb_attribute {
diff --git a/source4/dsdb/schema/schema_inferiors.c 
b/source4/dsdb/schema/schema_inferiors.c
index fe45641..d2c134e 100644
--- a/source4/dsdb/schema/schema_inferiors.c
+++ b/source4/dsdb/schema/schema_inferiors.c
@@ -328,7 +328,6 @@ int schema_fill_constructed(const struct dsdb_schema 
*schema)
 {
        int ret;
        struct dsdb_class *schema_class;
-       struct dsdb_attribute *attribute;
 
        schema_fill_from_ids(schema);
 
@@ -354,35 +353,5 @@ int schema_fill_constructed(const struct dsdb_schema 
*schema)
                schema_class->posssuperiors = NULL;
        }
 
-       /* setup fast access to one_way_link and DN format */
-       for (attribute=schema->attributes; attribute; 
attribute=attribute->next) {
-               attribute->dn_format = 
dsdb_dn_oid_to_format(attribute->syntax->ldap_oid);
-
-               if (attribute->dn_format == DSDB_INVALID_DN) {
-                       attribute->one_way_link = false;
-                       continue;
-               }
-
-               /* these are not considered to be one way links for
-                  the purpose of DN link fixups */
-               if (ldb_attr_cmp("distinguishedName", 
attribute->lDAPDisplayName) == 0 ||
-                   ldb_attr_cmp("objectCategory", attribute->lDAPDisplayName) 
== 0) {
-                       attribute->one_way_link = false;
-                       continue;
-               }
-
-               if (attribute->linkID == 0) {
-                       attribute->one_way_link = true;
-                       continue;
-               }
-               /* handle attributes with a linkID but no backlink */
-               if (dsdb_attribute_by_linkID(schema, attribute->linkID) == 
NULL) {
-                       attribute->one_way_link = true;
-                       continue;
-               }
-               attribute->one_way_link = false;
-       }
-
-
        return LDB_SUCCESS;
 }
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c
index 9dee0a4..8cb06bb 100644
--- a/source4/dsdb/schema/schema_set.c
+++ b/source4/dsdb/schema/schema_set.c
@@ -30,6 +30,11 @@
 #include "librpc/gen_ndr/ndr_misc.h"
 #include "lib/util/tsort.h"
 
+/* change this when we change something in our schema code that
+ * requires a re-index of the database
+ */
+#define SAMDB_INDEXING_VERSION "2"
+
 /*
   override the name to attribute handler function
  */
@@ -95,6 +100,12 @@ static int dsdb_schema_set_attributes(struct ldb_context 
*ldb, struct dsdb_schem
                goto op_error;
        }
 
+
+       ret = ldb_msg_add_string(msg_idx, "@IDXVERSION", 
SAMDB_INDEXING_VERSION);
+       if (ret != LDB_SUCCESS) {
+               goto op_error;
+       }
+
        for (attr = schema->attributes; attr; attr = attr->next) {
                const char *syntax = attr->syntax->ldb_syntax;
 
@@ -200,6 +211,44 @@ op_error:
        return ldb_operr(ldb);
 }
 
+
+/*
+  create extra attribute shortcuts
+ */
+static void dsdb_setup_attribute_shortcuts(struct ldb_context *ldb, struct 
dsdb_schema *schema)
+{
+       struct dsdb_attribute *attribute;
+
+       /* setup fast access to one_way_link and DN format */
+       for (attribute=schema->attributes; attribute; 
attribute=attribute->next) {
+               attribute->dn_format = 
dsdb_dn_oid_to_format(attribute->syntax->ldap_oid);
+
+               if (attribute->dn_format == DSDB_INVALID_DN) {
+                       attribute->one_way_link = false;
+                       continue;
+               }
+
+               /* these are not considered to be one way links for
+                  the purpose of DN link fixups */
+               if (ldb_attr_cmp("distinguishedName", 
attribute->lDAPDisplayName) == 0 ||
+                   ldb_attr_cmp("objectCategory", attribute->lDAPDisplayName) 
== 0) {
+                       attribute->one_way_link = false;
+                       continue;
+               }
+
+               if (attribute->linkID == 0) {
+                       attribute->one_way_link = true;
+                       continue;
+               }
+               /* handle attributes with a linkID but no backlink */
+               if (dsdb_attribute_by_linkID(schema, attribute->linkID) == 
NULL) {
+                       attribute->one_way_link = true;
+                       continue;
+               }
+               attribute->one_way_link = false;
+       }
+}
+
 static int uint32_cmp(uint32_t c1, uint32_t c2)
 {
        if (c1 == c2) return 0;
@@ -272,6 +321,7 @@ int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
        struct dsdb_attribute *a;
        unsigned int i;
        unsigned int num_int_id;
+       int ret;
 
        /* free all caches */
        dsdb_sorted_accessors_free(schema);
@@ -354,6 +404,14 @@ int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
        TYPESAFE_QSORT(schema->attributes_by_attributeID_oid, 
schema->num_attributes, dsdb_compare_attribute_by_attributeID_oid);
        TYPESAFE_QSORT(schema->attributes_by_linkID, schema->num_attributes, 
dsdb_compare_attribute_by_linkID);
 
+       dsdb_setup_attribute_shortcuts(ldb, schema);
+
+       ret = schema_fill_constructed(schema);
+       if (ret != LDB_SUCCESS) {
+               dsdb_sorted_accessors_free(schema);
+               return ret;
+       }
+
        return LDB_SUCCESS;
 
 failed:
@@ -361,24 +419,6 @@ failed:
        return ldb_oom(ldb);
 }
 
-int dsdb_setup_schema_inversion(struct ldb_context *ldb, struct dsdb_schema 
*schema)
-{
-       /* Walk the list of schema classes */
-
-       /*  For each subClassOf, add us to subclasses of the parent */
-
-       /* collect these subclasses into a recursive list of total subclasses, 
preserving order */
-
-       /* For each subclass under 'top', write the index from it's
-        * order as an integer in the dsdb_class (for sorting
-        * objectClass lists efficiently) */
-
-       /* Walk the list of schema classes */
-
-       /*  Create a 'total possible superiors' on each class */
-       return LDB_SUCCESS;
-}
-
 /**
  * Attach the schema to an opaque pointer on the ldb,
  * so ldb modules can find it
@@ -393,11 +433,6 @@ int dsdb_set_schema(struct ldb_context *ldb, struct 
dsdb_schema *schema)
                return ret;
        }
 
-       ret = schema_fill_constructed(schema);
-       if (ret != LDB_SUCCESS) {
-               return ret;
-       }
-
        old_schema = ldb_get_opaque(ldb, "dsdb_schema");
 
        ret = ldb_set_opaque(ldb, "dsdb_schema", schema);
diff --git a/source4/dsdb/schema/schema_syntax.c 
b/source4/dsdb/schema/schema_syntax.c
index d443c00..e875bee 100644
--- a/source4/dsdb/schema/schema_syntax.c
+++ b/source4/dsdb/schema/schema_syntax.c
@@ -229,9 +229,11 @@ static WERROR dsdb_syntax_BOOL_ldb_to_drsuapi(const struct 
dsdb_syntax_ctx *ctx,
                blobs[i] = data_blob_talloc(blobs, NULL, 4);
                W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
 
-               if (strcmp("TRUE", (const char *)in->values[i].data) == 0) {
+               if (in->values[i].length >= 4 &&
+                   strncmp("TRUE", (const char *)in->values[i].data, 
in->values[i].length) == 0) {
                        SIVAL(blobs[i].data, 0, 0x00000001);
-               } else if (strcmp("FALSE", (const char *)in->values[i].data) == 
0) {
+               } else if (in->values[i].length >= 5 &&
+                          strncmp("FALSE", (const char *)in->values[i].data, 
in->values[i].length) == 0) {
                        SIVAL(blobs[i].data, 0, 0x00000000);
                } else {
                        return WERR_FOOBAR;
@@ -252,22 +254,23 @@ static WERROR dsdb_syntax_BOOL_validate_ldb(const struct 
dsdb_syntax_ctx *ctx,
        }
 
        for (i=0; i < in->num_values; i++) {
-               int t, f;
-
                if (in->values[i].length == 0) {
                        return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
                }
 
-               t = strncmp("TRUE",
+               if (in->values[i].length >= 4 &&
+                   strncmp("TRUE",
                            (const char *)in->values[i].data,
-                           in->values[i].length);
-               f = strncmp("FALSE",
+                           in->values[i].length) == 0) {
+                       continue;
+               }
+               if (in->values[i].length >= 5 &&
+                   strncmp("FALSE",
                            (const char *)in->values[i].data,
-                           in->values[i].length);
-
-               if (t != 0 && f != 0) {
-                       return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
+                           in->values[i].length) == 0) {


-- 
Samba Shared Repository

Reply via email to