summaryrefslogtreecommitdiff
path: root/usr/src/lib/libresolv2/common/dst/support.c
diff options
context:
space:
mode:
authorRao Shoaib <Rao.Shoaib@Sun.COM>2009-11-11 08:45:41 -0800
committerRao Shoaib <Rao.Shoaib@Sun.COM>2009-11-11 08:45:41 -0800
commit9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829 (patch)
treedf51891a276edf456c1481f49653a76cdfedee53 /usr/src/lib/libresolv2/common/dst/support.c
parent0324f02a004039d6377111191fdd7134452d7817 (diff)
downloadillumos-gate-9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829.tar.gz
6289479 libresolv2 clean up and alignment with libbind.6.0
Diffstat (limited to 'usr/src/lib/libresolv2/common/dst/support.c')
-rw-r--r--usr/src/lib/libresolv2/common/dst/support.c183
1 files changed, 30 insertions, 153 deletions
diff --git a/usr/src/lib/libresolv2/common/dst/support.c b/usr/src/lib/libresolv2/common/dst/support.c
index 4b3438f604..730397f4c0 100644
--- a/usr/src/lib/libresolv2/common/dst/support.c
+++ b/usr/src/lib/libresolv2/common/dst/support.c
@@ -1,11 +1,5 @@
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c,v 1.11 2001/05/29 05:48:16 marka Exp $";
+static const char rcsid[] = "$Header: /proj/cvs/prod/libbind/dst/support.c,v 1.6 2005/10/11 00:10:13 marka Exp $";
-/*
- * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
@@ -39,64 +33,8 @@ static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c,
#include "dst_internal.h"
#include "port_after.h"
-/*
- * dst_s_conv_bignum_u8_to_b64
- * This function converts binary data stored as a u_char[] to a
- * base-64 string. Leading zeroes are discarded. If a header is
- * supplied, it is prefixed to the input prior to encoding. The
- * output is \n\0 terminated (the \0 is not included in output length).
- * Parameters
- * out_buf binary data to convert
- * header character string to prefix to the output (label)
- * bin_data binary data
- * bin_len size of binary data
- * Return
- * -1 not enough space in output work area
- * 0 no output
- * >0 number of bytes written to output work area
- */
-
-int
-dst_s_conv_bignum_u8_to_b64(char *out_buf, const int out_len,
- const char *header, const u_char *bin_data,
- const int bin_len)
-{
- const u_char *bp = bin_data;
- char *op = out_buf;
- int lenh = 0, len64 = 0;
- int local_in_len = bin_len;
- int local_out_len = out_len;
-
- if (bin_data == NULL || bin_len <= 0) /* no data no */
- return (0);
- if (out_buf == NULL || out_len <= 0) /* no output_work area */
- return (-1);
-
- /* suppress leading \0 */
- for (; (*bp == 0x0) && (local_in_len > 0); local_in_len--)
- bp++;
-
- if (header) { /* add header to output string */
- lenh = strlen(header);
- if (lenh < out_len)
- memcpy(op, header, lenh);
- else
- return (-1);
- local_out_len -= lenh;
- op += lenh;
- }
- len64 = b64_ntop(bp, local_in_len, op, local_out_len - 2);
- if (len64 < 0)
- return (-1);
- op += len64++;
- *(op++) = '\n'; /* put CR in the output */
- *op = '\0'; /* make sure output is 0 terminated */
- return (lenh + len64);
-}
-
-
-/*
+/*%
* dst_s_verify_str()
* Validate that the input string(*str) is at the head of the input
* buffer(**buf). If so, move the buffer head pointer (*buf) to
@@ -114,73 +52,20 @@ int
dst_s_verify_str(const char **buf, const char *str)
{
int b, s;
- if (*buf == NULL) /* error checks */
+ if (*buf == NULL) /*%< error checks */
return (0);
if (str == NULL || *str == '\0')
return (1);
- b = strlen(*buf); /* get length of strings */
+ b = strlen(*buf); /*%< get length of strings */
s = strlen(str);
- if (s > b || strncmp(*buf, str, s)) /* check if same */
- return (0); /* not a match */
- (*buf) += s; /* advance pointer */
+ if (s > b || strncmp(*buf, str, s)) /*%< check if same */
+ return (0); /*%< not a match */
+ (*buf) += s; /*%< advance pointer */
return (1);
}
-
-/*
- * dst_s_conv_bignum_b64_to_u8
- * Read a line of base-64 encoded string from the input buffer,
- * convert it to binary, and store it in an output area. The
- * input buffer is read until reaching a newline marker or the
- * end of the buffer. The binary data is stored in the last X
- * number of bytes of the output area where X is the size of the
- * binary output. If the operation is successful, the input buffer
- * pointer is advanced. This procedure does not do network to host
- * byte order conversion.
- * Parameters
- * buf Pointer to encoded input string. Pointer is updated if
- * function is successfull.
- * loc Output area.
- * loclen Size in bytes of output area.
- * Return
- * >0 Return = number of bytes of binary data stored in loc.
- * 0 Failure.
- */
-
-int
-dst_s_conv_bignum_b64_to_u8(const char **buf, u_char *loc, const int loclen)
-{
- int blen;
- char *bp;
- u_char bstr[RAW_KEY_SIZE];
-
- if (buf == NULL || *buf == NULL) { /* error checks */
- EREPORT(("dst_s_conv_bignum_b64_to_u8: null input buffer.\n"));
- return (0);
- }
- bp = strchr(*buf, '\n'); /* find length of input line */
- if (bp != NULL)
- *bp = (u_char) NULL;
-
- blen = b64_pton(*buf, bstr, sizeof(bstr));
- if (blen <= 0) {
- EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is null.\n"));
- return (0);
- }
- else if (loclen < blen) {
- EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is longer than output buffer.\n"));
- return (0);
- }
- if (bp)
- *buf = bp; /* advancing buffer past \n */
- memset(loc, 0, loclen - blen); /* clearing unused output area */
- memcpy(loc + loclen - blen, bstr, blen); /* write last blen bytes */
- return (blen);
-}
-
-
-/*
+/*%
* dst_s_calculate_bits
* Given a binary number represented in a u_char[], determine
* the number of significant bits used.
@@ -204,8 +89,7 @@ dst_s_calculate_bits(const u_char *str, const int max_bits)
return (bits);
}
-
-/*
+/*%
* calculates a checksum used in dst for an id.
* takes an array of bytes and a length.
* returns a 16 bit checksum.
@@ -218,7 +102,7 @@ dst_s_id_calc(const u_char *key, const int keysize)
int size = keysize;
if (!key || (keysize <= 0))
- return (-1);
+ return (0xffffU);
for (ac = 0; size > 1; size -= 2, kp += 2)
ac += ((*kp) << 8) + *(kp + 1);
@@ -230,7 +114,7 @@ dst_s_id_calc(const u_char *key, const int keysize)
return (ac & 0xffff);
}
-/*
+/*%
* dst_s_dns_key_id() Function to calculate DNSSEC footprint from KEY record
* rdata
* Input:
@@ -246,7 +130,7 @@ dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len)
return 0;
/* compute id */
- if (dns_key_rdata[3] == KEY_RSA) /* Algorithm RSA */
+ if (dns_key_rdata[3] == KEY_RSA) /*%< Algorithm RSA */
return dst_s_get_int16((const u_char *)
&dns_key_rdata[rdata_len - 3]);
else if (dns_key_rdata[3] == KEY_HMAC_MD5)
@@ -257,7 +141,7 @@ dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len)
return dst_s_id_calc(dns_key_rdata, rdata_len);
}
-/*
+/*%
* dst_s_get_int16
* This routine extracts a 16 bit integer from a two byte character
* string. The character string is assumed to be in network byte
@@ -276,8 +160,7 @@ dst_s_get_int16(const u_char *buf)
return (a);
}
-
-/*
+/*%
* dst_s_get_int32
* This routine extracts a 32 bit integer from a four byte character
* string. The character string is assumed to be in network byte
@@ -297,8 +180,7 @@ dst_s_get_int32(const u_char *buf)
return (a);
}
-
-/*
+/*%
* dst_s_put_int16
* Take a 16 bit integer and store the value in a two byte
* character string. The integer is assumed to be in network
@@ -316,8 +198,7 @@ dst_s_put_int16(u_int8_t *buf, const u_int16_t val)
buf[1] = (u_int8_t)(val);
}
-
-/*
+/*%
* dst_s_put_int32
* Take a 32 bit integer and store the value in a four byte
* character string. The integer is assumed to be in network
@@ -337,13 +218,12 @@ dst_s_put_int32(u_int8_t *buf, const u_int32_t val)
buf[3] = (u_int8_t)(val);
}
-
-/*
+/*%
* dst_s_filename_length
*
* This function returns the number of bytes needed to hold the
* filename for a key file. '/', '\' and ':' are not allowed.
- * form: K<keyname>+<alg>+<id>.<suffix>
+ * form: K&lt;keyname&gt;+&lt;alg&gt;+&lt;id&gt;.&lt;suffix&gt;
*
* Returns 0 if the filename would contain either '\', '/' or ':'
*/
@@ -369,13 +249,12 @@ dst_s_filename_length(const char *name, const char *suffix)
return (1 + strlen(name) + 6 + strlen(suffix));
}
-
-/*
+/*%
* dst_s_build_filename ()
* Builds a key filename from the key name, it's id, and a
* suffix. '\', '/' and ':' are not allowed. fA filename is of the
- * form: K<keyname><id>.<suffix>
- * form: K<keyname>+<alg>+<id>.<suffix>
+ * form: K&lt;keyname&gt;&lt;id&gt;.&lt;suffix&gt;
+ * form: K&lt;keyname&gt;+&lt;alg&gt;+&lt;id&gt;.&lt;suffix&gt;
*
* Returns -1 if the conversion fails:
* if the filename would be too long for space allotted
@@ -409,7 +288,7 @@ dst_s_build_filename(char *filename, const char *name, u_int16_t id,
return (0);
}
-/*
+/*%
* dst_s_fopen ()
* Open a file in the dst_path directory. If perm is specified, the
* file is checked for existence first, and not opened if it exists.
@@ -426,19 +305,15 @@ dst_s_fopen(const char *filename, const char *mode, int perm)
{
FILE *fp;
char pathname[PATH_MAX];
- size_t plen = sizeof(pathname);
+
+ if (strlen(filename) + strlen(dst_path) >= sizeof(pathname))
+ return (NULL);
if (*dst_path != '\0') {
strcpy(pathname, dst_path);
- plen -= strlen(pathname);
- }
- else
- pathname[0] = '\0';
-
- if (plen > strlen(filename))
- strncpy(&pathname[PATH_MAX - plen], filename, plen-1);
- else
- return (NULL);
+ strcat(pathname, filename);
+ } else
+ strcpy(pathname, filename);
fp = fopen(pathname, mode);
if (perm)
@@ -463,3 +338,5 @@ dst_s_dump(const int mode, const u_char *data, const int size,
#endif
}
}
+
+/*! \file */