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");
}
ldns_signing_algorithm alg;
ldns_hash h;
char *program = argv[0];
+ int nofile = 0;
ldns_rdf *origin = NULL;
ldns_status result;
fprintf(stderr, "Error: Crypto library does not support SHA256 digests!");
#endif
h = LDNS_SHA256;
- }
+ }
+ if (strcmp(argv[0], "-n") == 0) {
+ nofile=1;
+ }
argv++, argc--;
}
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);
ldns_rr_list *hostsfilenames;
size_t i;
uint8_t ip6;
- ldns_rr_list *hostsfile;
a = NULL;
aaaa = NULL;
"%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);
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;