3 #include "port_before.h"
4 #include "fd_setsize.h"
9 #include <netinet/in.h>
10 #include <arpa/nameser.h>
11 #include <arpa/inet.h>
23 #include "port_after.h"
26 #include "res_debug.h"
29 /*% res_nsendsigned */
31 res_nsendsigned(res_state statp
, const u_char
*msg
, int msglen
,
32 ns_tsig_key
*key
, u_char
*answer
, int anslen
)
38 int newmsglen
, bufsize
, siglen
;
47 nstatp
= (res_state
) malloc(sizeof(*statp
));
52 memcpy(nstatp
, statp
, sizeof(*statp
));
54 bufsize
= msglen
+ 1024;
55 newmsg
= (u_char
*) malloc(bufsize
);
61 memcpy(newmsg
, msg
, msglen
);
64 if (ns_samename(key
->alg
, NS_TSIG_ALG_HMAC_MD5
) != 1)
67 dstkey
= dst_buffer_to_key(key
->name
, KEY_HMAC_MD5
,
68 NS_KEY_TYPE_AUTH_ONLY
,
80 ret
= ns_sign(newmsg
, &newmsglen
, bufsize
, NOERROR
, dstkey
, NULL
, 0,
86 if (ret
== NS_TSIG_ERROR_NO_SPACE
)
93 if (newmsglen
> PACKETSZ
|| nstatp
->options
& RES_USEVC
)
96 nstatp
->options
|= RES_IGNTC
;
98 nstatp
->options
|= RES_USEVC
;
100 * Stop res_send printing the answer.
102 nstatp
->options
&= ~RES_DEBUG
;
103 nstatp
->pfcode
&= ~RES_PRF_REPLY
;
107 len
= res_nsend(nstatp
, newmsg
, newmsglen
, answer
, anslen
);
111 dst_free_key(dstkey
);
115 ret
= ns_verify(answer
, &len
, dstkey
, sig
, siglen
,
116 NULL
, NULL
, &tsig_time
, nstatp
->options
& RES_KEEPTSIG
);
118 Dprint((statp
->options
& RES_DEBUG
) ||
119 ((statp
->pfcode
& RES_PRF_REPLY
) &&
120 (statp
->pfcode
& RES_PRF_HEAD1
)),
121 (stdout
, ";; got answer:\n"));
123 DprintQ((statp
->options
& RES_DEBUG
) ||
124 (statp
->pfcode
& RES_PRF_REPLY
),
126 answer
, (anslen
> len
) ? len
: anslen
);
129 Dprint(statp
->pfcode
& RES_PRF_REPLY
,
130 (stdout
, ";; server rejected TSIG (%s)\n",
133 Dprint(statp
->pfcode
& RES_PRF_REPLY
,
134 (stdout
, ";; TSIG invalid (%s)\n",
140 dst_free_key(dstkey
);
148 hp
= (HEADER
*) answer
;
149 if (hp
->tc
&& !usingTCP
&& (statp
->options
& RES_IGNTC
) == 0U) {
150 nstatp
->options
&= ~RES_IGNTC
;
154 Dprint((statp
->options
& RES_DEBUG
) ||
155 ((statp
->pfcode
& RES_PRF_REPLY
) &&
156 (statp
->pfcode
& RES_PRF_HEAD1
)),
157 (stdout
, ";; got answer:\n"));
159 DprintQ((statp
->options
& RES_DEBUG
) ||
160 (statp
->pfcode
& RES_PRF_REPLY
),
162 answer
, (anslen
> len
) ? len
: anslen
);
164 Dprint(statp
->pfcode
& RES_PRF_REPLY
, (stdout
, ";; TSIG ok\n"));
168 dst_free_key(dstkey
);