]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
read keys, some small fixes
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Thu, 11 Aug 2005 13:09:33 +0000 (13:09 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Thu, 11 Aug 2005 13:09:33 +0000 (13:09 +0000)
keys.c
rr.c
signzone.c
zone.c

diff --git a/keys.c b/keys.c
index 5a02971c8ee9e1bf2ea829ada7ca2bafb266a05a..bf00eea5767fb9ec368e6656cae70cc39e250755 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -85,7 +85,7 @@ ldns_key_new_frm_fp(FILE *fp)
                return NULL;
        }
        if (strncmp(d, "v1.2", strlen(d)) != 0) {
-               printf("Wrong version\n");
+               printf("Wrong version. This version of ldns only supports 1.2\n");
                return NULL;
        }
 
@@ -96,19 +96,23 @@ ldns_key_new_frm_fp(FILE *fp)
                /* no version information */
                return NULL;
        }
-       if (strncmp(d, "1 RSA", strlen(d)) == 0) {
+
+       if (strncmp(d, "1 RSA", 2) == 0) {
                alg = LDNS_SIGN_RSAMD5; /* md5, really?? */
        }
-       if (strncmp(d, "3 DSA", strlen(d)) == 0) {
+       if (strncmp(d, "3 DSA", 2) == 0) {
                alg = LDNS_SIGN_DSA; 
        }
+       if (strncmp(d, "5 RSASHA1", 2) == 0) {
+               alg = LDNS_SIGN_RSASHA1;
+       }
 
        LDNS_FREE(d);
 
        switch(alg) {
                case 0:
                default:
-                       printf("No algorithm seen, bailing out\n");
+                       printf("No or unknown algorithm seen, bailing out\n");
                        return NULL;
                case LDNS_SIGN_RSAMD5:
                case LDNS_SIGN_RSASHA1:
diff --git a/rr.c b/rr.c
index ded4f77ad2f68f148e7980d840dcae0ab7627249..d206739a51fd4bc97e2479011ef00dbfd2b439c6 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -23,6 +23,7 @@ ldns_rr_new(void)
                 return NULL;
        }
        
+       ldns_rr_set_owner(rr, NULL);
        ldns_rr_set_rd_count(rr, 0);
        rr->_rdata_fields = NULL; 
        ldns_rr_set_ttl(rr, 0);
@@ -129,7 +130,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
        rr_buf = LDNS_MALLOC(ldns_buffer);
        rd_buf = LDNS_MALLOC(ldns_buffer);
        rd = LDNS_XMALLOC(char, LDNS_MAX_RDFLEN);
-       if (!owner || !ttl || !clas || !rdata ||
+       if (!new || !owner || !ttl || !clas || !rdata ||
                        !rr_buf || !rd_buf || !rd) {
                return NULL;
        }
@@ -148,6 +149,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                LDNS_FREE(rd);
                LDNS_FREE(rd_buf);
                ldns_buffer_free(rr_buf); 
+               ldns_rr_free(new);
                return NULL;
        }
        if (ldns_bget_token(rr_buf, ttl, "\t\n ", 21) == -1) {
@@ -158,6 +160,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                LDNS_FREE(rd);
                LDNS_FREE(rd_buf);
                ldns_buffer_free(rr_buf);
+               ldns_rr_free(new);
                return NULL;
        }
        ttl_val = ldns_str2period(ttl, &endptr); /* i'm not using endptr */
@@ -191,6 +194,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                        LDNS_FREE(rd);
                        LDNS_FREE(rd_buf);
                        ldns_buffer_free(rr_buf);
+                       ldns_rr_free(new);
                        return NULL;
                }
                clas_val = ldns_get_rr_class_by_name(clas);
@@ -215,6 +219,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                        LDNS_FREE(rd);
                        LDNS_FREE(rd_buf);
                        ldns_buffer_free(rr_buf);
+                       ldns_rr_free(new);
                        return NULL;
                }
        }
@@ -227,6 +232,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                LDNS_FREE(rd);
                LDNS_FREE(rd_buf);
                ldns_buffer_free(rr_buf);
+               ldns_rr_free(new);
                return NULL;
        }
 
