Subject: strftime, updated sprintf & vsprintf, new fingerd, new syslog (#233)
Index:	lib/libc/, etc/fingerd, man/man3/ 2.11BSD

Description:
	The strftime(3) function was missing from 2.11BSD.  The syslog(3)
	function was an old version.  vsprintf(3) and sprintf(3) returned
	a "char *" instead of the number of characters placed in the output
	string.

Repeat-By:
	Observation.

Fix:
	Thanks to Robin Birch for contributing the first port of syslog(3)
	and strftime(3).  Initially he simply wanted the new 'fingerd(8)'
	(which offers logging and security enhancements over the old version)
	and the newer syslog(3) function.
	
	Since the new syslog(3) routines calls strftime(3) that module had to 
	be ported.  Then since the new strftime(3) wants a count returned 
	from [v]sprintf(3) those routines had to be fixed.

	Note:  fprintf, vfprintf and printf have not changed.  It is not
	       possible to return the number of characters processed by
	       those routines without a rewrite/port of the stdio package.

	The update below consists of 3 parts:

		1) A shell script which will save the replaced files to
		   ".old" files (vsprintf.c is renamed to vsprintf.c.old, etc),
		   unshar the archive described in 2), and finally apply
		   the patch described  in 3).

		2) A shar file of new replacement sources.  The shell
		   script in 1) will unpack this shar file.

		   The shar file consists of the following file:

			/usr/src/sys/h/syslog.h
			/usr/src/etc/fingerd
			/usr/src/lib/libc/gen/strftime.c
			/usr/src/lib/libc/gen/syslog.c
			/usr/src/lib/libc/stdio/sprintf.c
			/usr/src/lib/libc/stdio/vsprintf.c
			/usr/src/man/man3/syslog.3
			/usr/src/man/man3/strftime.3

		3) A patch file which will update the following files:

			/VERSION
			/usr/include/paths.h
			/usr/lib/lint/llib-lc
			/usr/src/lib/libc/gen/Makefile
			/usr/src/man/man3/Makefile
			/usr/src/man/man3/printf.3

	To install this kit copy this file to /tmp/foo and remove everything
	from the beginning of the file to the line "---cut here---".

	Then:

		sh /tmp/foo
		sh /tmp/233.script

	At this point all the necessary files have been installed and
	updated.  You may wish to update the dependencies in libc/gen/Makefile
	(this is optional if you're in a hurry) by doing:

		cd /usr/src/lib/libc/gen
		make depend

	Next the C-library (libc.a) must be updated.  If you know how you
	may compile only those modules which were changed and update (don't
	forget to ranlib afterwards) libc.a and /usr/lib/libc_p.a manually.
	Otherwise you should simply recompile libc.a:

		cd /usr/src/lib/libc
		make
		make install

	(this takes about an hour or so)

	The man pages are next:

		cd /usr/src/man/man3
		/usr/man/manroff strftime.3 > strftime.0
		/usr/man/manroff syslog.3 > syslog.0
		/usr/man/manroff printf.3 > printf.0
		install -m 444 strftime.0 /usr/man/cat3
		cp syslog.0 printf.0 /usr/man/cat3
		rm *.0

	The lint library needs to be updated too:

		cd /usr/src/usr.bin/lint
		./libs

	Now 'fingerd' is rebuilt:

		cd /usr/src/etc/fingerd
		make
		make install
		make clean

	Finally some clean up.

		rm /tmp/233.patch /tmp/233.shar /tmp/233.script
		cd /usr/src/lib/libc
		make clean
		rm /usr/src/sys/h/syslog.h.old
		rm -r /usr/src/etc/fingerd.old
		rm /usr/src/lib/libc/gen/syslog.c.old
		rm /usr/src/lib/libc/stdio/sprintf.c.old
		rm /usr/src/lib/libc/stdio/vsprintf.c.old
		rm /usr/src/man/man3/syslog.3.old
		rm /VERSION~
		rm /usr/include/paths.h~
		rm /usr/lib/lint/llib-lc~
		rm /usr/src/lib/libc/gen/Makefile~
		rm /usr/src/man/man3/Makefile~
		rm /usr/src/man/man3/printf.3~

----------------------------cut here------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	/tmp/233.script
#	/tmp/233.shar
#	/tmp/233.patch
# This archive created: Wed Apr  5 20:38:29 1995
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f '/tmp/233.script'
then
	echo shar: "will not over-write existing file '/tmp/233.script'"
else
sed 's/^Z//' << \SHAR_EOF > '/tmp/233.script'
Z#! /bin/sh
Z
Zif [ ! -s /tmp/233.shar ]; then
Z	echo "The shar file /tmp/233.shar containing the new files to be"
Z	echo "on the system does not exist.  It should have extracted at the"
Z	echo "same time as this shell script."
Z	exit 1
Zfi
Z
Zif [ ! -s /tmp/233.patch ]; then
Z	echo "The patch file /tmp/233.patch does not exist.  It should have"
Z	echo "been extracted at the same time as this script."
Z	exit 1
Zfi
Z
Zecho "Renaming replaced files..."
Zset -x
Zmv -f /usr/src/sys/h/syslog.h /usr/src/sys/h/syslog.h.old
Zmv -f /usr/src/etc/fingerd /usr/src/etc/fingerd.old
Zmv -f /usr/src/lib/libc/gen/strftime.c /usr/src/lib/libc/gen/strftime.c.old
Zmv -f /usr/src/lib/libc/gen/syslog.c /usr/src/lib/libc/gen/syslog.c.old
Zmv -f /usr/src/lib/libc/stdio/sprintf.c /usr/src/lib/libc/stdio/sprintf.c.old
Zmv -f /usr/src/lib/libc/stdio/vsprintf.c /usr/src/lib/libc/stdio/vsprintf.c.old
Zmv -f /usr/src/man/man3/syslog.3 /usr/src/man/man3/syslog.3.old
Zmv -f /usr/src/man/man3/strftime.3 /usr/src/man/man3/strftime.3.old
Zset -
Z
Zecho "Extracting replacement files from shar archive /tmp/233.shar..."
Zsh /tmp/233.shar
Z
Zecho "Applying the patch file..."
Zpatch -p0 < /tmp/233.patch
SHAR_EOF
fi
if test -f '/tmp/233.shar'
then
	echo shar: "will not over-write existing file '/tmp/233.shar'"
else
sed 's/^Z//' << \SHAR_EOF > '/tmp/233.shar'
Z#! /bin/sh
Z# This is a shell archive, meaning:
Z# 1. Remove everything above the #! /bin/sh line.
Z# 2. Save the resulting text in a file.
Z# 3. Execute the file with /bin/sh (not csh) to create:
Z#	/usr/src/sys/h/syslog.h
Z#	/usr/src/etc/fingerd
Z#	/usr/src/lib/libc/gen/strftime.c
Z#	/usr/src/lib/libc/gen/syslog.c
Z#	/usr/src/lib/libc/stdio/sprintf.c
Z#	/usr/src/lib/libc/stdio/vsprintf.c
Z#	/usr/src/man/man3/syslog.3
Z#	/usr/src/man/man3/strftime.3
Z# This archive created: Wed Apr  5 19:50:12 1995
Zexport PATH; PATH=/bin:/usr/bin:$PATH
Zif test -f '/usr/src/sys/h/syslog.h'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/sys/h/syslog.h'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/sys/h/syslog.h'
ZX/*
ZX * Copyright (c) 1982, 1986, 1988, 1993
ZX *	The Regents of the University of California.  All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms, with or without
ZX * modification, are permitted provided that the following conditions
ZX * are met:
ZX * 1. Redistributions of source code must retain the above copyright
ZX *    notice, this list of conditions and the following disclaimer.
ZX * 2. Redistributions in binary form must reproduce the above copyright
ZX *    notice, this list of conditions and the following disclaimer in the
ZX *    documentation and/or other materials provided with the distribution.
ZX * 3. All advertising materials mentioning features or use of this software
ZX *    must display the following acknowledgement:
ZX *	This product includes software developed by the University of
ZX *	California, Berkeley and its contributors.
ZX * 4. Neither the name of the University nor the names of its contributors
ZX *    may be used to endorse or promote products derived from this software
ZX *    without specific prior written permission.
ZX *
ZX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX * SUCH DAMAGE.
ZX *
ZX *	@(#)syslog.h	8.1.1 (2.11BSD) 1995/04/01
ZX * $Id: syslog.h,v 1.4 1994/08/21 04:42:00 paul Exp $
ZX */
ZX
ZX#ifndef _SYS_SYSLOG_H_
ZX#define _SYS_SYSLOG_H_
ZX
ZX#define	_PATH_LOG	"/dev/log"
ZX
ZX/*
ZX * priorities/facilities are encoded into a single 16-bit quantity, where the
ZX * bottom 3 bits are the priority (0-7) and the top 13 bits are the facility
ZX * (0-big number).  Both the priorities and the facilities map roughly
ZX * one-to-one to strings in the syslogd(8) source code.  This mapping is
ZX * included in this file.
ZX *
ZX * priorities (these are ordered)
ZX */
ZX#define	LOG_EMERG	0	/* system is unusable */
ZX#define	LOG_ALERT	1	/* action must be taken immediately */
ZX#define	LOG_CRIT	2	/* critical conditions */
ZX#define	LOG_ERR		3	/* error conditions */
ZX#define	LOG_WARNING	4	/* warning conditions */
ZX#define	LOG_NOTICE	5	/* normal but significant condition */
ZX#define	LOG_INFO	6	/* informational */
ZX#define	LOG_DEBUG	7	/* debug-level messages */
ZX
ZX#define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
ZX				/* extract priority */
ZX#define	LOG_PRI(p)	((p) & LOG_PRIMASK)
ZX#define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
ZX
ZX#ifdef SYSLOG_NAMES
ZX#define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
ZX				/* mark "facility" */
ZX#define	INTERNAL_MARK	LOG_MAKEPRI(LOG_NFACILITIES, 0)
ZXtypedef struct _code {
ZX	char	*c_name;
ZX	int	c_val;
ZX} CODE;
ZX
ZXCODE prioritynames[] = {
ZX	"alert",	LOG_ALERT,
ZX	"crit",		LOG_CRIT,
ZX	"debug",	LOG_DEBUG,
ZX	"emerg",	LOG_EMERG,
ZX	"err",		LOG_ERR,
ZX	"error",	LOG_ERR,		/* DEPRECATED */
ZX	"info",		LOG_INFO,
ZX	"none",		INTERNAL_NOPRI,		/* INTERNAL */
ZX	"notice",	LOG_NOTICE,
ZX	"panic", 	LOG_EMERG,		/* DEPRECATED */
ZX	"warn",		LOG_WARNING,		/* DEPRECATED */
ZX	"warning",	LOG_WARNING,
ZX	NULL,		-1,
ZX};
ZX#endif
ZX
ZX/* facility codes */
ZX#define	LOG_KERN	(0<<3)	/* kernel messages */
ZX#define	LOG_USER	(1<<3)	/* random user-level messages */
ZX#define	LOG_MAIL	(2<<3)	/* mail system */
ZX#define	LOG_DAEMON	(3<<3)	/* system daemons */
ZX#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
ZX#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
ZX#define	LOG_LPR		(6<<3)	/* line printer subsystem */
ZX#define	LOG_NEWS	(7<<3)	/* network news subsystem */
ZX#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
ZX#define	LOG_CRON	(9<<3)	/* clock daemon */
ZX#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
ZX#define	LOG_FTP		(11<<3)	/* ftp daemon */
ZX
ZX	/* other codes through 15 reserved for system use */
ZX#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
ZX#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
ZX
ZX#define	LOG_NFACILITIES	24	/* current number of facilities */
ZX#define	LOG_FACMASK	0x03f8	/* mask to extract facility part */
ZX				/* facility of pri */
ZX#define	LOG_FAC(p)	(((p) & LOG_FACMASK) >> 3)
ZX
ZX#ifdef SYSLOG_NAMES
ZXCODE facilitynames[] = {
ZX	"auth",		LOG_AUTH,
ZX	"authpriv",	LOG_AUTHPRIV,
ZX	"cron", 	LOG_CRON,
ZX	"daemon",	LOG_DAEMON,
ZX	"ftp",		LOG_FTP,
ZX	"kern",		LOG_KERN,
ZX	"lpr",		LOG_LPR,
ZX	"mail",		LOG_MAIL,
ZX	"mark", 	INTERNAL_MARK,		/* INTERNAL */
ZX	"news",		LOG_NEWS,
ZX	"security",	LOG_AUTH,		/* DEPRECATED */
ZX	"syslog",	LOG_SYSLOG,
ZX	"user",		LOG_USER,
ZX	"uucp",		LOG_UUCP,
ZX	"local0",	LOG_LOCAL0,
ZX	"local1",	LOG_LOCAL1,
ZX	"local2",	LOG_LOCAL2,
ZX	"local3",	LOG_LOCAL3,
ZX	"local4",	LOG_LOCAL4,
ZX	"local5",	LOG_LOCAL5,
ZX	"local6",	LOG_LOCAL6,
ZX	"local7",	LOG_LOCAL7,
ZX	NULL,		-1,
ZX};
ZX#endif
ZX
ZX#ifdef KERNEL
ZX#define	LOG_PRINTF	-1	/* pseudo-priority to indicate use of printf */
ZX#endif
ZX
ZX/*
ZX * arguments to setlogmask.
ZX */
ZX#define	LOG_MASK(pri)	(1 << (pri))		/* mask for one priority */
ZX#define	LOG_UPTO(pri)	((1 << ((pri)+1)) - 1)	/* all priorities through pri */
ZX
ZX/*
ZX * Option flags for openlog.
ZX *
ZX * LOG_ODELAY no longer does anything.
ZX * LOG_NDELAY is the inverse of what it used to be.
ZX */
ZX#define	LOG_PID		0x01	/* log the pid with each message */
ZX#define	LOG_CONS	0x02	/* log on the console if errors in sending */
ZX#define	LOG_ODELAY	0x04	/* delay open until first syslog() (default) */
ZX#define	LOG_NDELAY	0x08	/* don't delay open */
ZX#define	LOG_NOWAIT	0x10	/* don't wait for console forks: DEPRECATED */
ZX#define	LOG_PERROR	0x20	/* log to stderr as well */
ZX
ZX#endif
ZSHAR_EOF
Zfi
Zif test ! -d '/usr/src/etc/fingerd'
Zthen
Z	mkdir '/usr/src/etc/fingerd'
Zfi
Zcd '/usr/src/etc/fingerd'
Zif test -f 'Makefile'
Zthen
Z	echo shar: "will not over-write existing file 'Makefile'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > 'Makefile'
ZX#	Makefile for fingerd
ZX#
ZX#	Version 1.0 - 1995/04/01
ZX#
ZXSEPFLAG= -i
ZXCFLAGS = -O
ZX
ZXSRCS = fingerd.c
ZXOBJS = fingerd.o
ZX
ZXall:	fingerd fingerd.0
ZX
ZXfingerd: ${OBJS}
ZX	${CC} ${SEPFLAG} -o fingerd ${OBJS}
ZX
ZXfingerd.0: fingerd.8
ZX	/usr/man/manroff fingerd.8 > fingerd.0
ZX
ZXinstall: all
ZX	install -s -m 755 -g bin -o bin fingerd ${DESTDIR}/etc
ZX	install -m 444 -g bin -o bin fingerd.0 ${DESTDIR}/usr/man/cat8
ZX
ZXclean:	
ZX	rm -f *.o fingerd *.core fingerd.0
ZX
ZXcleandir: clean
ZX	rm -f tags
ZX
ZXdepend: ${SRCS}
ZX	mkdep -p ${CFLAGS} ${SRCS}
ZX
ZXlint: ${SRCS}
ZX	lint ${CFLAGS} ${SRCS}
ZX
ZXtags: ${SRCS}
ZX	ctags ${SRCS}
ZSHAR_EOF
Zfi
Zif test -f 'fingerd.8'
Zthen
Z	echo shar: "will not over-write existing file 'fingerd.8'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > 'fingerd.8'
ZX.\" Copyright (c) 1980, 1991, 1993
ZX.\"	The Regents of the University of California.  All rights reserved.
ZX.\"
ZX.\" Redistribution and use in source and binary forms, with or without
ZX.\" modification, are permitted provided that the following conditions
ZX.\" are met:
ZX.\" 1. Redistributions of source code must retain the above copyright
ZX.\"    notice, this list of conditions and the following disclaimer.
ZX.\" 2. Redistributions in binary form must reproduce the above copyright
ZX.\"    notice, this list of conditions and the following disclaimer in the
ZX.\"    documentation and/or other materials provided with the distribution.
ZX.\" 3. All advertising materials mentioning features or use of this software
ZX.\"    must display the following acknowledgement:
ZX.\"	This product includes software developed by the University of
ZX.\"	California, Berkeley and its contributors.
ZX.\" 4. Neither the name of the University nor the names of its contributors
ZX.\"    may be used to endorse or promote products derived from this software
ZX.\"    without specific prior written permission.
ZX.\"
ZX.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX.\" SUCH DAMAGE.
ZX.\"
ZX.\"     @(#)fingerd.8	8.1.1 (2.11BSD) 1995/04/01
ZX.\"
ZX.TH FINGERD 8 "April 1, 1995"
ZX.UC 5
ZX.SH NAME
ZXfingerd \- remote user information server
ZX.SH SYNOPSIS
ZX.B fingerd [-s][-l][-p \fIfilename\fP ]
ZX.SH DESCRIPTION
ZX.B Fingerd
ZXis a simple protocol based on
ZX.I RFC1196
ZXthat provides an interface to the
ZXName and Finger programs at several network sites.
ZXThe program is supposed to return a friendly,
ZXhuman-oriented status report on either the system at the moment
ZXor a particular person in depth.
ZXThere is no required format and the
ZXprotocol consists mostly of specifying a single
ZX``command line''.
ZX.PP
ZX.B Fingerd
ZXlistens for
ZXTCP
ZXrequests at port 79.
ZXOnce connected it reads a single command line
ZXterminated by a
ZX<CRLF>
ZXwhich is passed to
ZX.IR finger (1).
ZX.B Fingerd
ZXcloses its connections as soon as the output is finished.
ZX.PP
ZXIf the line is null (i.e. just a
ZX<CRLF>
ZXis sent) then 
ZX.I finger
ZXreturns a
ZX``default''
ZXreport that lists all people logged into
ZXthe system at that moment.
ZX.PP
ZXIf a user name is specified (e.g.
ZXeric<CRLF> )
ZXthen the
ZXresponse lists more extended information for only that particular user,
ZXwhether logged in or not.
ZXAllowable
ZX``names''
ZXin the command line include both
ZX``login names''
ZXand
ZX``user names''.
ZXIf a name is ambiguous, all possible derivations are returned.
ZX.PP
ZXThe following options may be passed to
ZX.B fingerd
ZXas server program arguments in
ZX\fI/etc/inetd.conf\fP:
ZX.IP \-s
ZXEnable secure mode.
ZXQueries without a user name are rejected and
ZXforwarding of queries to other remote hosts is denied.
ZX.IP \-l
ZXEnable logging.
ZXThe name of the host originating the query is reported via
ZX.IR syslog (3)
ZXat LOG_NOTICE priority.
ZX.IP \-p
ZXUse an alternate program as the local information provider.
ZXThe default local program
ZXexecuted by
ZX.B fingerd
ZXis 
ZX.IR finger (1).
ZXBy specifying a customized local server,
ZXthis option allows a system manager
ZXto have more control over what information is
ZXprovided to remote sites.
ZX.PP
ZX.SH SEE ALSO
ZX.IR finger (1)
ZX.SH BUGS
ZXConnecting directly to the server from a
ZXTIP
ZXor an equally narrow-minded
ZXTELNET\-protocol
ZXuser program can result
ZXin meaningless attempts at option negotiation being sent to the
ZXserver, which will foul up the command line interpretation.
ZX.B Fingerd
ZXshould be taught to filter out
ZXIAC's
ZXand perhaps even respond
ZXnegatively
ZX(IAC WON'T)
ZXto all option commands received.
ZX.SH HISTORY
ZXThe
ZX.B fingerd
ZXcommand appeared in
ZX4.3BSD.
ZSHAR_EOF
Zfi
Zif test -f 'fingerd.c'
Zthen
Z	echo shar: "will not over-write existing file 'fingerd.c'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > 'fingerd.c'
ZX/*
ZX * Copyright (c) 1983, 1993
ZX *	The Regents of the University of California.  All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms, with or without
ZX * modification, are permitted provided that the following conditions
ZX * are met:
ZX * 1. Redistributions of source code must retain the above copyright
ZX *    notice, this list of conditions and the following disclaimer.
ZX * 2. Redistributions in binary form must reproduce the above copyright
ZX *    notice, this list of conditions and the following disclaimer in the
ZX *    documentation and/or other materials provided with the distribution.
ZX * 3. All advertising materials mentioning features or use of this software
ZX *    must display the following acknowledgement:
ZX *	This product includes software developed by the University of
ZX *	California, Berkeley and its contributors.
ZX * 4. Neither the name of the University nor the names of its contributors
ZX *    may be used to endorse or promote products derived from this software
ZX *    without specific prior written permission.
ZX *
ZX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX * SUCH DAMAGE.
ZX */
ZX
ZX#if	defined(DOSCCS) & !defined(lint)
ZXstatic char copyright[] =
ZX"@(#) Copyright (c) 1983, 1993\n\
ZX	The Regents of the University of California.  All rights reserved.\n";
ZX#endif /* not lint */
ZX
ZX#if	defined(DOSCCS) & !defined(lint)
ZXstatic char sccsid[] = "@(#)fingerd.c	8.1.1 (2.11BSD) 1995/04/01";
ZX#endif /* not lint */
ZX
ZX#include <sys/types.h>
ZX#include <sys/socket.h>
ZX#include <netinet/in.h>
ZX#include <arpa/inet.h>
ZX#include <sys/errno.h>
ZX
ZX#include <syslog.h>
ZX#include <netdb.h>
ZX#include <stdio.h>
ZX#include <strings.h>
ZX#include "pathnames.h"
ZX
ZXextern char *optarg;
ZXextern int optind, opterr, errno;
ZX
ZXint
ZXmain(argc, argv)
ZX	int argc;
ZX	char *argv[];
ZX{
ZX	register FILE *fp;
ZX	register int ch;
ZX	register char *lp;
ZX	struct hostent *hp;
ZX	struct sockaddr_in sin;
ZX	int p[2], logging, secure, sval;
ZX#define	ENTRIES	50
ZX	char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog;
ZX
ZX	prog = _PATH_FINGER;
ZX	logging = secure = 0;
ZX	openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON);
ZX	opterr = 0;
ZX	while ((ch = getopt(argc, argv, "slp:")) != EOF)
ZX		switch (ch) {
ZX		case 'l':
ZX			logging = 1;
ZX			break;
ZX		case 'p':
ZX			prog = optarg;
ZX			break;
ZX		case 's':
ZX			secure = 1;
ZX			break;
ZX		case '?':
ZX		default:
ZX			err("illegal option -- %c", ch);
ZX		}
ZX
ZX	if (logging) {
ZX		sval = sizeof(sin);
ZX		if (getpeername(0, (struct sockaddr *)&sin, &sval) < 0)
ZX			err("getpeername: %s", strerror(errno));
ZX		if (hp = gethostbyaddr((char *)&sin.sin_addr.s_addr,
ZX		    sizeof(sin.sin_addr.s_addr), AF_INET))
ZX			lp = hp->h_name;
ZX		else
ZX			lp = inet_ntoa(sin.sin_addr);
ZX		syslog(LOG_NOTICE, "query from %s", lp);
ZX	}
ZX
ZX	if (!fgets(line, sizeof(line), stdin))
ZX		exit(1);
ZX	
ZX	comp = &av[1];
ZX	for (lp = line, ap = &av[2];;) {
ZX		*ap = strtok(lp, " \t\r\n");
ZX		if (!*ap) {
ZX			if (secure && ap == &av[2]) {
ZX				puts("must provide username\r\n");
ZX				exit(1);
ZX			}
ZX			break;
ZX		}
ZX		if (secure && strchr(*ap, '@')) {
ZX			puts("fowarding service denied\r\n");
ZX			exit(1);
ZX		}
ZX
ZX		/* RFC742: "/[Ww]" == "-l" */
ZX		if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) {
ZX			av[1] = "-l";
ZX			comp = &av[0];
ZX		}
ZX		else if (++ap == av + ENTRIES)
ZX			break;
ZX		lp = NULL;
ZX	}
ZX
ZX	if (lp = strrchr(prog, '/'))
ZX		*comp = ++lp;
ZX	else
ZX		*comp = prog;
ZX	if (pipe(p) < 0)
ZX		err("pipe: %s", strerror(errno));
ZX
ZX	switch(vfork()) {
ZX	case 0:
ZX		(void)close(p[0]);
ZX		if (p[1] != 1) {
ZX			(void)dup2(p[1], 1);
ZX			(void)close(p[1]);
ZX		}
ZX		execv(prog, comp);
ZX		err("execv: %s: %s", prog, strerror(errno));
ZX		_exit(1);
ZX	case -1:
ZX		err("fork: %s", strerror(errno));
ZX	}
ZX	(void)close(p[1]);
ZX	if (!(fp = fdopen(p[0], "r")))
ZX		err("fdopen: %s", strerror(errno));
ZX	while ((ch = getc(fp)) != EOF) {
ZX		if (ch == '\n')
ZX			putchar('\r');
ZX		putchar(ch);
ZX	}
ZX	exit(0);
ZX}
ZX
ZX#if __STDC__
ZX#include <stdarg.h>
ZX#else
ZX#include <varargs.h>
ZX#endif
ZX
ZXvoid
ZX#if __STDC__
ZXerr(const char *fmt, ...)
ZX#else
ZXerr(fmt, va_alist)
ZX	char *fmt;
ZX        va_dcl
ZX#endif
ZX{
ZX	va_list ap;
ZX#if __STDC__
ZX	va_start(ap, fmt);
ZX#else
ZX	va_start(ap);
ZX#endif
ZX	(void)vsyslog(LOG_ERR, fmt, ap);
ZX	va_end(ap);
ZX	exit(1);
ZX	/* NOTREACHED */
ZX}
ZSHAR_EOF
Zfi
Zif test -f 'pathnames.h'
Zthen
Z	echo shar: "will not over-write existing file 'pathnames.h'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > 'pathnames.h'
ZX/*
ZX * Copyright (c) 1989, 1993
ZX *	The Regents of the University of California.  All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms, with or without
ZX * modification, are permitted provided that the following conditions
ZX * are met:
ZX * 1. Redistributions of source code must retain the above copyright
ZX *    notice, this list of conditions and the following disclaimer.
ZX * 2. Redistributions in binary form must reproduce the above copyright
ZX *    notice, this list of conditions and the following disclaimer in the
ZX *    documentation and/or other materials provided with the distribution.
ZX * 3. All advertising materials mentioning features or use of this software
ZX *    must display the following acknowledgement:
ZX *	This product includes software developed by the University of
ZX *	California, Berkeley and its contributors.
ZX * 4. Neither the name of the University nor the names of its contributors
ZX *    may be used to endorse or promote products derived from this software
ZX *    without specific prior written permission.
ZX *
ZX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX * SUCH DAMAGE.
ZX *
ZX *	@(#)pathnames.h	8.1 (Berkeley) 6/4/93
ZX *	@(#)pathnames.h 8.1.1 (2.11BSD) 1995/04/01
ZX */
ZX
ZX#define	_PATH_FINGER	"/usr/ucb/finger"
ZSHAR_EOF
Zfi
Zcd ..
Zif test -f '/usr/src/lib/libc/gen/strftime.c'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/strftime.c'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/strftime.c'
ZX/*
ZX * Copyright (c) 1989, 1993
ZX *	The Regents of the University of California.  All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms, with or without
ZX * modification, are permitted provided that the following conditions
ZX * are met:
ZX * 1. Redistributions of source code must retain the above copyright
ZX *    notice, this list of conditions and the following disclaimer.
ZX * 2. Redistributions in binary form must reproduce the above copyright
ZX *    notice, this list of conditions and the following disclaimer in the
ZX *    documentation and/or other materials provided with the distribution.
ZX * 3. All advertising materials mentioning features or use of this software
ZX *    must display the following acknowledgement:
ZX *	This product includes software developed by the University of
ZX *	California, Berkeley and its contributors.
ZX * 4. Neither the name of the University nor the names of its contributors
ZX *    may be used to endorse or promote products derived from this software
ZX *    without specific prior written permission.
ZX *
ZX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX * SUCH DAMAGE.
ZX */
ZX
ZX#if defined(LIBC_SCCS) && !defined(lint)
ZXstatic char sccsid[] = "@(#)strftime.c	8.1.1 (2.11BSD) 1995/04/01";
ZX#endif /* LIBC_SCCS and not lint */
ZX
ZX#include <sys/types.h>
ZX#include <sys/time.h>
ZX#include <tzfile.h>
ZX#include <string.h>
ZX
ZXstatic char *Afmt[] = {
ZX	"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
ZX	"Saturday",
ZX};
ZXstatic char *Bfmt[] = {
ZX	"January", "February", "March", "April", "May", "June", "July",
ZX	"August", "September", "October", "November", "December",
ZX};
ZX
ZXstatic size_t gsize;
ZXstatic char *pt;
ZXstatic int _add();
ZXstatic int _conv();
ZXstatic size_t _fmt();
ZX
ZXsize_t
ZXstrftime(s, maxsize, format, t)
ZX	char *s;
ZX	size_t maxsize;
ZX	char *format;
ZX	struct tm *t;
ZX{
ZX
ZX	pt = s;
ZX	if ((gsize = maxsize) < 1)
ZX		return(0);
ZX	if (_fmt(format, t)) {
ZX		*pt = '\0';
ZX		return(maxsize - gsize);
ZX	}
ZX	return(0);
ZX}
ZX
ZXstatic size_t
ZX_fmt(format, t)
ZX	register char *format;
ZX	register struct tm *t;
ZX{
ZX	char	ch, *cp, junk[4];
ZX
ZX	for (; *format; ++format) {
ZX		if (*format == '%')
ZX			switch(ch = *++format) {
ZX			case '\0':
ZX				--format;
ZX				break;
ZX			case 'A':
ZX			case 'a':
ZX				if (t->tm_wday < 0 || t->tm_wday > 6)
ZX					return(0);
ZX				if	(ch == 'a')
ZX					{
ZX					bcopy(Afmt[t->tm_wday], junk, 3);
ZX					junk[3] = '\0';
ZX					cp = junk;
ZX					}
ZX				else
ZX					cp = Afmt[t->tm_wday];
ZX				if (!_add(cp))
ZX					return(0);
ZX				continue;
ZX			case 'B':
ZX			case 'b':
ZX			case 'h':
ZX				if (t->tm_mon < 0 || t->tm_mon > 11)
ZX					return(0);
ZX				if	(ch == 'b')
ZX					{
ZX					bcopy(Bfmt[t->tm_mon], junk, 3);
ZX					junk[3] = '\0';
ZX					cp = junk;
ZX					}
ZX				else
ZX					cp = Bfmt[t->tm_mon];
ZX				if (!_add(cp))
ZX					return(0);
ZX				continue;
ZX			case 'C':
ZX				if (!_fmt("%a %b %e %H:%M:%S %Y", t))
ZX					return(0);
ZX				continue;
ZX			case 'c':
ZX				if (!_fmt("%m/%d/%y %H:%M:%S", t))
ZX					return(0);
ZX				continue;
ZX			case 'D':
ZX				if (!_fmt("%m/%d/%y", t))
ZX					return(0);
ZX				continue;
ZX			case 'd':
ZX				if (!_conv(t->tm_mday, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'e':
ZX				if (!_conv(t->tm_mday, 2, ' '))
ZX					return(0);
ZX				continue;
ZX			case 'H':
ZX				if (!_conv(t->tm_hour, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'I':
ZX				if (!_conv(t->tm_hour % 12 ?
ZX				    t->tm_hour % 12 : 12, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'j':
ZX				if (!_conv(t->tm_yday + 1, 3, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'k':
ZX				if (!_conv(t->tm_hour, 2, ' '))
ZX					return(0);
ZX				continue;
ZX			case 'l':
ZX				if (!_conv(t->tm_hour % 12 ?
ZX				    t->tm_hour % 12 : 12, 2, ' '))
ZX					return(0);
ZX				continue;
ZX			case 'M':
ZX				if (!_conv(t->tm_min, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'm':
ZX				if (!_conv(t->tm_mon + 1, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'n':
ZX				if (!_add("\n"))
ZX					return(0);
ZX				continue;
ZX			case 'p':
ZX				if (!_add(t->tm_hour >= 12 ? "PM" : "AM"))
ZX					return(0);
ZX				continue;
ZX			case 'R':
ZX				if (!_fmt("%H:%M", t))
ZX					return(0);
ZX				continue;
ZX			case 'r':
ZX				if (!_fmt("%I:%M:%S %p", t))
ZX					return(0);
ZX				continue;
ZX			case 'S':
ZX				if (!_conv(t->tm_sec, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'T':
ZX			case 'X':
ZX				if (!_fmt("%H:%M:%S", t))
ZX					return(0);
ZX				continue;
ZX			case 't':
ZX				if (!_add("\t"))
ZX					return(0);
ZX				continue;
ZX			case 'U':
ZX				if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7,
ZX				    2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'W':
ZX				if (!_conv((t->tm_yday + 7 -
ZX				    (t->tm_wday ? (t->tm_wday - 1) : 6))
ZX				    / 7, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'w':
ZX				if (!_conv(t->tm_wday, 1, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'x':
ZX				if (!_fmt("%m/%d/%y", t))
ZX					return(0);
ZX				continue;
ZX			case 'y':
ZX				if (!_conv((t->tm_year + TM_YEAR_BASE)
ZX				    % 100, 2, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'Y':
ZX				if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0'))
ZX					return(0);
ZX				continue;
ZX			case 'Z':
ZX				if (!t->tm_zone || !_add(t->tm_zone))
ZX					return(0);
ZX				continue;
ZX			case '%':
ZX			/*
ZX			 * X311J/88-090 (4.12.3.5): if conversion char is
ZX			 * undefined, behavior is undefined.  Print out the
ZX			 * character itself as printf(3) does.
ZX			 */
ZX			default:
ZX				break;
ZX		}
ZX		if (!gsize--)
ZX			return(0);
ZX		*pt++ = *format;
ZX	}
ZX	return(gsize);
ZX}
ZX
ZXstatic int
ZX_conv(n, digits, pad)
ZX	int n, digits, pad;
ZX{
ZX	static char buf[10];
ZX	register char *p;
ZX
ZX	for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
ZX		*p-- = n % 10 + '0';
ZX	while (p > buf && digits-- > 0)
ZX		*p-- = pad;
ZX	return(_add(++p));
ZX}
ZX
ZXstatic int
ZX_add(str)
ZX	register char *str;
ZX{
ZX	for (;; ++pt, --gsize) {
ZX		if (!gsize)
ZX			return(0);
ZX		if (!(*pt = *str++))
ZX			return(1);
ZX	}
ZX}
ZSHAR_EOF
Zfi
Zif test -f '/usr/src/lib/libc/gen/syslog.c'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/syslog.c'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/syslog.c'
ZX/*
ZX * Copyright (c) 1983, 1988, 1993
ZX *	The Regents of the University of California.  All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms, with or without
ZX * modification, are permitted provided that the following conditions
ZX * are met:
ZX * 1. Redistributions of source code must retain the above copyright
ZX *    notice, this list of conditions and the following disclaimer.
ZX * 2. Redistributions in binary form must reproduce the above copyright
ZX *    notice, this list of conditions and the following disclaimer in the
ZX *    documentation and/or other materials provided with the distribution.
ZX * 3. All advertising materials mentioning features or use of this software
ZX *    must display the following acknowledgement:
ZX *	This product includes software developed by the University of
ZX *	California, Berkeley and its contributors.
ZX * 4. Neither the name of the University nor the names of its contributors
ZX *    may be used to endorse or promote products derived from this software
ZX *    without specific prior written permission.
ZX *
ZX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX * SUCH DAMAGE.
ZX */
ZX
ZX#if defined(LIBC_SCCS) && !defined(lint)
ZXstatic char sccsid[] = "@(#)syslog.c	8.4.1 (2.11BSD) 1995/04/01";
ZX#endif /* LIBC_SCCS and not lint */
ZX
ZX#include <sys/types.h>
ZX#include <sys/socket.h>
ZX#include <syslog.h>
ZX#include <sys/uio.h>
ZX#include <netdb.h>
ZX
ZX#include <errno.h>
ZX#include <fcntl.h>
ZX#include <paths.h>
ZX#include <stdio.h>
ZX#include <string.h>
ZX#include <time.h>
ZX
ZX#include <varargs.h>
ZX
ZX#define	STDERR_FILENO	2
ZX
ZXstatic	int	LogFile = -1;		/* fd for log */
ZXstatic	char	connected;		/* have done connect */
ZX#ifdef	pdp11
ZXstatic	char	ToFile = 0;		/* set if logfile is used */
ZX#endif
ZXstatic	int	LogStat = 0;		/* status bits, set by openlog() */
ZXstatic	char	*LogTag = NULL;		/* string to tag the entry with */
ZXstatic	int	LogFacility = LOG_USER;	/* default facility code */
ZXstatic	int	LogMask = 0xff;		/* mask of priorities to be logged */
ZX#ifdef	pdp11
ZXstatic	char	logfile[] = "/usr/adm/messages";
ZX#endif
ZX
ZXextern	char	*__progname;		/* Program name, from crt0. */
ZXextern	int	errno;			/* error number */
ZX
ZX/*
ZX * syslog, vsyslog --
ZX *	print message on log file; output is intended for syslogd(8).
ZX */
ZXvoid
ZXsyslog(pri, fmt, va_alist)
ZX	int pri;
ZX	char *fmt;
ZX	va_dcl
ZX{
ZX	va_list ap;
ZX
ZX	va_start(ap);
ZX	vsyslog(pri, fmt, ap);
ZX	va_end(ap);
ZX}
ZX
ZXvoid
ZXvsyslog(pri, fmt, ap)
ZX	int pri;
ZX	register char *fmt;
ZX	va_list ap;
ZX{
ZX	int cnt;
ZX	char ch;
ZX	register char *p, *t;
ZX	time_t now;
ZX	int fd, saved_errno;
ZX	char *stdp, tbuf[640], fmt_cpy[512];
ZX
ZX#define	INTERNALLOG	LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
ZX	/* Check for invalid bits. */
ZX	if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
ZX		syslog(INTERNALLOG,
ZX		    "syslog: bad fac/pri: %x", pri);
ZX		pri &= LOG_PRIMASK|LOG_FACMASK;
ZX	}
ZX
ZX	/* Check priority against setlogmask values. */
ZX	if (!LOG_MASK(LOG_PRI(pri)) & LogMask)
ZX		return;
ZX
ZX	saved_errno = errno;
ZX
ZX	/* Set default facility if none specified. */
ZX	if ((pri & LOG_FACMASK) == 0)
ZX		pri |= LogFacility;
ZX
ZX	/* Build the message. */
ZX	(void)time(&now);
ZX	p = tbuf + sprintf(tbuf, "<%d>", pri);
ZX	p += strftime(p, sizeof (tbuf) - (p - tbuf), "%h %e %T ",
ZX	    localtime(&now));
ZX	if (LogStat & LOG_PERROR)
ZX		stdp = p;
ZX	if (LogTag == NULL)
ZX		LogTag = __progname;
ZX	if (LogTag != NULL)
ZX		p += sprintf(p, "%s", LogTag);
ZX	if (LogStat & LOG_PID)
ZX		p += sprintf(p, "[%d]", getpid());
ZX	if (LogTag != NULL) {
ZX		*p++ = ':';
ZX		*p++ = ' ';
ZX	}
ZX
ZX	/* Substitute error message for %m. */
ZX	for (t = fmt_cpy; ch = *fmt; ++fmt)
ZX		if (ch == '%' && fmt[1] == 'm') {
ZX			++fmt;
ZX			t += sprintf(t, "%s", strerror(saved_errno));
ZX		} else
ZX			*t++ = ch;
ZX	*t = '\0';
ZX
ZX	p += vsprintf(p, fmt_cpy, ap);
ZX	cnt = p - tbuf;
ZX
ZX	/* Output to stderr if requested. */
ZX	if (LogStat & LOG_PERROR) {
ZX		struct iovec iov[2];
ZX		register struct iovec *v = iov;
ZX
ZX		v->iov_base = stdp;
ZX		v->iov_len = cnt - (stdp - tbuf);
ZX		++v;
ZX		v->iov_base = "\n";
ZX		v->iov_len = 1;
ZX		(void)writev(STDERR_FILENO, iov, 2);
ZX	}
ZX
ZX	/* Get connected, output the message to the local logger. */
ZX	if (!connected)
ZX		openlog(LogTag, LogStat | LOG_NDELAY, 0);
ZX#ifdef	pdp11
ZX	if (ToFile) {
ZX		if (write(LogFile, tbuf, cnt) == cnt)
ZX			return;
ZX	}
ZX	else
ZX#endif
ZX	if (send(LogFile, tbuf, cnt, 0) >= 0)
ZX		return;
ZX
ZX	/*
ZX	 * Output the message to the console; don't worry about blocking,
ZX	 * if console blocks everything will.  Make sure the error reported
ZX	 * is the one from the syslogd failure.
ZX	 */
ZX	if (LogStat & LOG_CONS &&
ZX	    (fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) {
ZX		(void)strcat(tbuf, "\r\n");
ZX		cnt += 2;
ZX		p = index(tbuf, '>') + 1;
ZX		(void)write(fd, p, cnt - (p - tbuf));
ZX		(void)close(fd);
ZX	}
ZX}
ZX
ZXstatic struct sockaddr SyslogAddr;	/* AF_UNIX address of local logger */
ZX
ZXvoid
ZXopenlog(ident, logstat, logfac)
ZX	char *ident;
ZX	int logstat;
ZX	register int logfac;
ZX{
ZX	if (ident != NULL)
ZX		LogTag = ident;
ZX	LogStat = logstat;
ZX	if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
ZX		LogFacility = logfac;
ZX
ZX	if (LogFile == -1) {
ZX		SyslogAddr.sa_family = AF_UNIX;
ZX		(void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
ZX		    sizeof(SyslogAddr.sa_data));
ZX		if (LogStat & LOG_NDELAY) {
ZX			LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
ZX#ifdef	pdp11
ZX			if (LogFile == -1) {
ZX				LogFile = open(logfile, O_WRONLY|O_APPEND);
ZX				ToFile = 1;
ZX			}
ZX			else
ZX				ToFile = 0;
ZX#endif
ZX			if (LogFile == -1)
ZX				return;
ZX			(void)fcntl(LogFile, F_SETFD, 1);
ZX		}
ZX	}
ZX	if (LogFile != -1 && !connected)
ZX		if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) {
ZX			(void)close(LogFile);
ZX			LogFile = -1;
ZX		} else
ZX			connected = 1;
ZX}
ZX
ZXvoid
ZXcloselog()
ZX{
ZX	(void)close(LogFile);
ZX	LogFile = -1;
ZX	connected = 0;
ZX}
ZX
ZX/* setlogmask -- set the log mask level */
ZXint
ZXsetlogmask(pmask)
ZX	register int pmask;
ZX{
ZX	register int omask;
ZX
ZX	omask = LogMask;
ZX	if (pmask != 0)
ZX		LogMask = pmask;
ZX	return (omask);
ZX}
ZSHAR_EOF
Zfi
Zif test -f '/usr/src/lib/libc/stdio/sprintf.c'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/lib/libc/stdio/sprintf.c'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/stdio/sprintf.c'
ZX/*
ZX * Copyright (c) 1988 Regents of the University of California.
ZX * All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms are permitted
ZX * provided that the above copyright notice and this paragraph are
ZX * duplicated in all such forms and that any documentation,
ZX * advertising materials, and other materials related to such
ZX * distribution and use acknowledge that the software was developed
ZX * by the University of California, Berkeley.  The name of the
ZX * University may not be used to endorse or promote products derived
ZX * from this software without specific prior written permission.
ZX * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
ZX * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
ZX * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
ZX */
ZX
ZX#if defined(LIBC_SCCS) && !defined(lint)
ZXstatic char sccsid[] = "@(#)vsprintf.c	5.2.1 (2.11BSD) 1995/04/02";
ZX#endif /* LIBC_SCCS and not lint */
ZX
ZX#include	<stdio.h>
ZX
ZXint
ZXsprintf(str, fmt, args)
ZX	char *str, *fmt;
ZX{
ZX	FILE _strbuf;
ZX
ZX	_strbuf._flag = _IOWRT+_IOSTRG;
ZX	_strbuf._ptr = str;
ZX	_strbuf._cnt = 32767;
ZX	_doprnt(fmt, &args, &_strbuf);
ZX	*_strbuf._ptr = 0;
ZX	return(_strbuf._ptr - str);
ZX}
ZSHAR_EOF
Zfi
Zif test -f '/usr/src/lib/libc/stdio/vsprintf.c'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/lib/libc/stdio/vsprintf.c'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/stdio/vsprintf.c'
ZX/*
ZX * Copyright (c) 1988 Regents of the University of California.
ZX * All rights reserved.
ZX *
ZX * Redistribution and use in source and binary forms are permitted
ZX * provided that the above copyright notice and this paragraph are
ZX * duplicated in all such forms and that any documentation,
ZX * advertising materials, and other materials related to such
ZX * distribution and use acknowledge that the software was developed
ZX * by the University of California, Berkeley.  The name of the
ZX * University may not be used to endorse or promote products derived
ZX * from this software without specific prior written permission.
ZX * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
ZX * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
ZX * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
ZX */
ZX
ZX#if defined(LIBC_SCCS) && !defined(lint)
ZXstatic char sccsid[] = "@(#)vsprintf.c	5.2.1 (2.11BSD) 1995/04/02";
ZX#endif /* LIBC_SCCS and not lint */
ZX
ZX#include <stdio.h>
ZX#include <varargs.h>
ZX
ZXint
ZXvsprintf(str, fmt, ap)
ZX	char *str, *fmt;
ZX	va_list ap;
ZX{
ZX	FILE f;
ZX
ZX	f._flag = _IOWRT+_IOSTRG;
ZX	f._ptr = str;
ZX	f._cnt = 32767;
ZX	_doprnt(fmt, ap, &f);
ZX	*f._ptr = 0;
ZX	return (f._ptr - str);
ZX}
ZSHAR_EOF
Zfi
Zif test -f '/usr/src/man/man3/syslog.3'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/man/man3/syslog.3'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/man/man3/syslog.3'
ZX.\" Copyright (c) 1985, 1991, 1993
ZX.\"	The Regents of the University of California.  All rights reserved.
ZX.\"
ZX.\" Redistribution and use in source and binary forms, with or without
ZX.\" modification, are permitted provided that the following conditions
ZX.\" are met:
ZX.\" 1. Redistributions of source code must retain the above copyright
ZX.\"    notice, this list of conditions and the following disclaimer.
ZX.\" 2. Redistributions in binary form must reproduce the above copyright
ZX.\"    notice, this list of conditions and the following disclaimer in the
ZX.\"    documentation and/or other materials provided with the distribution.
ZX.\" 3. All advertising materials mentioning features or use of this software
ZX.\"    must display the following acknowledgement:
ZX.\"	This product includes software developed by the University of
ZX.\"	California, Berkeley and its contributors.
ZX.\" 4. Neither the name of the University nor the names of its contributors
ZX.\"    may be used to endorse or promote products derived from this software
ZX.\"    without specific prior written permission.
ZX.\"
ZX.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX.\" SUCH DAMAGE.
ZX.\"
ZX.\"     @(#)syslog.3	8.1.1 (2.11BSD) 1995/04/01
ZX.\"
ZX.TH SYSLOG 3 "April 1, 1995"
ZX.UC 5
ZX.SH NAME
ZXsyslog , vsyslog , openlog , closelog , setlogmask \- control system log
ZX.SH SYNOPSIS
ZX.B #include <syslog.h>
ZX.br
ZX.B #include <varargs.h>
ZX.PP
ZX.B void syslog(priority, message, ...);
ZX.br
ZX.B int priority;
ZX.br
ZX.B char *message;
ZX.PP
ZX.B void vsyslog(priority, message, args);
ZX.br
ZX.B int priority;
ZX.br
ZX.B char *message;
ZX.br
ZX.B va_list args;
ZX.PP
ZX.B void openlog(ident, logopt, facility);
ZX.br
ZX.B char *ident;
ZX.br
ZX.B int logopt;
ZX.br
ZX.B int facility;
ZX.PP
ZX.B void closelog();
ZX.PP
ZX.B int setlogmask(maskpri);
ZX.br
ZX.B int maskpri;
ZX.SH DESCRIPTION
ZXThe
ZX.IR syslog ()
ZXfunction
ZXwrites
ZX.I message
ZXto the system message logger.
ZXThe message is then written to the system console, log files,
ZXlogged-in users, or forwarded to other machines as appropriate. (See
ZX.IR syslogd (8)).
ZX.PP
ZXThe message is identical to a
ZX.IR printf (3)
ZXformat string, except that
ZX.B %m
ZXis replaced by the current error
ZXmessage as denoted by the global variable \fIerrno\fP.
ZXSee
ZX.IR strerror (3)).
ZXA trailing newline is added if none is present.
ZX.PP
ZXThe
ZX.IR vsyslog ()
ZXfunction
ZXis an alternate form in which the arguments have already been captured
ZXusing the variable-length argument facilities of
ZX.IR varargs (3).
ZX.PP
ZXThe message is tagged with
ZX.IR priority .
ZXPriorities are encoded as a
ZX.I facility
ZXand a
ZX.IR level .
ZXThe facility describes the part of the system
ZXgenerating the message.
ZXThe level is selected from the following
ZX.I ordered
ZX(high to low) list:
ZX.IP LOG_EMERG \w'LOG_AUTHORITY'u+3
ZXA panic condition.
ZXThis is normally broadcast to all users.
ZX.IP LOG_ALERT \w'LOG_AUTHORITY'u+3
ZXA condition that should be corrected immediately, such as a corrupted
ZXsystem database.
ZX.IP LOG_CRIT \w'LOG_AUTHORITY'u+3
ZXCritical conditions, e.g., hard device errors.
ZX.IP LOG_ERR \w'LOG_AUTHORITY'u+3
ZXErrors.
ZX.IP LOG_WARNING \w'LOG_AUTHORITY'u+3
ZXWarning messages.
ZX.IP LOG_NOTICE \w'LOG_AUTHORITY'u+3
ZXConditions that are not error conditions,
ZXbut should possibly be handled specially.
ZX.IP LOG_INFO \w'LOG_AUTHORITY'u+3
ZXInformational messages.
ZX.IP LOG_DEBUG \w'LOG_AUTHORITY'u+3
ZXMessages that contain information
ZXnormally of use only when debugging a program.
ZX.PP
ZXThe
ZX.IR openlog ()
ZXfunction
ZXprovides for more specialized processing of the messages sent
ZXby
ZX.IR syslog ()
ZXand
ZX.IR vsyslog ().
ZXThe parameter
ZX.I ident
ZXis a string that will be prepended to every message.
ZXThe
ZX.I logopt
ZXargument
ZXis a bit field specifying logging options, which is formed by
ZX.B OR'ing
ZXone or more of the following values:
ZX.IP LOG_CONS \w'LOG_AUTHPRIV'u+3
ZXIf
ZX.IR syslog
ZXcannot pass the message to
ZX.IR syslogd
ZXit will attempt to write the message to the console (\fB/dev/console\fP).
ZX.IP LOG_NDELAY \w'LOG_AUTHPRIV'u+3
ZXOpen the connection to
ZX.IR syslogd
ZXimmediately.
ZXNormally the open is delayed until the first message is logged.
ZXUseful for programs that need to manage the order in which file
ZXdescriptors are allocated.
ZX.IP LOG_PERROR \w'LOG_AUTHPRIV'u+3
ZXWrite the message to standard error output as well to the system log.
ZX.IP LOG_PID \w'LOG_AUTHPRIV'u+3
ZXLog the process id with each message: useful for identifying
ZXinstantiations of daemons.
ZX.PP
ZXThe
ZX.IR facility
ZXparameter encodes a default facility to be assigned to all messages
ZXthat do not have an explicit facility encoded:
ZX.IP LOG_AUTH \w'LOG_AUTHPRIV'u+3
ZXThe authorization system:
ZX.IR login (1),
ZX.IR su (1),
ZX.IR getty (8),
ZXetc.
ZX.IP LOG_AUTHPRIV \w'LOG_AUTHPRIV'u+3
ZXThe same as
ZX.B LOG_AUTH ,
ZXbut logged to a file readable only by
ZXselected individuals.
ZX.IP LOG_CRON \w'LOG_AUTHPRIV'u+3
ZXThe clock daemon.
ZX.IP LOG_DAEMON \w'LOG_AUTHPRIV'u+3
ZXSystem daemons, such as
ZX.IR routed (8),
ZXthat are not provided for explicitly by other facilities.
ZX.IP LOG_KERN \w'LOG_AUTHPRIV'u+3
ZXMessages generated by the kernel.
ZXThese cannot be generated by any user processes.
ZX.IP LOG_LPR \w'LOG_AUTHPRIV'u+3
ZXThe line printer spooling system:
ZX.IR lpr (1),
ZX.IR lpc (8),
ZX.IR lpd (8),
ZXetc.
ZX.IP LOG_MAIL \w'LOG_AUTHPRIV'u+3
ZXThe mail system.
ZX.IP LOG_NEWS \w'LOG_AUTHPRIV'u+3
ZXThe network news system.
ZX.IP LOG_SYSLOG \w'LOG_AUTHPRIV'u+3
ZXMessages generated internally by
ZX.IR syslogd (8).
ZX.IP LOG_USER \w'LOG_AUTHPRIV'u+3
ZXMessages generated by random user processes.
ZXThis is the default facility identifier if none is specified.
ZX.IP LOG_UUCP \w'LOG_AUTHPRIV'u+3
ZXThe uucp system.
ZX.IP LOG_LOCAL0 \w'LOG_AUTHPRIV'u+3
ZXReserved for local use.
ZXSimilarly for \fBLOG_LOCAL1\fP through \fBLOG_LOCAL7\fP.
ZX.PP
ZXThe
ZX.IR closelog
ZXfunction
ZXcan be used to close the log file.
ZX.PP
ZXThe
ZX.IR setlogmask
ZXfunction
ZXsets the log priority mask to
ZX.I maskpri
ZXand returns the previous mask.
ZXCalls to
ZX.IR syslog
ZXwith a priority not set in
ZX.I maskpri
ZXare rejected.
ZXThe mask for an individual priority
ZX.I pri
ZXis calculated by the macro
ZX.IR LOG_MASK (pri).
ZXThe mask for all priorities up to and including
ZX.I toppri
ZXis given by the macro
ZX.IR LOG_UPTO (toppri).
ZXThe default allows all priorities to be logged.
ZX.PP
ZX.SH RETURN VALUES
ZXThe routines
ZX.IR closelog (),
ZX.IR openlog (),
ZX.IR syslog ()
ZXand
ZX.IR vsyslog ()
ZXreturn no value.
ZX.PP
ZXThe routine
ZX.IR setlogmask ()
ZXalways returns the previous log mask level.
ZX.PP
ZX.SH EXAMPLES
ZX.IP "" 8
ZXsyslog(LOG_ALERT, "who: internal error 23");
ZX
ZXopenlog("ftpd", LOG_PID, LOG_DAEMON);
ZXsetlogmask(LOG_UPTO(LOG_ERR));
ZXsyslog(LOG_INFO, "Connection from host %d", CallingHost);
ZX
ZXsyslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
ZX.PP
ZX.SH SEE ALSO
ZX.I logger(1), syslogd(8)
ZX.SH BUGS
ZXUnder 2.11BSD the logfile \fB/usr/adm/messages\fP is used if a non
ZXnetworking kernel has been booted.  That file must be publically writeable
ZXin this case.
ZX.SH HISTORY
ZXThese
ZXfunctions appeared in 4.2BSD.
ZSHAR_EOF
Zfi
Zif test -f '/usr/src/man/man3/strftime.3'
Zthen
Z	echo shar: "will not over-write existing file '/usr/src/man/man3/strftime.3'"
Zelse
Zsed 's/^X//' << \SHAR_EOF > '/usr/src/man/man3/strftime.3'
ZX.\" Copyright (c) 1989, 1991, 1993
ZX.\"	The Regents of the University of California.  All rights reserved.
ZX.\"
ZX.\" This code is derived from software contributed to Berkeley by
ZX.\" the American National Standards Committee X3, on Information
ZX.\" Processing Systems.
ZX.\"
ZX.\" Redistribution and use in source and binary forms, with or without
ZX.\" modification, are permitted provided that the following conditions
ZX.\" are met:
ZX.\" 1. Redistributions of source code must retain the above copyright
ZX.\"    notice, this list of conditions and the following disclaimer.
ZX.\" 2. Redistributions in binary form must reproduce the above copyright
ZX.\"    notice, this list of conditions and the following disclaimer in the
ZX.\"    documentation and/or other materials provided with the distribution.
ZX.\" 3. All advertising materials mentioning features or use of this software
ZX.\"    must display the following acknowledgement:
ZX.\"	This product includes software developed by the University of
ZX.\"	California, Berkeley and its contributors.
ZX.\" 4. Neither the name of the University nor the names of its contributors
ZX.\"    may be used to endorse or promote products derived from this software
ZX.\"    without specific prior written permission.
ZX.\"
ZX.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ZX.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ZX.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ZX.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ZX.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ZX.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ZX.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ZX.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ZX.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ZX.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ZX.\" SUCH DAMAGE.
ZX.\"
ZX.\"     @(#)strftime.3	8.1.1 (2.11BSD) 1995/04/01
ZX.\"
ZX.TH STRFTIME 3 "April 1, 1995"
ZX.UC 5
ZX.SH NAME
ZXstrftime \- format date and time
ZX.SH SYNOPSIS
ZX.B #include <sys/types.h>
ZX.br
ZX.B #include <time.h>
ZX.br
ZX.B #include <string.h>
ZX.br
ZX.sp
ZX.B size_t strftime(buf, maxsize, format, timeptr)
ZX.br
ZX.B char *buf;
ZX.br
ZX.B size_t maxsize;
ZX.br
ZX.B char *format;
ZX.br
ZX.B struct tm *timeptr;
ZX.PP
ZX.SH DESCRIPTION
ZXThe
ZX.B strftime()
ZXfunction formats the information from
ZX.I timeptr
ZXinto the buffer
ZX.I buf
ZXaccording to the string pointed to by \fIformat\fP.
ZX.PP
ZXThe
ZX.I format
ZXstring consists of zero or more conversion specifications and
ZXordinary characters.
ZXAll ordinary characters are copied directly into the buffer.
ZXA conversion specification consists of a percent sign
ZX``%''
ZXand one other character.
ZX.PP
ZXNo more than
ZX.I maxsize
ZXcharacters will be placed into the array.
ZXIf the total number of resulting characters, including the terminating
ZXnull character, is not more than
ZX.IR maxsize ,
ZX.B strftime()
ZXreturns the number of characters in the array, not counting the
ZXterminating null.
ZXOtherwise, zero is returned.
ZX.PP
ZXEach conversion specification is replaced by the characters as
ZXfollows which are then copied into the buffer.
ZX.IP \&%A \w'xxxx'u+3
ZXis replaced by the full weekday name.
ZX.IP %a \w'xxxx'u+3
ZXis replaced by the abbreviated weekday name, where the abbreviation
ZXis the first three characters.
ZX.IP \&%B \w'xxxx'u+3
ZXis replaced by the full month name.
ZX.IP "%b or %h" \w'xxxx'u+3
ZXis replaced by the abbreviated month name, where the abbreviation is
ZXthe first three characters.
ZX.IP \&%C \w'xxxx'u+3	
ZXis equivalent to
ZX``%a %b %e %H:%M:%S %Y''
ZX(the format produced by
ZX.IR asctime (3)).
ZX.IP %c \w'xxxx'u+3
ZXis equivalent to
ZX``%m/%d/%y''.
ZX.IP \&%D \w'xxxx'u+3
ZXis replaced by the date in the format
ZX``mm/dd/yy''.
ZX.IP %d \w'xxxx'u+3
ZXis replaced by the day of the month as a decimal number (01-31).
ZX.IP %e \w'xxxx'u+3
ZXis replaced by the day of month as a decimal number (1-31); single
ZXdigits are preceded by a blank.
ZX.IP \&%H \w'xxxx'u+3
ZXis replaced by the hour (24-hour clock) as a decimal number (00-23).
ZX.IP \&%I \w'xxxx'u+3
ZXis replaced by the hour (12-hour clock) as a decimal number (01-12).
ZX.IP %j \w'xxxx'u+3
ZXis replaced by the day of the year as a decimal number (001-366).
ZX.IP %k \w'xxxx'u+3
ZXis replaced by the hour (24-hour clock) as a decimal number (0-23);
ZXsingle digits are preceded by a blank.
ZX.IP %l \w'xxxx'u+3
ZXis replaced by the hour (12-hour clock) as a decimal number (1-12);
ZXsingle digits are preceded by a blank.
ZX.IP \&%M \w'xxxx'u+3
ZXis replaced by the minute as a decimal number (00-59).
ZX.IP %m \w'xxxx'u+3
ZXis replaced by the month as a decimal number (01-12).
ZX.IP %n \w'xxxx'u+3
ZXis replaced by a newline.
ZX.IP %p \w'xxxx'u+3
ZXis replaced by either
ZX``AM''
ZXor
ZX``PM''
ZXas appropriate.
ZX.IP \&%R \w'xxxx'u+3
ZXis equivalent to
ZX``%H:%M''
ZX.IP %r \w'xxxx'u+3
ZXis equivalent to
ZX``%I:%M:%S %p'' .
ZX.IP %t \w'xxxx'u+3
ZXis replaced by a tab.
ZX.IP \&%S \w'xxxx'u+3
ZXis replaced by the second as a decimal number (00-60).
ZX.IP "\&%T or \&%X" \w'xxxx'u+3
ZXis equivalent to
ZX"%H:%M:%S" .
ZX.IP \&%U \w'xxxx'u+3
ZXis replaced by the week number of the year (Sunday as the first day of
ZXthe week) as a decimal number (00-53).
ZX.IP \&%W \w'xxxx'u+3
ZXis replaced by the week number of the year (Monday as the first day of
ZXthe week) as a decimal number (00-53).
ZX.IP %w \w'xxxx'u+3
ZXis replaced by the weekday (Sunday as the first day of the week)
ZXas a decimal number (0-6).
ZX.IP %x \w'xxxx'u+3
ZXis equivalent to
ZX``%m/%d/%y %H:%M:%S'' .
ZX.IP \&%Y \w'xxxx'u+3
ZXis replaced by the year with century as a decimal number.
ZX.IP %y \w'xxxx'u+3
ZXis replaced by the year without century as a decimal number (00-99).
ZX.IP \&%Z \w'xxxx'u+3
ZXis replaced by the time zone name.
ZX.IP %% \w'xxxx'u+3
ZXis replaced by
ZX`%' .
ZX.PP
ZX.SH SEE ALSO
ZX.IR date (1),
ZX.IR ctime (3),
ZX.IR printf (1),
ZX.IR printf (3)
ZX.SH STANDARDS
ZXThe
ZX.B strftime()
ZXfunction
ZXconforms to
ZXANSI X C3.159-1989(``ANSI C'').
ZX.SH BUGS
ZXThere is no conversion specification for the phase of the moon.
ZSHAR_EOF
Zfi
Zexit 0
Z#	End of shell archive
SHAR_EOF
fi
if test -f '/tmp/233.patch'
then
	echo shar: "will not over-write existing file '/tmp/233.patch'"
else
sed 's/^Z//' << \SHAR_EOF > '/tmp/233.patch'
Z*** /VERSION.old	Fri Mar 17 20:07:05 1995
Z--- /VERSION	Sun Apr  2 01:40:42 1995
Z***************
Z*** 1,4 ****
Z! Current Patch Level: 232
Z  
Z  2.11 BSD
Z  ============
Z--- 1,4 ----
Z! Current Patch Level: 233
Z  
Z  2.11 BSD
Z  ============
Z*** /usr/include/paths.h.old	Fri Feb  3 21:02:25 1995
Z--- /usr/include/paths.h	Sat Apr  1 22:38:07 1995
Z***************
Z*** 14,20 ****
Z   * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Z   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Z   *
Z!  *	@(#)pathnames.h	5.3.1 (2.11BSD) 2/3/95
Z   */
Z  
Z  #define	_PATH_BSHELL	"/bin/sh"
Z--- 14,20 ----
Z   * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Z   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Z   *
Z!  *	@(#)pathnames.h	5.3.3 (2.11BSD) 1995/04/01
Z   */
Z  
Z  #define	_PATH_BSHELL	"/bin/sh"
Z***************
Z*** 21,26 ****
Z--- 21,27 ----
Z  #define	_PATH_CSHELL	"/bin/csh"
Z  #define	_PATH_CP	"/bin/cp"
Z  #define	_PATH_RSH	"/usr/ucb/rsh"
Z+ #define	_PATH_CONSOLE	"/dev/console"
Z  #define	_PATH_DEVNULL	"/dev/null"
Z  #define	_PATH_TTY	"/dev/tty"
Z  #define	_PATH_DEV	"/dev"
Z*** /usr/lib/lint/llib-lc.old	Sun Jan 22 16:39:33 1995
Z--- /usr/lib/lint/llib-lc	Sun Apr  2 23:29:17 1995
Z***************
Z*** 456,462 ****
Z  	setbuffer( f, b, s ) FILE *f; char *b; {;}
Z  	setlinebuf( f ) FILE *f; {;}
Z  	/* VARARGS2 */
Z! char *	sprintf( s, f ) char *s, *f; { return(s);}
Z  	/* VARARGS2 */
Z  	sscanf( s, f ) char *s, *f; { return(1); }
Z  	ungetc( c, f ) FILE *f; {  return(c); }
Z--- 456,464 ----
Z  	setbuffer( f, b, s ) FILE *f; char *b; {;}
Z  	setlinebuf( f ) FILE *f; {;}
Z  	/* VARARGS2 */
Z! int	sprintf( s, f ) char *s, *f; { return(1);}
Z! 	/*  VARARGS2 */
Z! int	vsprintf( s, f ) char *s, *f; { return (1);}
Z  	/* VARARGS2 */
Z  	sscanf( s, f ) char *s, *f; { return(1); }
Z  	ungetc( c, f ) FILE *f; {  return(c); }
Z*** /usr/src/lib/libc/gen/Makefile.old	Sat Feb  4 23:19:56 1995
Z--- /usr/src/lib/libc/gen/Makefile	Sat Apr  1 23:16:43 1995
Z***************
Z*** 3,9 ****
Z  # All rights reserved.  The Berkeley software License Agreement
Z  # specifies the terms and conditions for redistribution.
Z  #
Z! #	@(#)Makefile	5.7.2 (2.11BSD GTE) 2/4/95
Z  #
Z  # Several routines have been rewritten in assembly language for the VAX and
Z  # the PDP. If you are not running on a VAX or PDP, you should use the
Z--- 3,9 ----
Z  # All rights reserved.  The Berkeley software License Agreement
Z  # specifies the terms and conditions for redistribution.
Z  #
Z! #	@(#)Makefile	5.7.3 (2.11BSD) 1995/04/01
Z  #
Z  # Several routines have been rewritten in assembly language for the VAX and
Z  # the PDP. If you are not running on a VAX or PDP, you should use the
Z***************
Z*** 22,30 ****
Z  	opendir.c perror.c popen.c psignal.c qsort.c random.c readdir.c \
Z  	regex.c scandir.c seekdir.c setgid.c setegid.c setrgid.c setuid.c \
Z  	setenv.c seteuid.c setruid.c siglist.c signal.c siginterrupt.c \
Z! 	sleep.c strcasecmp.c swab.c sysctl.c syslog.c system.c telldir.c \
Z! 	time.c timezone.c ttyname.c ttyslot.c ualarm.c usleep.c valloc.c \
Z! 	strdup.c strsep.c uname.c wait.c wait3.c waitpid.c
Z  STDOBJ=	abort.o alarm.o atoi.o atol.o calloc.o closedir.o crypt.o \
Z  	ctime.o ctype_.o daemon.o devname.o err.o errlst.o execvp.o fakcu.o \
Z  	fstab.o gcvt.o getenv.o getgrent.o getgrgid.o getgrnam.o getlogin.o \
Z--- 22,30 ----
Z  	opendir.c perror.c popen.c psignal.c qsort.c random.c readdir.c \
Z  	regex.c scandir.c seekdir.c setgid.c setegid.c setrgid.c setuid.c \
Z  	setenv.c seteuid.c setruid.c siglist.c signal.c siginterrupt.c \
Z! 	sleep.c strcasecmp.c strftime.c swab.c sysctl.c syslog.c system.c \
Z! 	telldir.c time.c timezone.c ttyname.c ttyslot.c ualarm.c usleep.c \
Z! 	valloc.c strdup.c strsep.c uname.c wait.c wait3.c waitpid.c
Z  STDOBJ=	abort.o alarm.o atoi.o atol.o calloc.o closedir.o crypt.o \
Z  	ctime.o ctype_.o daemon.o devname.o err.o errlst.o execvp.o fakcu.o \
Z  	fstab.o gcvt.o getenv.o getgrent.o getgrgid.o getgrnam.o getlogin.o \
Z***************
Z*** 34,42 ****
Z  	opendir.o perror.o popen.o psignal.o qsort.o random.o readdir.o \
Z  	regex.o scandir.o seekdir.o setgid.o setegid.o setrgid.o setuid.o \
Z  	setenv.o seteuid.o setruid.o siglist.o signal.o siginterrupt.o \
Z! 	sleep.o strcasecmp.o swab.o sysctl.o syslog.o system.o telldir.o \
Z! 	time.o timezone.o ttyname.o ttyslot.o ualarm.o usleep.o valloc.o \
Z! 	strdup.o strsep.o uname.o wait.o wait3.o waitpid.o
Z  
Z  TAGSFILE=tags
Z  
Z--- 34,42 ----
Z  	opendir.o perror.o popen.o psignal.o qsort.o random.o readdir.o \
Z  	regex.o scandir.o seekdir.o setgid.o setegid.o setrgid.o setuid.o \
Z  	setenv.o seteuid.o setruid.o siglist.o signal.o siginterrupt.o \
Z! 	sleep.o strcasecmp.o strftime.o swab.o sysctl.o syslog.o system.o \
Z! 	telldir.o time.o timezone.o ttyname.o ttyslot.o ualarm.o usleep.o \
Z! 	valloc.o strdup.o strsep.o uname.o wait.o wait3.o waitpid.o
Z  
Z  TAGSFILE=tags
Z
Z*** /usr/src/man/man3/Makefile.old	Fri Feb  3 21:35:23 1995
Z--- /usr/src/man/man3/Makefile	Sat Apr  1 22:47:58 1995
Z***************
Z*** 14,20 ****
Z  # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Z  # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Z  #
Z! #	@(#)Makefile	5.4.2 (2.11BSD GTE) 2/3/95
Z  #
Z  MDIR=	/usr/man/cat3
Z  SRCS1=	abort.3 abs.3 alarm.3 asinh.3 assert.3 atof.3 bstring.3 byteorder.3 \
Z--- 14,20 ----
Z  # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Z  # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Z  #
Z! #	@(#)Makefile	5.4.3 (2.11BSD) 1995/04/01
Z  #
Z  MDIR=	/usr/man/cat3
Z  SRCS1=	abort.3 abs.3 alarm.3 asinh.3 assert.3 atof.3 bstring.3 byteorder.3 \
Z***************
Z*** 31,38 ****
Z  	pause.3 perror.3 plot.3 popen.3 printf.3 psignal.3 putc.3 puts.3 \
Z  	qsort.3 rand.3 random.3 rcmd.3 regex.3 resolver.3 rexec.3 scandir.3 \
Z  	scanf.3 setbuf.3 setjmp.3 setuid.3 siginterrupt.3 signal.3 sin.3 \
Z! 	sinh.3 sleep.3 sqrt.3 stdio.3 string.3 strtok.3 stty.3 swab.3 \
Z! 	sysctl.3 syslog.3 \
Z  	system.3 termcap.3 time.3 times.3 ttyname.3 ualarm.3 ungetc.3 \
Z  	usleep.3 utime.3 valloc.3 varargs.3
Z  OBJS1=	abort.0 abs.0 alarm.0 asinh.0 assert.0 atof.0 bstring.0 byteorder.0 \
Z--- 31,38 ----
Z  	pause.3 perror.3 plot.3 popen.3 printf.3 psignal.3 putc.3 puts.3 \
Z  	qsort.3 rand.3 random.3 rcmd.3 regex.3 resolver.3 rexec.3 scandir.3 \
Z  	scanf.3 setbuf.3 setjmp.3 setuid.3 siginterrupt.3 signal.3 sin.3 \
Z! 	sinh.3 sleep.3 sqrt.3 stdio.3 strftime.3 string.3 strtok.3 stty.3 \
Z! 	swab.3 sysctl.3 syslog.3 \
Z  	system.3 termcap.3 time.3 times.3 ttyname.3 ualarm.3 ungetc.3 \
Z  	usleep.3 utime.3 valloc.3 varargs.3
Z  OBJS1=	abort.0 abs.0 alarm.0 asinh.0 assert.0 atof.0 bstring.0 byteorder.0 \
Z***************
Z*** 49,56 ****
Z  	pause.0 perror.0 plot.0 popen.0 printf.0 psignal.0 putc.0 puts.0 \
Z  	qsort.0 rand.0 random.0 rcmd.0 regex.0 resolver.0 rexec.0 scandir.0 \
Z  	scanf.0 setbuf.0 setjmp.0 setuid.0 siginterrupt.0 signal.0 sin.0 \
Z! 	sinh.0 sleep.0 sqrt.0 stdio.0 string.0 strtok.0 stty.0 swab.0 \
Z! 	sysctl.0 syslog.0 \
Z  	system.0 termcap.0 time.0 times.0 ttyname.0 ualarm.0 ungetc.0 \
Z  	usleep.0 utime.0 valloc.0 varargs.0
Z  REMO1=	edata.0 etext.0 j1.0 jn.0 ns_addr.0 ns_ntoa.0 y0.0 y1.0 yn.0 acos.0 \
Z--- 49,56 ----
Z  	pause.0 perror.0 plot.0 popen.0 printf.0 psignal.0 putc.0 puts.0 \
Z  	qsort.0 rand.0 random.0 rcmd.0 regex.0 resolver.0 rexec.0 scandir.0 \
Z  	scanf.0 setbuf.0 setjmp.0 setuid.0 siginterrupt.0 signal.0 sin.0 \
Z! 	sinh.0 sleep.0 sqrt.0 stdio.0 strftime.0 string.0 strtok.0 stty.0 \
Z! 	swab.0 sysctl.0 syslog.0 \
Z  	system.0 termcap.0 time.0 times.0 ttyname.0 ualarm.0 ungetc.0 \
Z  	usleep.0 utime.0 valloc.0 varargs.0
Z  REMO1=	edata.0 etext.0 j1.0 jn.0 ns_addr.0 ns_ntoa.0 y0.0 y1.0 yn.0 acos.0 \
Z*** /usr/src/man/man3/printf.3.old	Wed Aug 10 03:14:39 1988
Z--- /usr/src/man/man3/printf.3	Sun Apr  2 23:42:20 1995
Z***************
Z*** 1,13 ****
Z! .\"	@(#)printf.3s	6.5 (Berkeley) 8/10/88
Z  .\"
Z  .TH PRINTF 3S "August 10, 1988"
Z  .AT 3
Z  .SH NAME
Z! printf, fprintf, sprintf \- formatted output conversion
Z  .SH SYNOPSIS
Z  .B #include <stdio.h>
Z  .PP
Z! .B printf(format
Z  .RB [ ,
Z  arg ] ...
Z  .B )
Z--- 1,13 ----
Z! .\"	@(#)printf.3s	6.5.1 (2.11BSD) 1995/04/02
Z  .\"
Z  .TH PRINTF 3S "August 10, 1988"
Z  .AT 3
Z  .SH NAME
Z! printf, fprintf, sprintf, vfprintf, vsprintf \- formatted output conversion
Z  .SH SYNOPSIS
Z  .B #include <stdio.h>
Z  .PP
Z! .B char *printf(format
Z  .RB [ ,
Z  arg ] ...
Z  .B )
Z***************
Z*** 14,20 ****
Z  .br
Z  .B char *format;
Z  .PP
Z! .B fprintf(stream, format
Z  .RB [ ,
Z  arg ] ...
Z  .B )
Z--- 14,20 ----
Z  .br
Z  .B char *format;
Z  .PP
Z! .B char *fprintf(stream, format
Z  .RB [ ,
Z  arg ] ...
Z  .B )
Z***************
Z*** 25,31 ****
Z  .br
Z  .B char *format;
Z  .PP
Z! .B sprintf(s, format
Z  .RB [ ,
Z  arg ] ...
Z  .B )
Z--- 25,31 ----
Z  .br
Z  .B char *format;
Z  .PP
Z! .B int sprintf(s, format
Z  .RB [ ,
Z  arg ] ...
Z  .B )
Z***************
Z*** 34,46 ****
Z  .PP
Z  .B #include <varargs.h>
Z  .br
Z! .B vprintf(format, args)
Z  .br
Z  .B char *format;
Z  .br
Z  .B va_list args;
Z  .PP
Z! .B vfprintf(stream, format, args)
Z  .br
Z  .B FILE *stream;
Z  .br
Z--- 34,46 ----
Z  .PP
Z  .B #include <varargs.h>
Z  .br
Z! .B char *vprintf(format, args)
Z  .br
Z  .B char *format;
Z  .br
Z  .B va_list args;
Z  .PP
Z! .B char *vfprintf(stream, format, args)
Z  .br
Z  .B FILE *stream;
Z  .br
Z***************
Z*** 48,54 ****
Z  .br
Z  .B va_list args;
Z  .PP
Z! .B vsprintf(s, format, args)
Z  .br
Z  .B char *s, *format;
Z  .br
Z--- 48,54 ----
Z  .br
Z  .B va_list args;
Z  .PP
Z! .B int vsprintf(s, format, args)
Z  .br
Z  .B char *s, *format;
Z  .br
Z***************
Z*** 239,245 ****
Z  .SH "SEE ALSO"
Z  putc(3S), scanf(3S)
Z  .SH BUGS
Z! Very wide fields (>128 characters) fail.
Z  .LP
Z! The functions still supports \fI%D\fP, \fI%O\fP, and \fI%U\fP.  Do not
Z! use these formats, as they will be disappearing soon.
Z--- 239,249 ----
Z  .SH "SEE ALSO"
Z  putc(3S), scanf(3S)
Z  .SH BUGS
Z! Very wide fields (>300 characters) fail.
Z  .LP
Z! Only \fIsprintf\fP and \fIvsprintf\fP return a count of characters 
Z! transferred.
Z! .LP
Z! The functions still supports \fI%D\fP, \fI%O\fP, \fI%U\fP and 
Z! \fI%X\fP.  Do not
Z! use these formats, as they will be disappearing real soon now.
SHAR_EOF
fi
exit 0
#	End of shell archive
