Commit 51f40ab4 authored by Mike Hibler's avatar Mike Hibler

The Evisceration of Tip, Chapter 1.

Taken from the man page (ntip.1):
----
     Ntip differs from the traditional tip in a number of ways:

     1.   It does not support calling a remote system, all auto-dialing code
          has been removed.

     2.   All the cheezy file transfer support has been removed.

     3.   Most of the tilde escapes have been removed.  Mostly these were the
          file trasfer related ones.  See below for what remains.

     4.   Ntip ignores 90% of the remote(5) capabilities.  You can set the
          baud rate (br) and the device (dv).  Period.

     5.   All of tips variables are still present, but most don't do anything.
          It is left as an exercise to the interested user to differentiate.

     6.   By default, it operates in ``raw'' mode instead of the usual
          ``cbreak'' mode.  This means that all input processing (if any) is
          performed by the remote system.  Raw mode also disables
          ``raisechar'' and ``force'' variable interpretation.  Yes, you can
          actually run emacs on an ntip line (modulo the '~' thing).

     7.   Tip is the poster-child for fork-without-exec, creating separate
          reader and writer processes executing ``the same code.''  Ntip is a
          child of convenience and consists of a single process using
          select(2).

     8.   Ntip no longer uses uucp(1) style locking.  It relies on the TIOCEX-
          CL ioctl (see tty(4))  to provide ``reasonably mutually exclusive''
          access.  While it is still technically possible that two parties
          could open the same line and both get ``exclusive'' access to it, we
          consider this to be the source of amusing anecdotes rather than a
          bug.
