]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1747. [func] Make public the function to read a key file,
authorMark Andrews <marka@isc.org>
Thu, 14 Oct 2004 05:55:52 +0000 (05:55 +0000)
committerMark Andrews <marka@isc.org>
Thu, 14 Oct 2004 05:55:52 +0000 (05:55 +0000)
                        dst_key_read_public(). [RT #12450]

CHANGES
lib/dns/sec/dst/dst_api.c
lib/dns/sec/dst/include/dst/dst.h

diff --git a/CHANGES b/CHANGES
index 849e7b1c55fd716664f96f28c6c36ae1eeb5a4f6..84f7525cef6db8565fef058a438f7077642c72b6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+1747.  [func]          Make public the function to read a key file,
+                       dst_key_read_public(). [RT #12450]
+
 1745.  [placeholder]   rt12745
 
 1744.  [bug]           If tuple2msgname() failed to convert a tuple to
index 8d12bee55e1d749475fd37f464153a6b3128dad9..4d8c0b28c9c2c5d50c0be787124c39b61082d41b 100644 (file)
@@ -18,7 +18,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: dst_api.c,v 1.118 2004/10/01 00:10:59 marka Exp $
+ * $Id: dst_api.c,v 1.119 2004/10/14 05:55:51 marka Exp $
  */
 
 #include <config.h>
@@ -69,10 +69,6 @@ static dst_key_t *   get_key_struct(dns_name_t *name,
                                       unsigned int bits,
                                       dns_rdataclass_t rdclass,
                                       isc_mem_t *mctx);
-static isc_result_t    read_public_key(const char *filename,
-                                       int type,
-                                       isc_mem_t *mctx,
-                                       dst_key_t **keyp);
 static isc_result_t    write_public_key(const dst_key_t *key, int type,
                                         const char *directory);
 static isc_result_t    buildfilename(dns_name_t *name,
@@ -392,7 +388,15 @@ dst_key_fromnamedfile(const char *filename, int type, isc_mem_t *mctx,
        REQUIRE(mctx != NULL);
        REQUIRE(keyp != NULL && *keyp == NULL);
 
-       result = read_public_key(filename, type, mctx, &pubkey);
+       newfilenamelen = strlen(filename) + 5;
+       newfilename = isc_mem_get(mctx, newfilenamelen);
+       if (newfilename == NULL)
+               return (ISC_R_NOMEMORY);
+       result = addsuffix(newfilename, newfilenamelen, filename, ".key");
+       INSIST(result == ISC_R_SUCCESS);
+
+       result = dst_key_read_public(newfilename, type, mctx, &pubkey);
+       isc_mem_put(mctx, newfilename, newfilenamelen);
        if (result != ISC_R_SUCCESS)
                return (result);
 
@@ -825,9 +829,9 @@ get_key_struct(dns_name_t *name, unsigned int alg,
 /*
  * Reads a public key from disk
  */
-static isc_result_t
-read_public_key(const char *filename, int type,
-               isc_mem_t *mctx, dst_key_t **keyp)
+isc_result_t
+dst_key_read_public(const char *filename, int type,
+                   isc_mem_t *mctx, dst_key_t **keyp)
 {
        u_char rdatabuf[DST_KEY_MAXSIZE];
        isc_buffer_t b;
@@ -837,25 +841,16 @@ read_public_key(const char *filename, int type,
        isc_result_t ret;
        dns_rdata_t rdata = DNS_RDATA_INIT;
        unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
-       char *newfilename;
-       unsigned int newfilenamelen;
        dns_rdataclass_t rdclass = dns_rdataclass_in;
        isc_lexspecials_t specials;
        isc_uint32_t ttl;
        isc_result_t result;
        dns_rdatatype_t keytype;
 
-       newfilenamelen = strlen(filename) + 5;
-       newfilename = isc_mem_get(mctx, newfilenamelen);
-       if (newfilename == NULL)
-               return (ISC_R_NOMEMORY);
-       ret = addsuffix(newfilename, newfilenamelen, filename, ".key");
-       INSIST(ret == ISC_R_SUCCESS);
-
        /*
         * Open the file and read its formatted contents
         * File format:
-        *    domain.name [ttl] [class] KEY <flags> <protocol> <algorithm> <key>
+        *    domain.name [ttl] [class] [KEY|DNSKEY] <flags> <protocol> <algorithm> <key>
         */
 
        /* 1500 should be large enough for any key */
@@ -870,7 +865,7 @@ read_public_key(const char *filename, int type,
        isc_lex_setspecials(lex, specials);
        isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);
 
-       ret = isc_lex_openfile(lex, newfilename);
+       ret = isc_lex_openfile(lex, filename);
        if (ret != ISC_R_SUCCESS)
                goto cleanup;
 
@@ -942,8 +937,6 @@ read_public_key(const char *filename, int type,
  cleanup:
        if (lex != NULL)
                isc_lex_destroy(&lex);
-       isc_mem_put(mctx, newfilename, newfilenamelen);
-
        return (ret);
 }
 
index 0589efe110886edeb7495644b50e1c0ea20b3cbe..20dd8136cd2a79fda988b242e839ff01765834f2 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dst.h,v 1.48 2004/06/11 00:27:01 marka Exp $ */
+/* $Id: dst.h,v 1.49 2004/10/14 05:55:52 marka Exp $ */
 
 #ifndef DST_DST_H
 #define DST_DST_H 1
@@ -253,6 +253,29 @@ dst_key_fromnamedfile(const char *filename, int type, isc_mem_t *mctx,
  *     If successful, *keyp will contain a valid key.
  */
 
+
+isc_result_t
+dst_key_read_public(const char *filename, int type,
+                   isc_mem_t *mctx, dst_key_t **keyp);
+/*
+ * Reads a public key from permanent storage.  The key must be a public key.
+ *
+ * Requires:
+ *     "filename" is not NULL
+ *     "type" is DST_TYPE_KEY look for a KEY record otherwise DNSKEY
+ *     "mctx" is a valid memory context
+ *     "keyp" is not NULL and "*keyp" is NULL.
+ *
+ * Returns:
+ *     ISC_R_SUCCESS
+ *      DST_R_BADKEYTYPE if the key type is not the expected one
+ *      ISC_R_UNEXPECTEDTOKEN if the file can not be parsed as a public key
+ *     any other result indicates failure
+ *
+ * Ensures:
+ *     If successful, *keyp will contain a valid key.
+ */
+
 isc_result_t
 dst_key_tofile(const dst_key_t *key, int type, const char *directory);
 /*