Commit ad98a869 authored by Mark Andrews's avatar Mark Andrews
Browse files

1747. [func] Make public the function to read a key file,

                        dst_key_read_public(). [RT #12450]
parent 00661650
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
......
......@@ -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);
}
......
......@@ -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);
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment