]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
schema_fsmo: prepare auto allocation of schema oid prefixes
authorStefan Metzmacher <metze@samba.org>
Mon, 30 Jun 2008 15:17:24 +0000 (17:17 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 1 Jul 2008 15:58:47 +0000 (17:58 +0200)
This implements the logic in the schema_fsmo_add() function,
but it only calls a dummy dsdb_create_prefix_mapping() yet.

metze

source/dsdb/samdb/ldb_modules/schema_fsmo.c
source/dsdb/schema/schema_init.c

index 0fcda0a430f19e573e7546de0e1a5c35b7e09b06..01108605ec5b1567267894336c257ce252703276 100644 (file)
@@ -241,7 +241,65 @@ static int schema_fsmo_init(struct ldb_module *module)
        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 (!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;
+       }
+
+       attributeID = samdb_result_string(req->op.add.message, "attributeID", NULL);
+       governsID = samdb_result_string(req->op.add.message, "governsID", NULL);
+
+       if (attributeID) {
+               oid_attr = "attributeID";
+               oid = attributeID;
+       } else if (governsID) {
+               oid_attr = "governsID";
+               oid = governsID;
+       }
+
+       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
 };
index 6f8958dab8f29b2486c53d24758eb5237aa78d8c..9c70e9b7c8247d70835dfa9f74000fda9f6e3c58 100644 (file)
@@ -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) { \