]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
completed ldns-rrsig and made a few changes to the library
authorMiek Gieben <miekg@NLnetLabs.nl>
Mon, 21 Nov 2005 10:38:27 +0000 (10:38 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Mon, 21 Nov 2005 10:38:27 +0000 (10:38 +0000)
examples/Makefile.in
examples/ldns-rrsig.1
examples/ldns-rrsig.c
ldns/rdata.h
ldns/rr.h
rdata.c
rr.c

index 769fb7c8c0eb6e255ea8af892446205a2437cb97..dc85f6311a16cfea308b8e0d1ad886c94ff7c622 100644 (file)
@@ -21,15 +21,16 @@ COMPILE         = $(CC) $(CPPFLAGS) $(CFLAGS)
 LINK            = $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS)
 
 HEADER         = config.h
-PROGRAMS       = ldns-read-zone \
-                 ldns-mx \
-                 ldns-chaos \
-                 ldns-update \
-                 ldns-keygen \
-                 ldns-key2ds \
-                 ldns-signzone \
-                 ldns-version \
-                 ldns-rrsig
+SOURCES        = ldns-read-zone.c \
+                 ldns-mx.c \
+                 ldns-chaos.c \
+                 ldns-update.c \
+                 ldns-keygen.c \
+                 ldns-key2ds.c \
+                 ldns-signzone.c \
+                 ldns-version.c \
+                 ldns-rrsig.c
+PROGRAMS=$(SOURCES:.c=)
 
 .PHONY:        all clean realclean
 
@@ -63,8 +64,8 @@ ldns-rrsig:   ldns-rrsig.o
                $(LINK) -o $@ $+
 
 ## implicit rule
-%.o:
-       $(COMPILE) -c $(srcdir)/$*.c
+%.o:   $(srcdir)/%.c
+       $(COMPILE) -c $(srcdir)/$<
 
 clean:
        rm -f *.o
index 9cd76126633631456c0bb13e4196fe7da0dc1185..3aee863e057d42736626c34e76190fd23e154268 100644 (file)
@@ -4,18 +4,19 @@ ldns-rrsig \- print out the inception and expiration dates in human
 readable form
 .SH SYNOPSIS
 .B ldns-rrsig 
-.IR [
--t
+.IR domain
+[ 
+.IR type 
 ]
 
-.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.
+a RRSIG. The first argument is a domain name. \fBldns-rrsig\fR will
+query the authoritative servers for that domain to get a list of RRSIGs.
+It will then print out the inception and experiration dates for the RRSIG
+covering the SOA record.
+.PP
+If the second argument \fBtype\fR is given the RRSIG covering that type will be shown.
 
 .SH AUTHOR
 Written by the ldns team as an example for ldns usage.
index c99ec87a7a7e3ddc7364beae0abd4b0ca6dddaad..b054d188c5c81cd2c6e088a7965bec33a474dd7c 100644 (file)
 
 int
 usage(FILE *fp, char *prog) {
-       fprintf(fp, "%s domain\n", prog);
+       fprintf(fp, "%s domain [type]\n", prog);
        fprintf(fp, "  print out the inception and expiration dates\n");
        fprintf(fp, "  in a more human readable form\n");
-       fprintf(fp, "  -t <type>\tquery for RRSIG(<type>)\n");
+       fprintf(fp, "  <type>\tquery for RRSIG(<type>), defaults to SOA\n");
        return 0;
 }
 
@@ -31,6 +31,7 @@ main(int argc, char *argv[])
        ldns_rr_list *ns_ip;
        uint8_t i, j;
        ldns_rr_type t;
+       char * type_name;
        time_t incep, expir;
        char incep_buf[26];
        char expir_buf[26];
@@ -41,11 +42,10 @@ main(int argc, char *argv[])
        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) {
+       if (argc < 2) {
                usage(stdout, argv[0]);
                exit(EXIT_FAILURE);
        } else {
@@ -57,6 +57,20 @@ main(int argc, char *argv[])
                }
        }
 
+       if (argc == 3) {
+               /* optional type arg */
+               type_name = strdup(argv[2]);
+               t = ldns_rdf2rr_type(
+                       ldns_rdf_new_frm_str(LDNS_RDF_TYPE_TYPE, type_name));
+               if (t == 0) {
+                       fprintf(stderr, " *** %s is not a valid RR type\n", type_name);
+                       exit(EXIT_FAILURE);
+               }
+       } else {
+               t = LDNS_RR_TYPE_SOA; 
+               type_name = "SOA";
+       }
+
        /* create a new resolver from /etc/resolv.conf */
        localres = ldns_resolver_new_frm_file(NULL);
 
