support.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
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 $";
/*
* 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.
*
* Permission to use, copy modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
*/
#include "port_before.h"
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#include <string.h>
#include <errno.h>
#include <resolv.h>
#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
const int bin_len)
{
int local_in_len = bin_len;
int local_out_len = out_len;
return (0);
return (-1);
/* suppress leading \0 */
bp++;
if (header) { /* add header to output string */
else
return (-1);
local_out_len -= lenh;
}
if (len64 < 0)
return (-1);
}
/*
* 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
* the first byte of data following the string(*str).
* Parameters
* buf Input buffer.
* str Input string.
* Return
* 0 *str is not the head of **buff
* 1 *str is the head of **buff, *buf is is advanced to
* the tail of **buf.
*/
int
{
int b, s;
return (0);
return (1);
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
{
int blen;
char *bp;
EREPORT(("dst_s_conv_bignum_b64_to_u8: null input buffer.\n"));
return (0);
}
if (blen <= 0) {
EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is null.\n"));
return (0);
}
EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is longer than output buffer.\n"));
return (0);
}
if (bp)
return (blen);
}
/*
* dst_s_calculate_bits
* Given a binary number represented in a u_char[], determine
* the number of significant bits used.
* Parameters
* str An input character string containing a binary number.
* max_bits The maximum possible significant bits.
* Return
* N The number of significant bits in str.
*/
int
{
u_char i, j = 0x80;
int bits;
bits -= 8;
for (i = *p; (i & j) != j; j >>= 1)
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.
*/
{
return (-1);
if (size > 0)
return (ac & 0xffff);
}
/*
* dst_s_dns_key_id() Function to calculate DNSSEC footprint from KEY record
* rdata
* Input:
* dns_key_rdata: the raw data in wire format
* rdata_len: the size of the input data
* Output:
*/
{
if (!dns_key_rdata)
return 0;
/* compute id */
return dst_s_get_int16((const u_char *)
/* compatibility */
return 0;
else
/* compute a checksum on the key part of the key rr */
}
/*
* 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
* order and may be unaligned. The number returned is in host order.
* Parameter
* buf A two byte character string.
* Return
* The converted integer value.
*/
{
register u_int16_t a = 0;
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
* order and may be unaligned. The number returned is in host order.
* Parameter
* buf A four byte character string.
* Return
* The converted integer value.
*/
{
register u_int32_t a = 0;
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
* order and the string is returned in host order.
*
* Parameters
* buf Storage for a two byte character string.
* val 16 bit integer.
*/
void
{
}
/*
* 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
* order and the string is returned in host order.
*
* Parameters
* buf Storage for a four byte character string.
* val 32 bit integer.
*/
void
{
}
/*
* 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>
*
* Returns 0 if the filename would contain either '\', '/' or ':'
*/
{
return (0);
return (0);
return (0);
return (0);
return (0);
return (0);
return (0);
return (0);
}
/*
* 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>
*
* Returns -1 if the conversion fails:
* if the filename would be too long for space allotted
* if the filename would contain a '\', '/' or ':'
* Returns 0 on success
*/
int
{
return (-1);
return (-1);
return (-1);
return (-1);
(const char *) suffix);
return (-1);
return (-1);
return (-1);
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.
* Parameters
* filename File to open
* mode Mode to open the file (passed directly to fopen)
* perm File permission, if creating a new file.
* Returns
* NULL Failure
* NON-NULL (FILE *) of opened file.
*/
FILE *
{
if (*dst_path != '\0') {
}
else
pathname[0] = '\0';
else
return (NULL);
if (perm)
return (fp);
}
void
const char *msg)
{
if (size > 0) {
#ifdef LONG_TEST
int n ;
#else
#endif
}
}