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/net2wire.c | 105 +----------------------------------------------- 1 file changed, 2 insertions(+), 103 deletions(-) (limited to 'tools/dnssec/net2wire.c') diff --git a/tools/dnssec/net2wire.c b/tools/dnssec/net2wire.c index f97483f..bbf1269 100644 --- a/tools/dnssec/net2wire.c +++ b/tools/dnssec/net2wire.c @@ -22,108 +22,7 @@ #include #include -static int debug = 1; - -static getdns_return_t -dump_reply(FILE *fp, getdns_dict *reply, const char *section_name) -{ - getdns_list *section = NULL; - size_t section_len = -1; - getdns_return_t r; - uint8_t res_buf[4096], *res = NULL; - size_t res_len = sizeof(res_buf); - - r = getdns_dict_get_list(reply, section_name, §ion); - if (r) { - fprintf(stderr, - "unable to get section \"%s\" from reply\n", - section_name); - return r; - } - - r = getdns_list_get_length(section, §ion_len); - if (r) { - fprintf(stderr, "unable to get length of section\n"); - return r; - } - - for (size_t j = 0; j < section_len; j++) { - getdns_dict *rr = NULL; - - r = getdns_list_get_dict(section, j , &rr); - if (r) { - fprintf(stderr, "unable to get rr from entry " - "%d: %d\n", j, r); - return r; - } - - r = getdns_rr_dict2wire(rr, &res, &res_len); - if (r) { - fprintf(stderr, - "unable to convert entry %d " - "to wire format: %d\n", j, r); - return r; - } - - if (0 && debug) { - char *s = getdns_pretty_print_dict(rr); - puts(s); - free(s); - } - - if (fwrite(res, 1, res_len, fp) != res_len) { - fprintf(stderr, - "unable to write buffer to file: %s\n", - strerror(errno)); - return -errno; - } - - free(res); - } - - return 0; -} - -int -dump_tree(FILE *fp, const getdns_dict *response, const char *tree_name) -{ - getdns_return_t r; - getdns_list *tree = NULL; - size_t n_replies = -1; - - r = getdns_dict_get_list(response, tree_name, &tree); - if (r) { - fprintf(stderr, "unable to get tree %s\n", tree_name); - return r; - } - - r = getdns_list_get_length(tree, &n_replies); - if (r) { - fprintf(stderr, "unable to get number of replies\n"); - return r; - } - - for (size_t i = 0; i < n_replies; i++) { - getdns_dict *reply = NULL; - - r = getdns_list_get_dict(tree, i, &reply); - if (r) { - fprintf(stderr, "unable to get reply %d from tree\n", i); - return r; - } - - if (debug) { - char *s = getdns_pretty_print_dict(reply); - printf("Pretty-printing reply #%d:%s\n", i, s); - free(s); - } - - dump_reply(fp, reply, "answer"); - } - - return 0; -} - +#include "common.h" /* Set up the callback function, which will also do the processing of the results */ void callback(getdns_context *context, @@ -171,7 +70,7 @@ void callback(getdns_context *context, static char *TREES[] = {"replies_tree", "validation_chain"}; static const int TREES_LEN = 2; for (int i = 0; i < TREES_LEN; i++) { - if (dump_tree(treeoutfp, response, TREES[i])) + if (dump_tree(treeoutfp, response, TREES[i], "answer")) fprintf(stderr, "Could not dump %s to file\n", TREES[i]); else if ((r = getdns_dict_get_bindata(response, "/just_address_answers/0/address_data", &address_data))) -- cgit v1.1