@@ -124,24 +138,20 @@ main(int argc, char *argv[])
                } 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(
+                               if (ldns_rdf2rr_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));
-
+                       if (ldns_rr_list_rr_count(rrsig_type) == 0) {
+                               fprintf(stderr, " *** No RRSIG(%S) type found\n",
+                                       type_name);
+                               exit(EXIT_FAILURE);
+                       }
+                       
                        for(i = 0; i < ldns_rr_list_rr_count(rrsig_type); i++) {
                                incep = ldns_rdf2native_time_t(
                                        ldns_rr_rrsig_inception(
@@ -157,11 +167,8 @@ main(int argc, char *argv[])
                                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);
-
-
+                               fprintf(stdout, "%s RRSIG(%s):  %s - %s\n",
+                                       argv[1], type_name, incep_buf, expir_buf);
                        }
 
                }
index ec89c27248e64c530f0a1ff2791e1019cd260da6..42fd1fb49f25ab91841a61f22ac4e15472346b04 100644 (file)
@@ -286,28 +286,28 @@ ldns_rdf  *ldns_rdf_address_reverse(ldns_rdf *rd);
  * \param[in] rd the ldns_rdf to operate on
  * \return uint8_t the value extracted
  */
-uint8_t                ldns_rdf2native_int8(ldns_rdf *rd);
+uint8_t                ldns_rdf2native_int8(const ldns_rdf *rd);
 
 /** 
  * returns the native uint16_t representation from the rdf.
  * \param[in] rd the ldns_rdf to operate on
  * \return uint16_t the value extracted
  */
-uint16_t       ldns_rdf2native_int16(ldns_rdf *rd);
+uint16_t       ldns_rdf2native_int16(const ldns_rdf *rd);
 
 /** 
  * returns the native uint32_t representation from the rdf.
  * \param[in] rd the ldns_rdf to operate on
  * \return uint32_t the value extracted
  */
-uint32_t       ldns_rdf2native_int32(ldns_rdf *rd);
+uint32_t       ldns_rdf2native_int32(const ldns_rdf *rd);
 
 /** 
  * returns the native time_t representation from the rdf.
  * \param[in] rd the ldns_rdf to operate on
  * \return time_t the value extracted (32 bits currently)
  */
-time_t                 ldns_rdf2native_time_t(ldns_rdf *rd);
+time_t                 ldns_rdf2native_time_t(const ldns_rdf *rd);
 
 /**
  * converts a ttl value (like 5d2h) to a long.
@@ -325,7 +325,7 @@ uint32_t    ldns_str2period(const char *nptr, const char **endptr);
  * \return struct sockaddr* the address in the format so other
  * functions can use it (sendto)
  */
-struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(ldns_rdf *rd, uint16_t port, size_t *size);
+struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size);
 
 /** 
  * returns an rdf with the sockaddr info. works for ip4 and ip6
index 885ea60254ac8940d5c876798d2b2e7b204cc88a..bd2914717ec81e7cedc9fa151c172a4a288858a9 100644 (file)
--- a/ldns/rr.h
+++ b/ldns/rr.h
@@ -674,6 +674,16 @@ ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor
  */
 ldns_rr_list *ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos);
 
+/**
+ * convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual
+ * LDNS_RR_TYPE. This is usefull in the case when inspecting
+ * the rrtype covered field of an RRSIG.
+ * \param[in] rd the rdf to look at
+ * \return a ldns_rr_type with equivalent LDNS_RR_TYPE
+ *
+ */
+ldns_rr_type    ldns_rdf2rr_type(const ldns_rdf *rd);
+
 /* added while doing lua */
 bool ldns_rr_list_insert_rr(ldns_rr_list *rr_list, ldns_rr *r, size_t count);
 
diff --git a/rdata.c b/rdata.c
index 0647c57aab60f85f594237e8a29480d2cf5e057b..052ab69440762d62e6e9869b38382d22da489649 100644 (file)
--- a/rdata.c
+++ b/rdata.c
@@ -71,51 +71,49 @@ ldns_rdf_set_data(ldns_rdf *rd, void *d)
 /* for types that allow it, return
  * the native/host order type */
 uint8_t
-ldns_rdf2native_int8(ldns_rdf *rd)
+ldns_rdf2native_int8(const ldns_rdf *rd)
 {
        uint8_t data;
-       
-       switch(ldns_rdf_get_type(rd)) {
-               case LDNS_RDF_TYPE_CLASS:
-               case LDNS_RDF_TYPE_ALG:
-               case LDNS_RDF_TYPE_INT8:
-                       memcpy(&data, ldns_rdf_data(rd), sizeof(data));
-                       return data;
-               default:
-                       return 0;
+
+       /* only allow 8 bit rdfs */
+       if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_BYTE) {
+               return 0;
        }
+       
+       memcpy(&data, ldns_rdf_data(rd), sizeof(data));
+       return data;
 }
 
 uint16_t
