The branch, v4-0-test has been updated
       via  9018b85e834de6714a78304ba1c7018838e30a61 (commit)
       via  8538d305c803268c712a90879f29a2a74ba0ef03 (commit)
      from  cd5e48649ce0987952b2b55ea79c3ecceecfafd5 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit 9018b85e834de6714a78304ba1c7018838e30a61
Author: Stefan Metzmacher <[EMAIL PROTECTED]>
Date:   Mon Jun 30 17:17:24 2008 +0200

    schema_fsmo: prepare auto allocation of schema oid prefixes
    
    This implements the logic in the schema_fsmo_add() function,
    but it only calls a dummy dsdb_create_prefix_mapping() yet.
    
    metze

commit 8538d305c803268c712a90879f29a2a74ba0ef03
Author: Stefan Metzmacher <[EMAIL PROTECTED]>
Date:   Tue Jul 1 16:35:13 2008 +0200

    schema_fsmo: move fsmo info into struct dsdb_schema
    
    metze

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

Summary of changes:
 source/dsdb/samdb/ldb_modules/rootdse.c     |    5 +-
 source/dsdb/samdb/ldb_modules/schema_fsmo.c |   90 +++++++++++++++++++-------
 source/dsdb/samdb/samdb.h                   |    5 --
 source/dsdb/schema/schema.h                 |    5 ++
 source/dsdb/schema/schema_init.c            |   29 +++++++++
 5 files changed, 101 insertions(+), 33 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/dsdb/samdb/ldb_modules/rootdse.c 
