]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
merged changes from 1.2.x branch (rev. 2412:2415)
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Thu, 9 Aug 2007 09:03:41 +0000 (09:03 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Thu, 9 Aug 2007 09:03:41 +0000 (09:03 +0000)
examples/ldns-key2ds.1
examples/ldns-key2ds.c
higher.c
resolver.c
rr.c

index c7a3ec2711f382a293e708156f29283368c3ae8d..2ff8771a2d976075ba963e9c65f29d7fe82c6098 100644 (file)
@@ -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<name>+<alg>+<id>).
 
+.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.
 
index 10848dfe35c545d435196bb41180e416dfd12b75..7d3d030af2dbb5c4f90aa487b6e100c67aa4ba98 100644 (file)
 
 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<name>+<alg>+<id>.ds\n");
        fprintf(fp, "  The base name (K<name>+<alg>+<id> 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);
index 4c966b86499cad5f2830eea4649ec001488d9a09..f1777088a863c1b7fb694d2e6c9036cca2d81c24 100644 (file)
--- 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);
index 58bf03603d9488680754cc6fad34a603857ac1b8..50af35f3c2a4b15416cc873aae5a88dd9841e483 100644 (file)
@@ -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 0192c920de32e4ad65b1e021e9ef47347d9d5375..7a450df1a291c7b1b1f1caa78cdf54b2b274b4ec 100644 (file)
--- 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;