]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Some more soa serial functions.
authorWillem Toorop <willem@NLnetLabs.nl>
Mon, 14 Nov 2011 14:31:39 +0000 (14:31 +0000)
committerWillem Toorop <willem@NLnetLabs.nl>
Mon, 14 Nov 2011 14:31:39 +0000 (14:31 +0000)
examples/ldns-read-zone.1
examples/ldns-read-zone.c
ldns/rr_functions.h
ldns_symbols.def
rr_functions.c

index dd5755ce1b69688e8fdbb28e27255f3646c86bd4..127f14e49f2e31aa909d0a281cabfae80097b8b9 100644 (file)
@@ -36,9 +36,17 @@ that is of type NSEC, NSEC3, RRSIG or DNSKEY. DS records are still
 printed.
 
 .TP
-\fB-S\fR \fI[+|0]number\fR
+\fB-S\fR \fI[[+|0]number | YYYYMMDDxx | unixtime ]\fR
 Set serial number to the given \fInumber\fR, or when preceded by a sign,
-offset the exisiting number with it.
+offset the exisiting number with it. When giving the literal strings 
+\fIYYYYMMDDxx\fR or \fIunixtime\fR, the serial number is tried to be reset
+in date or in unixtime format respectively. Though is the updated serial
+number is smaller than the original one, the original one is simply
+increased by one.
+
+When updating a zone's serial serial number, it will be stripped from DNSSEC
+data as well.
+
 
 .TP
 \fB-v\fR
index 276d1dfca87bb1df67efdfde01618c3cd88a1fb6..6794a5d42da2496016240e2df1cbcbe99c027e07 100644 (file)
@@ -60,12 +60,18 @@ main(int argc, char **argv)
                                printf("\t-h show this text\n");
                                printf("\t-n do not print the SOA record\n");
                                printf("\t-s strip DNSSEC data from the zone\n");
-                               printf("\t-S [+|-]<number>\n"
+                               printf("\t-S [[+|-]<number> | YYYYMMDDxx | "
+                                               " unixtime ]\n"
                                       "\t\tSet serial number to <number> or,"
                                                " when preceded by a sign,\n"
                                       "\t\toffset the exisiting number with "
-                                               "<number>.\n");
-
+                                               "<number>.  With YYYYMMDDxx\n"
+                                      "\t\tthe serial is formatted as a date"
+                                               ", and with unixtime as the\n"
+                                      "\t\tnumber of seconds since 1-1-1970."
+                                               "  However, on serial number"
+                                      "\n\t\tdecrease, +1 is used in stead"
+                                               ".  (implies -s)\n");
                                printf("\t-v shows the version and exits\n");
                                printf("\t-z sort the zone (implies -c).\n");
                                printf("\nif no file is given standard input is read\n");
@@ -100,11 +106,18 @@ main(int argc, char **argv)
                                                atoi(optarg);
                                        soa_serial_increment_func =
                                                ldns_soa_serial_identity;
+                               } else if (!strcasecmp(optarg, "YYYYMMDDxx")){
+                                       soa_serial_increment_func =
+                                               ldns_soa_serial_YYYYMMDDxx;
+                               } else if (!strcasecmp(optarg, "unixtime")){
+                                       soa_serial_increment_func =
+                                               ldns_soa_serial_unixtime;
                                } else {
                                        fprintf(stderr, "-S expects a number "
                                                "optionally preceded by a "
                                                "+ or - sign to indicate an "
-                                               "offset.\n");
+                                               "offset, or the text YYYYMM"
+                                               "DDxx or unixtime\n");
                                        exit(EXIT_FAILURE);
                                }
                                break;
index dade1442ce6376c2d174fd3e15cdbcab75060dfd..3a56630247e6c2e1da9bc5a2369aadaec11c93eb 100644 (file)
@@ -257,6 +257,8 @@ typedef uint32_t (*ldns_soa_serial_increment_func_t)(uint32_t, void*);
 uint32_t ldns_soa_serial_identity(uint32_t _, void *data);
 uint32_t ldns_soa_serial_increment(uint32_t s, void *_);
 uint32_t ldns_soa_serial_increment_by(uint32_t s, void *data);
+uint32_t ldns_soa_serial_unixtime(uint32_t s, void *data);
+uint32_t ldns_soa_serial_YYYYMMDDxx(uint32_t s, void *data);
 
 void ldns_rr_soa_increment(
                ldns_rr *soa);
index 8552bb30965b1bc94563d0284117f077eeb2d5b4..6dc04b12d0f0917195190273aaf58e0efc87f868 100644 (file)
@@ -666,9 +666,11 @@ ldns_sign_public_dsa
 ldns_sign_public_evp
 ldns_sign_public_rsamd5
 ldns_sign_public_rsasha1
+ldns_soa_serial_YYYYMMDDxx
 ldns_soa_serial_identity
 ldns_soa_serial_increment
 ldns_soa_serial_increment_by
+ldns_soa_serial_unixtime
 ldns_sockaddr_storage2rdf
 ldns_str2period
 ldns_str2rdf_a
index 14b44a714ad8e66c6e094bc223d7725ff5e4559a..7231b096fd0a0e6bc535ee2468e12d4b633be0b9 100644 (file)
@@ -356,6 +356,25 @@ uint32_t ldns_soa_serial_increment_by(uint32_t s, void *data)
        return s + (intptr_t) data;
 }
 
+uint32_t ldns_soa_serial_YYYYMMDDxx(uint32_t s, void *data)
+{
+       struct tm tm;
+       char s_str[11];
+       uint32_t new_s;
+       time_t t = data ? (time_t) (intptr_t) data : ldns_time(NULL);
+
+       strftime(s_str, 11, "%Y%m%d00", localtime_r(&t, &tm));
+       s_str[10] = 0;
+       new_s = atoi(s_str);
+       return new_s > s ? new_s : s+1;
+}
+
+uint32_t ldns_soa_serial_unixtime(uint32_t s, void *data)
+{
+       uint32_t new_s = (uint32_t)(data ? (intptr_t) data : ldns_time(NULL));
+       return new_s > s ? new_s : s+1;
+}
+
 void
 ldns_rr_soa_increment(ldns_rr *soa)
 {