The branch, master has been updated
       via  9e9887d s4:samdb:rootdse: implement the schemaUpgradeInProgress 
operation in ldap modify
       via  c5934d9 s4-schema: set subClassOf by default to top if not specified
       via  9887d39 s4-schema: remove unused variable
       via  e3fa5d7 s4-schema: Generate some schema related attribute as MS AD 
is doing if they are not present in ldb requests
       via  167c6eb s4-schema: rename dsdb_attribute_from_ldb to 
dsdb_set_attribute_from_ldb  and dsdb_class_from_ldb to dsdb_set_class_from_ldb
       via  6ccaf27 s4: use enums instead of strings it's cheaper
      from  e49efe9 Fix typo

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


- Log -----------------------------------------------------------------
commit 9e9887d3232b335b5494f2d536a1fa8a625de86c
Author: Michael Adam <[email protected]>
Date:   Fri Apr 6 02:20:37 2012 +0200

    s4:samdb:rootdse: implement the schemaUpgradeInProgress operation in ldap 
modify
    
    This is preliminary in that it is implemented as a no-op for a start
    just to be able to successfully answer the request, which seems to be
    sufficient in order to e.g. survive the exchange schema extensions.
    
    Signed-off-by: Matthieu Patou <[email protected]>
    
    Autobuild-User: Michael Adam <[email protected]>
    Autobuild-Date: Wed Apr 18 02:48:28 CEST 2012 on sn-devel-104

commit c5934d9a1cbf0ff8c2e4740f4cd2546e6e89731c
Author: Matthieu Patou <[email protected]>
Date:   Mon Apr 16 23:24:10 2012 -0700

    s4-schema: set subClassOf by default to top if not specified
    
    Signed-off-by: Michael Adam <[email protected]>

commit 9887d390b17e60c8ac4d267b47a998a27522f6dd
Author: Matthieu Patou <[email protected]>
Date:   Mon Apr 16 15:34:24 2012 -0700

    s4-schema: remove unused variable

commit e3fa5d7d2ad8b7c6248a8df4a0841bf974a6b5a1
Author: Matthieu Patou <[email protected]>
Date:   Mon Apr 16 15:22:24 2012 -0700

    s4-schema: Generate some schema related attribute as MS AD is doing if they 
are not present in ldb requests

commit 167c6eb61ee6211a63ffd98f9b86fa300472ea96
Author: Matthieu Patou <[email protected]>
Date:   Sun Apr 15 14:50:20 2012 -0700

    s4-schema: rename dsdb_attribute_from_ldb to dsdb_set_attribute_from_ldb  
and dsdb_class_from_ldb to dsdb_set_class_from_ldb

commit 6ccaf279da949e945a09e90d3be8ec5b74128369
Author: Matthieu Patou <[email protected]>
Date:   Sun Apr 15 12:37:00 2012 -0700

    s4: use enums instead of strings it's cheaper

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

Summary of changes:
 source4/dsdb/samdb/ldb_modules/rootdse.c     |   33 ++++++++
 source4/dsdb/samdb/ldb_modules/samldb.c      |  103 ++++++++++++++++++++++----
 source4/dsdb/samdb/ldb_modules/schema_load.c |    4 -
 source4/dsdb/samdb/samdb.h                   |    2 +
 source4/dsdb/schema/schema_init.c            |   35 +++++++--
 source4/dsdb/schema/schema_set.c             |    4 +-
 source4/dsdb/schema/tests/schema_syntax.c    |    4 +-
 source4/libcli/ldap/ldap_controls.c          |    1 +
 source4/setup/schema_samba4.ldif             |    1 +
 source4/torture/ldap/schema.c                |    4 +-
 10 files changed, 160 insertions(+), 31 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/samdb/ldb_modules/rootdse.c 
