[BACK]Return to dighost.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / dig

Diff for /src/usr.bin/dig/dighost.c between version 1.25 and 1.26

version 1.25, 2020/02/25 18:10:17 version 1.26, 2020/09/13 09:33:39
Line 56 
Line 56 
 #include <isc/hex.h>  #include <isc/hex.h>
 #include <isc/log.h>  #include <isc/log.h>
 #include <isc/netaddr.h>  #include <isc/netaddr.h>
 #include <isc/parseint.h>  
 #include <isc/result.h>  #include <isc/result.h>
 #include <isc/serial.h>  #include <isc/serial.h>
 #include <isc/sockaddr.h>  #include <isc/sockaddr.h>
Line 911 
Line 910 
         isc_buffer_free(&namebuf);          isc_buffer_free(&namebuf);
 }  }
   
 static isc_result_t  
 parse_uint_helper(uint32_t *uip, const char *value, uint32_t max,  
                   const char *desc, int base) {  
         uint32_t n;  
         isc_result_t result = isc_parse_uint32(&n, value, base);  
         if (result == ISC_R_SUCCESS && n > max)  
                 result = ISC_R_RANGE;  
         if (result != ISC_R_SUCCESS) {  
                 printf("invalid %s '%s': %s\n", desc,  
                        value, isc_result_totext(result));  
                 return (result);  
         }  
         *uip = n;  
         return (ISC_R_SUCCESS);  
 }  
   
 isc_result_t  
 parse_uint(uint32_t *uip, const char *value, uint32_t max,  
            const char *desc) {  
         return (parse_uint_helper(uip, value, max, desc, 10));  
 }  
   
 isc_result_t  
 parse_xint(uint32_t *uip, const char *value, uint32_t max,  
            const char *desc) {  
         return (parse_uint_helper(uip, value, max, desc, 0));  
 }  
   
 static uint32_t  static uint32_t
 parse_bits(char *arg, const char *desc, uint32_t max) {  parse_bits(char *arg, uint32_t max) {
         isc_result_t result;  
         uint32_t tmp;          uint32_t tmp;
           const char *errstr;
   
         result = parse_uint(&tmp, arg, max, desc);          tmp = strtonum(arg, 0, max, &errstr);
         if (result != ISC_R_SUCCESS)          if (errstr != NULL)
                 fatal("couldn't parse digest bits");                  fatal("digest bits is %s: '%s'", errstr, arg);
         tmp = (tmp + 7) & ~0x7U;          tmp = (tmp + 7) & ~0x7U;
         return (tmp);          return (tmp);
 }  }
   
 isc_result_t  isc_result_t
 parse_netprefix(isc_sockaddr_t **sap, const char *value) {  parse_netprefix(isc_sockaddr_t **sap, const char *value) {
         isc_result_t result = ISC_R_SUCCESS;  
         isc_sockaddr_t *sa = NULL;          isc_sockaddr_t *sa = NULL;
         struct in_addr in4;          struct in_addr in4;
         struct in6_addr in6;          struct in6_addr in6;
Line 962 
Line 932 
         isc_boolean_t parsed = ISC_FALSE;          isc_boolean_t parsed = ISC_FALSE;
         isc_boolean_t prefix_parsed = ISC_FALSE;          isc_boolean_t prefix_parsed = ISC_FALSE;
         char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX/128")];          char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX/128")];
           const char *errstr;
   
         REQUIRE(sap != NULL && *sap == NULL);          REQUIRE(sap != NULL && *sap == NULL);
   
Line 982 
Line 953 
         slash = strchr(buf, '/');          slash = strchr(buf, '/');
         if (slash != NULL) {          if (slash != NULL) {
                 *slash = '\0';                  *slash = '\0';
                 result = isc_parse_uint32(&prefix_length, slash + 1, 10);                  prefix_length = strtonum(slash + 1, 0, 10, &errstr);
                 if (result != ISC_R_SUCCESS) {                  if (errstr != NULL) {
                         fatal("invalid prefix length in '%s': %s\n",                          fatal("prefix length is %s: '%s'", errstr, value);
                               value, isc_result_totext(result));  
                 }                  }
                 prefix_parsed = ISC_TRUE;                  prefix_parsed = ISC_TRUE;
         }          }
