From b69ff1c846250939de3e4f32ff4d07d6ee415009 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 30 Mar 2016 21:35:31 +0200 Subject: Add validatechain.c and move some code to common.c. dns-net2wire.c is nothing but an ugly hack on top of getdns_query.c making it save answer, validation_chain and trust anchors to three separate files. Used for testing purposes. validatechain takes the above mentioned three files as input and performs DNSSEC validation. --- tools/dnssec/dns-wire2text.c | 62 +++----------------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) (limited to 'tools/dnssec/dns-wire2text.c') diff --git a/tools/dnssec/dns-wire2text.c b/tools/dnssec/dns-wire2text.c index 896fc6e..1443bc4 100644 --- a/tools/dnssec/dns-wire2text.c +++ b/tools/dnssec/dns-wire2text.c @@ -9,6 +9,7 @@ #include #include #include +#include "common.h" #undef DEBUG @@ -34,63 +35,6 @@ hd(const char *buf, size_t buf_len) #define hd(a,b) #endif -#define CHUNKSIZE 4096 - -static size_t -read_inbuf(FILE *infp, uint8_t **bufp_out) -{ - size_t nread = 0; - uint8_t *wirebuf = malloc(CHUNKSIZE); - int chunks = 1; - - if (wirebuf == NULL) - goto out; - - while (1) - { - size_t n = fread(wirebuf + nread, 1, CHUNKSIZE, infp); - nread += n; - if (n < CHUNKSIZE) - break; /* Done. */ - - wirebuf = realloc(wirebuf, ++chunks * CHUNKSIZE); - if (wirebuf == NULL) - break; - } - - out: - if (bufp_out != NULL) - *bufp_out = wirebuf; - return nread; -} - -static getdns_return_t -wire_rrs2list(const uint8_t *buf, size_t buf_len, getdns_list **list_out) -{ - getdns_return_t r = GETDNS_RETURN_GOOD; - getdns_list *list = getdns_list_create(); - getdns_dict *dict = NULL; - size_t rr_count = 0; - - if (list == NULL) - return GETDNS_RETURN_MEMORY_ERROR; - while (buf_len > 0) - { - r = getdns_wire2rr_dict_scan(&buf, &buf_len, &dict); - if (r) - break; - r = getdns_list_set_dict(list, rr_count, dict); - getdns_dict_destroy(dict); /* The list has a copy. */ - if (r) - break; - rr_count++; - } - - if (list_out) - *list_out = list; - return r; -} - int main(int argc, char *argv[]) { @@ -108,10 +52,10 @@ main(int argc, char *argv[]) /* Read RRs in wire format. */ uint8_t *inbuf = NULL; - size_t inbuf_len = read_inbuf(infp, &inbuf); + size_t inbuf_len = read_buffer(infp, &inbuf, 0); if (inbuf == NULL) { - perror("read_inbuf"); + perror("read_buffer"); return errno; } if (infp != stdin) -- cgit v1.1