xref: /titanic_50/usr/src/lib/libresolv2/common/dst/support.c (revision 9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829)
1*9525b14bSRao Shoaib static const char rcsid[] = "$Header: /proj/cvs/prod/libbind/dst/support.c,v 1.6 2005/10/11 00:10:13 marka Exp $";
27c478bd9Sstevel@tonic-gate 
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate /*
57c478bd9Sstevel@tonic-gate  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Permission to use, copy modify, and distribute this software for any
87c478bd9Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
97c478bd9Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS
127c478bd9Sstevel@tonic-gate  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
137c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL
147c478bd9Sstevel@tonic-gate  * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT,
157c478bd9Sstevel@tonic-gate  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
167c478bd9Sstevel@tonic-gate  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
177c478bd9Sstevel@tonic-gate  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
187c478bd9Sstevel@tonic-gate  * WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
197c478bd9Sstevel@tonic-gate  */
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate #include "port_before.h"
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate #include <stdio.h>
247c478bd9Sstevel@tonic-gate #include <unistd.h>
257c478bd9Sstevel@tonic-gate #include <memory.h>
267c478bd9Sstevel@tonic-gate #include <string.h>
277c478bd9Sstevel@tonic-gate #include <errno.h>
287c478bd9Sstevel@tonic-gate #include <sys/stat.h>
297c478bd9Sstevel@tonic-gate #include <netinet/in.h>
307c478bd9Sstevel@tonic-gate #include <arpa/nameser.h>
317c478bd9Sstevel@tonic-gate #include <resolv.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include "dst_internal.h"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include "port_after.h"
367c478bd9Sstevel@tonic-gate 
37*9525b14bSRao Shoaib /*%
387c478bd9Sstevel@tonic-gate  * dst_s_verify_str()
397c478bd9Sstevel@tonic-gate  *     Validate that the input string(*str) is at the head of the input
407c478bd9Sstevel@tonic-gate  *     buffer(**buf).  If so, move the buffer head pointer (*buf) to
417c478bd9Sstevel@tonic-gate  *     the first byte of data following the string(*str).
427c478bd9Sstevel@tonic-gate  * Parameters
437c478bd9Sstevel@tonic-gate  *     buf     Input buffer.
447c478bd9Sstevel@tonic-gate  *     str     Input string.
457c478bd9Sstevel@tonic-gate  * Return
467c478bd9Sstevel@tonic-gate  *	0       *str is not the head of **buff
477c478bd9Sstevel@tonic-gate  *	1       *str is the head of **buff, *buf is is advanced to
487c478bd9Sstevel@tonic-gate  *	the tail of **buf.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate int
dst_s_verify_str(const char ** buf,const char * str)527c478bd9Sstevel@tonic-gate dst_s_verify_str(const char **buf, const char *str)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	int b, s;
55*9525b14bSRao Shoaib 	if (*buf == NULL)	/*%< error checks */
567c478bd9Sstevel@tonic-gate 		return (0);
577c478bd9Sstevel@tonic-gate 	if (str == NULL || *str == '\0')
587c478bd9Sstevel@tonic-gate 		return (1);
597c478bd9Sstevel@tonic-gate 
60*9525b14bSRao Shoaib 	b = strlen(*buf);	/*%< get length of strings */
617c478bd9Sstevel@tonic-gate 	s = strlen(str);
62*9525b14bSRao Shoaib 	if (s > b || strncmp(*buf, str, s))	/*%< check if same */
63*9525b14bSRao Shoaib 		return (0);	/*%< not a match */
64*9525b14bSRao Shoaib 	(*buf) += s;		/*%< advance pointer */
657c478bd9Sstevel@tonic-gate 	return (1);
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
68*9525b14bSRao Shoaib /*%
697c478bd9Sstevel@tonic-gate  * dst_s_calculate_bits
707c478bd9Sstevel@tonic-gate  *     Given a binary number represented in a u_char[], determine
717c478bd9Sstevel@tonic-gate  *     the number of significant bits used.
727c478bd9Sstevel@tonic-gate  * Parameters
737c478bd9Sstevel@tonic-gate  *     str       An input character string containing a binary number.
747c478bd9Sstevel@tonic-gate  *     max_bits The maximum possible significant bits.
757c478bd9Sstevel@tonic-gate  * Return
767c478bd9Sstevel@tonic-gate  *     N       The number of significant bits in str.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate int
dst_s_calculate_bits(const u_char * str,const int max_bits)807c478bd9Sstevel@tonic-gate dst_s_calculate_bits(const u_char *str, const int max_bits)
817c478bd9Sstevel@tonic-gate {
827c478bd9Sstevel@tonic-gate 	const u_char *p = str;
837c478bd9Sstevel@tonic-gate 	u_char i, j = 0x80;
847c478bd9Sstevel@tonic-gate 	int bits;
857c478bd9Sstevel@tonic-gate 	for (bits = max_bits; *p == 0x00 && bits > 0; p++)
867c478bd9Sstevel@tonic-gate 		bits -= 8;
877c478bd9Sstevel@tonic-gate 	for (i = *p; (i & j) != j; j >>= 1)
887c478bd9Sstevel@tonic-gate 		bits--;
897c478bd9Sstevel@tonic-gate 	return (bits);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
92*9525b14bSRao Shoaib /*%
937c478bd9Sstevel@tonic-gate  * calculates a checksum used in dst for an id.
947c478bd9Sstevel@tonic-gate  * takes an array of bytes and a length.
957c478bd9Sstevel@tonic-gate  * returns a 16  bit checksum.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate u_int16_t
dst_s_id_calc(const u_char * key,const int keysize)987c478bd9Sstevel@tonic-gate dst_s_id_calc(const u_char *key, const int keysize)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	u_int32_t ac;
1017c478bd9Sstevel@tonic-gate 	const u_char *kp = key;
1027c478bd9Sstevel@tonic-gate 	int size = keysize;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	if (!key || (keysize <= 0))
105*9525b14bSRao Shoaib 		return (0xffffU);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	for (ac = 0; size > 1; size -= 2, kp += 2)
1087c478bd9Sstevel@tonic-gate 		ac += ((*kp) << 8) + *(kp + 1);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if (size > 0)
1117c478bd9Sstevel@tonic-gate 		ac += ((*kp) << 8);
1127c478bd9Sstevel@tonic-gate 	ac += (ac >> 16) & 0xffff;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	return (ac & 0xffff);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate 
117*9525b14bSRao Shoaib /*%
1187c478bd9Sstevel@tonic-gate  * dst_s_dns_key_id() Function to calculate DNSSEC footprint from KEY record
1197c478bd9Sstevel@tonic-gate  *   rdata
1207c478bd9Sstevel@tonic-gate  * Input:
1217c478bd9Sstevel@tonic-gate  *	dns_key_rdata: the raw data in wire format
1227c478bd9Sstevel@tonic-gate  *      rdata_len: the size of the input data
1237c478bd9Sstevel@tonic-gate  * Output:
1247c478bd9Sstevel@tonic-gate  *      the key footprint/id calculated from the key data
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate u_int16_t
dst_s_dns_key_id(const u_char * dns_key_rdata,const int rdata_len)1277c478bd9Sstevel@tonic-gate dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate 	if (!dns_key_rdata)
1307c478bd9Sstevel@tonic-gate 		return 0;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	/* compute id */
133*9525b14bSRao Shoaib 	if (dns_key_rdata[3] == KEY_RSA)	/*%< Algorithm RSA */
1347c478bd9Sstevel@tonic-gate 		return dst_s_get_int16((const u_char *)
1357c478bd9Sstevel@tonic-gate 				       &dns_key_rdata[rdata_len - 3]);
1367c478bd9Sstevel@tonic-gate 	else if (dns_key_rdata[3] == KEY_HMAC_MD5)
1377c478bd9Sstevel@tonic-gate 		/* compatibility */
1387c478bd9Sstevel@tonic-gate 		return 0;
1397c478bd9Sstevel@tonic-gate 	else
1407c478bd9Sstevel@tonic-gate 		/* compute a checksum on the key part of the key rr */
1417c478bd9Sstevel@tonic-gate 		return dst_s_id_calc(dns_key_rdata, rdata_len);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
144*9525b14bSRao Shoaib /*%
1457c478bd9Sstevel@tonic-gate  * dst_s_get_int16
1467c478bd9Sstevel@tonic-gate  *     This routine extracts a 16 bit integer from a two byte character
1477c478bd9Sstevel@tonic-gate  *     string.  The character string is assumed to be in network byte
1487c478bd9Sstevel@tonic-gate  *     order and may be unaligned.  The number returned is in host order.
1497c478bd9Sstevel@tonic-gate  * Parameter
1507c478bd9Sstevel@tonic-gate  *     buf     A two byte character string.
1517c478bd9Sstevel@tonic-gate  * Return
1527c478bd9Sstevel@tonic-gate  *     The converted integer value.
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate u_int16_t
dst_s_get_int16(const u_char * buf)1567c478bd9Sstevel@tonic-gate dst_s_get_int16(const u_char *buf)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 	register u_int16_t a = 0;
1597c478bd9Sstevel@tonic-gate 	a = ((u_int16_t)(buf[0] << 8)) | ((u_int16_t)(buf[1]));
1607c478bd9Sstevel@tonic-gate 	return (a);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate 
163*9525b14bSRao Shoaib /*%
1647c478bd9Sstevel@tonic-gate  * dst_s_get_int32
1657c478bd9Sstevel@tonic-gate  *     This routine extracts a 32 bit integer from a four byte character
1667c478bd9Sstevel@tonic-gate  *     string.  The character string is assumed to be in network byte
1677c478bd9Sstevel@tonic-gate  *     order and may be unaligned.  The number returned is in host order.
1687c478bd9Sstevel@tonic-gate  * Parameter
1697c478bd9Sstevel@tonic-gate  *     buf     A four byte character string.
1707c478bd9Sstevel@tonic-gate  * Return
1717c478bd9Sstevel@tonic-gate  *     The converted integer value.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate u_int32_t
dst_s_get_int32(const u_char * buf)1757c478bd9Sstevel@tonic-gate dst_s_get_int32(const u_char *buf)
1767c478bd9Sstevel@tonic-gate {
1777c478bd9Sstevel@tonic-gate 	register u_int32_t a = 0;
1787c478bd9Sstevel@tonic-gate 	a = ((u_int32_t)(buf[0] << 24)) | ((u_int32_t)(buf[1] << 16)) |
1797c478bd9Sstevel@tonic-gate 		((u_int32_t)(buf[2] << 8)) | ((u_int32_t)(buf[3]));
1807c478bd9Sstevel@tonic-gate 	return (a);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
183*9525b14bSRao Shoaib /*%
1847c478bd9Sstevel@tonic-gate  * dst_s_put_int16
1857c478bd9Sstevel@tonic-gate  *     Take a 16 bit integer and store the value in a two byte
1867c478bd9Sstevel@tonic-gate  *     character string.  The integer is assumed to be in network
1877c478bd9Sstevel@tonic-gate  *     order and the string is returned in host order.
1887c478bd9Sstevel@tonic-gate  *
1897c478bd9Sstevel@tonic-gate  * Parameters
1907c478bd9Sstevel@tonic-gate  *     buf     Storage for a two byte character string.
1917c478bd9Sstevel@tonic-gate  *     val     16 bit integer.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate void
dst_s_put_int16(u_int8_t * buf,const u_int16_t val)1957c478bd9Sstevel@tonic-gate dst_s_put_int16(u_int8_t *buf, const u_int16_t val)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate 	buf[0] = (u_int8_t)(val >> 8);
1987c478bd9Sstevel@tonic-gate 	buf[1] = (u_int8_t)(val);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate 
201*9525b14bSRao Shoaib /*%
2027c478bd9Sstevel@tonic-gate  * dst_s_put_int32
2037c478bd9Sstevel@tonic-gate  *     Take a 32 bit integer and store the value in a four byte
2047c478bd9Sstevel@tonic-gate  *     character string.  The integer is assumed to be in network
2057c478bd9Sstevel@tonic-gate  *     order and the string is returned in host order.
2067c478bd9Sstevel@tonic-gate  *
2077c478bd9Sstevel@tonic-gate  * Parameters
2087c478bd9Sstevel@tonic-gate  *     buf     Storage for a four byte character string.
2097c478bd9Sstevel@tonic-gate  *     val     32 bit integer.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate void
dst_s_put_int32(u_int8_t * buf,const u_int32_t val)2137c478bd9Sstevel@tonic-gate dst_s_put_int32(u_int8_t *buf, const u_int32_t val)
2147c478bd9Sstevel@tonic-gate {
2157c478bd9Sstevel@tonic-gate 	buf[0] = (u_int8_t)(val >> 24);
2167c478bd9Sstevel@tonic-gate 	buf[1] = (u_int8_t)(val >> 16);
2177c478bd9Sstevel@tonic-gate 	buf[2] = (u_int8_t)(val >> 8);
2187c478bd9Sstevel@tonic-gate 	buf[3] = (u_int8_t)(val);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate 
221*9525b14bSRao Shoaib /*%
2227c478bd9Sstevel@tonic-gate  *  dst_s_filename_length
2237c478bd9Sstevel@tonic-gate  *
2247c478bd9Sstevel@tonic-gate  *	This function returns the number of bytes needed to hold the
2257c478bd9Sstevel@tonic-gate  *	filename for a key file.  '/', '\' and ':' are not allowed.
226*9525b14bSRao Shoaib  *	form:  K&lt;keyname&gt;+&lt;alg&gt;+&lt;id&gt;.&lt;suffix&gt;
2277c478bd9Sstevel@tonic-gate  *
2287c478bd9Sstevel@tonic-gate  *	Returns 0 if the filename would contain either '\', '/' or ':'
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate size_t
dst_s_filename_length(const char * name,const char * suffix)2317c478bd9Sstevel@tonic-gate dst_s_filename_length(const char *name, const char *suffix)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate 	if (name == NULL)
2347c478bd9Sstevel@tonic-gate 		return (0);
2357c478bd9Sstevel@tonic-gate 	if (strrchr(name, '\\'))
2367c478bd9Sstevel@tonic-gate 		return (0);
2377c478bd9Sstevel@tonic-gate 	if (strrchr(name, '/'))
2387c478bd9Sstevel@tonic-gate 		return (0);
2397c478bd9Sstevel@tonic-gate 	if (strrchr(name, ':'))
2407c478bd9Sstevel@tonic-gate 		return (0);
2417c478bd9Sstevel@tonic-gate 	if (suffix == NULL)
2427c478bd9Sstevel@tonic-gate 		return (0);
2437c478bd9Sstevel@tonic-gate 	if (strrchr(suffix, '\\'))
2447c478bd9Sstevel@tonic-gate 		return (0);
2457c478bd9Sstevel@tonic-gate 	if (strrchr(suffix, '/'))
2467c478bd9Sstevel@tonic-gate 		return (0);
2477c478bd9Sstevel@tonic-gate 	if (strrchr(suffix, ':'))
2487c478bd9Sstevel@tonic-gate 		return (0);
2497c478bd9Sstevel@tonic-gate 	return (1 + strlen(name) + 6 + strlen(suffix));
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate 
252*9525b14bSRao Shoaib /*%
2537c478bd9Sstevel@tonic-gate  *  dst_s_build_filename ()
2547c478bd9Sstevel@tonic-gate  *	Builds a key filename from the key name, it's id, and a
2557c478bd9Sstevel@tonic-gate  *	suffix.  '\', '/' and ':' are not allowed. fA filename is of the
256*9525b14bSRao Shoaib  *	form:  K&lt;keyname&gt;&lt;id&gt;.&lt;suffix&gt;
257*9525b14bSRao Shoaib  *	form: K&lt;keyname&gt;+&lt;alg&gt;+&lt;id&gt;.&lt;suffix&gt;
2587c478bd9Sstevel@tonic-gate  *
2597c478bd9Sstevel@tonic-gate  *	Returns -1 if the conversion fails:
2607c478bd9Sstevel@tonic-gate  *	  if the filename would be too long for space allotted
2617c478bd9Sstevel@tonic-gate  *	  if the filename would contain a '\', '/' or ':'
2627c478bd9Sstevel@tonic-gate  *	Returns 0 on success
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate int
dst_s_build_filename(char * filename,const char * name,u_int16_t id,int alg,const char * suffix,size_t filename_length)2667c478bd9Sstevel@tonic-gate dst_s_build_filename(char *filename, const char *name, u_int16_t id,
2677c478bd9Sstevel@tonic-gate 		     int alg, const char *suffix, size_t filename_length)
2687c478bd9Sstevel@tonic-gate {
2697c478bd9Sstevel@tonic-gate 	u_int32_t my_id;
2707c478bd9Sstevel@tonic-gate 	if (filename == NULL)
2717c478bd9Sstevel@tonic-gate 		return (-1);
2727c478bd9Sstevel@tonic-gate 	memset(filename, 0, filename_length);
2737c478bd9Sstevel@tonic-gate 	if (name == NULL)
2747c478bd9Sstevel@tonic-gate 		return (-1);
2757c478bd9Sstevel@tonic-gate 	if (suffix == NULL)
2767c478bd9Sstevel@tonic-gate 		return (-1);
2777c478bd9Sstevel@tonic-gate 	if (filename_length < 1 + strlen(name) + 4 + 6 + 1 + strlen(suffix))
2787c478bd9Sstevel@tonic-gate 		return (-1);
2797c478bd9Sstevel@tonic-gate 	my_id = id;
2807c478bd9Sstevel@tonic-gate 	sprintf(filename, "K%s+%03d+%05d.%s", name, alg, my_id,
2817c478bd9Sstevel@tonic-gate 		(const char *) suffix);
2827c478bd9Sstevel@tonic-gate 	if (strrchr(filename, '/'))
2837c478bd9Sstevel@tonic-gate 		return (-1);
2847c478bd9Sstevel@tonic-gate 	if (strrchr(filename, '\\'))
2857c478bd9Sstevel@tonic-gate 		return (-1);
2867c478bd9Sstevel@tonic-gate 	if (strrchr(filename, ':'))
2877c478bd9Sstevel@tonic-gate 		return (-1);
2887c478bd9Sstevel@tonic-gate 	return (0);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
291*9525b14bSRao Shoaib /*%
2927c478bd9Sstevel@tonic-gate  *  dst_s_fopen ()
2937c478bd9Sstevel@tonic-gate  *     Open a file in the dst_path directory.  If perm is specified, the
2947c478bd9Sstevel@tonic-gate  *     file is checked for existence first, and not opened if it exists.
2957c478bd9Sstevel@tonic-gate  *  Parameters
2967c478bd9Sstevel@tonic-gate  *     filename  File to open
2977c478bd9Sstevel@tonic-gate  *     mode       Mode to open the file (passed directly to fopen)
2987c478bd9Sstevel@tonic-gate  *     perm       File permission, if creating a new file.
2997c478bd9Sstevel@tonic-gate  *  Returns
3007c478bd9Sstevel@tonic-gate  *     NULL       Failure
3017c478bd9Sstevel@tonic-gate  *     NON-NULL  (FILE *) of opened file.
3027c478bd9Sstevel@tonic-gate  */
3037c478bd9Sstevel@tonic-gate FILE *
dst_s_fopen(const char * filename,const char * mode,int perm)3047c478bd9Sstevel@tonic-gate dst_s_fopen(const char *filename, const char *mode, int perm)
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate 	FILE *fp;
3077c478bd9Sstevel@tonic-gate 	char pathname[PATH_MAX];
308*9525b14bSRao Shoaib 
309*9525b14bSRao Shoaib 	if (strlen(filename) + strlen(dst_path) >= sizeof(pathname))
310*9525b14bSRao Shoaib 		return (NULL);
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	if (*dst_path != '\0') {
3137c478bd9Sstevel@tonic-gate 		strcpy(pathname, dst_path);
314*9525b14bSRao Shoaib 		strcat(pathname, filename);
315*9525b14bSRao Shoaib 	} else
316*9525b14bSRao Shoaib 		strcpy(pathname, filename);
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	fp = fopen(pathname, mode);
3197c478bd9Sstevel@tonic-gate 	if (perm)
3207c478bd9Sstevel@tonic-gate 		chmod(pathname, perm);
3217c478bd9Sstevel@tonic-gate 	return (fp);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate void
dst_s_dump(const int mode,const u_char * data,const int size,const char * msg)3257c478bd9Sstevel@tonic-gate dst_s_dump(const int mode, const u_char *data, const int size,
3267c478bd9Sstevel@tonic-gate 	    const char *msg)
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	UNUSED(data);
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	if (size > 0) {
3317c478bd9Sstevel@tonic-gate #ifdef LONG_TEST
3327c478bd9Sstevel@tonic-gate 		static u_char scratch[1000];
3337c478bd9Sstevel@tonic-gate 		int n ;
3347c478bd9Sstevel@tonic-gate 		n = b64_ntop(data, scratch, size, sizeof(scratch));
3357c478bd9Sstevel@tonic-gate 		printf("%s: %x %d %s\n", msg, mode, n, scratch);
3367c478bd9Sstevel@tonic-gate #else
3377c478bd9Sstevel@tonic-gate 		printf("%s,%x %d\n", msg, mode, size);
3387c478bd9Sstevel@tonic-gate #endif
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate }
341*9525b14bSRao Shoaib 
342*9525b14bSRao Shoaib /*! \file */
343