s4-schema: keep track of the timestamp of the most recently changed/created object
[ddiss/samba.git] / source4 / dsdb / schema / schema_set.c
index 18f3ab7b7cc79f895a6fa7b8bf0362a27d8314f9..286a8a3f23f5f4c8b966dfdb551b3f8832c4d3b7 100644 (file)
@@ -665,14 +665,23 @@ int dsdb_schema_fill_extended_dn(struct ldb_context *ldb, struct dsdb_schema *sc
 WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb, struct dsdb_schema *schema,
                                       struct ldb_message *msg)
 {
+       const char* tstring;
+       time_t ts;
        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);
+       }
+       tstring = ldb_msg_find_attr_as_string(msg, "whenChanged", NULL);
+       /* keep a trace of the ts of the most recently changed object */
+       if (tstring) {
+               ts = ldb_string_to_time(tstring);
+               if (ts > schema->ts_last_change) {
+                       schema->ts_last_change = ts;
+               }
        }
-
        /* Don't fail on things not classes or attributes */
        return WERR_OK;
 }
@@ -683,7 +692,9 @@ WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb, struct dsdb_sche
  * schema itself to the directory.
  */
 
-WERROR dsdb_set_schema_from_ldif(struct ldb_context *ldb, const char *pf, const char *df)
+WERROR dsdb_set_schema_from_ldif(struct ldb_context *ldb,
+                                const char *pf, const char *df,
+                                const char *dn)
 {
        struct ldb_ldif *ldif;
        struct ldb_message *msg;
@@ -702,9 +713,16 @@ WERROR dsdb_set_schema_from_ldif(struct ldb_context *ldb, const char *pf, const
        }
 
        schema = dsdb_new_schema(mem_ctx);
-
+       if (!schema) {
+               goto nomem;
+       }
+       schema->base_dn = ldb_dn_new(schema, ldb, dn);
+       if (!schema->base_dn) {
+               goto nomem;
+       }
        schema->fsmo.we_are_master = true;
-       schema->fsmo.master_dn = ldb_dn_new_fmt(schema, ldb, "@PROVISION_SCHEMA_MASTER");
+       schema->fsmo.update_allowed = true;
+       schema->fsmo.master_dn = ldb_dn_new(schema, ldb, "@PROVISION_SCHEMA_MASTER");
        if (!schema->fsmo.master_dn) {
                goto nomem;
        }
@@ -744,6 +762,7 @@ WERROR dsdb_set_schema_from_ldif(struct ldb_context *ldb, const char *pf, const
                goto failed;
        }
 
+       schema->ts_last_change = 0;
        /* load the attribute and class definitions out of df */
        while ((ldif = ldb_ldif_read_string(ldb, &df))) {
                talloc_steal(mem_ctx, ldif);