@@ -258,6 +264,7 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                                        LDNS_FREE(rd);
                                        LDNS_FREE(rd_buf);
                                        ldns_buffer_free(rr_buf);
+                                       ldns_rr_free(new);
                                        return NULL;
                                }
                        }
index 75d629f6b28882d0ab3972d93fa14995f0e71219..9cfca3fced565904f91e05a463cc6758d33455a8 100644 (file)
 
 int
 usage(FILE *fp, char *prog) {
-       fprintf(fp, "%s [OPTIONS] <zone name> <zonefile> <keyfile>\n", prog);
+       fprintf(fp, "%s [OPTIONS] <zone name> <zonefile> <keyfile(s)>\n", prog);
        fprintf(fp, "  signs the zone with the given private key\n");
 fprintf(fp, "currently only reads zonefile and prints it\n");
 fprintf(fp, "todo: settable ttl, class?");
+fprintf(fp, "you can specify multiple keyfiles");
        return 0;
 }
 
@@ -25,16 +26,23 @@ main(int argc, char *argv[])
        const char *zonefile_name;
        FILE *zonefile = NULL;
        const char *zone_name = NULL;
-       
+       int argi;
+
        ldns_zone *orig_zone = NULL;
        ldns_rr_list *orig_rrs = NULL;
        ldns_rr *orig_soa = NULL;
+
+       FILE *keyfile = NULL;
+       ldns_key *key = NULL;
+       ldns_key_list *keys;
        
        ldns_rdf *origin = NULL;
        uint16_t ttl = 0;
        ldns_rr_class class = LDNS_RR_CLASS_IN; 
+
+       ldns_rr_list *rrs;
        
-       if (argc != 3) {
+       if (argc < 3) {
                usage(stdout, argv[0]);
                exit(1);
        } else {
@@ -42,6 +50,31 @@ main(int argc, char *argv[])
                zonefile_name = argv[2];
        }
 
+       keys = ldns_key_list_new();
+
+       argi = 3;
+       while (argi < argc) {
+               keyfile = fopen(argv[argi], "r");
+               if (!keyfile) {
+                       fprintf(stderr, "Error: unable to read k%s (%s)\n", argv[argi], strerror(errno));
+               } else {
+                       key = ldns_key_new_frm_fp(keyfile);
+                       if (key) {
+                               ldns_key_list_push_key(keys, key);
+                       } else {
+                               fprintf(stderr, "Error reading key from %s\n", argv[argi]);
+                       }
+                       fclose(keyfile);
+               }
+               argi++;
+       }
+       
+       if (ldns_key_list_key_count(keys) < 1) {
+               fprintf(stderr, "Error: no keys to sign with. Aborting.\n\n");
+               usage(stderr, argv[0]);
+               return 1;
+       }
+
        if (!origin) {
                /* default to root origin */
                /*origin = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, ".");*/
@@ -60,12 +93,18 @@ main(int argc, char *argv[])
                if (!orig_zone) {
                        fprintf(stderr, "Zone not read\n");
                } else {
-                       printf("Zone read\n");
+                       printf("Zone read.\nSOA:\n");
                        orig_soa = ldns_zone_soa(orig_zone);
                        orig_rrs = ldns_zone_rrs(orig_zone);
+
                        ldns_rr_print(stdout, orig_soa);
-                       ldns_rr_list_print(stdout, orig_rrs);
-               
+                       printf("\n");
+
+                       rrs = ldns_rr_list_new();
+                       ldns_rr_list_push_rr(rrs, orig_soa);
+                       ldns_rr_list_cat(rrs, orig_rrs);
+
+                       ldns_rr_list_free(rrs);
                        ldns_zone_deep_free(orig_zone);
                }
 
diff --git a/zone.c b/zone.c
index e81eb613ca84c7a9b1dee4f96321c355902ea242..81c30ea6745a63b7c7576d41a9e1ab9f756915f4 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -107,7 +107,9 @@ ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c)
        if (i > 9) {
                /* there is a lot of crap here, bail out before somebody gets
                 * hurt */
-               ldns_rr_free(rr);
+               if (rr) {
+                       ldns_rr_free(rr);
+               }
                return NULL;
        }