s4/samldb: schemaInfo attribute must be updated when adding new Schema object
authorKamen Mazdrashki <kamenim@samba.org>
Tue, 6 Apr 2010 12:17:05 +0000 (15:17 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Fri, 9 Apr 2010 09:21:30 +0000 (12:21 +0300)
source4/dsdb/samdb/ldb_modules/samldb.c

index 24d1450d9cce2351398938649d045ee4573e0619..3b2d283006ff0e25a387114acbedd0baf53acf19 100644 (file)
@@ -1054,6 +1054,44 @@ static int samldb_check_rdn(struct ldb_module *module, struct ldb_dn *dn)
        return LDB_SUCCESS;
 }
 
+static int samldb_schema_info_update(struct samldb_ctx *ac)
+{
+       WERROR werr;
+       struct ldb_context *ldb;
+       struct dsdb_schema *schema;
+
+       /* replicated update should always go through */
+       if (ldb_request_get_control(ac->req, DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
+               return LDB_SUCCESS;
+       }
+
+       /* do not update schemaInfo during provisioning */
+       if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
+               return LDB_SUCCESS;
+       }
+
+       ldb = ldb_module_get_ctx(ac->module);
+       schema = dsdb_get_schema(ldb, NULL);
+       if (!schema) {
+               ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+                             "samldb_schema_info_update: no dsdb_schema loaded");
+               DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       werr = dsdb_module_schema_info_update(ac->module, schema, 0);
+       if (!W_ERROR_IS_OK(werr)) {
+               ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+                             "samldb_schema_info_update: "
+                             "dsdb_module_schema_info_update failed with %s",
+                             win_errstr(werr));
+               DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       return LDB_SUCCESS;
+}
+
 /*
  * samldb_sid_from_dn (async)
  */
@@ -1800,6 +1838,12 @@ static int samldb_add(struct ldb_module *module, struct ldb_request *req)
                        return ret;
                }
 
+               ret = samldb_schema_info_update(ac);
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(ac);
+                       return ret;
+               }
+
                return samldb_fill_object(ac, "classSchema");
        }
 
@@ -1812,6 +1856,12 @@ static int samldb_add(struct ldb_module *module, struct ldb_request *req)
                        return ret;
                }
 
+               ret = samldb_schema_info_update(ac);
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(ac);
+                       return ret;
+               }
+
                return samldb_fill_object(ac, "attributeSchema");
        }