[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r3835 - in trunk/OpenDNSSEC/signer/src: . daemon signer

Matthijs Mekking matthijs at nlnetlabs.nl
Tue Aug 31 12:09:40 CEST 2010


Author: matthijs
Date: 2010-08-31 12:09:40 +0200 (Tue, 31 Aug 2010)
New Revision: 3835

Added:
   trunk/OpenDNSSEC/signer/src/signer/backup.c
   trunk/OpenDNSSEC/signer/src/signer/backup.h
Modified:
   trunk/OpenDNSSEC/signer/src/Makefile.am
   trunk/OpenDNSSEC/signer/src/daemon/engine.c
   trunk/OpenDNSSEC/signer/src/signer/signconf.c
   trunk/OpenDNSSEC/signer/src/signer/signconf.h
   trunk/OpenDNSSEC/signer/src/signer/zone.c
   trunk/OpenDNSSEC/signer/src/signer/zone.h
Log:
recover from backup functions
recover .state, .sc



Modified: trunk/OpenDNSSEC/signer/src/Makefile.am
===================================================================
--- trunk/OpenDNSSEC/signer/src/Makefile.am	2010-08-31 08:39:50 UTC (rev 3834)
+++ trunk/OpenDNSSEC/signer/src/Makefile.am	2010-08-31 10:09:40 UTC (rev 3835)
@@ -30,6 +30,7 @@
 				parser/zonelistparser.c parser/zonelistparser.h \
 				scheduler/locks.c scheduler/locks.h \
 				scheduler/task.c scheduler/task.h \
+				signer/backup.c signer/backup.h \
 				signer/domain.c signer/domain.h \
 				signer/hsm.c signer/hsm.h \
 				signer/nsec3params.c signer/nsec3params.h \

Modified: trunk/OpenDNSSEC/signer/src/daemon/engine.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/daemon/engine.c	2010-08-31 08:39:50 UTC (rev 3834)
+++ trunk/OpenDNSSEC/signer/src/daemon/engine.c	2010-08-31 10:09:40 UTC (rev 3835)
@@ -667,6 +667,43 @@
 
 
 /**
+ * Try to recover from the backup files.
+ *
+ */
+static void
+engine_recover_from_backups(engine_type* engine)
+{
+    ldns_rbnode_t* node = LDNS_RBTREE_NULL;
+    zone_type* zone = NULL;
+
+    se_log_assert(engine);
+    se_log_assert(engine->zonelist);
+    se_log_assert(engine->zonelist->zones);
+
+    lock_basic_lock(&engine->tasklist->tasklist_lock);
+    engine->tasklist->loading = 1;
+    lock_basic_unlock(&engine->tasklist->tasklist_lock);
+
+    node = ldns_rbtree_first(engine->zonelist->zones);
+    while (node && node != LDNS_RBTREE_NULL) {
+        zone = (zone_type*) node->key;
+        lock_basic_lock(&zone->zone_lock);
+        lock_basic_lock(&engine->tasklist->tasklist_lock);
+        zone_recover_from_backup(zone, engine->tasklist);
+        lock_basic_unlock(&engine->tasklist->tasklist_lock);
+        lock_basic_unlock(&zone->zone_lock);
+        node = ldns_rbtree_next(node);
+    }
+
+    lock_basic_lock(&engine->tasklist->tasklist_lock);
+    engine->tasklist->loading = 0;
+    lock_basic_unlock(&engine->tasklist->tasklist_lock);
+
+    return;
+}
+
+
+/**
  * Start zonefetcher.
  *
  */
@@ -791,6 +828,7 @@
 {
     engine_type* engine = NULL;
     int use_syslog = 0;
+    int zl_changed = 0;
 
     se_log_assert(cfgfile);
     se_log_init(NULL, use_syslog, cmdline_verbosity);
@@ -825,14 +863,19 @@
 
     /* run */
     while (engine->need_to_exit == 0) {
+        zl_changed = (engine_update_zonelist(engine, NULL) == 0);
+
         if (engine->need_to_reload) {
             se_log_verbose("reload engine");
             engine->need_to_reload = 0;
         } else {
             se_log_debug("signer engine started");
+            /* try to recover from backups */
+            engine_recover_from_backups(engine);
         }
 
-        if (engine_update_zonelist(engine, NULL) == 0) {
+        if (zl_changed) {
+            zl_changed = 0;
             engine_update_zones(engine, NULL, NULL);
         }
 

Modified: trunk/OpenDNSSEC/signer/src/signer/signconf.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/signconf.c	2010-08-31 08:39:50 UTC (rev 3834)
+++ trunk/OpenDNSSEC/signer/src/signer/signconf.c	2010-08-31 10:09:40 UTC (rev 3835)
@@ -34,6 +34,7 @@
 #include "parser/confparser.h"
 #include "parser/signconfparser.h"
 #include "scheduler/task.h"
+#include "signer/backup.h"
 #include "signer/se_key.h"
 #include "signer/signconf.h"
 #include "util/duration.h"
@@ -137,7 +138,68 @@
 }
 
 
+/**
+ * Read a signer configuration from backup.
+ *
+ */
+signconf_type*
+signconf_recover_from_backup(const char* filename)
+{
+    signconf_type* signconf = NULL;
+    FILE* scfd = NULL;
 
+    scfd = se_fopen(filename, NULL, "r");
+    if (scfd) {
+        signconf = signconf_create();
+
+        if (!backup_read_check_str(scfd, ODS_SE_FILE_MAGIC) ||
+            !backup_read_check_str(scfd, "; name:") ||
+            !backup_read_str(scfd, &signconf->name) ||
+            !backup_read_check_str(scfd, "; filename:") ||
+            !backup_read_str(scfd, &signconf->filename) ||
+            !backup_read_check_str(scfd, "; last_modified:") ||
+            !backup_read_time_t(scfd, &signconf->last_modified) ||
+            !backup_read_check_str(scfd, "; sig_resign_interval:") ||
+            !backup_read_duration(scfd, &signconf->sig_resign_interval) ||
+            !backup_read_check_str(scfd, "; sig_refresh_interval:") ||
+            !backup_read_duration(scfd, &signconf->sig_refresh_interval) ||
+            !backup_read_check_str(scfd, "; sig_validity_default:") ||
+            !backup_read_duration(scfd, &signconf->sig_validity_default) ||
+            !backup_read_check_str(scfd, "; sig_validity_denial:") ||
+            !backup_read_duration(scfd, &signconf->sig_validity_denial) ||
+            !backup_read_check_str(scfd, "; sig_jitter:") ||
+            !backup_read_duration(scfd, &signconf->sig_jitter) ||
+            !backup_read_check_str(scfd, "; sig_inception_offset:") ||
+            !backup_read_duration(scfd, &signconf->sig_inception_offset) ||
+            !backup_read_check_str(scfd, "; nsec_type:") ||
+            !backup_read_rr_type(scfd, &signconf->nsec_type) ||
+            !backup_read_check_str(scfd, "; dnskey_ttl:") ||
+            !backup_read_duration(scfd, &signconf->dnskey_ttl) ||
+            !backup_read_check_str(scfd, "; soa_ttl:") ||
+            !backup_read_duration(scfd, &signconf->soa_ttl) ||
+            !backup_read_check_str(scfd, "; soa_min:") ||
+            !backup_read_duration(scfd, &signconf->soa_min) ||
+            !backup_read_check_str(scfd, "; soa_serial:") ||
+            !backup_read_str(scfd, &signconf->soa_serial) ||
+            !backup_read_check_str(scfd, "; audit:") ||
+            !backup_read_int(scfd, &signconf->audit) ||
+            !backup_read_check_str(scfd, ODS_SE_FILE_MAGIC))
+        {
+            se_log_error("unable to recover signconf backup file %s: corrupt "
+                "backup file ", filename?filename:"(null)");
+            signconf_cleanup(signconf);
+            signconf = NULL;
+        }
+        se_fclose(scfd);
+        return signconf;
+    }
+
+    se_log_debug("unable to recover signconf backup file %s",
+        filename?filename:"(null)");
+    return NULL;
+}
+
+
 /**
  * Backup duration.
  *

Modified: trunk/OpenDNSSEC/signer/src/signer/signconf.h
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/signconf.h	2010-08-31 08:39:50 UTC (rev 3834)
+++ trunk/OpenDNSSEC/signer/src/signer/signconf.h	2010-08-31 10:09:40 UTC (rev 3835)
@@ -92,8 +92,16 @@
 signconf_type* signconf_read(const char* filename, time_t last_modified);
 
 /**
+ * Read signer configuration from backup.
+ * \param[in] filename file name
+ * \return signconf_type* signer configuration
+ *
+ */
+signconf_type* signconf_recover_from_backup(const char* filename);
+
+/**
  * Backup signer configuration.
- * \param sc signer configuration settings
+ * \param[in] sc signer configuration settings
  *
  */
 void signconf_backup(signconf_type* sc);

Modified: trunk/OpenDNSSEC/signer/src/signer/zone.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/zone.c	2010-08-31 08:39:50 UTC (rev 3834)
+++ trunk/OpenDNSSEC/signer/src/signer/zone.c	2010-08-31 10:09:40 UTC (rev 3835)
@@ -34,6 +34,7 @@
 #include "adapter/adapter.h"
 #include "scheduler/locks.h"
 #include "scheduler/task.h"
+#include "signer/backup.h"
 #include "signer/hsm.h"
 #include "signer/nsec3params.h"
 #include "signer/signconf.h"
@@ -644,12 +645,12 @@
     fd = se_fopen(filename, NULL, "w");
     if (fd) {
         fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
-        fprintf(fd, "name: %s\n", zone->name?zone->name:"(null)");
-        fprintf(fd, "class: %i\n", (int) zone->klass);
-        fprintf(fd, "default_ttl: %u\n", zone->zonedata->default_ttl);
-        fprintf(fd, "inbound_serial: %u\n", zone->zonedata->inbound_serial);
-        fprintf(fd, "internal_serial: %u\n", zone->zonedata->internal_serial);
-        fprintf(fd, "outbound_serial: %u\n", zone->zonedata->outbound_serial);
+        fprintf(fd, "; name: %s\n", zone->name?zone->name:"(null)");
+        fprintf(fd, "; class: %i\n", (int) zone->klass);
+        fprintf(fd, "; default_ttl: %u\n", zone->zonedata->default_ttl);
+        fprintf(fd, "; inbound_serial: %u\n", zone->zonedata->inbound_serial);
+        fprintf(fd, "; internal_serial: %u\n", zone->zonedata->internal_serial);
+        fprintf(fd, "; outbound_serial: %u\n", zone->zonedata->outbound_serial);
         fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
         se_fclose(fd);
     } else {
@@ -664,6 +665,70 @@
 
 
 /**
+ * Recover from backup.
+ *
+ */
+void
+zone_recover_from_backup(zone_type* zone, struct tasklist_struct* tl)
+{
+    int klass = 0;
+    char* filename = NULL;
+    FILE* fd = NULL;
+
+    se_log_assert(zone);
+    se_log_assert(zone->zonedata);
+
+    filename = se_build_path(zone->name, ".state", 0);
+    fd = se_fopen(filename, NULL, "w");
+    se_free((void*)filename);
+    if (fd) {
+        if (!backup_read_check_str(fd, ODS_SE_FILE_MAGIC) ||
+            !backup_read_check_str(fd, "; name: ") ||
+            !backup_read_check_str(fd, zone->name) ||
+            !backup_read_check_str(fd, "; class:") ||
+            !backup_read_int(fd, &klass) ||
+            !backup_read_check_str(fd, "; default_ttl:") ||
+            !backup_read_uint32_t(fd, &zone->zonedata->default_ttl) ||
+            !backup_read_check_str(fd, "; inbound_serial:") ||
+            !backup_read_uint32_t(fd, &zone->zonedata->inbound_serial) ||
+            !backup_read_check_str(fd, "; internal_serial:") ||
+            !backup_read_uint32_t(fd, &zone->zonedata->internal_serial) ||
+            !backup_read_check_str(fd, "; outbound_serial:") ||
+            !backup_read_uint32_t(fd, &zone->zonedata->outbound_serial) ||
+            !backup_read_check_str(fd, ODS_SE_FILE_MAGIC))
+        {
+            se_log_error("unable to recover zone state backup file %s.state: "
+                "corrupt state file ", zone->name);
+            se_fclose(fd);
+            return;
+        }
+        se_fclose(fd);
+    } else {
+        se_log_debug("unable to recover zone state backup file %s.state",
+            zone->name);
+        return;
+    }
+
+    /* let's see if we can recover the signconf now */
+    filename = se_build_path(zone->name, ".sc", 0);
+    zone->signconf = signconf_recover_from_backup((const char*) filename);
+    se_free((void*)filename);
+    if (!zone->signconf) {
+        /* no, stop recovering process */
+        return;
+    }
+
+    /* time for the keys and nsec3params file */
+
+    /* zone data */
+
+    /* task */
+
+    return;
+}
+
+
+/**
  * Clean up a zone.
  *
  */

Modified: trunk/OpenDNSSEC/signer/src/signer/zone.h
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/zone.h	2010-08-31 08:39:50 UTC (rev 3834)
+++ trunk/OpenDNSSEC/signer/src/signer/zone.h	2010-08-31 10:09:40 UTC (rev 3835)
@@ -164,6 +164,14 @@
 int zone_backup_state(zone_type* zone);
 
 /**
+ * Recover from backup.
+ * \param[in] zone corresponding zone
+ * \param[in] tl task list
+ *
+ */
+void zone_recover_from_backup(zone_type* zone, struct tasklist_struct* tl);
+
+/**
  * Clean up a zone.
  * \param[in] zone zone to cleanup
  *




More information about the Opendnssec-commits mailing list