From: Willem Toorop Date: Mon, 14 Nov 2011 14:31:39 +0000 (+0000) Subject: Some more soa serial functions. X-Git-Tag: release-1.6.12~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47bfc93a11d2f6d8112033115598801dc7bb4cf4;p=thirdparty%2Fldns.git Some more soa serial functions. --- diff --git a/examples/ldns-read-zone.1 b/examples/ldns-read-zone.1 index dd5755ce..127f14e4 100644 --- a/examples/ldns-read-zone.1 +++ b/examples/ldns-read-zone.1 @@ -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 diff --git a/examples/ldns-read-zone.c b/examples/ldns-read-zone.c index 276d1dfc..6794a5d4 100644 --- a/examples/ldns-read-zone.c +++ b/examples/ldns-read-zone.c @@ -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 [+|-]\n" + printf("\t-S [[+|-] | YYYYMMDDxx | " + " unixtime ]\n" "\t\tSet serial number to or," " when preceded by a sign,\n" "\t\toffset the exisiting number with " - ".\n"); - + ". 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; diff --git a/ldns/rr_functions.h b/ldns/rr_functions.h index dade1442..3a566302 100644 --- a/ldns/rr_functions.h +++ b/ldns/rr_functions.h @@ -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); diff --git a/ldns_symbols.def b/ldns_symbols.def index 8552bb30..6dc04b12 100644 --- a/ldns_symbols.def +++ b/ldns_symbols.def @@ -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 diff --git a/rr_functions.c b/rr_functions.c index 14b44a71..7231b096 100644 --- a/rr_functions.c +++ b/rr_functions.c @@ -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) {