From: Jelte Jansen Date: Thu, 9 Aug 2007 09:03:41 +0000 (+0000) Subject: merged changes from 1.2.x branch (rev. 2412:2415) X-Git-Tag: ldns-1.3.0_pre_20070822~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc03d97bf10fbf939bfb8fd3c7b4b7bea2cba0c5;p=thirdparty%2Fldns.git merged changes from 1.2.x branch (rev. 2412:2415) --- diff --git a/examples/ldns-key2ds.1 b/examples/ldns-key2ds.1 index c7a3ec27..2ff8771a 100644 --- a/examples/ldns-key2ds.1 +++ b/examples/ldns-key2ds.1 @@ -12,6 +12,20 @@ it will create a .ds file with the DS RR in it. It prints out the basename for this file (K++). +.SH OPTIONS +.TP +\fB-n\fR +Write the result DS Resource Record to stdout instead of a file + +.TP +\fB-1\fR +Use SHA1 as the hash function (default) + +.TP +\fB-2\fR +Use SHA256 as the hash function + + .SH AUTHOR Written by the ldns team as an example for ldns usage. diff --git a/examples/ldns-key2ds.c b/examples/ldns-key2ds.c index 10848dfe..7d3d030a 100644 --- a/examples/ldns-key2ds.c +++ b/examples/ldns-key2ds.c @@ -15,13 +15,14 @@ void usage(FILE *fp, char *prog) { - fprintf(fp, "%s [-1|-2] keyfile\n", prog); + fprintf(fp, "%s [-n] [-1|-2] keyfile\n", prog); fprintf(fp, " Generate a DS RR from the key\n"); fprintf(fp, " The following file will be created: "); fprintf(fp, "K++.ds\n"); fprintf(fp, " The base name (K++ will be printed to stdout\n"); fprintf(fp, "Options:\n"); - fprintf(fp, " -1 (default): use SHA1 for the DS hash\n"); + fprintf(fp, " -n: do not write to file but to stdout\n"); + fprintf(fp, " -1: (default): use SHA1 for the DS hash\n"); fprintf(fp, " -2: use SHA256 for the DS hash\n"); } @@ -36,6 +37,7 @@ main(int argc, char *argv[]) ldns_signing_algorithm alg; ldns_hash h; char *program = argv[0]; + int nofile = 0; ldns_rdf *origin = NULL; ldns_status result; @@ -52,7 +54,10 @@ main(int argc, char *argv[]) fprintf(stderr, "Error: Crypto library does not support SHA256 digests!"); #endif h = LDNS_SHA256; - } + } + if (strcmp(argv[0], "-n") == 0) { + nofile=1; + } argv++, argc--; } @@ -95,18 +100,21 @@ main(int argc, char *argv[]) dsname = LDNS_XMALLOC(char, strlen(owner) + 16); snprintf(dsname, strlen(owner) + 15, "K%s+%03u+%05u.ds", owner, alg, (unsigned int) ldns_calc_keytag(k)); - dsfp = fopen(dsname, "w"); - if (!dsfp) { - fprintf(stderr, "Unable to open %s: %s\n", dsname, strerror(errno)); - exit(EXIT_FAILURE); - } else { - ldns_rr_print(dsfp, ds); - fclose(dsfp); + if (nofile) + ldns_rr_print(stdout,ds); + else { + dsfp = fopen(dsname, "w"); + if (!dsfp) { + fprintf(stderr, "Unable to open %s: %s\n", dsname, strerror(errno)); + exit(EXIT_FAILURE); + } else { + ldns_rr_print(dsfp, ds); + fclose(dsfp); + fprintf(stdout, "K%s+%03u+%05u\n", owner, alg, (unsigned int) ldns_calc_keytag(k)); + } } ldns_rr_free(ds); - fprintf(stdout, "K%s+%03u+%05u\n", owner, alg, (unsigned int) ldns_calc_keytag(k)); - ldns_rr_free(k); free(owner); LDNS_FREE(dsname); diff --git a/higher.c b/higher.c index 4c966b86..f1777088 100644 --- a/higher.c +++ b/higher.c @@ -29,7 +29,6 @@ ldns_get_rr_list_addr_by_name(ldns_resolver *res, ldns_rdf *name, ldns_rr_class ldns_rr_list *hostsfilenames; size_t i; uint8_t ip6; - ldns_rr_list *hostsfile; a = NULL; aaaa = NULL; @@ -208,7 +207,7 @@ ldns_get_rr_list_hosts_frm_fp_l(FILE *fp, int *line_nr) "%s IN A %s", word, addr); } parse_result = ldns_rr_new_frm_str(&rr, rr_str, 0, NULL, NULL); - if (parse_result == LDNS_STATUS_OK) { + if (parse_result == LDNS_STATUS_OK && ldns_rr_owner(rr) && ldns_rr_rd_count(rr) > 0) { ldns_rr_list_push_rr(list, ldns_rr_clone(rr)); } ldns_rr_free(rr); diff --git a/resolver.c b/resolver.c index 58bf0360..50af35f3 100644 --- a/resolver.c +++ b/resolver.c @@ -296,7 +296,11 @@ ldns_resolver_push_nameserver_rr(ldns_resolver *r, ldns_rr *rr) return LDNS_STATUS_ERR; } address = ldns_rr_rdf(rr, 0); /* extract the ip number */ - return ldns_resolver_push_nameserver(r, address); + if (address) { + return ldns_resolver_push_nameserver(r, address); + } else { + return LDNS_STATUS_ERR; + } } ldns_status diff --git a/rr.c b/rr.c index 0192c920..7a450df1 100644 --- a/rr.c +++ b/rr.c @@ -1150,13 +1150,17 @@ ldns_rr_clone(const ldns_rr *rr) if (!new_rr) { return NULL; } - ldns_rr_set_owner(new_rr, ldns_rdf_clone(ldns_rr_owner(rr))); + if (ldns_rr_owner(rr)) { + ldns_rr_set_owner(new_rr, ldns_rdf_clone(ldns_rr_owner(rr))); + } ldns_rr_set_ttl(new_rr, ldns_rr_ttl(rr)); ldns_rr_set_type(new_rr, ldns_rr_get_type(rr)); ldns_rr_set_class(new_rr, ldns_rr_get_class(rr)); for (i = 0; i < ldns_rr_rd_count(rr); i++) { - ldns_rr_push_rdf(new_rr, ldns_rdf_clone(ldns_rr_rdf(rr, i))); + if (ldns_rr_rdf(rr,i)) { + ldns_rr_push_rdf(new_rr, ldns_rdf_clone(ldns_rr_rdf(rr, i))); + } } return new_rr;