-ldns_rdf2native_int16(ldns_rdf *rd)
+ldns_rdf2native_int16(const ldns_rdf *rd)
 {
        uint16_t data;
-       
-       switch(ldns_rdf_get_type(rd)) {
-               case LDNS_RDF_TYPE_INT16:
-                       memcpy(&data, ldns_rdf_data(rd), sizeof(data));
-                       return ntohs(data);
-               default:
-                       return 0;
+
+       /* only allow 16 bit rdfs */
+       if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_WORD) {
+               return 0;
        }
+       
+       memcpy(&data, ldns_rdf_data(rd), sizeof(data));
+       return ntohs(data);
 }
 
 uint32_t
-ldns_rdf2native_int32(ldns_rdf *rd)
+ldns_rdf2native_int32(const ldns_rdf *rd)
 {
        uint32_t data;
-       
-       switch(ldns_rdf_get_type(rd)) {
-               case LDNS_RDF_TYPE_INT32:
-                       memcpy(&data, ldns_rdf_data(rd), sizeof(data));
-                       return ntohl(data);
-               default:
-                       return 0;
+
+       /* only allow 32 bit rdfs */
+       if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_DOUBLEWORD) {
+               return 0;
        }
+       
+       memcpy(&data, ldns_rdf_data(rd), sizeof(data));
+       return ntohl(data);
 }
 
 time_t
-ldns_rdf2native_time_t(ldns_rdf *rd)
+ldns_rdf2native_time_t(const ldns_rdf *rd)
 {
        uint32_t data;
        
@@ -129,7 +127,7 @@ ldns_rdf2native_time_t(ldns_rdf *rd)
 }
 
 struct sockaddr_storage *
-ldns_rdf2native_sockaddr_storage(ldns_rdf *rd, uint16_t port, size_t *size)
+ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size)
 {
        struct sockaddr_storage *data;
        struct sockaddr_in  *data_in;
@@ -203,7 +201,7 @@ ldns_sockaddr_storage2rdf(struct sockaddr_storage *sock, uint16_t *port)
 ldns_rdf *
 ldns_native2rdf_int8(ldns_rdf_type type, uint8_t value)
 {
-       return ldns_rdf_new_frm_data(type, 1, &value);
+       return ldns_rdf_new_frm_data(type, LDNS_RDF_SIZE_BYTE, &value);
 }
 
 ldns_rdf *
@@ -211,7 +209,7 @@ ldns_native2rdf_int16(ldns_rdf_type type, uint16_t value)
 {
        uint16_t *rdf_data = LDNS_XMALLOC(uint16_t, 1);
        ldns_write_uint16(rdf_data, value);
-       return ldns_rdf_new(type, 2, rdf_data);
+       return ldns_rdf_new(type, LDNS_RDF_SIZE_WORD, rdf_data);
 }
 
 ldns_rdf *
@@ -219,7 +217,7 @@ ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value)
 {
        uint32_t *rdf_data = LDNS_XMALLOC(uint32_t, 1);
        ldns_write_uint32(rdf_data, value);
-       return ldns_rdf_new(type, 4, rdf_data);
+       return ldns_rdf_new(type, LDNS_RDF_SIZE_DOUBLEWORD, rdf_data);
 }
 
 ldns_rdf *
diff --git a/rr.c b/rr.c
index 9867d428d8f85eb09b9626720a78205b437bbac4..c3e55c555cd0ef7c50b7c2b0d7f7109c359eacd0 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -374,8 +374,6 @@ ldns_rr_new_frm_str(const char *str, uint16_t default_ttl, ldns_rdf *origin)
                                }
                        }
        }
-       
-
        LDNS_FREE(rd);
        ldns_buffer_free(rd_buf);
        ldns_buffer_free(rr_buf);
@@ -1809,3 +1807,20 @@ ldns_get_rr_class_by_name(const char *name)
        return 0;
 }
 
+
+ldns_rr_type
+ldns_rdf2rr_type(const ldns_rdf *rd)
+{
+        ldns_rr_type r;
+
+        if (!rd) {
+                return 0;
+        }
+
+        if (ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_TYPE) {
+                return 0;
+        }
+
+        r = (ldns_rr_type) ldns_rdf2native_int16(rd);
+        return r;
+}