b/source/dsdb/samdb/ldb_modules/rootdse.c
index 50f333d..75f99a1 100644
--- a/source/dsdb/samdb/ldb_modules/rootdse.c
+++ b/source/dsdb/samdb/ldb_modules/rootdse.c
@@ -164,14 +164,11 @@ static int rootdse_add_dynamic(struct ldb_module *module, 
struct ldb_message *ms
        }
 
        if (do_attribute_explicit(attrs, "validFSMOs")) {
-               const struct dsdb_schema_fsmo *schema_fsmo;
                const struct dsdb_naming_fsmo *naming_fsmo;
                const struct dsdb_pdc_fsmo *pdc_fsmo;
                const char *dn_str;
 
-               schema_fsmo = talloc_get_type(ldb_get_opaque(module->ldb, 
"dsdb_schema_fsmo"),
-                                             struct dsdb_schema_fsmo);
-               if (schema_fsmo && schema_fsmo->we_are_master) {
+               if (schema && schema->fsmo.we_are_master) {
                        dn_str = 
ldb_dn_get_linearized(samdb_schema_dn(module->ldb));
                        if (dn_str && dn_str[0]) {
                                if (ldb_msg_add_fmt(msg, "validFSMOs", "%s", 
dn_str) != 0) {
diff --git a/source/dsdb/samdb/ldb_modules/schema_fsmo.c 
b/source/dsdb/samdb/ldb_modules/schema_fsmo.c
index bc1e60a..0110860 100644
--- a/source/dsdb/samdb/ldb_modules/schema_fsmo.c
+++ b/source/dsdb/samdb/ldb_modules/schema_fsmo.c
@@ -38,7 +38,6 @@ static int schema_fsmo_init(struct ldb_module *module)
        TALLOC_CTX *mem_ctx;
        struct ldb_dn *schema_dn;
        struct dsdb_schema *schema;
-       struct dsdb_schema_fsmo *schema_fsmo;
        struct ldb_result *schema_res;
        const struct ldb_val *prefix_val;
        const struct ldb_val *info_val;
@@ -54,8 +53,6 @@ static int schema_fsmo_init(struct ldb_module *module)
                NULL
        };
 
-       module->private_data = NULL;
-
        if (dsdb_get_schema(module->ldb)) {
                return ldb_next_init(module);
        }
@@ -74,12 +71,6 @@ static int schema_fsmo_init(struct ldb_module *module)
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       schema_fsmo = talloc_zero(mem_ctx, struct dsdb_schema_fsmo);
-       if (!schema_fsmo) {
-               ldb_oom(module->ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
        schema = dsdb_new_schema(mem_ctx, 
lp_iconv_convenience(ldb_get_opaque(module->ldb, "loadparm")));
        if (!schema) {
                ldb_oom(module->ldb);
@@ -225,6 +216,13 @@ static int schema_fsmo_init(struct ldb_module *module)
        }
        talloc_free(c_res);
 
+       schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(module->ldb, schema, 
schema_res->msgs[0], "fSMORoleOwner");
+       if (ldb_dn_compare(samdb_ntds_settings_dn(module->ldb), 
schema->fsmo.master_dn) == 0) {
+               schema->fsmo.we_are_master = true;
+       } else {
+               schema->fsmo.we_are_master = false;
+       }
+
        /* dsdb_set_schema() steal schema into the ldb_context */
        ret = dsdb_set_schema(module->ldb, schema);
        if (ret != LDB_SUCCESS) {
@@ -235,29 +233,73 @@ static int schema_fsmo_init(struct ldb_module *module)
                return ret;
        }
 
-       schema_fsmo->master_dn = ldb_msg_find_attr_as_dn(module->ldb, 
schema_fsmo, schema_res->msgs[0], "fSMORoleOwner");
-       if (ldb_dn_compare(samdb_ntds_settings_dn(module->ldb), 
schema_fsmo->master_dn) == 0) {
-               schema_fsmo->we_are_master = true;
-       } else {
-               schema_fsmo->we_are_master = false;
+       ldb_debug(module->ldb, LDB_DEBUG_TRACE,
+                         "schema_fsmo_init: we are master: %s\n",
+                         (schema->fsmo.we_are_master?"yes":"no"));
+
+       talloc_free(mem_ctx);
+       return ldb_next_init(module);
+}
+
+static int schema_fsmo_add(struct ldb_module *module, struct ldb_request *req)
+{
+       struct dsdb_schema *schema;
+       const char *attributeID = NULL;
+       const char *governsID = NULL;
+       const char *oid_attr = NULL;
+       const char *oid = NULL;
+       uint32_t id32;
+       WERROR status;
+
+       schema = dsdb_get_schema(module->ldb);
+       if (!schema) {
+               return ldb_next_request(module, req);
        }
 
-       if (ldb_set_opaque(module->ldb, "dsdb_schema_fsmo", schema_fsmo) != 
LDB_SUCCESS) {
-               ldb_oom(module->ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+       if (!schema->fsmo.we_are_master) {
+               ldb_debug_set(module->ldb, LDB_DEBUG_ERROR,
+                         "schema_fsmo_add: we are not master: reject 
request\n");
+               return LDB_ERR_UNWILLING_TO_PERFORM;
        }
 
-       module->private_data = talloc_steal(module, schema_fsmo);
+       attributeID = samdb_result_string(req->op.add.message, "attributeID", 
NULL);
+       governsID = samdb_result_string(req->op.add.message, "governsID", NULL);
 
-       ldb_debug(module->ldb, LDB_DEBUG_TRACE,
-                         "schema_fsmo_init: we are master: %s\n",
-                         (schema_fsmo->we_are_master?"yes":"no"));
+       if (attributeID) {
+               oid_attr = "attributeID";
+               oid = attributeID;
+       } else if (governsID) {
+               oid_attr = "governsID";
+               oid = governsID;
+       }
 
-       talloc_free(mem_ctx);
-       return ldb_next_init(module);
+       if (!oid) {
+               return ldb_next_request(module, req);
+       }
+
+       status = dsdb_map_oid2int(schema, oid, &id32);
+       if (W_ERROR_IS_OK(status)) {
+               return ldb_next_request(module, req);
+       } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
+               ldb_debug_set(module->ldb, LDB_DEBUG_ERROR,
+                         "schema_fsmo_add: failed to map %s[%s]: %s\n",
+                         oid_attr, oid, win_errstr(status));
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+
+       status = dsdb_create_prefix_mapping(module->ldb, schema, oid);
+       if (!W_ERROR_IS_OK(status)) {
+               ldb_debug_set(module->ldb, LDB_DEBUG_ERROR,
+                         "schema_fsmo_add: failed to create prefix mapping for 
%s[%s]: %s\n",
+                         oid_attr, oid, win_errstr(status));
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+
+       return ldb_next_request(module, req);
 }
 
 _PUBLIC_ const struct ldb_module_ops ldb_schema_fsmo_module_ops = {
        .name           = "schema_fsmo",
-       .init_context   = schema_fsmo_init
+       .init_context   = schema_fsmo_init,
+       .add            = schema_fsmo_add
 };
diff --git a/source/dsdb/samdb/samdb.h b/source/dsdb/samdb/samdb.h
index 8370857..75aa819 100644
--- a/source/dsdb/samdb/samdb.h
+++ b/source/dsdb/samdb/samdb.h
@@ -80,11 +80,6 @@ struct dsdb_extended_replicated_objects {
        struct dsdb_extended_replicated_object *objects;
 };
 
-struct dsdb_schema_fsmo {
-       bool we_are_master;
-       struct ldb_dn *master_dn;
-};
-
 struct dsdb_naming_fsmo {
        bool we_are_master;
        struct ldb_dn *master_dn;
diff --git a/source/dsdb/schema/schema.h b/source/dsdb/schema/schema.h
index bb34235..6fce354 100644
--- a/source/dsdb/schema/schema.h
+++ b/source/dsdb/schema/schema.h
@@ -150,6 +150,11 @@ struct dsdb_schema {
        struct dsdb_attribute *attributes;
        struct dsdb_class *classes;
 
+       struct {
+               bool we_are_master;
+               struct ldb_dn *master_dn;
+       } fsmo;
+
        struct smb_iconv_convenience *iconv_convenience;
 };
 
diff --git a/source/dsdb/schema/schema_init.c b/source/dsdb/schema/schema_init.c
index c046cb5..9c70e9b 100644
--- a/source/dsdb/schema/schema_init.c
+++ b/source/dsdb/schema/schema_init.c
@@ -334,6 +334,29 @@ WERROR dsdb_map_int2oid(const struct dsdb_schema *schema, 
uint32_t in, TALLOC_CT
        return WERR_DS_NO_MSDS_INTID;
 }
 
+/*
+ * this function is called from within a ldb transaction from the schema_fsmo 
module
+ */
+WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema 
*schema, const char *full_oid)
+{
+       /*
+        * TODO:
+        *      - (maybe) read the old prefixMap attribute and parse it
+        *
+        *      - recheck the prefix doesn't exist (because the ldb
+        *        has maybe a more uptodate value than schem->prefixes
+        *
+        *      - calculate a new mapping for the oid prefix of full_oid
+        *      - store the new prefixMap attribute
+        *
+        *      - (maybe) update schema->prefixes
+        *      or
+        *      - better find a way to indicate a schema reload,
+        *        so that other processes also notice the schema change
+        */
+       return WERR_NOT_SUPPORTED;
+}
+
 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
        (p)->elem = samdb_result_string(msg, attr, NULL);\
        if (strict && (p)->elem == NULL) { \
@@ -1164,6 +1187,12 @@ WERROR dsdb_attach_schema_from_ldif_file(struct 
ldb_context *ldb, const char *pf
 
        schema = dsdb_new_schema(mem_ctx, 
lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")));
 
+       schema->fsmo.we_are_master = true;
+       schema->fsmo.master_dn = ldb_dn_new_fmt(schema, ldb, 
"@PROVISION_SCHEMA_MASTER");
+       if (!schema->fsmo.master_dn) {
+               goto nomem;
+       }
+
        /*
         * load the prefixMap attribute from pf
         */


-- 
Samba Shared Repository

Reply via email to