diff options
Diffstat (limited to 'usr/src/lib/libresolv2/common/resolv/res_sendsigned.c')
-rw-r--r-- | usr/src/lib/libresolv2/common/resolv/res_sendsigned.c | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c b/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c index 63fe5cc2d9..63ae07ce3d 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c +++ b/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c @@ -1,12 +1,3 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * No ISC copyright for this file. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include "fd_setsize.h" @@ -33,7 +24,7 @@ #include "res_debug.h" -/* res_nsendsigned */ +/*% res_nsendsigned */ int res_nsendsigned(res_state statp, const u_char *msg, int msglen, ns_tsig_key *key, u_char *answer, int anslen) @@ -47,6 +38,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen, HEADER *hp; time_t tsig_time; int ret; + int len; dst_init(); @@ -60,6 +52,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen, bufsize = msglen + 1024; newmsg = (u_char *) malloc(bufsize); if (newmsg == NULL) { + free(nstatp); errno = ENOMEM; return (-1); } @@ -95,34 +88,51 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen, return (ret); } - if (newmsglen > PACKETSZ || (nstatp->options & RES_IGNTC)) + if (newmsglen > PACKETSZ || nstatp->options & RES_USEVC) usingTCP = 1; if (usingTCP == 0) nstatp->options |= RES_IGNTC; else nstatp->options |= RES_USEVC; + /* + * Stop res_send printing the answer. + */ + nstatp->options &= ~RES_DEBUG; + nstatp->pfcode &= ~RES_PRF_REPLY; retry: - ret = res_nsend(nstatp, newmsg, newmsglen, answer, anslen); - if (ret < 0) { + len = res_nsend(nstatp, newmsg, newmsglen, answer, anslen); + if (len < 0) { free (nstatp); free (newmsg); dst_free_key(dstkey); - return (ret); + return (len); } - anslen = ret; - ret = ns_verify(answer, &anslen, dstkey, sig, siglen, + ret = ns_verify(answer, &len, dstkey, sig, siglen, NULL, NULL, &tsig_time, nstatp->options & RES_KEEPTSIG); if (ret != 0) { -#ifdef ORIGINAL_ISC_CODE - Dprint(nstatp->pfcode & RES_PRF_REPLY, - (stdout, ";; TSIG invalid (%s)\n", p_rcode(ret))); -#else - Dprint(nstatp->pfcode & RES_PRF_REPLY, - (stdout, ";; TSIG invalid (%s)\n", p_rcode(-ret))); -#endif + Dprint((statp->options & RES_DEBUG) || + ((statp->pfcode & RES_PRF_REPLY) && + (statp->pfcode & RES_PRF_HEAD1)), + (stdout, ";; got answer:\n")); + + DprintQ((statp->options & RES_DEBUG) || + (statp->pfcode & RES_PRF_REPLY), + (stdout, "%s", ""), + answer, (anslen > len) ? len : anslen); + + if (ret > 0) { + Dprint(statp->pfcode & RES_PRF_REPLY, + (stdout, ";; server rejected TSIG (%s)\n", + p_rcode(ret))); + } else { + Dprint(statp->pfcode & RES_PRF_REPLY, + (stdout, ";; TSIG invalid (%s)\n", + p_rcode(-ret))); + } + free (nstatp); free (newmsg); dst_free_key(dstkey); @@ -132,17 +142,29 @@ retry: errno = ENOTTY; return (-1); } - Dprint(nstatp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n")); hp = (HEADER *) answer; - if (hp->tc && usingTCP == 0) { + if (hp->tc && !usingTCP && (statp->options & RES_IGNTC) == 0U) { nstatp->options &= ~RES_IGNTC; usingTCP = 1; goto retry; } + Dprint((statp->options & RES_DEBUG) || + ((statp->pfcode & RES_PRF_REPLY) && + (statp->pfcode & RES_PRF_HEAD1)), + (stdout, ";; got answer:\n")); + + DprintQ((statp->options & RES_DEBUG) || + (statp->pfcode & RES_PRF_REPLY), + (stdout, "%s", ""), + answer, (anslen > len) ? len : anslen); + + Dprint(statp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n")); free (nstatp); free (newmsg); dst_free_key(dstkey); - return (anslen); + return (len); } + +/*! \file */ |