[net.sources] uucp on one phone line

gertjan@txsil.UUCP (12/20/84)

#!/bin/sh
sed 's/^X//' <<'this-is-README' >README
X	This program is in use by us for one phone line
X	for dial in and dial out. There might be much better
X	solutions to the problem, but the best one is having
X	separate phone lines.
X
X	all our uucp and uux calls go with the -r parameter
X	and in the /usr/lib/crontab the uucico call is at follows
X
X 05 * * * * /etc/dial out; sleep 5; /etc/dial in
X
X	the program 'chmod' and 'owner' as follows:
X
X ---s--x--x  1 root        16384 Nov 25 15:42 /etc/dial
X
this-is-README
sed 's/^X//' <<'the-manual-page' >dial.8
X.TH DIAL 8 LOCAL
X.SH NAME
Xdial \- change the modem line to in or out
X.SH SYNOPSIS
X/etc/dial \fBin\fP|\fBout\fP
X.SH DESCRIPTION
X.I Dial
Xchanges the modemline to a
X.I dialin
Xor
X.I dialout
Xline. Appropriate checking is done to avoid conflicts with
Xeither 
X.I uucp
Xor
X.I kermit
Xand people who are logged on from home.
X.sp
XThis program is very local and works only on
X.IR /dev/tty00 .
X.SH DIAGNOSTICS
XThe error messages are self explanatory.
X.SH AUTHOR
XGertjan Vinkesteyn
the-manual-page
sed 's/^X//' <<'the-program' >dial.c
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X
Xchar	lck[]	= "/usr/spool/uucp/LCK..tty00";
Xchar	tty[]	= "/dev/tty00";
X
Xmain(argc, argv)
Xint	argc;
Xchar	**argv;
X{
X	register char	*p;
X	char	buf[10];
X	FILE	*Ti, *To;
X	struct stat	statbuf;
X
X	if (argc != 2)
X		usage();
X	if ((strcmp(*++argv, "in") == 0) || (strcmp(*argv,"out") == 0)) {
X		if (access(lck) == 0) {
X			fprintf(stderr, "%s exists, program abort\n", lck);
X			Abort();
X		}
X		if (stat(tty, &statbuf) < 0) {
X			fprintf(stderr,"stat failed\n");
X			Abort();
X		}
X		if (statbuf.st_uid != 0 && statbuf.st_uid != 5) {
X			fprintf(stderr,
X	"root or uucp does not own %s, somebody might be logged on\n", tty);
X			Abort();
X		}
X		if ((Ti = fopen("/etc/ttys", "r")) == NULL) {
X			fprintf(stderr, "Cannot open `/etc/ttys'\n");
X			usage();
X		}
X		if ((To = fopen("/etc/ttysnew", "w")) == NULL) {
X			fprintf(stderr, "Cannot creat `/etc/ttysnew'\n");
X			usage();
X		}
X		while ((p = fgets(buf, sizeof buf, Ti))) {
X			if (strncmp(&buf[2], "tty00", 5) == 0) {
X				if (strcmp(*argv,"in") == 0) {
X					*p = '1';
X				} else {
X					*p = '0';
X					if (chmod(tty, 0666) != 0)
X						fprintf(stderr,
X						"Cannot chmod `/dev/tty00'\n");
X					else 
X						chown(tty, 5, 1);
X				}
X			}
X			fputs(buf, To);
X		}
X		fclose(To);
X		fclose(Ti);
X		if (unlink("/etc/ttys") == -1) {
X			fprintf(stderr, "Cannot unlink /etc/ttys\n");
X			Abort();
X		}
X		if (link("/etc/ttysnew", "/etc/ttys") == -1) {
X			fprintf(stderr, "Cannot link /etc/ttysnew /etc/ttys\n");
X			fprintf(stderr,
X		"FATAL. Now we don't have a /etc/ttys file anymore!!\n");
X			Abort();
X		}
X		if (unlink("/etc/ttysnew") == -1) {
X			fprintf(stderr, "Cannot unlink /etc/ttysnew\n");
X			Abort();
X		}
X	} else
X		usage();
X	if (kill (1, 1) != 0)
X		fprintf(stderr, "Cannot kill -1 1\n");
X}
X
Xusage()
X{
X	fprintf(stderr, "Usage: `dial in' or `dial out'\n");
X	exit();
X}
X
XAbort()
X{
X	fprintf(stderr, "dial abort\n");
X	exit(-1);
X}
the-program