aboutsummaryrefslogtreecommitdiff
path: root/contrib/isc-dhcp/minires/res_sendsigned.c
diff options
context:
space:
mode:
authorMurray Stokely <murray@FreeBSD.org>2002-02-19 11:04:34 +0000
committerMurray Stokely <murray@FreeBSD.org>2002-02-19 11:04:34 +0000
commitce99b771f886a2c842db7aa803c9a5a5918f42c8 (patch)
tree229464d9b3244ab78e2784c9a0a1f78de317089a /contrib/isc-dhcp/minires/res_sendsigned.c
parent7657fb140fbd218ea326d55bd3c43c4077f03d9a (diff)
downloadsrc-ce99b771f886a2c842db7aa803c9a5a5918f42c8.tar.gz
src-ce99b771f886a2c842db7aa803c9a5a5918f42c8.zip
Import ISC DHCP 3.0.1 RC6 client.
Notes
Notes: svn path=/vendor/isc-dhcp/dist/; revision=90908
Diffstat (limited to 'contrib/isc-dhcp/minires/res_sendsigned.c')
-rw-r--r--contrib/isc-dhcp/minires/res_sendsigned.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/contrib/isc-dhcp/minires/res_sendsigned.c b/contrib/isc-dhcp/minires/res_sendsigned.c
new file mode 100644
index 000000000000..be213afe7abd
--- /dev/null
+++ b/contrib/isc-dhcp/minires/res_sendsigned.c
@@ -0,0 +1,116 @@
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "minires/minires.h"
+#include "arpa/nameser.h"
+
+#include <isc-dhcp/dst.h>
+
+/* res_nsendsigned */
+isc_result_t
+res_nsendsigned(res_state statp,
+ double *msg, unsigned msglen, ns_tsig_key *key,
+ double *answer, unsigned anslen, unsigned *anssize)
+{
+ res_state nstatp;
+ DST_KEY *dstkey;
+ int usingTCP = 0;
+ double *newmsg;
+ unsigned newmsglen;
+ unsigned bufsize, siglen;
+ u_char sig[64];
+ HEADER *hp;
+ time_t tsig_time;
+ unsigned ret;
+ isc_result_t rcode;
+
+ dst_init();
+
+ nstatp = (res_state) malloc(sizeof(*statp));
+ if (nstatp == NULL)
+ return ISC_R_NOMEMORY;
+ memcpy(nstatp, statp, sizeof(*statp));
+
+ bufsize = msglen + 1024;
+ newmsg = (double *) malloc(bufsize);
+ if (newmsg == NULL)
+ return ISC_R_NOMEMORY;
+ memcpy(newmsg, msg, msglen);
+ newmsglen = msglen;
+
+ if (ns_samename(key->alg, NS_TSIG_ALG_HMAC_MD5) != 1)
+ dstkey = NULL;
+ else
+ dstkey = dst_buffer_to_key(key->name, KEY_HMAC_MD5,
+ NS_KEY_TYPE_AUTH_ONLY,
+ NS_KEY_PROT_ANY,
+ key->data, key->len);
+ if (dstkey == NULL) {
+ free(nstatp);
+ free(newmsg);
+ return ISC_R_BADKEY;
+ }
+
+ nstatp->nscount = 1;
+ siglen = sizeof(sig);
+ rcode = ns_sign((u_char *)newmsg, &newmsglen, bufsize,
+ NOERROR, dstkey, NULL, 0,
+ sig, &siglen, 0);
+ if (rcode != ISC_R_SUCCESS) {
+ free (nstatp);
+ free (newmsg);
+ return rcode;
+ }
+
+ if (newmsglen > PACKETSZ || (nstatp->options & RES_IGNTC))
+ usingTCP = 1;
+ if (usingTCP == 0)
+ nstatp->options |= RES_IGNTC;
+ else
+ nstatp->options |= RES_USEVC;
+
+retry:
+
+ rcode = res_nsend(nstatp, newmsg, newmsglen, answer, anslen, &ret);
+ if (rcode != ISC_R_SUCCESS) {
+ free (nstatp);
+ free (newmsg);
+ return rcode;
+ }
+
+ anslen = ret;
+ rcode = ns_verify((u_char *)answer, &anslen, dstkey, sig, siglen,
+ NULL, NULL, &tsig_time,
+ (nstatp->options & RES_KEEPTSIG) ? 1 : 0);
+ if (rcode != ISC_R_SUCCESS) {
+ Dprint(nstatp->pfcode & RES_PRF_REPLY,
+ (stdout, ";; TSIG invalid (%s)\n", p_rcode(ret)));
+ free (nstatp);
+ free (newmsg);
+ return rcode;
+ }
+ Dprint(nstatp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n"));
+
+ hp = (HEADER *) answer;
+ if (hp->tc && usingTCP == 0) {
+ nstatp->options &= ~RES_IGNTC;
+ usingTCP = 1;
+ goto retry;
+ }
+
+ free (nstatp);
+ free (newmsg);
+ *anssize = anslen;
+ return ISC_R_SUCCESS;
+}