]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Have 'named -V' report geoip-directory
authorMark Andrews <marka@isc.org>
Tue, 5 Nov 2019 01:56:58 +0000 (12:56 +1100)
committerMark Andrews <marka@isc.org>
Wed, 6 Nov 2019 01:12:43 +0000 (12:12 +1100)
(cherry picked from commit 2eaa75c3801252e6dd7a40dd87618bd07a915e20)

bin/named/main.c

index 2fe6d4595d746e5f152aa9206444b08e585c33f2..4f298d35a449ebd2d27d405be9302d282ae7c04d 100644 (file)
@@ -65,6 +65,7 @@
 #define NS_MAIN 1
 
 #include <named/builtin.h>
+#include <named/config.h>
 #include <named/control.h>
 #include <named/fuzz.h>
 #include <named/globals.h>     /* Explicit, though named/log.h includes it. */
@@ -434,6 +435,114 @@ set_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
                *ret = 0;
 }
 
+static void
+printversion(bool verbose) {
+       char rndcconf[PATH_MAX], *dot = NULL;
+       isc_mem_t *mctx = NULL;
+       cfg_parser_t *parser = NULL;
+       cfg_obj_t *config = NULL;
+       const cfg_obj_t *defaults = NULL, *obj = NULL;
+
+       printf("%s %s%s%s <id:%s>\n",
+              ns_g_product, ns_g_version,
+              (*ns_g_description != '\0') ? " " : "",
+              ns_g_description, ns_g_srcid);
+
+       if (!verbose) {
+               return;
+       }
+       printf("running on %s\n", ns_os_uname());
+       printf("built by %s with %s\n", ns_g_builder, ns_g_configargs);
+#ifdef __clang__
+       printf("compiled by CLANG %s\n", __VERSION__);
+#else
+#if defined(__ICC) || defined(__INTEL_COMPILER)
+       printf("compiled by ICC %s\n", __VERSION__);
+#else
+#ifdef __GNUC__
+       printf("compiled by GCC %s\n", __VERSION__);
+#endif
+#endif
+#endif
+#ifdef _MSC_VER
+       printf("compiled by MSVC %d\n", _MSC_VER);
+#endif
+#ifdef __SUNPRO_C
+       printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
+#endif
+#ifdef OPENSSL
+       printf("compiled with OpenSSL version: %s\n", OPENSSL_VERSION_TEXT);
+#if !defined(LIBRESSL_VERSION_NUMBER) && \
+    OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 or higher */
+       printf("linked to OpenSSL version: %s\n",
+              OpenSSL_version(OPENSSL_VERSION));
+#else
+       printf("linked to OpenSSL version: %s\n",
+              SSLeay_version(SSLEAY_VERSION));
+#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
+#endif
+#ifdef HAVE_LIBXML2
+       printf("compiled with libxml2 version: %s\n", LIBXML_DOTTED_VERSION);
+       printf("linked to libxml2 version: %s\n", xmlParserVersion);
+#endif
+#if defined(HAVE_JSON) && defined(JSON_C_VERSION)
+       printf("compiled with libjson-c version: %s\n", JSON_C_VERSION);
+       printf("linked to libjson-c version: %s\n", json_c_version());
+#endif
+#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
+       printf("compiled with zlib version: %s\n", ZLIB_VERSION);
+       printf("linked to zlib version: %s\n", zlibVersion());
+#endif
+#ifdef ISC_PLATFORM_USETHREADS
+       printf("threads support is enabled\n");
+#else
+       printf("threads support is disabled\n");
+#endif
+
+       /*
+        * The default rndc.conf and rndc.key paths are in the same
+        * directory, but named only has rndc.key defined internally.
+        * We construct the rndc.conf path from it. (We could use
+        * NAMED_SYSCONFDIR here but the result would look wrong on
+        * Windows.)
+        */
+       strlcpy(rndcconf, ns_g_keyfile, sizeof(rndcconf));
+       dot = strrchr(rndcconf, '.');
+       if (dot != NULL) {
+               size_t len = dot - rndcconf + 1;
+               snprintf(dot + 1, PATH_MAX - len, "conf");
+       }
+
+#define RTC(x) RUNTIME_CHECK((x) == ISC_R_SUCCESS)
+       RTC(isc_mem_create(0, 0, &mctx));
+       RTC(cfg_parser_create(mctx, ns_g_lctx, &parser));
+       RTC(ns_config_parsedefaults(parser, &config));
+       RTC(cfg_map_get(config, "options", &defaults));
+
+       /*
+        * Print default configuration paths.
+        */
+       printf("\n");
+       printf("default paths:\n");
+       printf("  named configuration:  %s\n", ns_g_conffile);
+       printf("  rndc configuration:   %s\n", rndcconf);
+       RTC(cfg_map_get(defaults, "bindkeys-file", &obj));
+       printf("  DNSSEC root key:      %s\n", cfg_obj_asstring(obj));
+       printf("  nsupdate session key: %s\n", ns_g_defaultsessionkeyfile);
+       printf("  named PID file:       %s\n", ns_g_defaultpidfile);
+       printf("  named lock file:      %s\n", ns_g_defaultlockfile);
+#if defined(HAVE_GEOIP2)
+       obj = NULL;
+       RTC(cfg_map_get(defaults, "geoip-directory", &obj));
+       if (cfg_obj_isstring(obj)) {
+               printf("  geoip-directory:      %s\n", cfg_obj_asstring(obj));
+       }
+#endif /* HAVE_GEOIP2 */
+       cfg_obj_destroy(parser, &config);
+       cfg_parser_destroy(&parser);
+       isc_mem_detach(&mctx);
+}
+
 static void
 parse_fuzz_arg(void) {
        if (!strncmp(isc_commandline_argument, "client:", 7)) {
@@ -679,71 +788,10 @@ parse_command_line(int argc, char *argv[]) {
                        ns_g_username = isc_commandline_argument;
                        break;
                case 'v':
-                       printf("%s %s%s%s <id:%s>\n",
-                              ns_g_product, ns_g_version,
-                              (*ns_g_description != '\0') ? " " : "",
-                              ns_g_description, ns_g_srcid);
+                       printversion(false);
                        exit(0);
                case 'V':
-                       printf("%s %s%s%s <id:%s>\n", ns_g_product, ns_g_version,
-                              (*ns_g_description != '\0') ? " " : "",
-                              ns_g_description, ns_g_srcid);
-                       printf("running on %s\n", ns_os_uname());
-                       printf("built by %s with %s\n",
-                              ns_g_builder, ns_g_configargs);
-#ifdef __clang__
-                       printf("compiled by CLANG %s\n", __VERSION__);
-#else
-#if defined(__ICC) || defined(__INTEL_COMPILER)
-                       printf("compiled by ICC %s\n", __VERSION__);
-#else
-#ifdef __GNUC__
-                       printf("compiled by GCC %s\n", __VERSION__);
-#endif
-#endif
-#endif
-#ifdef _MSC_VER
-                       printf("compiled by MSVC %d\n", _MSC_VER);
-#endif
-#ifdef __SUNPRO_C
-                       printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
-#endif
-#ifdef OPENSSL
-                       printf("compiled with OpenSSL version: %s\n",
-                              OPENSSL_VERSION_TEXT);
-#if !defined(LIBRESSL_VERSION_NUMBER) && \
-    OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 or higher */
-                       printf("linked to OpenSSL version: %s\n",
-                              OpenSSL_version(OPENSSL_VERSION));
-
-#else
-                       printf("linked to OpenSSL version: %s\n",
-                              SSLeay_version(SSLEAY_VERSION));
-#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
-#endif
-#ifdef HAVE_LIBXML2
-                       printf("compiled with libxml2 version: %s\n",
-                              LIBXML_DOTTED_VERSION);
-                       printf("linked to libxml2 version: %s\n",
-                              xmlParserVersion);
-#endif
-#if defined(HAVE_JSON) && defined(JSON_C_VERSION)
-                       printf("compiled with libjson-c version: %s\n",
-                              JSON_C_VERSION);
-                       printf("linked to libjson-c version: %s\n",
-                              json_c_version());
-#endif
-#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
-                       printf("compiled with zlib version: %s\n",
-                              ZLIB_VERSION);
-                       printf("linked to zlib version: %s\n",
-                              zlibVersion());
-#endif
-#ifdef ISC_PLATFORM_USETHREADS
-                       printf("threads support is enabled\n");
-#else
-                       printf("threads support is disabled\n");
-#endif
+                       printversion(true);
                        exit(0);
                case 'x':
                        /* Obsolete. No longer in use. Ignore. */