----
parent a2df644d
CC = gcc -g
CC = gcc -g -O2
# for BSD
#CFLAGS = -O
#LIBS= -lutil
OBJS = cmds.o cmdtab.o hunt.o partab.o \
remote.o tip.o value.o vars.o getcap.o
# for Linux
CFLAGS = -O -DLINUX
LIBS= -ldb
#
# If HAVE_UUCPLOCK is defined you need -lutil for BSD
#
LIBS=
OBJS = acu.o acutab.o cmds.o cmdtab.o cu.o hunt.o log.o partab.o \
remote.o tip.o tipout.o value.o vars.o getcap.o
DESTDIR = /usr/site
DESTDIR = /usr/testbed
all: tip
all: tip.static # tip
tip: $(OBJS)
$(CC) -o tip $(OBJS) $(LIBS)
......@@ -20,8 +18,11 @@ tip: $(OBJS)
tip.static: $(OBJS)
$(CC) -static -o tip.static $(OBJS) $(LIBS)
install:
install -s -c tip $(DESTDIR)/bin/tip
$(OBJS): tipconf.h tip.h
install: all
# install -s -c tip $(DESTDIR)/bin/tip
install -s -c tip.static $(DESTDIR)/bin/ntip
clean:
rm -f $(OBJS) tip tip.static
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: acu.c,v 1.1 2000-12-22 18:48:46 mike Exp $";
#endif /* not lint */
#include "tipconf.h"
#include "tip.h"
#if UNIDIALER
acu_t* unidialer_getmodem (const char *modem_name);
#endif
static acu_t *acu = NOACU;
static int conflag;
static void acuabort();
static acu_t *acutype();
static jmp_buf jmpbuf;
/*
* Establish connection for tip
*
* If DU is true, we should dial an ACU whose type is AT.
* The phone numbers are in PN, and the call unit is in CU.
*
* If the PN is an '@', then we consult the PHONES file for
* the phone numbers. This file is /etc/phones, unless overriden
* by an exported shell variable.
*
* The data base files must be in the format:
* host-name[ \t]*phone-number
* with the possibility of multiple phone numbers
* for a single host acting as a rotary (in the order
* found in the file).
*/
char *
connect()
{
register char *cp = PN;
char *phnum, string[256];
FILE *fd;
int tried = 0;
if (!DU) { /* regular connect message */
if (CM != NOSTR)
xpwrite(FD, CM, size(CM));
logent(value(HOST), "", DV, "call completed");
return (NOSTR);
}
/*
* @ =>'s use data base in PHONES environment variable
* otherwise, use /etc/phones
*/
signal(SIGINT, acuabort);
signal(SIGQUIT, acuabort);
if (setjmp(jmpbuf)) {
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
printf("\ncall aborted\n");
logent(value(HOST), "", "", "call aborted");
if (acu != NOACU) {
boolean(value(VERBOSE)) = FALSE;
if (conflag)
disconnect(NOSTR);
else
(*acu->acu_abort)();
}
return ("interrupt");
}
if ((acu = acutype(AT)) == NOACU)
return ("unknown ACU type");
if (*cp != '@') {
while (*cp) {
for (phnum = cp; *cp && *cp != ','; cp++)
;
if (*cp)
*cp++ = '\0';
if ((conflag = (*acu->acu_dialer)(phnum, CU))) {
if (CM != NOSTR)
xpwrite(FD, CM, size(CM));
logent(value(HOST), phnum, acu->acu_name,
"call completed");
return (NOSTR);
} else
logent(value(HOST), phnum, acu->acu_name,
"call failed");
tried++;
}
} else {
if ((fd = fopen(PH, "r")) == NOFILE) {
printf("%s: ", PH);
return ("can't open phone number file");
}
while (fgets(string, sizeof(string), fd) != NOSTR) {
for (cp = string; !any(*cp, " \t\n"); cp++)
;
if (*cp == '\n') {
fclose(fd);
return ("unrecognizable host name");
}
*cp++ = '\0';
if (strcmp(string, value(HOST)))
continue;
while (any(*cp, " \t"))
cp++;
if (*cp == '\n') {
fclose(fd);
return ("missing phone number");
}
for (phnum = cp; *cp && *cp != ',' && *cp != '\n'; cp++)
;
if (*cp)
*cp++ = '\0';
if ((conflag = (*acu->acu_dialer)(phnum, CU))) {
fclose(fd);
if (CM != NOSTR)
xpwrite(FD, CM, size(CM));
logent(value(HOST), phnum, acu->acu_name,
"call completed");
return (NOSTR);
} else
logent(value(HOST), phnum, acu->acu_name,
"call failed");
tried++;
}
fclose(fd);
}
if (!tried)
logent(value(HOST), "", acu->acu_name, "missing phone number");
else
(*acu->acu_abort)();
return (tried ? "call failed" : "missing phone number");
}
void
disconnect(reason)
char *reason;
{
if (!conflag) {
logent(value(HOST), "", DV, "call terminated");
return;
}
if (reason == NOSTR) {
logent(value(HOST), "", acu->acu_name, "call terminated");
if (boolean(value(VERBOSE)))
printf("\r\ndisconnecting...");
} else
logent(value(HOST), "", acu->acu_name, reason);
(*acu->acu_disconnect)();
}
static void
acuabort(s)
{
signal(s, SIG_IGN);
longjmp(jmpbuf, 1);
}
static acu_t *
acutype(s)
register char *s;
{
register acu_t *p;
extern acu_t acutable[];
for (p = acutable; p->acu_name != '\0'; p++)
if (!strcmp(s, p->acu_name))
return (p);
#if UNIDIALER
return unidialer_getmodem (s);
#else
return (NOACU);
#endif
}
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)acutab.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: acutab.c,v 1.1 2000-12-22 18:48:46 mike Exp $";
#endif /* not lint */
#include "tipconf.h"
#include "tip.h"
extern int df02_dialer(), df03_dialer(),
biz31f_dialer(),
biz31w_dialer(),
biz22f_dialer(),
biz22w_dialer(),
ven_dialer(),
hay_dialer(),
cour_dialer(),
multitech_dialer(),
t3000_dialer(),
v3451_dialer(),
v831_dialer(),
dn_dialer();
extern void df_disconnect(), df_abort(),
biz31_disconnect(), biz31_abort(),
biz22_disconnect(), biz22_abort(),
ven_disconnect(), ven_abort(),
hay_disconnect(), hay_abort(),
cour_disconnect(), cour_abort(),
multitech_disconnect(), multitech_abort(),
t3000_disconnect(), t3000_abort(),
v3451_disconnect(), v3451_abort(),
v831_disconnect(), v831_abort(),
dn_disconnect(), dn_abort();
acu_t acutable[] = {
#if BIZ1031
"biz31f", biz31f_dialer, biz31_disconnect, biz31_abort,
"biz31w", biz31w_dialer, biz31_disconnect, biz31_abort,
#endif
#if BIZ1022
"biz22f", biz22f_dialer, biz22_disconnect, biz22_abort,
"biz22w", biz22w_dialer, biz22_disconnect, biz22_abort,
#endif
#if DF02
"df02", df02_dialer, df_disconnect, df_abort,
#endif
#if DF03
"df03", df03_dialer, df_disconnect, df_abort,
#endif
#if DN11
"dn11", dn_dialer, dn_disconnect, dn_abort,
#endif
#if VENTEL
"ventel",ven_dialer, ven_disconnect, ven_abort,
#endif
#if HAYES
"hayes",hay_dialer, hay_disconnect, hay_abort,
#endif
#if COURIER
"courier",cour_dialer, cour_disconnect, cour_abort,
#endif
#if MULTITECH
"multitech",multitech_dialer, multitech_disconnect, multitech_abort,
#endif
#if T3000
"t3000",t3000_dialer, t3000_disconnect, t3000_abort,
#endif
#if V3451
#if !V831
"vadic",v3451_dialer, v3451_disconnect, v3451_abort,
#endif
"v3451",v3451_dialer, v3451_disconnect, v3451_abort,
#endif
#if V831
#if !V3451
"vadic",v831_dialer, v831_disconnect, v831_abort,
#endif
"v831",v831_dialer, v831_disconnect, v831_abort,
#endif
0, 0, 0, 0
};
This diff is collapsed.
......@@ -36,27 +36,17 @@
static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: cmdtab.c,v 1.1 2000-12-22 18:48:47 mike Exp $";
"$Id: cmdtab.c,v 1.2 2000-12-27 00:49:33 mike Exp $";
#endif /* not lint */
#include "tipconf.h"
#include "tip.h"
extern int shell(), getfl(), sendfile(), chdirectory();
extern int finish(), help(), pipefile(), pipeout(), variable();
extern int cu_take(), cu_put(), dollar(), genbrk(), suspend();
extern int shell(), chdirectory();
extern int finish(), help(), variable();
extern dollar(), genbrk(), suspend();
esctable_t etable[] = {
{ '!', NORM, "shell", shell },
{ '<', NORM, "receive file from remote host", getfl },
{ '>', NORM, "send file to remote host", sendfile },
{ 't', NORM, "take file from remote UNIX", cu_take },
{ 'p', NORM, "put file to remote UNIX", cu_put },
{ '|', NORM, "pipe remote file", pipefile },
{ '$', NORM, "pipe local command to remote host", pipeout },
#if CONNECT
{ 'C', NORM, "connect program to remote host",consh },
#endif
{ 'c', NORM, "change directory", chdirectory },
{ '.', NORM, "exit from tip", finish },
{CTRL('d'),NORM,"exit from tip", finish },
......
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: cu.c,v 1.1 2000-12-22 18:48:47 mike Exp $";
#endif /* not lint */
#include "tipconf.h"
#include "tip.h"
void cleanup();
#if INCLUDE_CU_INTERFACE
/*
* Botch the interface to look like cu's
*/
cumain(argc, argv)
char *argv[];
{
register int i;
static char sbuf[12];
if (argc < 2) {
printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
exit(8);
}
CU = DV = NOSTR;
BR = DEFBR;
for (; argc > 1; argv++, argc--) {
if (argv[1][0] != '-')
PN = argv[1];
else switch (argv[1][1]) {
case 't':
HW = 1, DU = -1;
--argc;
continue;
case 'a':
CU = argv[2]; ++argv; --argc;
break;
case 's':
if (argc < 3 || speed(atoi(argv[2])) == 0) {
fprintf(stderr, "cu: unsupported speed %s\n",
argv[2]);
exit(3);
}
BR = atoi(argv[2]); ++argv; --argc;
break;
case 'l':
DV = argv[2]; ++argv; --argc;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (CU)
CU[strlen(CU)-1] = argv[1][1];
if (DV)
DV[strlen(DV)-1] = argv[1][1];
break;
default:
printf("Bad flag %s", argv[1]);
break;
}
}
signal(SIGINT, cleanup);
signal(SIGQUIT, cleanup);
signal(SIGHUP, cleanup);
signal(SIGTERM, cleanup);
/*
* The "cu" host name is used to define the
* attributes of the generic dialer.
*/
(void)snprintf(sbuf, sizeof(sbuf), "cu%d", BR);
if ((i = hunt(sbuf)) == 0) {
printf("all ports busy\n");
exit(3);
}
if (i == -1) {
printf("link down\n");
(void)uu_unlock(uucplock);
exit(3);
}
setbuf(stdout, NULL);
loginit();
user_uid();
vinit();
setparity("none");
boolean(value(VERBOSE)) = 0;
if (HW)
ttysetup(speed(BR));
if (connect()) {
printf("Connect failed\n");
daemon_uid();
(void)uu_unlock(uucplock);
exit(1);
}
if (!HW)
ttysetup(speed(BR));
}
#endif /* INCLUDE_CU_INTERFACE */
......@@ -38,6 +38,8 @@
static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94";
#endif /* LIBC_SCCS and not lint */
#include "tipconf.h"
#include <sys/types.h>
#include <ctype.h>
......
......@@ -36,16 +36,17 @@
static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: hunt.c,v 1.1 2000-12-22 18:48:47 mike Exp $";
"$Id: hunt.c,v 1.2 2000-12-27 00:49:34 mike Exp $";
#endif /* not lint */
#include "tip.h"
#include <sys/types.h>
#include <err.h>
#ifndef LINUX
#include <libutil.h>
#endif
#include "tipconf.h"
#include "tip.h"
extern char *getremote();
extern char *rindex();
......@@ -71,12 +72,14 @@ hunt(name)
f = signal(SIGALRM, dead);
while ((cp = getremote(name))) {
deadfl = 0;
#if HAVE_UUCPLOCK
uucplock = rindex(cp, '/')+1;
if ((res = uu_lock(uucplock)) != UU_LOCK_OK) {
if (res != UU_LOCK_INUSE)
fprintf(stderr, "uu_lock: %s\n", uu_lockerr(res));
continue;
}
#endif
/*
* Straight through call units, such as the BIZCOMP,
* VADIC and the DF, must indicate they're hardwired in
......@@ -89,6 +92,8 @@ hunt(name)
if (setjmp(deadline) == 0) {
alarm(10);
FD = open(cp, O_RDWR);
if (FD >= 0)
ioctl(FD, TIOCEXCL, 0);
}
alarm(0);
if (FD < 0) {
......@@ -96,14 +101,12 @@ hunt(name)
deadfl = 1;
}
if (!deadfl) {
ioctl(FD, TIOCEXCL, 0);
#if HAVE_TERMIOS
{
struct termios t;
if (tcgetattr(FD, &t) == 0) {
t.c_cflag |= HUPCL;
(void)tcsetattr(FD, TCSANOW, &t);
}
struct termios t;
if (tcgetattr(FD, &t) == 0) {
t.c_cflag |= HUPCL;
(void)tcsetattr(FD, TCSANOW, &t);
}
#else /* HAVE_TERMIOS */
#ifdef TIOCHPCL
......@@ -113,7 +116,9 @@ hunt(name)
signal(SIGALRM, SIG_DFL);
return ((int)cp);
}
#if HAVE_UUCPLOCK
(void)uu_unlock(uucplock);
#endif
}
signal(SIGALRM, f);
return (deadfl ? -1 : (int)cp);
......
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id: log.c,v 1.1 2000-12-22 18:48:48 mike Exp $";
#endif /* not lint */
#include "tipconf.h"
#include "tip.h"
#include <err.h>
#if ACULOG
static FILE *flog = NULL;
/*
* Log file maintenance routines
*/
void
logent(group, num, acu, message)
char *group, *num, *acu, *message;
{
char *user, *timestamp;
struct passwd *pwd;
time_t t;
if (flog == NULL)
return;
if (flock(fileno(flog), LOCK_EX) < 0) {
warn("flock");
return;
}
if ((user = getlogin()) == NOSTR)
if ((pwd = getpwuid(getuid())) == NOPWD)
user = "???";
else
user = pwd->pw_name;
t = time(0);
timestamp = ctime(&t);
timestamp[24] = '\0';
fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
user, timestamp, group,
#if PRISTINE
"",
#else
num,
#endif
acu, message);
(void) fflush(flog);
(void) flock(fileno(flog), LOCK_UN);
}
void
loginit()
{
flog = fopen(value(LOG), "a");
if (flog == NULL)
fprintf(stderr, "can't open log file %s.\r\n", value(LOG));
}
#endif
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)modems.5 3/24/95
.\"
.Dd March 24, 1995