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

Matthijs Mekking matthijs at nlnetlabs.nl
Tue Aug 31 14:06:15 CEST 2010


Author: matthijs
Date: 2010-08-31 14:06:15 +0200 (Tue, 31 Aug 2010)
New Revision: 3839

Modified:
   trunk/OpenDNSSEC/signer/src/scheduler/task.c
   trunk/OpenDNSSEC/signer/src/signer/backup.c
   trunk/OpenDNSSEC/signer/src/signer/signconf.c
   trunk/OpenDNSSEC/signer/src/signer/zone.c
Log:
fix corrupt state of backup files

Modified: trunk/OpenDNSSEC/signer/src/scheduler/task.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/scheduler/task.c	2010-08-31 11:35:52 UTC (rev 3838)
+++ trunk/OpenDNSSEC/signer/src/scheduler/task.c	2010-08-31 12:06:15 UTC (rev 3839)
@@ -91,13 +91,13 @@
     }
 
     if (fd) {
-        fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
-        fprintf(fd, "; who: %s\n", task->who);
-        fprintf(fd, "; what: %i\n", (int) task->what);
-        fprintf(fd, "; when: %u\n", (uint32_t) task->when);
-        fprintf(fd, "; flush: %i\n", task->flush);
-        fprintf(fd, "; backoff: %u\n", (uint32_t) task->backoff);
-        fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+        fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
+        fprintf(fd, ";who: %s\n", task->who);
+        fprintf(fd, ";what: %i\n", (int) task->what);
+        fprintf(fd, ";when: %u\n", (uint32_t) task->when);
+        fprintf(fd, ";flush: %i\n", task->flush);
+        fprintf(fd, ";backoff: %u\n", (uint32_t) task->backoff);
+        fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
     } else {
         se_log_warning("cannot backup task for zone %s: cannot open file %s for "
         "writing", task->who?task->who:"(null)", filename?filename:"(null)");

Modified: trunk/OpenDNSSEC/signer/src/signer/backup.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/backup.c	2010-08-31 11:35:52 UTC (rev 3838)
+++ trunk/OpenDNSSEC/signer/src/signer/backup.c	2010-08-31 12:06:15 UTC (rev 3839)
@@ -34,6 +34,7 @@
 #include "config.h"
 #include "util/duration.h"
 #include "util/file.h"
+#include "util/log.h"
 
 #include <ldns/ldns.h>
 
@@ -47,7 +48,7 @@
     static char buf[4000];
     buf[sizeof(buf)-1]=0;
     while (1) {
-        if (fscanf(in, " %3990s", buf) != 1) {
+        if (fscanf(in, "%3990s", buf) != 1) {
             return 0;
         }
         if (buf[0] != '#') {
@@ -69,9 +70,11 @@
 {
     char *p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read check string \'%s\'\n", str);
         return 0;
     }
     if (se_strcmp(p, str) != 0) {
+        se_log_debug("backup: \'%s\' does not match \'%s\'\n", p, str);
         return 0;
     }
     return 1;
@@ -87,6 +90,7 @@
 {
     char *p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read string\n");
         return 0;
     }
     *str = p;
@@ -103,6 +107,7 @@
 {
     char* p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read time\n");
        return 0;
     }
     *v=atol(p);
@@ -119,6 +124,7 @@
 {
     char* p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read duration\n");
        return 0;
     }
     *v=duration_create_from_string((const char*) p);
@@ -135,6 +141,7 @@
 {
     char* p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read rr type\n");
        return 0;
     }
     *v=(ldns_rr_type) atoi(p);
@@ -151,6 +158,7 @@
 {
     char* p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read integer\n");
        return 0;
     }
     *v=atoi(p);
@@ -167,6 +175,7 @@
 {
     char* p = backup_read_token(in);
     if (!p) {
+        se_log_debug("backup: cannot read uint32_t\n");
        return 0;
     }
     *v= (uint32_t)atol(p);

Modified: trunk/OpenDNSSEC/signer/src/signer/signconf.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/signconf.c	2010-08-31 11:35:52 UTC (rev 3838)
+++ trunk/OpenDNSSEC/signer/src/signer/signconf.c	2010-08-31 12:06:15 UTC (rev 3839)
@@ -153,35 +153,35 @@
         signconf = signconf_create();
 
         if (!backup_read_check_str(scfd, ODS_SE_FILE_MAGIC) ||
-            !backup_read_check_str(scfd, "; name:") ||
+            !backup_read_check_str(scfd, ";name:") ||
             !backup_read_str(scfd, &signconf->name) ||
-            !backup_read_check_str(scfd, "; filename:") ||
+            !backup_read_check_str(scfd, ";filename:") ||
             !backup_read_str(scfd, &signconf->filename) ||
-            !backup_read_check_str(scfd, "; last_modified:") ||
+            !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_check_str(scfd, ";sig_resign_interval:") ||
             !backup_read_duration(scfd, &signconf->sig_resign_interval) ||
-            !backup_read_check_str(scfd, "; sig_refresh_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_check_str(scfd, ";sig_validity_default:") ||
             !backup_read_duration(scfd, &signconf->sig_validity_default) ||
-            !backup_read_check_str(scfd, "; sig_validity_denial:") ||
+            !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_check_str(scfd, ";sig_jitter:") ||
             !backup_read_duration(scfd, &signconf->sig_jitter) ||
-            !backup_read_check_str(scfd, "; sig_inception_offset:") ||
+            !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_check_str(scfd, ";nsec_type:") ||
             !backup_read_rr_type(scfd, &signconf->nsec_type) ||
-            !backup_read_check_str(scfd, "; dnskey_ttl:") ||
+            !backup_read_check_str(scfd, ";dnskey_ttl:") ||
             !backup_read_duration(scfd, &signconf->dnskey_ttl) ||
-            !backup_read_check_str(scfd, "; soa_ttl:") ||
+            !backup_read_check_str(scfd, ";soa_ttl:") ||
             !backup_read_duration(scfd, &signconf->soa_ttl) ||
-            !backup_read_check_str(scfd, "; soa_min:") ||
+            !backup_read_check_str(scfd, ";soa_min:") ||
             !backup_read_duration(scfd, &signconf->soa_min) ||
-            !backup_read_check_str(scfd, "; soa_serial:") ||
+            !backup_read_check_str(scfd, ";soa_serial:") ||
             !backup_read_str(scfd, &signconf->soa_serial) ||
-            !backup_read_check_str(scfd, "; audit:") ||
+            !backup_read_check_str(scfd, ";audit:") ||
             !backup_read_int(scfd, &signconf->audit) ||
             !backup_read_check_str(scfd, ODS_SE_FILE_MAGIC))
         {
@@ -208,7 +208,7 @@
 signconf_backup_duration(FILE* fd, const char* opt, duration_type* duration)
 {
     char* str = duration2string(duration);
-    fprintf(fd, "; %s: %s\n", opt, str);
+    fprintf(fd, ";%s: %s\n", opt, str);
     se_free((void*) str);
     return;
 }
@@ -230,10 +230,10 @@
     filename = se_build_path(sc->name, ".sc", 0);
     fd = se_fopen(filename, NULL, "w");
     if (fd) {
-        fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
-        fprintf(fd, "; name: %s\n", sc->name?sc->name:"(null)");
-        fprintf(fd, "; filename: %s\n", sc->filename?sc->filename:"(null)");
-        fprintf(fd, "; last_modified: %u\n", (uint32_t) sc->last_modified);
+        fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
+        fprintf(fd, ";name: %s\n", sc->name?sc->name:"(null)");
+        fprintf(fd, ";filename: %s\n", sc->filename?sc->filename:"(null)");
+        fprintf(fd, ";last_modified: %u\n", (uint32_t) sc->last_modified);
 
         signconf_backup_duration(fd, "sig_resign_interval",
             sc->sig_resign_interval);
@@ -248,25 +248,19 @@
         signconf_backup_duration(fd, "sig_inception_offset",
             sc->sig_inception_offset);
 
-        fprintf(fd, "; nsec_type: %u\n", (unsigned int) sc->nsec_type);
-        if (sc->nsec_type == LDNS_RR_TYPE_NSEC3) {
-            fprintf(fd, "nsec3_optout: %i\n", sc->nsec3_optout);
-            fprintf(fd, "nsec3_algo: %u\n", sc->nsec3_algo);
-            fprintf(fd, "nsec3_iterations: %u\n", sc->nsec3_iterations);
-            fprintf(fd, "nsec3_salt: %s\n", sc->nsec3_salt?sc->nsec3_salt:"-");
-        }
+        fprintf(fd, ";nsec_type: %u\n", (unsigned int) sc->nsec_type);
 
         signconf_backup_duration(fd, "dnskey_ttl", sc->dnskey_ttl);
         /** Keys are backed up in .dnskeys */
 
         signconf_backup_duration(fd, "soa_ttl", sc->soa_ttl);
         signconf_backup_duration(fd, "soa_min", sc->soa_min);
-        fprintf(fd, "; soa_serial: %s\n",
+        fprintf(fd, ";soa_serial: %s\n",
             sc->soa_serial?sc->soa_serial:"(null)");
 
-        fprintf(fd, "; audit: %i\n", sc->audit);
+        fprintf(fd, ";audit: %i\n", sc->audit);
 
-        fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+        fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
         se_fclose(fd);
     } else {
         se_log_warning("cannot backup signconf: cannot open file "

Modified: trunk/OpenDNSSEC/signer/src/signer/zone.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/zone.c	2010-08-31 11:35:52 UTC (rev 3838)
+++ trunk/OpenDNSSEC/signer/src/signer/zone.c	2010-08-31 12:06:15 UTC (rev 3839)
@@ -302,14 +302,14 @@
                     key->locator?key->locator:"(null)");
                 break;
             } else if (fd) {
-                fprintf(fd, "; DNSKEY\n");
-                fprintf(fd, "; locator: %s\n",
+                fprintf(fd, ";DNSKEY\n");
+                fprintf(fd, ";locator: %s\n",
                     key->locator?key->locator:"(null)");
-                fprintf(fd, "; algorithm: %u\n", key->algorithm);
-                fprintf(fd, "; flags: %u\n", key->flags);
-                fprintf(fd, "; publish: %i\n", key->publish);
-                fprintf(fd, "; ksk: %i\n", key->ksk);
-                fprintf(fd, "; zsk: %i\n", key->zsk);
+                fprintf(fd, ";algorithm: %u\n", key->algorithm);
+                fprintf(fd, ";flags: %u\n", key->flags);
+                fprintf(fd, ";publish: %i\n", key->publish);
+                fprintf(fd, ";ksk: %i\n", key->ksk);
+                fprintf(fd, ";zsk: %i\n", key->zsk);
                 ldns_rr_print(fd, dnskey);
             }
         }
@@ -363,11 +363,11 @@
         se_log_error("error adding NSEC3PARAMS record to zone %s",
             zone->name?zone->name:"(null)");
     } else if (fd) {
-        fprintf(fd, "; NSEC3PARAMS\n");
-        fprintf(fd, "; salt: %s\n", zone->signconf->nsec3_salt);
-        fprintf(fd, "; algorithm: %u\n", zone->nsec3params->algorithm);
-        fprintf(fd, "; flags: %u\n", zone->nsec3params->flags);
-        fprintf(fd, "; iterations: %u\n", zone->nsec3params->iterations);
+        fprintf(fd, ";NSEC3PARAMS\n");
+        fprintf(fd, ";salt: %s\n", zone->signconf->nsec3_salt);
+        fprintf(fd, ";algorithm: %u\n", zone->nsec3params->algorithm);
+        fprintf(fd, ";flags: %u\n", zone->nsec3params->flags);
+        fprintf(fd, ";iterations: %u\n", zone->nsec3params->iterations);
         ldns_rr_print(fd, nsec3params_rr);
     }
     return error;
@@ -406,7 +406,7 @@
     filename = se_build_path(zone->name, ".dnskeys", 0);
     fd = se_fopen(filename, NULL, "w");
     if (fd) {
-        fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+        fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
     }
 
     error = zone_publish_dnskeys(zone, fd);
@@ -425,7 +425,7 @@
     }
 
     if (fd) {
-        fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+        fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
         se_fclose(fd);
     } else {
         se_log_warning("cannot backup DNSKEY / NSEC3PARAMS records: "
@@ -565,9 +565,9 @@
         filename = se_build_path(zone->name, ".denial", 0);
         fd = se_fopen(filename, NULL, "w");
         if (fd) {
-            fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+            fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
             zonedata_print_nsec(fd, zone->zonedata);
-            fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+            fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
             se_fclose(fd);
         } else {
             se_log_warning("cannot backup NSEC(3) records: cannot open file "
@@ -611,9 +611,9 @@
         filename = se_build_path(zone->name, ".rrsigs", 0);
         fd = se_fopen(filename, NULL, "w");
         if (fd) {
-            fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+            fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
             zonedata_print_rrsig(fd, zone->zonedata);
-            fprintf(fd, ";%s\n", ODS_SE_FILE_MAGIC);
+            fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC);
             se_fclose(fd);
         } else {
             se_log_warning("cannot backup RRSIG records: cannot open file "
@@ -644,14 +644,14 @@
     filename = se_build_path(zone->name, ".state", 0);
     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, ";%s\n", ODS_SE_FILE_MAGIC);
+        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, "%s\n", ODS_SE_FILE_MAGIC);
         se_fclose(fd);
     } else {
         se_log_error("cannot backup zone: cannot open file "
@@ -679,21 +679,21 @@
     se_log_assert(zone->zonedata);
 
     filename = se_build_path(zone->name, ".state", 0);
-    fd = se_fopen(filename, NULL, "w");
+    fd = se_fopen(filename, NULL, "r");
     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, ";name:") ||
             !backup_read_check_str(fd, zone->name) ||
-            !backup_read_check_str(fd, "; class:") ||
+            !backup_read_check_str(fd, ";class:") ||
             !backup_read_int(fd, &klass) ||
-            !backup_read_check_str(fd, "; default_ttl:") ||
+            !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_check_str(fd, ";inbound_serial:") ||
             !backup_read_uint32_t(fd, &zone->zonedata->inbound_serial) ||
-            !backup_read_check_str(fd, "; internal_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_check_str(fd, ";outbound_serial:") ||
             !backup_read_uint32_t(fd, &zone->zonedata->outbound_serial) ||
             !backup_read_check_str(fd, ODS_SE_FILE_MAGIC))
         {




More information about the Opendnssec-commits mailing list