From bb2dfb3f49ab707d751c0d83eb26938ed29a1b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 11 Jun 2018 12:49:06 +0200 Subject: [PATCH 1/3] Add dns_zone_logv() Add a new libdns function, dns_zone_logv(), which takes a single va_list argument rather than a variable number of arguments and can be used as a base for implementing more specific zone logging functions. --- lib/dns/include/dns/zone.h | 9 +++++++++ lib/dns/win32/libdns.def.in | 1 + lib/dns/zone.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 22fc47df9c..4a7a9f9430 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -1968,6 +1968,15 @@ dns_zone_setdialup(dns_zone_t *zone, dns_dialuptype_t dialup); *\li 'dialup' to be a valid dialup type. */ +void +dns_zone_logv(dns_zone_t *zone, isc_logcategory_t *category, int level, + const char *prefix, const char *msg, va_list ap); +/*%< + * Log the message 'msg...' at 'level' using log category 'category', including + * text that identifies the message as applying to 'zone'. If the (optional) + * 'prefix' is not NULL, it will be placed at the start of the entire log line. + */ + void dns_zone_log(dns_zone_t *zone, int level, const char *msg, ...) ISC_FORMAT_PRINTF(3, 4); diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index 3f9e1f26f8..ce44becd63 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -1209,6 +1209,7 @@ dns_zone_loadandthaw dns_zone_loadnew dns_zone_log dns_zone_logc +dns_zone_logv dns_zone_maintenance dns_zone_markdirty dns_zone_name diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 19a573241f..cbd286512a 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -13763,6 +13763,37 @@ dns_zone_nameonly(dns_zone_t *zone, char *buf, size_t length) { zone_name_tostr(zone, buf, length); } +void +dns_zone_logv(dns_zone_t *zone, isc_logcategory_t *category, int level, + const char *prefix, const char *fmt, va_list ap) +{ + char message[4096]; + const char *zstr; + + if (!isc_log_wouldlog(dns_lctx, level)) { + return; + } + + vsnprintf(message, sizeof(message), fmt, ap); + + switch (zone->type) { + case dns_zone_key: + zstr = "managed-keys-zone"; + break; + case dns_zone_redirect: + zstr = "redirect-zone"; + break; + default: + zstr = "zone "; + } + + isc_log_write(dns_lctx, category, DNS_LOGMODULE_ZONE, level, + "%s%s%s%s: %s", + (prefix != NULL ? prefix : ""), + (prefix != NULL ? ": " : ""), + zstr, zone->strnamerd, message); +} + static void notify_log(dns_zone_t *zone, int level, const char *fmt, ...) { va_list ap; From 5c03cd339e1c02cc0b05b95bb201d79d38129482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 11 Jun 2018 12:49:06 +0200 Subject: [PATCH 2/3] Reimplement all zone logging functions using dns_zone_logv() In order to decrease code duplication, express the logic contained in all zone logging functions using dns_zone_logv() calls. --- lib/dns/zone.c | 52 +++++--------------------------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/lib/dns/zone.c b/lib/dns/zone.c index cbd286512a..df47fe797a 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -13797,16 +13797,10 @@ dns_zone_logv(dns_zone_t *zone, isc_logcategory_t *category, int level, static void notify_log(dns_zone_t *zone, int level, const char *fmt, ...) { va_list ap; - char message[4096]; - - if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) - return; va_start(ap, fmt); - vsnprintf(message, sizeof(message), fmt, ap); + dns_zone_logv(zone, DNS_LOGCATEGORY_NOTIFY, level, NULL, fmt, ap); va_end(ap); - isc_log_write(dns_lctx, DNS_LOGCATEGORY_NOTIFY, DNS_LOGMODULE_ZONE, - level, "zone %s: %s", zone->strnamerd, message); } void @@ -13814,67 +13808,31 @@ dns_zone_logc(dns_zone_t *zone, isc_logcategory_t *category, int level, const char *fmt, ...) { va_list ap; - char message[4096]; - - if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) - return; va_start(ap, fmt); - vsnprintf(message, sizeof(message), fmt, ap); + dns_zone_logv(zone, category, level, NULL, fmt, ap); va_end(ap); - isc_log_write(dns_lctx, category, DNS_LOGMODULE_ZONE, - level, "%s%s: %s", (zone->type == dns_zone_key) ? - "managed-keys-zone" : (zone->type == dns_zone_redirect) ? - "redirect-zone" : "zone ", zone->strnamerd, message); } void dns_zone_log(dns_zone_t *zone, int level, const char *fmt, ...) { va_list ap; - char message[4096]; - - if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) - return; va_start(ap, fmt); - vsnprintf(message, sizeof(message), fmt, ap); + dns_zone_logv(zone, DNS_LOGCATEGORY_GENERAL, level, NULL, fmt, ap); va_end(ap); - isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_ZONE, - level, "%s%s: %s", (zone->type == dns_zone_key) ? - "managed-keys-zone" : (zone->type == dns_zone_redirect) ? - "redirect-zone" : "zone ", zone->strnamerd, message); } static void zone_debuglog(dns_zone_t *zone, const char *me, int debuglevel, const char *fmt, ...) { - va_list ap; - char message[4096]; int level = ISC_LOG_DEBUG(debuglevel); - const char *zstr; - - if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) - return; + va_list ap; va_start(ap, fmt); - vsnprintf(message, sizeof(message), fmt, ap); + dns_zone_logv(zone, DNS_LOGCATEGORY_GENERAL, level, me, fmt, ap); va_end(ap); - - switch (zone->type) { - case dns_zone_key: - zstr = "managed-keys-zone"; - break; - case dns_zone_redirect: - zstr = "redirect-zone"; - break; - default: - zstr = "zone"; - } - - isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_ZONE, - level, "%s: %s %s: %s", me, zstr, zone->strnamerd, - message); } static int From c8de677eaeec447b5c8eb562fa025bf57d8fa982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 11 Jun 2018 12:49:06 +0200 Subject: [PATCH 3/3] Add CHANGES entry 4969. [cleanup] Refactor zone logging functions. [GL #269] --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index 2a03c7b511..8c4b0acf6e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +4969. [cleanup] Refactor zone logging functions. [GL #269] + 4968. [bug] If glue records are signed, attempt to validate them. [GL #209]