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