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;
}
/* 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:
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);
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;
}
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) {
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 */
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);
LDNS_FREE(rd);
LDNS_FREE(rd_buf);
ldns_buffer_free(rr_buf);
+ ldns_rr_free(new);
return NULL;
}
}
LDNS_FREE(rd);
LDNS_FREE(rd_buf);
ldns_buffer_free(rr_buf);
+ ldns_rr_free(new);
return NULL;
}
LDNS_FREE(rd);
LDNS_FREE(rd_buf);
ldns_buffer_free(rr_buf);
+ ldns_rr_free(new);
return NULL;
}
}
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;
}
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 {
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, ".");*/
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);
}