]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
some fixes for the splitting. Add the cat. Disabled making of dpa, because the sucker...
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 14 Dec 2005 13:50:13 +0000 (13:50 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 14 Dec 2005 13:50:13 +0000 (13:50 +0000)
examples/Makefile.in
examples/ldns-zcat.c [new file with mode: 0644]
examples/ldns-zsplit.c

index 63648417090370c098cd91993b152a5cde8ca9db..9e6fe5e1f866c432b1e204260af498089394c21b 100644 (file)
@@ -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 (file)
index 0000000..57d3a91
--- /dev/null
@@ -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 <errno.h>
+#include <ldns/dns.h>
+
+void
+usage(FILE *f, char *progname)
+{
+               fprintf(f, "Usage: %s [OPTIONS] <zonefile>\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);
+}
index 66033948226dcf6c0b5afd3d4befd97335e60250..268f6d2cf58f7fe8d3e876cd76c3a4e6cc84c87e 100644 (file)
 void
 usage(FILE *f, char *progname)
 {
-               fprintf(f, "Usage: %s [OPTIONS] <zonefile>\n", progname);
+               fprintf(f, "Usage: %s [OPTIONS] <zonefile> <keys>\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 */