From: Willem Toorop Date: Thu, 21 Aug 2014 14:32:25 +0000 (+0200) Subject: Make drill accept dig style -y option too X-Git-Tag: release-1.7.0-rc1~157 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f370d0521890360aa9f00aed629917d7ae6a793;p=thirdparty%2Fldns.git Make drill accept dig style -y option too (-y <[algo:]name:key> i.s.o. -y ) --- diff --git a/Changelog b/Changelog index 8ac521fc..b43ad596 100644 --- a/Changelog +++ b/Changelog @@ -14,6 +14,8 @@ TBD * bugfix #573: ldns-keygen write private keys with mode 0600. Thanks Leon Weber * Fix configure to make ldns compile with LibreSSL 2.0 + * drill now also accepts dig style -y option + (-y <[algo:]name:key> i.s.o. -y ) 1.6.17 2014-01-10 * Fix ldns_dnssec_zone_new_frm_fp_l to allow the last parsed line of a diff --git a/drill/drill.c b/drill/drill.c index ea360241..5307e61f 100644 --- a/drill/drill.c +++ b/drill/drill.c @@ -376,9 +376,7 @@ main(int argc, char *argv[]) tsig_algorithm[strlen(optarg) - tsig_separator2 - 1] = '\0'; } else { tsig_separator2 = strlen(optarg); - tsig_algorithm = xmalloc(26); - strncpy(tsig_algorithm, "hmac-md5.sig-alg.reg.int.", 25); - tsig_algorithm[25] = '\0'; + tsig_algorithm = strdup("hmac-md5.sig-alg.reg.int"); } tsig_name = xmalloc(tsig_separator + 1); tsig_data = xmalloc(tsig_separator2 - tsig_separator); @@ -599,6 +597,39 @@ main(int argc, char *argv[]) } if (tsig_name && tsig_data) { + /* With dig TSIG keys are also specified with -y, + * but format with drill is: -y + * and with dig: -y [hmac:]name:key + * + * When we detect an unknown tsig algorithm in algo, + * but a known algorithm in name, we cane assume dig + * order was used. + * + * Following if statement is to anticipate and correct dig order + */ + if ( strcasecmp(tsig_algorithm, "hmac-md5.sig-alg.reg.int") + && strcasecmp(tsig_algorithm, "hmac-md5") + && strcasecmp(tsig_algorithm, "hmac-sha1") + && strcasecmp(tsig_algorithm, "hmac-sha256") + && ( + strcasecmp(tsig_name, "hmac-md5.sig-alg.reg.int") == 0 + || strcasecmp(tsig_name, "hmac-md5") == 0 + || strcasecmp(tsig_name, "hmac-sha1") == 0 + || strcasecmp(tsig_name, "hmac-sha256") == 0 + )) { + + /* Roll options */ + char *tmp_tsig_algorithm = tsig_name; + tsig_name = tsig_data; + tsig_data = tsig_algorithm; + tsig_algorithm = tmp_tsig_algorithm; + } + + if (strcasecmp(tsig_algorithm, "hmac-md5") == 0) { + free(tsig_algorithm); + tsig_algorithm = strdup("hmac-md5.sig-alg.reg.int"); + } + ldns_resolver_set_tsig_keyname(res, tsig_name); ldns_resolver_set_tsig_keydata(res, tsig_data); ldns_resolver_set_tsig_algorithm(res, tsig_algorithm);