From: Miek Gieben Date: Wed, 14 Dec 2005 13:50:13 +0000 (+0000) Subject: some fixes for the splitting. Add the cat. Disabled making of dpa, because the sucker... X-Git-Tag: release-1.1.0~514 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fa322b9de5a7fda09323029da3493cf85b57e612;p=thirdparty%2Fldns.git some fixes for the splitting. Add the cat. Disabled making of dpa, because the sucker doesn't compile anymore...It really wasn\'t me :) --- diff --git a/examples/Makefile.in b/examples/Makefile.in index 63648417..9e6fe5e1 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -31,10 +31,10 @@ SOURCES = ldns-read-zone.c \ ldns-version.c \ ldns-rrsig.c \ ldns-walk.c \ - ldns-dpa.c \ +# ldns-dpa.c \ ldns-threshold-update.c \ - ldns-zsplit.c -# ldns-catzone.c + ldns-zsplit.c \ + ldns-zcat.c PROGRAMS=$(SOURCES:.c=) @@ -79,6 +79,9 @@ ldns-dpa: ldns-dpa.o ldns-zsplit: ldns-zsplit.o $(LINK) -o $@ $+ +ldns-zcat: ldns-zcat.o + $(LINK) -o $@ $+ + ldns-threshold-update: ldns-threshold-update.o $(LINK) -o $@ $+ diff --git a/examples/ldns-zcat.c b/examples/ldns-zcat.c new file mode 100644 index 00000000..57d3a912 --- /dev/null +++ b/examples/ldns-zcat.c @@ -0,0 +1,66 @@ +/* + * read a zone from disk and split it up: + * + * zone: SOA a b c d e f g h i j k l + * becomes: + * zone1: SOA a b c d e f + * zone2: SOA f g h i k l + * + * ldns-catzone removes the last name and put + * the zone back together. + * + * This way you can incremental sign a zone + * + * See the file LICENSE for the license + */ + +#include "config.h" +#include +#include + +void +usage(FILE *f, char *progname) +{ + fprintf(f, "Usage: %s [OPTIONS] \n", progname); + fprintf(f, "\tThe generate zone file is printed to stdout\n"); + fprintf(f, "\tDNSKEYs found in subsequent zones are removed.\n"); + fprintf(f, "-o ORIGIN\tUse this as initial origin. For zones starting with @\n"); +} + +int +main(int argc, char **argv) +{ + char *progname; + FILE *fp; + int c; + ldns_rdf *origin; + char *progname; + + progname = strdup(argv[0]); + + while ((c = getopt(argc, argv, "n:o:")) != -1) { + switch(c) { + case 'o': + origin = ldns_dname_new_frm_str(strdup(optarg)); + if (!origin) { + printf("cannot convert to dname\n"); + exit(EXIT_FAILURE); + } + break; + default: + printf("Unrecognized option\n"); + usage(stdout, progname); + exit(EXIT_FAILURE); + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) { + usage(stdout, progname); + exit(EXIT_SUCCESS); + } + + exit(EXIT_SUCCESS); +} diff --git a/examples/ldns-zsplit.c b/examples/ldns-zsplit.c index 66033948..268f6d2c 100644 --- a/examples/ldns-zsplit.c +++ b/examples/ldns-zsplit.c @@ -28,16 +28,44 @@ void usage(FILE *f, char *progname) { - fprintf(f, "Usage: %s [OPTIONS] \n", progname); + fprintf(f, "Usage: %s [OPTIONS] \n", progname); fprintf(f, "\tSplit a zone file up.\n"); + fprintf(f, "\tkeys are inserted in the apex of each generated zone.\n"); fprintf(f, "\nOPTIONS:\n"); fprintf(f, "-n NUMBER\tSplit after this many names\n"); fprintf(f, "-o ORIGIN\tUse this as initial origin. For zones starting with @\n"); } +/* key the keys from the cmd line */ +ldns_rr_list * +open_keyfiles(char **files, uint16_t filec) +{ + uint16_t i; + ldns_rr_list *pubkeys; + ldns_rr *k; + FILE *kfp; + + pubkeys = ldns_rr_list_new(); + + for (i = 0; i < filec; i++) { + if (!(kfp = fopen(files[i], "r"))) { + printf("Error opening one of the key files\n"); + return NULL; + } + if (!(k = ldns_rr_new_frm_fp(kfp, NULL, NULL, NULL))) { + printf("Error parsing the on of the files\n"); + return NULL; + } + fclose(kfp); + ldns_rr_list_push_rr(pubkeys, k); + } + return pubkeys; +} + +/* open a new zone file with the correct suffix */ FILE * -open_newfile(char *basename, ldns_zone *z, size_t counter) +open_newfile(char *basename, ldns_zone *z, size_t counter, ldns_rr_list *keys) { char filename[FILE_SIZE]; FILE *fp; @@ -56,6 +84,10 @@ open_newfile(char *basename, ldns_zone *z, size_t counter) printf("Opening %s\n", filename); } ldns_rr_print(fp, ldns_zone_soa(z)); + if (keys) { + ldns_rr_list_print(fp, keys); + + } return fp; } @@ -78,6 +110,7 @@ main(int argc, char **argv) ldns_rdf *current_rdf; ldns_rr *current_rr; ldns_rr_list *last_rrset; + ldns_rr_list *pubkeys; progname = strdup(argv[0]); split = 0; @@ -124,6 +157,10 @@ main(int argc, char **argv) fprintf(stderr, "Unable to open %s: %s\n", argv[0], strerror(errno)); exit(EXIT_FAILURE); } + + /* get the keys */ + pubkeys = open_keyfiles(argv + 1, argc - 1); + /* suck in the entire zone ... */ if (!origin) { printf("Warning no origin is given I'm using . now\n"); @@ -143,7 +180,7 @@ main(int argc, char **argv) zrrs = ldns_zone_rrs(z); /* Setup */ - if (!(fp = open_newfile(argv[0], z, file_counter))) { + if (!(fp = open_newfile(argv[0], z, file_counter, pubkeys))) { exit(EXIT_FAILURE); } @@ -174,11 +211,11 @@ main(int argc, char **argv) lastname = NULL; splitting = NO_SPLIT; file_counter++; - if (!(fp = open_newfile(argv[0], z, file_counter))) { + if (!(fp = open_newfile(argv[0], z, file_counter, pubkeys))) { exit(EXIT_FAILURE); } - /* insert the RRset in the new file */ + /* insert the last RRset in the new file */ ldns_rr_list_print(fp, last_rrset); /* print the current rr */