b/source4/dsdb/samdb/ldb_modules/rootdse.c
index 46dbb75..f7c9896 100644
--- a/source4/dsdb/samdb/ldb_modules/rootdse.c
+++ b/source4/dsdb/samdb/ldb_modules/rootdse.c
@@ -1209,6 +1209,36 @@ static int rootdse_schemaupdatenow(struct ldb_module 
*module, struct ldb_request
        return ldb_module_done(req, NULL, NULL, ret);
 }
 
+static int rootdse_schemaupgradeinprogress(struct ldb_module *module, struct 
ldb_request *req)
+{
+       struct ldb_context *ldb = ldb_module_get_ctx(module);
+       struct ldb_result *ext_res;
+       int ret = LDB_SUCCESS;
+       struct ldb_dn *schema_dn;
+
+       schema_dn = ldb_get_schema_basedn(ldb);
+       if (!schema_dn) {
+               ldb_reset_err_string(ldb);
+               ldb_debug(ldb, LDB_DEBUG_WARNING,
+                         "rootdse_modify: no schema dn present: (skip 
ldb_extended call)\n");
+               return ldb_next_request(module, req);
+       }
+
+       /* FIXME we have to do something in order to relax constraints for DRS
+        * setting schemaUpgradeInProgress cause the fschemaUpgradeInProgress
+        * in all LDAP connection (2K3/2K3R2) or in the current connection (2K8 
and +)
+        * to be set to true.
+        */
+
+       /* from 5.113 LDAPConnections in DRSR.pdf
+        * fschemaUpgradeInProgress: A Boolean that specifies certain constraint
+        * validations are skipped when adding, updating, or removing directory
+        * objects on the opened connection. The skipped constraint validations
+        * are documented in the applicable constraint sections in [MS-ADTS].
+        */
+       return ldb_module_done(req, NULL, NULL, ret);
+}
+
 static int rootdse_add(struct ldb_module *module, struct ldb_request *req)
 {
        struct ldb_context *ldb = ldb_module_get_ctx(module);
@@ -1378,6 +1408,9 @@ static int rootdse_modify(struct ldb_module *module, 
struct ldb_request *req)
        if (ldb_msg_find_element(req->op.mod.message, "enableOptionalFeature")) 
{
                return rootdse_enableoptionalfeature(module, req);
        }
+       if (ldb_msg_find_element(req->op.mod.message, 
"schemaUpgradeInProgress")) {
+               return rootdse_schemaupgradeinprogress(module, req);
+       }
 
        ldb_set_errstring(ldb, "rootdse_modify: unknown attribute to change!");
        return LDB_ERR_UNWILLING_TO_PERFORM;
diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c 
b/source4/dsdb/samdb/ldb_modules/samldb.c
index d8f68c8..79ab1f8 100644
--- a/source4/dsdb/samdb/ldb_modules/samldb.c
+++ b/source4/dsdb/samdb/ldb_modules/samldb.c
@@ -42,6 +42,12 @@
 #include "libds/common/flag_mapping.h"
 
 struct samldb_ctx;
+enum samldb_add_type {
+       SAMLDB_TYPE_USER,
+       SAMLDB_TYPE_GROUP,
+       SAMLDB_TYPE_CLASS,
+       SAMLDB_TYPE_ATTRIBUTE
+};
 
 typedef int (*samldb_step_fn_t)(struct samldb_ctx *);
 
@@ -55,7 +61,7 @@ struct samldb_ctx {
        struct ldb_request *req;
 
        /* used for add operations */
-       const char *type;
+       enum samldb_add_type type;
 
        /* the resulting message */
        struct ldb_message *msg;
@@ -581,7 +587,8 @@ static int samldb_fill_object(struct samldb_ctx *ac)
        int ret;
 
        /* Add information for the different account types */
-       if (strcmp(ac->type, "user") == 0) {
+       switch(ac->type) {
+       case SAMLDB_TYPE_USER: {
                struct ldb_control *rodc_control = 
ldb_request_get_control(ac->req,
                                                                           
LDB_CONTROL_RODC_DCPROMO_OID);
                if (rodc_control != NULL) {
@@ -597,17 +604,28 @@ static int samldb_fill_object(struct samldb_ctx *ac)
 
                ret = samldb_add_step(ac, samldb_add_entry);
                if (ret != LDB_SUCCESS) return ret;
+               break;
+       }
 
-       } else if (strcmp(ac->type, "group") == 0) {
+       case SAMLDB_TYPE_GROUP: {
                /* check if we have a valid sAMAccountName */
                ret = samldb_add_step(ac, samldb_check_sAMAccountName);
                if (ret != LDB_SUCCESS) return ret;
 
                ret = samldb_add_step(ac, samldb_add_entry);
                if (ret != LDB_SUCCESS) return ret;
+               break;
+       }
 
-       } else if (strcmp(ac->type, "classSchema") == 0) {
+       case SAMLDB_TYPE_CLASS: {
                const struct ldb_val *rdn_value, *def_obj_cat_val;
+               unsigned int v = ldb_msg_find_attr_as_uint(ac->msg, 
"objectClassCategory", -2);
+
+               /* As discussed with Microsoft through dochelp in April 2012 
this is the behavior of windows*/
+               if (!ldb_msg_find_element(ac->msg, "subClassOf")) {
+                       ret = ldb_msg_add_string(ac->msg, "subClassOf", "top");
+                       if (ret != LDB_SUCCESS) return ret;
+               }
 
                ret = samdb_find_or_add_attribute(ldb, ac->msg,
                                                  "rdnAttId", "cn");
@@ -685,8 +703,20 @@ static int samldb_fill_object(struct samldb_ctx *ac)
                ret = samldb_add_step(ac, 
samldb_find_for_defaultObjectCategory);
                if (ret != LDB_SUCCESS) return ret;
 
-       } else if (strcmp(ac->type, "attributeSchema") == 0) {
+               /* -2 is not a valid objectClassCategory so it means the 
attribute wasn't present */
+               if (v == -2) {
+                       /* Windows 2003 does this*/
+                       ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg, 
"objectClassCategory", 0);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+               break;
+       }
+
+       case SAMLDB_TYPE_ATTRIBUTE: {
                const struct ldb_val *rdn_value;
+               struct ldb_message_element *el;
                rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
                if (rdn_value == NULL) {
                        return ldb_operr(ldb);
@@ -726,17 +756,51 @@ static int samldb_fill_object(struct samldb_ctx *ac)
                        }
                }
 
+               el = ldb_msg_find_element(ac->msg, "attributeSyntax");
+               if (el) {
+                       /*
+                        * No need to scream if there isn't as we have code 
later on
+                        * that will take care of it.
+                        */
+                       const struct dsdb_syntax *syntax = 
find_syntax_map_by_ad_oid((const char *)el->values[0].data);
+                       if (!syntax) {
+                               DEBUG(9, ("Can't find dsdb_syntax object for 
attributeSyntax %s\n",
+                                               (const char 
*)el->values[0].data));
+                       } else {
+                               unsigned int v = 
ldb_msg_find_attr_as_uint(ac->msg, "oMSyntax", 0);
+                               const struct ldb_val *val = 
ldb_msg_find_ldb_val(ac->msg, "oMObjectClass");
+
+                               if (v == 0) {
+                                       ret = samdb_msg_add_uint(ldb, ac->msg, 
ac->msg, "oMSyntax", syntax->oMSyntax);
+                                       if (ret != LDB_SUCCESS) {
+                                               return ret;
+                                       }
+                               }
+                               if (!val) {
+                                       struct ldb_val val2 = ldb_val_dup(ldb, 
&syntax->oMObjectClass);
+                                       if (val2.length > 0) {
+                                               ret = 
ldb_msg_add_value(ac->msg, "oMObjectClass", &val2, NULL);
+                                               if (ret != LDB_SUCCESS) {
+                                                       return ret;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
                /* handle msDS-IntID attribute */
                ret = samldb_add_handle_msDS_IntId(ac);
                if (ret != LDB_SUCCESS) return ret;
 
                ret = samldb_add_step(ac, samldb_add_entry);
                if (ret != LDB_SUCCESS) return ret;
+               break;
+       }
 
-       } else {
-               ldb_asprintf_errstring(ldb,
-                       "Invalid entry type!");
+       default:
+               ldb_asprintf_errstring(ldb, "Invalid entry type!");
                return LDB_ERR_OPERATIONS_ERROR;
+               break;
        }
 
        return samldb_first_step(ac);
@@ -862,7 +926,8 @@ static int samldb_objectclass_trigger(struct samldb_ctx *ac)
                if (ret != LDB_SUCCESS) return ret;
        }
 
-       if (strcmp(ac->type, "user") == 0) {
+       switch(ac->type) {
+       case SAMLDB_TYPE_USER: {
                bool uac_generated = false;
 
                /* Step 1.2: Default values */
@@ -1008,8 +1073,10 @@ static int samldb_objectclass_trigger(struct samldb_ctx 
*ac)
                                }
                        }
                }
+               break;
+       }
 
-       } else if (strcmp(ac->type, "group") == 0) {
+       case SAMLDB_TYPE_GROUP: {
                const char *tempstr;
 
                /* Step 2.2: Default values */
@@ -1051,6 +1118,14 @@ static int samldb_objectclass_trigger(struct samldb_ctx 
*ac)
                        el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
                        el2->flags = LDB_FLAG_MOD_REPLACE;
                }
+               break;
+       }
+
+       default:
+               ldb_asprintf_errstring(ldb,
+                               "Invalid entry type!");
+               return LDB_ERR_OPERATIONS_ERROR;
+               break;
        }
 
        return LDB_SUCCESS;
@@ -1967,7 +2042,7 @@ static int samldb_add(struct ldb_module *module, struct 
ldb_request *req)
 
        if (samdb_find_attribute(ldb, ac->msg,
                                 "objectclass", "user") != NULL) {
-               ac->type = "user";
+               ac->type = SAMLDB_TYPE_USER;
 
                ret = samldb_prim_group_trigger(ac);
                if (ret != LDB_SUCCESS) {
@@ -1984,7 +2059,7 @@ static int samldb_add(struct ldb_module *module, struct 
ldb_request *req)
 
        if (samdb_find_attribute(ldb, ac->msg,
                                 "objectclass", "group") != NULL) {
-               ac->type = "group";
+               ac->type = SAMLDB_TYPE_GROUP;
 
                ret = samldb_objectclass_trigger(ac);
                if (ret != LDB_SUCCESS) {
@@ -2009,7 +2084,7 @@ static int samldb_add(struct ldb_module *module, struct 
ldb_request *req)
                        return ret;
                }
 
-               ac->type = "classSchema";
+               ac->type = SAMLDB_TYPE_CLASS;
                return samldb_fill_object(ac);
        }
 
@@ -2021,7 +2096,7 @@ static int samldb_add(struct ldb_module *module, struct 
ldb_request *req)
                        return ret;
                }
 
-               ac->type = "attributeSchema";
+               ac->type = SAMLDB_TYPE_ATTRIBUTE;
                return samldb_fill_object(ac);
        }
 
diff --git a/source4/dsdb/samdb/ldb_modules/schema_load.c 
b/source4/dsdb/samdb/ldb_modules/schema_load.c
index ec574b3..4c166d5 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_load.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_load.c
@@ -324,10 +324,6 @@ static int schema_load_del_transaction(struct ldb_module 
*module)
 
 static int schema_load_extended(struct ldb_module *module, struct ldb_request 
*req)
 {
-       struct ldb_context *ldb;
-
-       ldb = ldb_module_get_ctx(module);
-
        if (strcmp(req->op.extended.oid, DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID) 
!= 0) {
                return ldb_next_request(module, req);
        }
diff --git a/source4/dsdb/samdb/samdb.h b/source4/dsdb/samdb/samdb.h
index ae6042c..50f7bf7 100644
--- a/source4/dsdb/samdb/samdb.h
+++ b/source4/dsdb/samdb/samdb.h
@@ -167,6 +167,8 @@ struct dsdb_create_partition_exop {
  */
 #define DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID "1.3.6.1.4.1.7165.4.4.2"
 
+#define DSDB_EXTENDED_SCHEMA_UPGRADE_IN_PROGRESS_OID "1.3.6.1.4.1.7165.4.4.6"
+
 #define DSDB_OPENLDAP_DEREFERENCE_CONTROL "1.3.6.1.4.1.4203.666.5.16"
 
 struct dsdb_openldap_dereference {
diff --git a/source4/dsdb/schema/schema_init.c 
b/source4/dsdb/schema/schema_init.c
index 9307050..2db708d 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/dsdb/schema/schema_init.c
@@ -614,14 +614,17 @@ static int dsdb_schema_setup_ldb_schema_attribute(struct 
ldb_context *ldb,
        }\
 } while (0)
 
-WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
-                              struct dsdb_schema *schema,
-                              struct ldb_message *msg)
+/** Create an dsdb_attribute out of ldb message, attr must be already talloced
+ */
+
+WERROR dsdb_attribute_from_ldb(const struct dsdb_schema *schema,
+                              struct ldb_message *msg,
+                              struct dsdb_attribute *attr)
 {
        WERROR status;
-       struct dsdb_attribute *attr = talloc_zero(schema, struct 
dsdb_attribute);
-       if (!attr) {
-               return WERR_NOMEM;
+       if (attr == NULL) {
+               DEBUG(0, ("%s: attr is null, it's expected not to be so\n", 
__location__));
+               return WERR_INVALID_PARAM;
        }
 
        GET_STRING_LDB(msg, "cn", attr, attr, cn, false);
@@ -690,6 +693,24 @@ WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
        GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
        GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
 
+       return WERR_OK;
+}
+
+WERROR dsdb_set_attribute_from_ldb(struct ldb_context *ldb,
+                              struct dsdb_schema *schema,
+                              struct ldb_message *msg)
+{
+       WERROR status;
+       struct dsdb_attribute *attr = talloc_zero(schema, struct 
dsdb_attribute);
+       if (!attr) {
+               return WERR_NOMEM;
+       }
+
+       status = dsdb_attribute_from_ldb(schema, msg, attr);
+       if (!W_ERROR_IS_OK(status)) {
+               return status;
+       }
+
        attr->syntax = dsdb_syntax_for_attribute(attr);
        if (!attr->syntax) {
                DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
@@ -709,7 +730,7 @@ WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
        return WERR_OK;
 }
 
-WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
+WERROR dsdb_set_class_from_ldb(struct dsdb_schema *schema,
                           struct ldb_message *msg)
 {
        WERROR status;
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c
index 4142842..8a43610 100644
--- a/source4/dsdb/schema/schema_set.c
+++ b/source4/dsdb/schema/schema_set.c
@@ -667,10 +667,10 @@ WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context 
*ldb, struct dsdb_sche
 {
        if (samdb_find_attribute(ldb, msg,
                                 "objectclass", "attributeSchema") != NULL) {
-               return dsdb_attribute_from_ldb(ldb, schema, msg);
+               return dsdb_set_attribute_from_ldb(ldb, schema, msg);
        } else if (samdb_find_attribute(ldb, msg,
                                 "objectclass", "classSchema") != NULL) {
-               return dsdb_class_from_ldb(schema, msg);
+               return dsdb_set_class_from_ldb(schema, msg);
        }
 
        /* Don't fail on things not classes or attributes */
diff --git a/source4/dsdb/schema/tests/schema_syntax.c 
b/source4/dsdb/schema/tests/schema_syntax.c
index 9127d08..419dc3d 100644
--- a/source4/dsdb/schema/tests/schema_syntax.c
+++ b/source4/dsdb/schema/tests/schema_syntax.c
@@ -74,9 +74,9 @@ static bool torture_syntax_add_OR_Name(struct torture_context 
*tctx,
        ldif = ldb_ldif_read_string(ldb, &ldif_str);
        torture_assert(tctx, ldif, "Failed to parse LDIF for authOrig");
 
-       werr = dsdb_attribute_from_ldb(ldb, schema, ldif->msg);
+       werr = dsdb_set_attribute_from_ldb(ldb, schema, ldif->msg);
        ldb_ldif_read_free(ldb, ldif);
-       torture_assert_werr_ok(tctx, werr, "dsdb_attribute_from_ldb() failed!");
+       torture_assert_werr_ok(tctx, werr, "dsdb_set_attribute_from_ldb() 
failed!");
 
        ldb_res = dsdb_set_schema(ldb, schema);
        torture_assert_int_equal(tctx, ldb_res, LDB_SUCCESS, "dsdb_set_schema() 
failed");
diff --git a/source4/libcli/ldap/ldap_controls.c 
b/source4/libcli/ldap/ldap_controls.c
index 9ee4b26..c8e5623 100644
--- a/source4/libcli/ldap/ldap_controls.c
+++ b/source4/libcli/ldap/ldap_controls.c
@@ -1182,6 +1182,7 @@ static const struct ldap_control_handler 
ldap_known_controls[] = {
        { DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID, NULL, NULL },
        { DSDB_EXTENDED_ALLOCATE_RID_POOL, NULL, NULL },
        { DSDB_CONTROL_NO_GLOBAL_CATALOG, NULL, NULL },
+       { DSDB_EXTENDED_SCHEMA_UPGRADE_IN_PROGRESS_OID, NULL, NULL },
        { NULL, NULL, NULL }
 };
 
diff --git a/source4/setup/schema_samba4.ldif b/source4/setup/schema_samba4.ldif
index 5f4a20a..3d004c5 100644
--- a/source4/setup/schema_samba4.ldif
+++ b/source4/setup/schema_samba4.ldif
@@ -202,6 +202,7 @@
 #Allocated: LDB_EXTENDED_SEQUENCE_NUMBER 1.3.6.1.4.1.7165.4.4.3
 #Allocated: DSDB_EXTENDED_CREATE_PARTITION_OID 1.3.6.1.4.1.7165.4.4.4
 #Allocated: DSDB_EXTENDED_ALLOCATE_RID_POOL 1.3.6.1.4.1.7165.4.4.5
+#Allocated: DSDB_EXTENDED_SCHEMA_UPGRADE_IN_PROGRESS_OID 1.3.6.1.4.1.7165.4.4.6
 
 
 ############
diff --git a/source4/torture/ldap/schema.c b/source4/torture/ldap/schema.c
index af33de9..66284f1 100644
--- a/source4/torture/ldap/schema.c
+++ b/source4/torture/ldap/schema.c
@@ -213,7 +213,7 @@ static int test_add_attribute(void *ptr, struct ldb_context 
*ldb, struct ldb_mes
        struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
        WERROR status;
 
-       status = dsdb_attribute_from_ldb(ldb, schema, msg);
+       status = dsdb_set_attribute_from_ldb(ldb, schema, msg);
        if (!W_ERROR_IS_OK(status)) {
                goto failed;
        }
@@ -228,7 +228,7 @@ static int test_add_class(void *ptr, struct ldb_context 
*ldb, struct ldb_message
        struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
        WERROR status;
 
-       status = dsdb_class_from_ldb(schema, msg);
+       status = dsdb_set_class_from_ldb(schema, msg);
        if (!W_ERROR_IS_OK(status)) {
                goto failed;
        }


-- 
Samba Shared Repository

Reply via email to