Line 1048 
Line 1018 
                 digestbits = 0;                  digestbits = 0;
         } else if (strncasecmp(buf, "hmac-sha1-", 10) == 0) {          } else if (strncasecmp(buf, "hmac-sha1-", 10) == 0) {
                 hmacname = DNS_TSIG_HMACSHA1_NAME;                  hmacname = DNS_TSIG_HMACSHA1_NAME;
                 digestbits = parse_bits(&buf[10], "digest-bits [0..160]", 160);                  digestbits = parse_bits(&buf[10], 160);
         } else if (strcasecmp(buf, "hmac-sha224") == 0) {          } else if (strcasecmp(buf, "hmac-sha224") == 0) {
                 hmacname = DNS_TSIG_HMACSHA224_NAME;                  hmacname = DNS_TSIG_HMACSHA224_NAME;
         } else if (strncasecmp(buf, "hmac-sha224-", 12) == 0) {          } else if (strncasecmp(buf, "hmac-sha224-", 12) == 0) {
                 hmacname = DNS_TSIG_HMACSHA224_NAME;                  hmacname = DNS_TSIG_HMACSHA224_NAME;
                 digestbits = parse_bits(&buf[12], "digest-bits [0..224]", 224);                  digestbits = parse_bits(&buf[12], 224);
         } else if (strcasecmp(buf, "hmac-sha256") == 0) {          } else if (strcasecmp(buf, "hmac-sha256") == 0) {
                 hmacname = DNS_TSIG_HMACSHA256_NAME;                  hmacname = DNS_TSIG_HMACSHA256_NAME;
         } else if (strncasecmp(buf, "hmac-sha256-", 12) == 0) {          } else if (strncasecmp(buf, "hmac-sha256-", 12) == 0) {
                 hmacname = DNS_TSIG_HMACSHA256_NAME;                  hmacname = DNS_TSIG_HMACSHA256_NAME;
                 digestbits = parse_bits(&buf[12], "digest-bits [0..256]", 256);                  digestbits = parse_bits(&buf[12], 256);
         } else if (strcasecmp(buf, "hmac-sha384") == 0) {          } else if (strcasecmp(buf, "hmac-sha384") == 0) {
                 hmacname = DNS_TSIG_HMACSHA384_NAME;                  hmacname = DNS_TSIG_HMACSHA384_NAME;
         } else if (strncasecmp(buf, "hmac-sha384-", 12) == 0) {          } else if (strncasecmp(buf, "hmac-sha384-", 12) == 0) {
                 hmacname = DNS_TSIG_HMACSHA384_NAME;                  hmacname = DNS_TSIG_HMACSHA384_NAME;
                 digestbits = parse_bits(&buf[12], "digest-bits [0..384]", 384);                  digestbits = parse_bits(&buf[12], 384);
         } else if (strcasecmp(buf, "hmac-sha512") == 0) {          } else if (strcasecmp(buf, "hmac-sha512") == 0) {
                 hmacname = DNS_TSIG_HMACSHA512_NAME;                  hmacname = DNS_TSIG_HMACSHA512_NAME;
         } else if (strncasecmp(buf, "hmac-sha512-", 12) == 0) {          } else if (strncasecmp(buf, "hmac-sha512-", 12) == 0) {
                 hmacname = DNS_TSIG_HMACSHA512_NAME;                  hmacname = DNS_TSIG_HMACSHA512_NAME;
                 digestbits = parse_bits(&buf[12], "digest-bits [0..512]", 512);                  digestbits = parse_bits(&buf[12], 512);
         } else {          } else {
                 fprintf(stderr, ";; Warning, ignoring "                  fprintf(stderr, ";; Warning, ignoring "
                         "invalid TSIG algorithm %s\n", buf);                          "invalid TSIG algorithm %s\n", buf);
Line 1346 
Line 1316 
         isc_buffer_t b;          isc_buffer_t b;
         isc_boolean_t found = ISC_FALSE;          isc_boolean_t found = ISC_FALSE;
         unsigned int i;          unsigned int i;
           const char *errstr;
   
         if (lookup->ednsoptscnt >= EDNSOPT_OPTIONS)          if (lookup->ednsoptscnt >= EDNSOPT_OPTIONS)
                 fatal("too many ednsopts");                  fatal("too many ednsopts");
Line 1359 
Line 1330 
         }          }
   
         if (!found) {          if (!found) {
                 result = parse_uint(&num, code, 65535, "ednsopt");                  num = strtonum(code, 0, 65535, &errstr);
                 if (result != ISC_R_SUCCESS)                  if (errstr != NULL)
                         fatal("bad edns code point: %s", code);                          fatal("edns code point is %s: '%s'", errstr, code);
         }          }
   
         if (lookup->ednsopts == NULL) {          if (lookup->ednsopts == NULL) {

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26