]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] printable NSID logging
authorEvan Hunt <each@isc.org>
Tue, 4 Mar 2014 04:51:14 +0000 (20:51 -0800)
committerEvan Hunt <each@isc.org>
Tue, 4 Mar 2014 04:51:14 +0000 (20:51 -0800)
3774. [func] When using "request-nsid", log the NSID value in
printable form as well as hex. [RT #20864]

CHANGES
lib/dns/resolver.c

diff --git a/CHANGES b/CHANGES
index f7d94c7a8bdc201f6bb14ee87cd828dc18e689cc..4dd640903ca2b62dcf26368b27653c596bf58eb3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3774.  [func]          When using "request-nsid", log the NSID value in
+                       printable form as well as hex. [RT #20864]
+
 3773.  [func]          "host", "nslookup" and "nsupdate" now have
                        options to print the version number and exit.
                        [RT #26057]
index 0e0e9033476634a8f697d69f5af0f527dd16e592..048a4f5fce9e062f1a572a5cfaa0c5fb3f6b6057 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id$ */
-
 /*! \file */
 
 #include <config.h>
+#include <ctype.h>
 
 #include <isc/log.h>
 #include <isc/platform.h>
@@ -6936,21 +6935,33 @@ log_nsid(isc_buffer_t *opt, size_t nsid_len, resquery_t *query,
        static const char hex[17] = "0123456789abcdef";
        char addrbuf[ISC_SOCKADDR_FORMATSIZE];
        isc_uint16_t buflen, i;
-       unsigned char *p, *buf, *nsid;
+       unsigned char *p, *buf, *pbuf, *nsid;
 
        /* Allocate buffer for storing hex version of the NSID */
        buflen = (isc_uint16_t)nsid_len * 2 + 1;
        buf = isc_mem_get(mctx, buflen);
        if (buf == NULL)
                return;
+       pbuf = isc_mem_get(mctx, nsid_len);
+       if (pbuf == NULL)
+               goto cleanup;
 
        /* Convert to hex */
        p = buf;
        nsid = isc_buffer_current(opt);
        for (i = 0; i < nsid_len; i++) {
-               *p++ = hex[(nsid[0] >> 4) & 0xf];
-               *p++ = hex[nsid[0] & 0xf];
-               nsid++;
+               *p++ = hex[(nsid[i] >> 4) & 0xf];
+               *p++ = hex[nsid[i] & 0xf];
+       }
+       *p = '\0';
+
+       /* Make printable version */
+       p = pbuf;
+       for (i = 0; i < nsid_len; i++) {
+               if (isprint(nsid[i]))
+                       *p++ = nsid[i];
+               else
+                       *p++ = '.';
        }
        *p = '\0';
 
@@ -6958,11 +6969,9 @@ log_nsid(isc_buffer_t *opt, size_t nsid_len, resquery_t *query,
                            sizeof(addrbuf));
        isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER,
                      DNS_LOGMODULE_RESOLVER, level,
-                     "received NSID '%s' from %s", buf, addrbuf);
-
-       /* Clean up */
+                     "received NSID %s (\"%s\") from %s", buf, pbuf, addrbuf);
+ cleanup:
        isc_mem_put(mctx, buf, buflen);
-       return;
 }
 
 static isc_boolean_t