]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Change the zoneverify.c to print the information to user supplied function
authorOndřej Surý <ondrej@sury.org>
Sun, 21 Jul 2019 12:07:20 +0000 (08:07 -0400)
committerOndřej Surý <ondrej@sury.org>
Wed, 31 Jul 2019 08:05:52 +0000 (10:05 +0200)
The lib/dns/zoneverify.c output was hardwired to stderr, which was inconsistent
with lib/dns/dnssec.c.  This commit changes zoneverify.c to print the normal run
information to caller supplied function - same model as in the lib/dns/dnssec.c.

bin/dnssec/dnssec-signzone.c
bin/dnssec/dnssec-verify.c
lib/dns/include/dns/zoneverify.h
lib/dns/zone.c
lib/dns/zoneverify.c

index 6a030ca594ca51f6c98761282cd6cc6b8ece8552..7a0155baa5550f50b58b61c076bb7ae99f46a015 100644 (file)
@@ -3883,7 +3883,7 @@ main(int argc, char *argv[]) {
        } else {
                vresult = dns_zoneverify_dnssec(NULL, gdb, gversion, gorigin,
                                                NULL, mctx, ignore_kskflag,
-                                               keyset_kskonly);
+                                               keyset_kskonly, report);
                if (vresult != ISC_R_SUCCESS) {
                        fprintf(output_stdout ? stderr : stdout,
                                "Zone verification failed (%s)\n",
index b38368b2dfea75d4113d3375fec3bb2260b860d9..caf97426950b6200de5b63bf85cb605437751ea3 100644 (file)
@@ -78,6 +78,15 @@ static dns_name_t *gorigin;          /* The database origin */
 static bool ignore_kskflag = false;
 static bool keyset_kskonly = false;
 
+static void
+report(const char *format, ...) {
+       va_list args;
+       va_start(args, format);
+       vfprintf(stdout, format, args);
+       va_end(args);
+       putc('\n', stdout);
+}
+
 /*%
  * Load the zone file from disk
  */
@@ -304,7 +313,7 @@ main(int argc, char *argv[]) {
        }
 
        gdb = NULL;
-       fprintf(stderr, "Loading zone '%s' from file '%s'\n", origin, file);
+       report("Loading zone '%s' from file '%s'\n", origin, file);
        loadzone(file, origin, rdclass, &gdb);
        gorigin = dns_db_origin(gdb);
        gclass = dns_db_class(gdb);
@@ -314,7 +323,8 @@ main(int argc, char *argv[]) {
        check_result(result, "dns_db_newversion()");
 
        result = dns_zoneverify_dnssec(NULL, gdb, gversion, gorigin, NULL,
-                                      mctx, ignore_kskflag, keyset_kskonly);
+                                      mctx, ignore_kskflag, keyset_kskonly,
+                                      report);
 
        dns_db_closeversion(gdb, &gversion, false);
        dns_db_detach(&gdb);
index b432935c69f0fc753220c733f2b3f6e9cfe895a0..d9aca5b0a1388b17fde7d42a50860181131fa044 100644 (file)
@@ -43,6 +43,7 @@ isc_result_t
 dns_zoneverify_dnssec(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver,
                      dns_name_t *origin, dns_keytable_t *secroots,
                      isc_mem_t *mctx, bool ignore_kskflag,
-                     bool keyset_kskonly);
+                     bool keyset_kskonly,
+                     void (*report)(const char *, ...));
 
 ISC_LANG_ENDDECLS
index 25e93d10473a8cc6073606926695d61a3c8bf3cf..100477eeb9e1a106dfb97ee03628edcb5d8e0846 100644 (file)
@@ -19881,7 +19881,7 @@ dns_zone_verifydb(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver) {
 
        origin = dns_db_origin(db);
        result = dns_zoneverify_dnssec(zone, db, version, origin, secroots,
-                                      zone->mctx, true, false);
+                                      zone->mctx, true, false, dnssec_report);
 
  done:
        if (secroots != NULL) {
index 29a06c4757a9d5aa4b5f3b6f7e7c349e1469bf7f..3d75efb7ceacacaa38a6c65bd4105d34ccb1b2f4 100644 (file)
@@ -116,23 +116,6 @@ zoneverify_log_error(const vctx_t *vctx, const char *fmt, ...) {
        va_end(ap);
 }
 
-/*%
- * If invoked from a standalone tool, print a message described by 'fmt' and
- * the variable arguments following it to stderr.
- */
-static void
-zoneverify_print(const vctx_t *vctx, const char *fmt, ...) {
-       va_list ap;
-
-       if (vctx->zone != NULL) {
-               return;
-       }
-
-       va_start(ap, fmt);
-       vfprintf(stderr, fmt, ap);
-       va_end(ap);
-}
-
 static bool
 is_delegation(const vctx_t *vctx, const dns_name_t *name, dns_dbnode_t *node,
              uint32_t *ttlp)
@@ -1679,13 +1662,13 @@ check_dnskey(vctx_t *vctx) {
 
 static void
 determine_active_algorithms(vctx_t *vctx, bool ignore_kskflag,
-                           bool keyset_kskonly)
+                           bool keyset_kskonly,
+                           void (*report)(const char *, ...))
 {
        char algbuf[DNS_SECALG_FORMATSIZE];
        int i;
 
-       zoneverify_print(vctx,
-                        "Verifying the zone using the following algorithms:");
+       report("Verifying the zone using the following algorithms:");
 
        for (i = 0; i < 256; i++) {
                if (ignore_kskflag) {
@@ -1698,10 +1681,10 @@ determine_active_algorithms(vctx_t *vctx, bool ignore_kskflag,
                }
                if (vctx->act_algorithms[i] != 0) {
                        dns_secalg_format(i, algbuf, sizeof(algbuf));
-                       zoneverify_print(vctx, " %s", algbuf);
+                       report(" %s", algbuf);
                }
        }
-       zoneverify_print(vctx, ".\n");
+       report(".\n");
 
        if (ignore_kskflag || keyset_kskonly) {
                return;
@@ -1930,7 +1913,7 @@ verify_nodes(vctx_t *vctx, isc_result_t *vresult) {
 }
 
 static isc_result_t
-check_bad_algorithms(const vctx_t *vctx) {
+check_bad_algorithms(const vctx_t *vctx, void (*report)(const char *, ...)) {
        char algbuf[DNS_SECALG_FORMATSIZE];
        bool first = true;
        int i;
@@ -1940,28 +1923,27 @@ check_bad_algorithms(const vctx_t *vctx) {
                        continue;
                }
                if (first) {
-                       zoneverify_print(vctx,
-                                        "The zone is not fully signed for "
-                                        "the following algorithms:");
+                       report("The zone is not fully signed "
+                              "for the following algorithms:");
                }
                dns_secalg_format(i, algbuf, sizeof(algbuf));
-               zoneverify_print(vctx, " %s", algbuf);
+               report(" %s", algbuf);
                first = false;
        }
 
        if (!first) {
-               zoneverify_print(vctx, ".\n");
+               report(".\n");
        }
 
        return (first ? ISC_R_SUCCESS : ISC_R_FAILURE);
 }
 
 static void
-print_summary(const vctx_t *vctx, bool keyset_kskonly) {
+print_summary(const vctx_t *vctx, bool keyset_kskonly, void (*report)(const char *, ...)) {
        char algbuf[DNS_SECALG_FORMATSIZE];
        int i;
 
-       zoneverify_print(vctx, "Zone fully signed:\n");
+       report("Zone fully signed:\n");
        for (i = 0; i < 256; i++) {
                if ((vctx->ksk_algorithms[i] == 0) &&
                    (vctx->standby_ksk[i] == 0) &&
@@ -1973,20 +1955,18 @@ print_summary(const vctx_t *vctx, bool keyset_kskonly) {
                        continue;
                }
                dns_secalg_format(i, algbuf, sizeof(algbuf));
-               zoneverify_print(vctx,
-                                "Algorithm: %s: KSKs: "
-                                "%u active, %u stand-by, %u revoked\n",
-                                algbuf, vctx->ksk_algorithms[i],
-                                vctx->standby_ksk[i],
-                                vctx->revoked_ksk[i]);
-               zoneverify_print(vctx,
-                                "%*sZSKs: "
-                                "%u active, %u %s, %u revoked\n",
-                                (int)strlen(algbuf) + 13, "",
-                                vctx->zsk_algorithms[i],
-                                vctx->standby_zsk[i],
-                                keyset_kskonly ? "present" : "stand-by",
-                                vctx->revoked_zsk[i]);
+               report("Algorithm: %s: KSKs: "
+                      "%u active, %u stand-by, %u revoked\n",
+                      algbuf, vctx->ksk_algorithms[i],
+                      vctx->standby_ksk[i],
+                      vctx->revoked_ksk[i]);
+               report("%*sZSKs: "
+                      "%u active, %u %s, %u revoked\n",
+                      (int)strlen(algbuf) + 13, "",
+                      vctx->zsk_algorithms[i],
+                      vctx->standby_zsk[i],
+                      keyset_kskonly ? "present" : "stand-by",
+                      vctx->revoked_zsk[i]);
        }
 }
 
@@ -1994,7 +1974,8 @@ isc_result_t
 dns_zoneverify_dnssec(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver,
                      dns_name_t *origin, dns_keytable_t *secroots,
                      isc_mem_t *mctx, bool ignore_kskflag,
-                     bool keyset_kskonly)
+                     bool keyset_kskonly,
+                     void (*report)(const char *, ...))
 {
        const char *keydesc = (secroots == NULL ? "self-signed" : "trusted");
        isc_result_t result, vresult = ISC_R_UNSET;
@@ -2028,7 +2009,8 @@ dns_zoneverify_dnssec(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver,
                goto done;
        }
 
-       determine_active_algorithms(&vctx, ignore_kskflag, keyset_kskonly);
+       determine_active_algorithms(&vctx, ignore_kskflag, keyset_kskonly,
+                                   report);
 
        result = verify_nodes(&vctx, &vresult);
        if (result != ISC_R_SUCCESS) {
@@ -2043,22 +2025,21 @@ dns_zoneverify_dnssec(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver,
                vresult = result;
        }
 
-       result = check_bad_algorithms(&vctx);
+       result = check_bad_algorithms(&vctx, report);
        if (result != ISC_R_SUCCESS) {
-               zoneverify_print(&vctx, "DNSSEC completeness test failed.\n");
+               report("DNSSEC completeness test failed.\n");
                goto done;
        }
 
        result = vresult;
        if (result != ISC_R_SUCCESS) {
-               zoneverify_print(&vctx,
-                                "DNSSEC completeness test failed (%s).\n",
-                                dns_result_totext(result));
+               report("DNSSEC completeness test failed (%s).\n",
+                      dns_result_totext(result));
                goto done;
        }
 
        if (vctx.goodksk || ignore_kskflag) {
-               print_summary(&vctx, keyset_kskonly);
+               print_summary(&vctx, keyset_kskonly, report);
        }
 
  done: