From: Miek Gieben Date: Wed, 16 Nov 2005 11:50:27 +0000 (+0000) Subject: new example which show the rrsig incep and expiration dates X-Git-Tag: release-1.1.0~616 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8bcd050281a0e61cbd2cb34fc30a3e867e63922;p=thirdparty%2Fldns.git new example which show the rrsig incep and expiration dates --- diff --git a/examples/Makefile.in b/examples/Makefile.in index 7da95358..769fb7c8 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -28,7 +28,8 @@ PROGRAMS = ldns-read-zone \ ldns-keygen \ ldns-key2ds \ ldns-signzone \ - ldns-version + ldns-version \ + ldns-rrsig .PHONY: all clean realclean @@ -58,6 +59,9 @@ ldns-keygen: ldns-keygen.o ldns-key2ds: ldns-key2ds.o $(LINK) -o $@ $+ +ldns-rrsig: ldns-rrsig.o + $(LINK) -o $@ $+ + ## implicit rule %.o: $(COMPILE) -c $(srcdir)/$*.c diff --git a/examples/ldns-mx.c b/examples/ldns-mx.c index 55c6f60a..ddc328c9 100644 --- a/examples/ldns-mx.c +++ b/examples/ldns-mx.c @@ -70,9 +70,7 @@ main(int argc, char *argv[]) ldns_resolver_deep_free(res); exit(EXIT_FAILURE); } else { - /* sort the list nicely */ - /* ldns_rr_list_sort(mx); */ - /* print the rrlist to stdout */ + ldns_rr_list_sort(mx); ldns_rr_list_print(stdout, mx); ldns_rr_list_deep_free(mx); } diff --git a/examples/ldns-rrsig.1 b/examples/ldns-rrsig.1 new file mode 100644 index 00000000..9cd76126 --- /dev/null +++ b/examples/ldns-rrsig.1 @@ -0,0 +1,29 @@ +.TH ldns-rrsig 1 "27 Apr 2005" +.SH NAME +ldns-rrsig \- print out the inception and expiration dates in human +readable form +.SH SYNOPSIS +.B ldns-rrsig +.IR [ +-t +] + +.IR DOMAIN + +.SH DESCRIPTION +\fBldns-rrsig\fR is used to print the expiration and inception date of +a RRSIG + +.SH OPTIONS +\fB-t\fR use the RRSIG which covers this type instead of SOA. + +.SH AUTHOR +Written by the ldns team as an example for ldns usage. + +.SH REPORTING BUGS +Report bugs to . + +.SH COPYRIGHT +Copyright (C) 2005 NLnet Labs. This is free software. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. diff --git a/examples/ldns-rrsig.c b/examples/ldns-rrsig.c new file mode 100644 index 00000000..c99ec87a --- /dev/null +++ b/examples/ldns-rrsig.c @@ -0,0 +1,172 @@ +/* + * mx is a small programs that prints out the mx records + * for a particulary domain + * (c) NLnet Labs, 2005 + * See the file LICENSE for the license + */ + +#include "config.h" + +#include + +int +usage(FILE *fp, char *prog) { + fprintf(fp, "%s domain\n", prog); + fprintf(fp, " print out the inception and expiration dates\n"); + fprintf(fp, " in a more human readable form\n"); + fprintf(fp, " -t \tquery for RRSIG()\n"); + return 0; +} + +int +main(int argc, char *argv[]) +{ + ldns_resolver *res; + ldns_resolver *localres; + ldns_rdf *domain; + ldns_pkt *p; + ldns_rr_list *rrsig; + ldns_rr_list *rrsig_type; + ldns_rr_list *ns; + ldns_rr_list *ns_ip; + uint8_t i, j; + ldns_rr_type t; + time_t incep, expir; + char incep_buf[26]; + char expir_buf[26]; + + p = NULL; + rrsig = NULL; + rrsig_type = NULL; + domain = NULL; + res = NULL; + localres = NULL; + t = LDNS_RR_TYPE_SOA; /* can be overruled on the cmd line, -t switch */ + + /* option parsing */ + + if (argc != 2) { + usage(stdout, argv[0]); + exit(EXIT_FAILURE); + } else { + /* create a rdf from the command line arg */ + domain = ldns_dname_new_frm_str(argv[1]); + if (!domain) { + usage(stdout, argv[0]); + exit(EXIT_FAILURE); + } + } + + /* create a new resolver from /etc/resolv.conf */ + localres = ldns_resolver_new_frm_file(NULL); + + if (!localres) { + exit(EXIT_FAILURE); + } + /* first get the nameserver of the domain in question */ + p = ldns_resolver_query(localres, domain, LDNS_RR_TYPE_NS, + LDNS_RR_CLASS_IN, LDNS_RD); + if (!p) { + fprintf(stderr," *** Could not find any nameserver for %s", argv[1]); + exit(EXIT_FAILURE); + } + ns = ldns_pkt_rr_list_by_type(p, LDNS_RR_TYPE_NS, LDNS_SECTION_ANSWER); + + if (!ns) { + fprintf(stderr," *** Could not find any nameserver for %s", argv[1]); + exit(EXIT_FAILURE); + } + + /* use our local resolver to resolv the names in the for usage in our + * new resolver */ + res = ldns_resolver_new(); + if (!res) { + exit(EXIT_FAILURE); + } + for(i = 0; i < ldns_rr_list_rr_count(ns); i++) { + ns_ip = ldns_get_rr_list_addr_by_name(localres, + ldns_rr_ns_nsdname(ldns_rr_list_rr(ns, i)), + LDNS_RR_CLASS_IN, LDNS_RD); + /* add these to new resolver */ + for(j = 0; j < ldns_rr_list_rr_count(ns_ip); j++) { + ldns_resolver_push_nameserver(res, + ldns_rr_a_address(ldns_rr_list_rr(ns_ip, j))); + } + + } + + /* enable DNSSEC */ + ldns_resolver_set_dnssec(res, true); + /* also set CD, we want EVERYTHING! */ + ldns_resolver_set_dnssec_cd(res, true); + + /* use the resolver to send it a query for the mx + * records of the domain given on the command line + */ + p = ldns_resolver_query(res, domain, LDNS_RR_TYPE_RRSIG, LDNS_RR_CLASS_IN, LDNS_RD); + + ldns_rdf_deep_free(domain); + + if (!p) { + exit(EXIT_FAILURE); + } else { + /* retrieve the RRSIG records from the answer section of that + * packet + */ + rrsig = ldns_pkt_rr_list_by_type(p, LDNS_RR_TYPE_RRSIG, LDNS_SECTION_ANSWER); + if (!rrsig) { + fprintf(stderr, + " *** invalid answer name %s after RRSIG query for %s\n", + argv[1], argv[1]); + ldns_pkt_free(p); + ldns_resolver_deep_free(res); + exit(EXIT_FAILURE); + } else { + rrsig_type = ldns_rr_list_new(); + + /* okay, this needs to be doctered out, the rdf type + * is LDNS_RDF_TYPE_TYPE, but I need to compare it + * with LDNS_RR_TYPEs. How to convert, do we want to + * convert? XXX */ + /* + for(i = 0; i < ldns_rr_list_rr_count(rrsig); i++) { + if (ldns_rr_get_type( + ldns_rr_rrsig_typecovered( + ldns_rr_list_rr(rrsig, i))) == t) { + ldns_rr_list_push_rr(rrsig_type, + ldns_rr_list_rr(rrsig, i)); + } + } + */ + /* FOR NOW TAKE ONLY THE FIRST ONE */ + ldns_rr_list_push_rr(rrsig_type, + ldns_rr_list_rr(rrsig, 0)); + + for(i = 0; i < ldns_rr_list_rr_count(rrsig_type); i++) { + incep = ldns_rdf2native_time_t( + ldns_rr_rrsig_inception( + ldns_rr_list_rr(rrsig_type, i))); + expir = ldns_rdf2native_time_t( + ldns_rr_rrsig_expiration( + ldns_rr_list_rr(rrsig_type, i))); + + /* convert to human readable */ + ctime_r(&incep, incep_buf); + ctime_r(&expir, expir_buf); + /* kill the newline */ + incep_buf[24] = '\0'; + expir_buf[24] = '\0'; + + /* assume SOA XXX*/ + fprintf(stdout, "%s RRSIG(SOA): %s - %s\n", + argv[1], incep_buf, expir_buf); + + + } + + } + } + ldns_pkt_free(p); + ldns_resolver_deep_free(res); + return 0; +}