From: Libor Peltan Date: Fri, 28 Jan 2022 16:58:00 +0000 (+0100) Subject: dump: allow rrsig timestamps past year 2106 in txt format... X-Git-Tag: v3.3.dev~188^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47dfd3d751f6ead6a9cf88709912897b63cdedbd;p=thirdparty%2Fknot-dns.git dump: allow rrsig timestamps past year 2106 in txt format... ...and optimized not to obtain time(NULL) on every dumped rdata in the cases of zone file, kdig and kjournalprint --- diff --git a/src/knot/updates/changesets.c b/src/knot/updates/changesets.c index a70b3fe747..d9c9d24f28 100644 --- a/src/knot/updates/changesets.c +++ b/src/knot/updates/changesets.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 CZ.NIC, z.s.p.o. +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ #include "knot/updates/apply.h" #include "knot/zone/zone-dump.h" #include "contrib/color.h" +#include "contrib/time.h" #include "libknot/libknot.h" static int handle_soa(knot_rrset_t **soa, const knot_rrset_t *rrset) @@ -590,6 +591,7 @@ void changeset_print(const changeset_t *changeset, FILE *outfile, bool color) char *buff = malloc(buflen); knot_dump_style_t style = KNOT_DUMP_STYLE_DEFAULT; + style.now = knot_time(); style.color = COL_RED(color); if (changeset->soa_from != NULL || !zone_contents_is_empty(changeset->remove)) { diff --git a/src/knot/zone/zone-dump.c b/src/knot/zone/zone-dump.c index 83b9ff7b95..41ec925461 100644 --- a/src/knot/zone/zone-dump.c +++ b/src/knot/zone/zone-dump.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 CZ.NIC, z.s.p.o. +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -158,6 +158,7 @@ int zone_dump_text(zone_contents_t *zone, FILE *file, bool comments, const char // Set structure with parameters. knot_dump_style_t style = KNOT_DUMP_STYLE_DEFAULT; style.color = color; + style.now = knot_time(); dump_params_t params = { .file = file, .buf = buf, diff --git a/src/libknot/rrset-dump.c b/src/libknot/rrset-dump.c index 25caae9826..51e29c2b77 100644 --- a/src/libknot/rrset-dump.c +++ b/src/libknot/rrset-dump.c @@ -41,6 +41,7 @@ #include "contrib/base64.h" #include "contrib/color.h" #include "contrib/ctype.h" +#include "contrib/time.h" #include "contrib/wire_ctx.h" #define RRSET_DUMP_LIMIT (2 * 1024 * 1024) @@ -87,6 +88,7 @@ const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT = { .hide_crypto = false, .ascii_to_idn = NULL, .color = NULL, + .now = 0, }; static void dump_string(rrset_dump_params_t *p, const char *str) @@ -685,6 +687,9 @@ static void wire_timestamp_to_str(rrset_dump_params_t *p) FILL_IN_INPUT(data) time_t timestamp = ntohl(data); + if (sizeof(time_t) > 4) { + timestamp = knot_time_from_u32(timestamp, p->style->now); + } if (p->style->human_timestamp) { struct tm result; diff --git a/src/libknot/rrset-dump.h b/src/libknot/rrset-dump.h index da7dc2c745..4631531758 100644 --- a/src/libknot/rrset-dump.h +++ b/src/libknot/rrset-dump.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 CZ.NIC, z.s.p.o. +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -56,6 +56,8 @@ typedef struct { /*!< Optional color control sequence which is put before every output line. * Not compatible with wrap. */ const char *color; + /*!< Time context for correct > 32 bit timestamp conversion. */ + uint64_t now; } knot_dump_style_t; /*! \brief Default dump style. */ diff --git a/src/utils/kdig/kdig_params.c b/src/utils/kdig/kdig_params.c index 3fc43c7a96..2cef812bcb 100644 --- a/src/utils/kdig/kdig_params.c +++ b/src/utils/kdig/kdig_params.c @@ -33,6 +33,7 @@ #include "contrib/sockaddr.h" #include "contrib/string.h" #include "contrib/strtonum.h" +#include "contrib/time.h" #include "contrib/ucw/lists.h" #include "libdnssec/error.h" #include "libdnssec/random.h" @@ -1512,6 +1513,7 @@ query_t *query_create(const char *owner, const query_t *conf) query->notify = false; query->flags = DEFAULT_FLAGS_DIG; query->style = DEFAULT_STYLE_DIG; + query->style.style.now = knot_time(); query->idn = true; query->nsid = false; query->edns = -1;