]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Teach dnssec-settime to read times that it writes
authorTony Finch <dot@dotat.at>
Mon, 29 Apr 2019 12:56:05 +0000 (13:56 +0100)
committerTony Finch <fanf@isc.org>
Mon, 23 May 2022 11:44:50 +0000 (13:44 +0200)
The dnssec-settime -p and -up options print times in asctime() and
UNIX time_t formats, respectively. The asctime() format can also be
found inside K*.key public key files. Key files also contain times in
the YYYYMMDDHHMMSS format that can be used in timing parameter
options.

The dnssec-settime -p and -up time formats are now acceptable in
timing parameter options to dnssec-settime and dnssec-keygen, so it is
no longer necessary to parse key files to retrieve times that are
acceptable in timing parameter options.

(cherry picked from commit c38a3230823a8a16eee4e3502419ccf5a309e354)

bin/dnssec/dnssec-keygen.rst
bin/dnssec/dnssec-settime.rst
bin/dnssec/dnssectool.c
bin/tests/system/metadata/tests.sh
doc/man/dnssec-keygen.1in
doc/man/dnssec-settime.1in

index 1185b63b9665a4333c01ad4cb078be3ca8f3ff2d..995170ab07aceedde3df1d88edce226f4a267d35 100644 (file)
@@ -221,14 +221,21 @@ Options
 Timing Options
 ~~~~~~~~~~~~~~
 
-Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS. If the
-argument begins with a ``+`` or ``-``, it is interpreted as an offset from
-the present time. For convenience, if such an offset is followed by one
-of the suffixes ``y``, ``mo``, ``w``, ``d``, ``h``, or ``mi``, then the offset is
-computed in years (defined as 365 24-hour days, ignoring leap years),
-months (defined as 30 24-hour days), weeks, days, hours, or minutes,
-respectively. Without a suffix, the offset is computed in seconds. To
-explicitly prevent a date from being set, use ``none`` or ``never``.
+Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS
+(which is the format used inside key files),
+or 'Day Mon DD HH:MM:SS YYYY' (as printed by ``dnssec-settime -p``),
+or UNIX epoch time (as printed by ``dnssec-settime -up``),
+or the literal ``now``.
+
+The argument can be followed by '+' or '-' and an offset from the
+given time. The literal ``now`` can be omitted before an offset. The
+offset can be followed by one of the suffixes 'y', 'mo', 'w', 'd',
+'h', or 'mi', so that it is computed in years (defined as 365 24-hour
+days, ignoring leap years), months (defined as 30 24-hour days),
+weeks, days, hours, or minutes, respectively. Without a suffix, the
+offset is computed in seconds.
+
+To unset a date, use ``none`` or ``never``.
 
 .. option:: -P date/offset
 
index 2b80dd404cfdb6f493bc877876b6b792e4893960..057ceea3aa873c33ed7d653a3d7f37d0a6f3bc3c 100644 (file)
@@ -108,14 +108,21 @@ Options
 Timing Options
 ~~~~~~~~~~~~~~
 
-Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS. If the
-argument begins with a ``+`` or ``-``, it is interpreted as an offset from
-the present time. For convenience, if such an offset is followed by one
-of the suffixes ``y``, ``mo``, ``w``, ``d``, ``h``, or ``mi``, then the offset is
-computed in years (defined as 365 24-hour days, ignoring leap years),
-months (defined as 30 24-hour days), weeks, days, hours, or minutes,
-respectively. Without a suffix, the offset is computed in seconds. To
-explicitly prevent a date from being set, use ``none`` or ``never``.
+Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS
+(which is the format used inside key files),
+or 'Day Mon DD HH:MM:SS YYYY' (as printed by ``dnssec-settime -p``),
+or UNIX epoch time (as printed by ``dnssec-settime -up``),
+or the literal ``now``.
+
+The argument can be followed by '+' or '-' and an offset from the
+given time. The literal ``now`` can be omitted before an offset. The
+offset can be followed by one of the suffixes 'y', 'mo', 'w', 'd',
+'h', or 'mi', so that it is computed in years (defined as 365 24-hour
+days, ignoring leap years), months (defined as 30 24-hour days),
+weeks, days, hours, or minutes, respectively. Without a suffix, the
+offset is computed in seconds.
+
+To unset a date, use ``none`` or ``never``.
 
 .. option:: -P date/offset
 
index a60af12fefcb2a7750bc799f418b323260cca3b7..f4fc3a865984c8b0d368daa5a0cc8ab65fc97f6d 100644 (file)
@@ -33,6 +33,7 @@
 #include <isc/result.h>
 #include <isc/string.h>
 #include <isc/time.h>
+#include <isc/tm.h>
 #include <isc/util.h>
 
 #include <dns/db.h>
