Commit 5d83b561 authored by Brian Wellington's avatar Brian Wellington
Browse files

Added dns_tsigrcode_totext/fromtext

parent 6afdb1e5
......@@ -56,6 +56,39 @@ isc_result_t dns_rcode_totext(dns_rcode_t rcode, isc_buffer_t *target);
* ISC_R_NOSPACE target buffer is too small
*/
isc_result_t dns_tsigrcode_fromtext(dns_rcode_t *rcodep,
isc_textregion_t *source);
/*
* Convert the text 'source' refers to into a TSIG/TKEY error value.
*
* Requires:
* 'rcodep' is a valid pointer.
*
* 'source' is a valid text region.
*
* Returns:
* ISC_R_SUCCESS on success
* DNS_R_UNKNOWN type is unknown
*/
isc_result_t dns_tsigrcode_totext(dns_rcode_t rcode, isc_buffer_t *target);
/*
* Put a textual representation of TSIG/TKEY error 'rcode' into 'target'.
*
* Requires:
* 'rcode' is a valid TSIG/TKEY error code.
*
* 'target' is a valid text buffer.
*
* Ensures:
* If the result is success:
* The used space in 'target' is updated.
*
* Returns:
* ISC_R_SUCCESS on success
* ISC_R_NOSPACE target buffer is too small
*/
ISC_LANG_ENDDECLS
#endif /* DNS_RCODE_H */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.96 2000/05/24 15:07:56 tale Exp $ */
/* $Id: rdata.c,v 1.97 2000/05/25 00:46:28 bwelling Exp $ */
#include <config.h>
#include <ctype.h>
......@@ -180,11 +180,23 @@ static const char decdigits[] = "0123456789";
{ dns_rcode_yxrrset, "YXRRSET", 0}, \
{ dns_rcode_nxrrset, "NXRRSET", 0}, \
{ dns_rcode_notauth, "NOTAUTH", 0}, \
{ dns_rcode_notzone, "NOTZONE", 0}, \
{ dns_rcode_notzone, "NOTZONE", 0},
#define ERCODENAMES \
/* extended rcodes */ \
{ dns_rcode_badvers, "BADVERS", 0}, \
{ 0, NULL, 0 }
#define TSIGRCODENAMES \
/* extended rcodes */ \
{ dns_tsigerror_badsig, "BADSIG", 0}, \
{ dns_tsigerror_badkey, "BADKEY", 0}, \
{ dns_tsigerror_badtime, "BADTIME", 0}, \
{ dns_tsigerror_badmode, "BADMODE", 0}, \
{ dns_tsigerror_badname, "BADNAME", 0}, \
{ dns_tsigerror_badalg, "BADALG", 0}, \
{ 0, NULL, 0 }
#define CERTNAMES \
{ 1, "SKIX", 0}, \
{ 2, "SPKI", 0}, \
......@@ -222,7 +234,8 @@ struct tbl {
int flags;
};
static struct tbl rcodes[] = { RCODENAMES };
static struct tbl rcodes[] = { RCODENAMES ERCODENAMES };
static struct tbl tsigrcodes[] = { RCODENAMES TSIGRCODENAMES };
static struct tbl certs[] = { CERTNAMES };
static struct tbl secalgs[] = { SECALGNAMES };
static struct tbl secprotos[] = { SECPROTONAMES };
......@@ -851,19 +864,10 @@ dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
isc_result_t
dns_rcode_fromtext(dns_rcode_t *rcodep, isc_textregion_t *source) {
int i = 0;
unsigned int n;
while (rcodes[i].name != NULL) {
n = strlen(rcodes[i].name);
if (n == source->length &&
strncasecmp(source->base, rcodes[i].name, n) == 0) {
*rcodep = rcodes[i].value;
return (ISC_R_SUCCESS);
}
i++;
}
return (DNS_R_UNKNOWN);
unsigned int value;
RETERR(dns_mnemonic_fromtext(&value, source, rcodes, 0xffff));
*rcodep = value;
return (ISC_R_SUCCESS);
}
isc_result_t
......@@ -871,6 +875,19 @@ dns_rcode_totext(dns_rcode_t rcode, isc_buffer_t *target) {
return (dns_mnemonic_totext(rcode, target, rcodes));
}
isc_result_t
dns_tsigrcode_fromtext(dns_rcode_t *rcodep, isc_textregion_t *source) {
unsigned int value;
RETERR(dns_mnemonic_fromtext(&value, source, tsigrcodes, 0xffff));
*rcodep = value;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_tsigrcode_totext(dns_rcode_t rcode, isc_buffer_t *target) {
return (dns_mnemonic_totext(rcode, target, tsigrcodes));
}
isc_result_t
dns_cert_fromtext(dns_cert_t *certp, isc_textregion_t *source) {
unsigned int value;
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: tsig_250.c,v 1.38 2000/05/22 12:37:28 marka Exp $ */
/* $Id: tsig_250.c,v 1.39 2000/05/25 00:46:31 bwelling Exp $ */
/* Reviewed: Thu Mar 16 13:39:43 PST 2000 by gson */
......@@ -36,6 +36,8 @@ fromtext_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
dns_name_t name;
isc_uint64_t sigtime;
isc_buffer_t buffer;
dns_rcode_t rcode;
long i;
char *e;
REQUIRE(type == 250);
......@@ -94,10 +96,18 @@ fromtext_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
/*
* Error.
*/
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
if (token.value.as_ulong > 0xffff)
return (ISC_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
!= ISC_R_SUCCESS)
{
i = strtol(token.value.as_pointer, &e, 10);
if (*e != 0)
return (DNS_R_UNKNOWN);
if (i < 0 || i > 0xffff)
return (ISC_R_RANGE);
rcode = (dns_rcode_t)i;
}
RETERR(uint16_tobuffer(rcode, target));
/*
* Other Len.
......@@ -206,8 +216,12 @@ totext_any_tsig(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
*/
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
RETERR(str_totext(" ", target));
else {
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
}
/*
* Other Size.
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: tkey_249.c,v 1.34 2000/05/22 12:37:59 marka Exp $ */
/* $Id: tkey_249.c,v 1.35 2000/05/25 00:46:32 bwelling Exp $ */
/*
* Reviewed: Thu Mar 16 17:35:30 PST 2000 by halley.
......@@ -78,8 +78,9 @@ fromtext_tkey(dns_rdataclass_t rdclass, dns_rdatatype_t type,
* Error.
*/
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
if (dns_rcode_fromtext(&rcode, &token.value.as_textregion)
!= ISC_R_SUCCESS) {
if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
!= ISC_R_SUCCESS)
{
i = strtol(token.value.as_pointer, &e, 10);
if (*e != 0)
return (DNS_R_UNKNOWN);
......@@ -171,7 +172,7 @@ totext_tkey(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
*/
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
if (dns_rcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
RETERR(str_totext(" ", target));
else {
sprintf(buf, "%lu ", n);
......
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