4 #include <netinet/in.h>
6 #include <sys/socket.h>
15 #include "minires/minires.h"
16 #include "arpa/nameser.h"
18 #include <isc-dhcp/dst.h>
22 res_nsendsigned(res_state statp,
23 double *msg, unsigned msglen, ns_tsig_key *key,
24 double *answer, unsigned anslen, unsigned *anssize)
31 unsigned bufsize, siglen;
40 nstatp = (res_state) malloc(sizeof(*statp));
42 return ISC_R_NOMEMORY;
43 memcpy(nstatp, statp, sizeof(*statp));
45 bufsize = msglen + 1024;
46 newmsg = (double *) malloc(bufsize);
48 return ISC_R_NOMEMORY;
49 memcpy(newmsg, msg, msglen);
52 if (ns_samename(key->alg, NS_TSIG_ALG_HMAC_MD5) != 1)
55 dstkey = dst_buffer_to_key(key->name, KEY_HMAC_MD5,
56 NS_KEY_TYPE_AUTH_ONLY,
67 rcode = ns_sign((u_char *)newmsg, &newmsglen, bufsize,
68 NOERROR, dstkey, NULL, 0,
70 if (rcode != ISC_R_SUCCESS) {
76 if (newmsglen > PACKETSZ || (nstatp->options & RES_IGNTC))
79 nstatp->options |= RES_IGNTC;
81 nstatp->options |= RES_USEVC;
85 rcode = res_nsend(nstatp, newmsg, newmsglen, answer, anslen, &ret);
86 if (rcode != ISC_R_SUCCESS) {
93 rcode = ns_verify((u_char *)answer, &anslen, dstkey, sig, siglen,
94 NULL, NULL, &tsig_time,
95 (nstatp->options & RES_KEEPTSIG) ? 1 : 0);
96 if (rcode != ISC_R_SUCCESS) {
97 Dprint(nstatp->pfcode & RES_PRF_REPLY,
98 (stdout, ";; TSIG invalid (%s)\n", p_rcode(ret)));
103 Dprint(nstatp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n"));
105 hp = (HEADER *) answer;
106 if (hp->tc && usingTCP == 0) {
107 nstatp->options &= ~RES_IGNTC;
115 return ISC_R_SUCCESS;