Handle schema reloading request.
[abartlet/samba.git/.git] / source4 / dsdb / samdb / ldb_modules / rootdse.c
index 50f333d09572bfd6d70150641f748ff5be174531..97491a2ae3911825b1bbeece0625c5d16948c94c 100644 (file)
@@ -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) {
@@ -394,9 +391,50 @@ static int rootdse_init(struct ldb_module *module)
        return ldb_next_init(module);
 }
 
+static int rootdse_modify(struct ldb_module *module, struct ldb_request *req)
+{
+       struct ldb_result *ext_res;
+       int ret;
+       struct ldb_dn *schema_dn;
+       struct ldb_message_element *schemaUpdateNowAttr;
+       
+       /*
+               If dn is not "" we should let it pass through
+       */
+       if (!ldb_dn_is_null(req->op.mod.message->dn)) {
+               return ldb_next_request(module, req);
+       }
+       
+       /*
+               dn is empty so check for schemaUpdateNow attribute
+               "The type of modification and values specified in the LDAP modify operation do not matter." MSDN
+       */
+       schemaUpdateNowAttr = ldb_msg_find_element(req->op.mod.message, "schemaUpdateNow");
+       if (!schemaUpdateNowAttr) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       schema_dn = samdb_schema_dn(module->ldb);
+       if (!schema_dn) {
+               ldb_reset_err_string(module->ldb);
+               ldb_debug(module->ldb, LDB_DEBUG_WARNING,
+                         "rootdse_modify: no schema dn present: (skip ldb_extended call)\n");
+               return ldb_next_request(module, req);
+       }
+
+       ret = ldb_extended(module->ldb, DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID, schema_dn, &ext_res);
+       if (ret != LDB_SUCCESS) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+       
+       talloc_free(ext_res);
+       return ret;
+}
+
 _PUBLIC_ const struct ldb_module_ops ldb_rootdse_module_ops = {
        .name                   = "rootdse",
-       .init_context           = rootdse_init,
-       .search                 = rootdse_search,
-       .request                = rootdse_request
+       .init_context   = rootdse_init,
+       .search         = rootdse_search,
+       .request                = rootdse_request,
+       .modify         = rootdse_modify
 };