From: Jelte Jansen Date: Thu, 11 Aug 2005 13:09:33 +0000 (+0000) Subject: read keys, some small fixes X-Git-Tag: release-1.0.0~299 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47ccd621eaed899fae18c82ceb2a121bc367e2a1;p=thirdparty%2Fldns.git read keys, some small fixes --- diff --git a/keys.c b/keys.c index 5a02971c..bf00eea5 100644 --- 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 ded4f77a..d206739a 100644 --- 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; } } diff --git a/signzone.c b/signzone.c index 75d629f6..9cfca3fc 100644 --- a/signzone.c +++ b/signzone.c @@ -12,10 +12,11 @@ int usage(FILE *fp, char *prog) { - fprintf(fp, "%s [OPTIONS] \n", prog); + fprintf(fp, "%s [OPTIONS] \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 e81eb613..81c30ea6 100644 --- 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; }