@@ -283,6 +284,7 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp) {
        const char *orig = str;
        char *endp;
        size_t n;
+       struct tm tm;
 
        if (isnone(str)) {
                if (setp != NULL) {
@@ -304,6 +306,8 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp) {
         *   now([+-]offset)
         *   YYYYMMDD([+-]offset)
         *   YYYYMMDDhhmmss([+-]offset)
+        *   Day Mon DD HH:MM:SS YYYY([+-]offset)
+        *   1234567890([+-]offset)
         *   [+-]offset
         */
        n = strspn(str, "0123456789");
@@ -323,9 +327,21 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp) {
                }
                base = val;
                str += n;
+       } else if (n == 10u &&
+                  (str[n] == '\0' || str[n] == '-' || str[n] == '+')) {
+               base = strtoll(str, &endp, 0);
+               str += 10;
        } else if (strncmp(str, "now", 3) == 0) {
                base = now;
                str += 3;
+       } else if (str[0] >= 'A' && str[0] <= 'Z') {
+               /* parse ctime() format as written by `dnssec-settime -p` */
+               endp = isc_tm_strptime(str, "%a %b %d %H:%M:%S %Y", &tm);
+               if (endp != str + 24) {
+                       fatal("time value %s is invalid", orig);
+               }
+               base = mktime(&tm);
+               str += 24;
        }
 
        if (str[0] == '\0') {
index b19d1cf7a9e0a673cc4102364c0f5416bacd8e8f..b3c2cd3fec8be7ad8ef1d38f02c6d174f1e907f0 100644 (file)
@@ -208,5 +208,21 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
+key=`$KEYGEN -q -a RSASHA1 $czone`
+
+echo_i "checking -p output time is accepted ($n)"
+t=`$SETTIME -pA $key | sed 's/.*: //'`
+$SETTIME -Psync "$t" $key > /dev/null 2>&1 || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=`expr $status + $ret`
+
+echo_i "checking -up output time is accepted ($n)"
+t=`$SETTIME -upA $key | sed 's/.*: //'`
+$SETTIME -Dsync "$t" $key > /dev/null 2>&1 || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=`expr $status + $ret`
+
 echo_i "exit status: $status"
 [ $status -eq 0 ] || exit 1
index dcd2ce35ed54ed5c6bd008e7a71fc897b964c889..672ecbc4bfe4457afacb3ce9e43a6c56e67a114d 100644 (file)
@@ -250,14 +250,21 @@ This option sets the debugging level.
 .UNINDENT
 .SH TIMING OPTIONS
 .sp
-Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS. If the
-argument begins with a \fB+\fP or \fB\-\fP, it is interpreted as an offset from
-the present time. For convenience, if such an offset is followed by one
-of the suffixes \fBy\fP, \fBmo\fP, \fBw\fP, \fBd\fP, \fBh\fP, or \fBmi\fP, then the offset is
-computed in years (defined as 365 24\-hour days, ignoring leap years),
-months (defined as 30 24\-hour days), weeks, days, hours, or minutes,
-respectively. Without a suffix, the offset is computed in seconds. To
-explicitly prevent a date from being set, use \fBnone\fP or \fBnever\fP\&.
+Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS
+(which is the format used inside key files),
+or \(aqDay Mon DD HH:MM:SS YYYY\(aq (as printed by \fBdnssec\-settime \-p\fP),
+or UNIX epoch time (as printed by \fBdnssec\-settime \-up\fP),
+or the literal \fBnow\fP\&.
+.sp
+The argument can be followed by \(aq+\(aq or \(aq\-\(aq and an offset from the
+given time. The literal \fBnow\fP can be omitted before an offset. The
+offset can be followed by one of the suffixes \(aqy\(aq, \(aqmo\(aq, \(aqw\(aq, \(aqd\(aq,
+\(aqh\(aq, or \(aqmi\(aq, so that it is computed in years (defined as 365 24\-hour
+days, ignoring leap years), months (defined as 30 24\-hour days),
+weeks, days, hours, or minutes, respectively. Without a suffix, the
+offset is computed in seconds.
+.sp
+To unset a date, use \fBnone\fP or \fBnever\fP\&.
 .INDENT 0.0
 .TP
 .B \-P date/offset
index 15bc234001d8eac0025e935d489d02ef742e8a02..f8dd6386c44981f0a607289f71ae58265cd990b1 100644 (file)
@@ -120,14 +120,21 @@ hardware service module (usually \fBpkcs11\fP).
 .UNINDENT
 .SH TIMING OPTIONS
 .sp
-Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS. If the
-argument begins with a \fB+\fP or \fB\-\fP, it is interpreted as an offset from
-the present time. For convenience, if such an offset is followed by one
-of the suffixes \fBy\fP, \fBmo\fP, \fBw\fP, \fBd\fP, \fBh\fP, or \fBmi\fP, then the offset is
-computed in years (defined as 365 24\-hour days, ignoring leap years),
-months (defined as 30 24\-hour days), weeks, days, hours, or minutes,
-respectively. Without a suffix, the offset is computed in seconds. To
-explicitly prevent a date from being set, use \fBnone\fP or \fBnever\fP\&.
+Dates can be expressed in the format YYYYMMDD or YYYYMMDDHHMMSS
+(which is the format used inside key files),
+or \(aqDay Mon DD HH:MM:SS YYYY\(aq (as printed by \fBdnssec\-settime \-p\fP),
+or UNIX epoch time (as printed by \fBdnssec\-settime \-up\fP),
+or the literal \fBnow\fP\&.
+.sp
+The argument can be followed by \(aq+\(aq or \(aq\-\(aq and an offset from the
+given time. The literal \fBnow\fP can be omitted before an offset. The
+offset can be followed by one of the suffixes \(aqy\(aq, \(aqmo\(aq, \(aqw\(aq, \(aqd\(aq,
+\(aqh\(aq, or \(aqmi\(aq, so that it is computed in years (defined as 365 24\-hour
+days, ignoring leap years), months (defined as 30 24\-hour days),
+weeks, days, hours, or minutes, respectively. Without a suffix, the
+offset is computed in seconds.
+.sp
+To unset a date, use \fBnone\fP or \fBnever\fP\&.
 .INDENT 0.0
 .TP
 .B \-P date/offset