1994-05-26 06:35:07 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-08-03 06:32:57 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 06:35:07 +00:00
|
|
|
"@(#) Copyright (c) 1990, 1991, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-08-03 06:32:57 +00:00
|
|
|
#if 0
|
1994-05-26 06:35:07 +00:00
|
|
|
static char sccsid[] = "@(#)startslip.c 8.1 (Berkeley) 6/5/93";
|
1998-08-03 06:32:57 +00:00
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1994-12-04 12:26:01 +00:00
|
|
|
#include <sys/types.h>
|
1996-12-10 17:11:53 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
1997-12-22 13:46:08 +00:00
|
|
|
#include <err.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
1997-12-22 13:46:08 +00:00
|
|
|
#include <libutil.h>
|
1996-12-10 17:11:53 +00:00
|
|
|
#include <paths.h>
|
|
|
|
#include <signal.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <stdio.h>
|
1995-09-15 20:06:50 +00:00
|
|
|
#include <stdlib.h>
|
1994-12-04 12:26:01 +00:00
|
|
|
#include <string.h>
|
1996-12-10 17:11:53 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <termios.h>
|
1994-12-04 12:26:01 +00:00
|
|
|
#include <unistd.h>
|
1996-12-10 17:11:53 +00:00
|
|
|
|
|
|
|
#include <net/slip.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#define DEFAULT_BAUD B9600
|
|
|
|
int speed = DEFAULT_BAUD;
|
|
|
|
#define FC_NONE 0 /* flow control: none */
|
1995-09-14 19:03:20 +00:00
|
|
|
#define FC_HW 1 /* flow control: hardware (RTS/CTS) */
|
1994-05-26 06:35:07 +00:00
|
|
|
int flowcontrol = FC_NONE;
|
1995-09-15 20:06:50 +00:00
|
|
|
int modem_control = 1; /* !CLOCAL+HUPCL iff we watch carrier. */
|
1995-09-18 14:01:11 +00:00
|
|
|
int sl_unit = -1;
|
1995-09-20 04:56:09 +00:00
|
|
|
int uucp_lock = 0; /* uucp locking */
|
1994-05-26 06:35:07 +00:00
|
|
|
char *annex;
|
1995-09-27 17:15:37 +00:00
|
|
|
char *username;
|
1994-05-26 06:35:07 +00:00
|
|
|
int hup;
|
1995-09-14 19:03:20 +00:00
|
|
|
int terminate;
|
1995-09-20 04:56:09 +00:00
|
|
|
int locked = 0; /* uucp lock active */
|
1994-12-04 12:26:01 +00:00
|
|
|
int logged_in = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
int wait_time = 60; /* then back off */
|
1995-09-14 19:03:20 +00:00
|
|
|
int script_timeout = 90; /* connect script default timeout */
|
1995-09-27 17:15:37 +00:00
|
|
|
time_t conn_time, start_time;
|
1995-09-15 20:06:50 +00:00
|
|
|
int MAXTRIES = 6; /* w/60 sec and doubling, takes an hour */
|
|
|
|
#define PIDFILE "%sstartslip.%s.pid"
|
1995-09-14 19:03:20 +00:00
|
|
|
|
|
|
|
#define MAXDIALS 20
|
|
|
|
char *dials[MAXDIALS];
|
|
|
|
int diali, dialc;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1995-09-15 17:30:03 +00:00
|
|
|
int fd = -1;
|
1995-09-14 22:01:06 +00:00
|
|
|
FILE *pfd;
|
1995-09-15 20:06:50 +00:00
|
|
|
char *dvname, *devicename;
|
1995-09-14 22:01:06 +00:00
|
|
|
char pidfile[80];
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int debug = 1;
|
|
|
|
#undef LOG_ERR
|
|
|
|
#undef LOG_INFO
|
|
|
|
#define syslog fprintf
|
|
|
|
#define LOG_ERR stderr
|
|
|
|
#define LOG_INFO stderr
|
|
|
|
#else
|
|
|
|
int debug = 0;
|
|
|
|
#endif
|
|
|
|
#define printd if (debug) printf
|
|
|
|
|
1997-06-19 14:38:53 +00:00
|
|
|
int carrier __P((void));
|
|
|
|
void down __P((int));
|
|
|
|
int getline __P((char *, int, int, time_t));
|
|
|
|
static void usage __P((void));
|
|
|
|
|
|
|
|
int
|
1994-05-26 06:35:07 +00:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
char *cp, **ap;
|
|
|
|
int ch, disc;
|
1995-09-17 21:47:24 +00:00
|
|
|
void sighup(), sigterm(), sigurg();
|
1995-09-14 22:01:06 +00:00
|
|
|
FILE *wfd = NULL;
|
1994-05-26 06:35:07 +00:00
|
|
|
char *dialerstring = 0, buf[BUFSIZ];
|
1995-09-17 21:47:24 +00:00
|
|
|
int unitnum, keepal = 0, outfill = 0;
|
1994-12-04 12:26:01 +00:00
|
|
|
char unitname[32];
|
1995-09-27 17:15:37 +00:00
|
|
|
char *password;
|
1994-12-04 12:26:01 +00:00
|
|
|
char *upscript = NULL, *downscript = NULL;
|
1994-05-26 06:35:07 +00:00
|
|
|
int first = 1, tries = 0;
|
1995-09-15 20:06:50 +00:00
|
|
|
time_t fintimeout;
|
1998-06-28 20:40:51 +00:00
|
|
|
long lpid;
|
1995-09-14 19:03:20 +00:00
|
|
|
pid_t pid;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct termios t;
|
|
|
|
|
1997-03-29 03:33:12 +00:00
|
|
|
while ((ch = getopt(argc, argv, "dhlb:s:t:w:A:U:D:W:K:O:S:L")) != -1)
|
1994-05-26 06:35:07 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
speed = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
1997-06-19 14:38:53 +00:00
|
|
|
if (diali >= MAXDIALS)
|
|
|
|
errx(1, "max dial strings number (%d) exceeded", MAXDIALS);
|
1995-09-14 19:03:20 +00:00
|
|
|
dials[diali++] = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
script_timeout = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
wait_time = atoi(optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
1995-09-15 20:06:50 +00:00
|
|
|
case 'W':
|
|
|
|
MAXTRIES = atoi(optarg);
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'A':
|
1994-12-04 12:26:01 +00:00
|
|
|
annex = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
upscript = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
downscript = strdup(optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
1995-09-20 04:56:09 +00:00
|
|
|
case 'L':
|
|
|
|
uucp_lock = 1;
|
|
|
|
break;
|
1995-09-15 20:06:50 +00:00
|
|
|
case 'l':
|
|
|
|
modem_control = 0;
|
|
|
|
break;
|
1995-09-14 19:03:20 +00:00
|
|
|
case 'h':
|
|
|
|
flowcontrol = FC_HW;
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
1995-09-17 21:47:24 +00:00
|
|
|
case 'K':
|
|
|
|
keepal = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
outfill = atoi(optarg);
|
|
|
|
break;
|
1995-09-18 14:01:11 +00:00
|
|
|
case 'S':
|
|
|
|
sl_unit = atoi(optarg);
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
usage();
|
|
|
|
|
1994-12-04 12:26:01 +00:00
|
|
|
/*
|
|
|
|
* Copy these so they exist after we clobber them.
|
|
|
|
*/
|
|
|
|
devicename = strdup(argv[0]);
|
|
|
|
username = strdup(argv[1]);
|
|
|
|
password = strdup(argv[2]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Security hack. Do not want private information such as the
|
|
|
|
* password and possible phone number to be left around.
|
|
|
|
* So we clobber the arguments.
|
|
|
|
*/
|
|
|
|
for (ap = argv - optind + 1; ap < argv + 3; ap++)
|
|
|
|
for (cp = *ap; *cp != 0; cp++)
|
|
|
|
*cp = '\0';
|
|
|
|
|
1995-09-14 19:03:20 +00:00
|
|
|
openlog("startslip", LOG_PID|LOG_PERROR, LOG_DAEMON);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
if (debug)
|
|
|
|
setbuf(stdout, NULL);
|
1995-05-30 06:12:45 +00:00
|
|
|
|
1995-09-17 21:47:24 +00:00
|
|
|
signal(SIGTERM, sigterm);
|
1995-09-15 20:06:50 +00:00
|
|
|
if ((dvname = strrchr(devicename, '/')) == NULL)
|
|
|
|
dvname = devicename;
|
1995-09-14 19:03:20 +00:00
|
|
|
else
|
1995-09-15 20:06:50 +00:00
|
|
|
dvname++;
|
2000-04-30 21:04:36 +00:00
|
|
|
if (snprintf(pidfile, sizeof(pidfile), PIDFILE, _PATH_VARRUN, dvname) >= sizeof(pidfile))
|
|
|
|
usage();
|
|
|
|
|
1995-09-14 19:03:20 +00:00
|
|
|
if ((pfd = fopen(pidfile, "r")) != NULL) {
|
1998-06-28 20:40:51 +00:00
|
|
|
if (fscanf(pfd, "%ld\n", &lpid) == 1) {
|
|
|
|
pid = lpid;
|
|
|
|
if (pid == lpid && pid > 0)
|
|
|
|
kill(pid, SIGTERM);
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
fclose(pfd);
|
1995-09-14 19:03:20 +00:00
|
|
|
pfd = NULL; /* not remove pidfile yet */
|
|
|
|
sleep(5); /* allow down script to be completed */
|
|
|
|
} else
|
1994-05-26 06:35:07 +00:00
|
|
|
restart:
|
1995-09-17 21:47:24 +00:00
|
|
|
signal(SIGHUP, SIG_IGN);
|
|
|
|
signal(SIGURG, SIG_IGN);
|
|
|
|
hup = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (wfd) {
|
|
|
|
printd("fclose, ");
|
|
|
|
fclose(wfd);
|
1995-09-27 17:15:37 +00:00
|
|
|
conn_time = time(NULL) - start_time;
|
1995-09-20 04:56:09 +00:00
|
|
|
if (uucp_lock)
|
|
|
|
uu_unlock(dvname);
|
1995-09-14 22:01:06 +00:00
|
|
|
locked = 0;
|
|
|
|
wfd = NULL;
|
|
|
|
fd = -1;
|
|
|
|
sleep(5);
|
1995-09-17 21:47:24 +00:00
|
|
|
} else if (fd >= 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
printd("close, ");
|
|
|
|
close(fd);
|
1995-09-27 17:15:37 +00:00
|
|
|
conn_time = time(NULL) - start_time;
|
1995-09-20 04:56:09 +00:00
|
|
|
if (uucp_lock)
|
|
|
|
uu_unlock(dvname);
|
1995-09-14 22:01:06 +00:00
|
|
|
locked = 0;
|
|
|
|
fd = -1;
|
1994-05-26 06:35:07 +00:00
|
|
|
sleep(5);
|
|
|
|
}
|
1995-09-27 17:15:37 +00:00
|
|
|
if (logged_in) {
|
1998-08-02 16:06:35 +00:00
|
|
|
syslog(LOG_INFO, "%s: connection time elapsed: %ld secs",
|
|
|
|
username, (long)conn_time);
|
1995-09-27 17:15:37 +00:00
|
|
|
sprintf(buf, "LINE=%d %s %s down",
|
|
|
|
diali ? (dialc - 1) % diali : 0,
|
|
|
|
downscript ? downscript : "/sbin/ifconfig" , unitname);
|
|
|
|
(void) system(buf);
|
|
|
|
logged_in = 0;
|
|
|
|
}
|
1995-09-15 20:34:55 +00:00
|
|
|
if (terminate)
|
1995-09-27 17:15:37 +00:00
|
|
|
down(0);
|
|
|
|
tries++;
|
|
|
|
if (MAXTRIES > 0 && tries > MAXTRIES) {
|
|
|
|
syslog(LOG_ERR, "%s: exiting login after %d tries", username, tries);
|
|
|
|
/* ???
|
|
|
|
if (first)
|
|
|
|
*/
|
|
|
|
down(3);
|
|
|
|
}
|
1995-09-16 05:18:20 +00:00
|
|
|
if (tries > 1) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_INFO, "%s: sleeping %d seconds (%d tries)",
|
|
|
|
username, wait_time * (tries - 1), tries);
|
1995-09-16 05:18:20 +00:00
|
|
|
sleep(wait_time * (tries - 1));
|
|
|
|
if (terminate)
|
|
|
|
goto restart;
|
1995-09-15 20:34:55 +00:00
|
|
|
}
|
1995-09-16 05:18:20 +00:00
|
|
|
|
|
|
|
if (daemon(1, debug) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: daemon: %m", username);
|
1995-09-15 20:34:55 +00:00
|
|
|
down(2);
|
|
|
|
}
|
1995-09-16 05:18:20 +00:00
|
|
|
|
1995-09-15 20:34:55 +00:00
|
|
|
pid = getpid();
|
1998-06-28 20:40:51 +00:00
|
|
|
printd("restart: pid %ld: ", (long)pid);
|
1995-09-15 20:34:55 +00:00
|
|
|
if ((pfd = fopen(pidfile, "w")) != NULL) {
|
1998-06-28 20:40:51 +00:00
|
|
|
fprintf(pfd, "%ld\n", (long)pid);
|
1995-09-15 20:34:55 +00:00
|
|
|
fclose(pfd);
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
printd("open");
|
1995-09-20 04:56:09 +00:00
|
|
|
if (uucp_lock) {
|
1997-03-31 22:51:00 +00:00
|
|
|
int res;
|
|
|
|
if ((res = uu_lock(dvname)) != UU_LOCK_OK) {
|
|
|
|
if (res != UU_LOCK_INUSE)
|
|
|
|
syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res));
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: can't lock %s", username, devicename);
|
1995-09-20 04:56:09 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
locked = 1;
|
1995-09-14 22:01:06 +00:00
|
|
|
}
|
1995-09-15 20:06:50 +00:00
|
|
|
if ((fd = open(devicename, O_RDWR | O_NONBLOCK)) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: open %s: %m", username, devicename);
|
1995-09-14 22:01:06 +00:00
|
|
|
if (first)
|
|
|
|
down(1);
|
|
|
|
else {
|
1995-09-20 04:56:09 +00:00
|
|
|
if (uucp_lock)
|
|
|
|
uu_unlock(dvname);
|
1995-09-14 22:01:06 +00:00
|
|
|
locked = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printd(" %d", fd);
|
|
|
|
signal(SIGHUP, sighup);
|
1995-09-15 17:30:03 +00:00
|
|
|
if (ioctl(fd, TIOCSCTTY, 0) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl (TIOCSCTTY): %m", username);
|
1995-09-15 17:30:03 +00:00
|
|
|
down(2);
|
|
|
|
}
|
1995-09-15 20:06:50 +00:00
|
|
|
if (tcsetpgrp(fd, getpid()) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: tcsetpgrp failed: %m", username);
|
1995-09-15 20:06:50 +00:00
|
|
|
down(2);
|
|
|
|
}
|
1995-09-15 20:34:55 +00:00
|
|
|
printd(", ioctl\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
if (tcgetattr(fd, &t) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: tcgetattr(%s): %m", username, devicename);
|
1995-09-14 22:01:06 +00:00
|
|
|
down(2);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
cfmakeraw(&t);
|
|
|
|
switch (flowcontrol) {
|
|
|
|
case FC_HW:
|
|
|
|
t.c_cflag |= (CRTS_IFLOW|CCTS_OFLOW);
|
|
|
|
break;
|
|
|
|
case FC_NONE:
|
|
|
|
t.c_cflag &= ~(CRTS_IFLOW|CCTS_OFLOW);
|
|
|
|
break;
|
|
|
|
}
|
1995-09-15 20:06:50 +00:00
|
|
|
if (modem_control)
|
|
|
|
t.c_cflag |= HUPCL;
|
|
|
|
else
|
|
|
|
t.c_cflag &= ~(HUPCL);
|
|
|
|
t.c_cflag |= CLOCAL; /* until modem commands passes */
|
1995-09-27 17:15:37 +00:00
|
|
|
cfsetispeed(&t, speed);
|
|
|
|
cfsetospeed(&t, speed);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (tcsetattr(fd, TCSAFLUSH, &t) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename);
|
1995-09-14 22:01:06 +00:00
|
|
|
down(2);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
sleep(2); /* wait for flakey line to settle */
|
1995-09-14 19:03:20 +00:00
|
|
|
if (hup || terminate)
|
1994-05-26 06:35:07 +00:00
|
|
|
goto restart;
|
|
|
|
|
|
|
|
wfd = fdopen(fd, "w+");
|
|
|
|
if (wfd == NULL) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: can't fdopen %s: %m", username, devicename);
|
1995-09-14 22:01:06 +00:00
|
|
|
down(2);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1995-09-16 05:18:20 +00:00
|
|
|
setbuf(wfd, NULL);
|
|
|
|
|
|
|
|
if (diali > 0)
|
|
|
|
dialerstring = dials[dialc++ % diali];
|
1994-05-26 06:35:07 +00:00
|
|
|
if (dialerstring) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_INFO, "%s: dialer string: %s\\r", username, dialerstring);
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(wfd, "%s\r", dialerstring);
|
1995-09-14 19:03:20 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
printd("\n");
|
|
|
|
|
1995-09-15 20:06:50 +00:00
|
|
|
fintimeout = time(NULL) + script_timeout;
|
|
|
|
if (modem_control) {
|
|
|
|
printd("waiting for carrier\n");
|
|
|
|
while (time(NULL) < fintimeout && !carrier()) {
|
|
|
|
sleep(1);
|
|
|
|
if (hup || terminate)
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
if (!carrier())
|
|
|
|
goto restart;
|
|
|
|
t.c_cflag &= ~(CLOCAL);
|
|
|
|
if (tcsetattr(fd, TCSANOW, &t) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename);
|
1995-09-15 20:06:50 +00:00
|
|
|
down(2);
|
|
|
|
}
|
1998-08-03 06:32:57 +00:00
|
|
|
/* Only now we able to receive HUP on carrier drop! */
|
1995-09-15 20:06:50 +00:00
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Log in
|
|
|
|
*/
|
|
|
|
printd("look for login: ");
|
|
|
|
for (;;) {
|
1995-09-15 20:06:50 +00:00
|
|
|
if (getline(buf, BUFSIZ, fd, fintimeout) == 0 || hup || terminate)
|
1994-05-26 06:35:07 +00:00
|
|
|
goto restart;
|
|
|
|
if (annex) {
|
|
|
|
if (bcmp(buf, annex, strlen(annex)) == 0) {
|
|
|
|
fprintf(wfd, "slip\r");
|
|
|
|
printd("Sent \"slip\"\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (bcmp(&buf[1], "sername:", 8) == 0) {
|
1994-12-04 12:26:01 +00:00
|
|
|
fprintf(wfd, "%s\r", username);
|
|
|
|
printd("Sent login: %s\n", username);
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (bcmp(&buf[1], "assword:", 8) == 0) {
|
1994-12-04 12:26:01 +00:00
|
|
|
fprintf(wfd, "%s\r", password);
|
|
|
|
printd("Sent password: %s\n", password);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
1995-09-14 19:03:20 +00:00
|
|
|
if (strstr(&buf[1], "ogin:") != NULL) {
|
1994-12-04 12:26:01 +00:00
|
|
|
fprintf(wfd, "%s\r", username);
|
|
|
|
printd("Sent login: %s\n", username);
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
1995-09-14 19:03:20 +00:00
|
|
|
if (strstr(&buf[1], "assword:") != NULL) {
|
1994-12-04 12:26:01 +00:00
|
|
|
fprintf(wfd, "%s\r", password);
|
|
|
|
printd("Sent password: %s\n", password);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:12:45 +00:00
|
|
|
|
1995-09-15 17:08:42 +00:00
|
|
|
sleep(5); /* Wait until login completed */
|
|
|
|
if (hup || terminate)
|
|
|
|
goto restart;
|
1995-09-27 17:15:37 +00:00
|
|
|
start_time = time(NULL);
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Attach
|
|
|
|
*/
|
|
|
|
printd("setd");
|
|
|
|
disc = SLIPDISC;
|
|
|
|
if (ioctl(fd, TIOCSETD, &disc) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl (%s, TIOCSETD): %m",
|
|
|
|
username, devicename);
|
1995-09-14 22:01:06 +00:00
|
|
|
down(2);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1995-09-18 14:01:11 +00:00
|
|
|
if (sl_unit >= 0 && ioctl(fd, SLIOCSUNIT, &sl_unit) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl(SLIOCSUNIT): %m", username);
|
1995-09-18 14:01:11 +00:00
|
|
|
down(2);
|
|
|
|
}
|
1995-09-19 03:37:07 +00:00
|
|
|
if (ioctl(fd, SLIOCGUNIT, &unitnum) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl(SLIOCGUNIT): %m", username);
|
1995-09-14 22:01:06 +00:00
|
|
|
down(2);
|
1994-12-04 12:26:01 +00:00
|
|
|
}
|
|
|
|
sprintf(unitname, "sl%d", unitnum);
|
|
|
|
|
1995-09-17 21:47:24 +00:00
|
|
|
if (keepal > 0) {
|
|
|
|
signal(SIGURG, sigurg);
|
|
|
|
if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl(SLIOCSKEEPAL): %m", username);
|
1995-09-17 21:47:24 +00:00
|
|
|
down(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outfill > 0 && ioctl(fd, SLIOCSOUTFILL, &outfill) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl(SLIOCSOUTFILL): %m", username);
|
1995-09-17 21:47:24 +00:00
|
|
|
down(2);
|
|
|
|
}
|
1995-09-19 03:37:07 +00:00
|
|
|
|
|
|
|
sprintf(buf, "LINE=%d %s %s up",
|
|
|
|
diali ? (dialc - 1) % diali : 0,
|
|
|
|
upscript ? upscript : "/sbin/ifconfig" , unitname);
|
|
|
|
(void) system(buf);
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
printd(", ready\n");
|
|
|
|
if (!first)
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_INFO, "%s: reconnected on %s (%d tries)", username, unitname, tries);
|
|
|
|
else
|
|
|
|
syslog(LOG_INFO, "%s: connected on %s", username, unitname);
|
1994-05-26 06:35:07 +00:00
|
|
|
first = 0;
|
|
|
|
tries = 0;
|
|
|
|
logged_in = 1;
|
1995-09-14 19:03:20 +00:00
|
|
|
while (hup == 0 && terminate == 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
sigpause(0L);
|
|
|
|
printd("sigpause return\n");
|
|
|
|
}
|
|
|
|
goto restart;
|
1997-06-19 14:38:53 +00:00
|
|
|
return(0); /* not reached */
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sighup()
|
|
|
|
{
|
|
|
|
|
|
|
|
printd("hup\n");
|
|
|
|
if (hup == 0 && logged_in)
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_INFO, "%s: got hangup signal", username);
|
1994-05-26 06:35:07 +00:00
|
|
|
hup = 1;
|
|
|
|
}
|
|
|
|
|
1995-09-17 21:47:24 +00:00
|
|
|
void
|
|
|
|
sigurg()
|
|
|
|
{
|
|
|
|
|
|
|
|
printd("urg\n");
|
|
|
|
if (hup == 0 && logged_in)
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_INFO, "%s: got dead line signal", username);
|
1995-09-17 21:47:24 +00:00
|
|
|
hup = 1;
|
|
|
|
}
|
|
|
|
|
1995-09-14 19:03:20 +00:00
|
|
|
void
|
|
|
|
sigterm()
|
|
|
|
{
|
|
|
|
|
|
|
|
printd("terminate\n");
|
|
|
|
if (terminate == 0 && logged_in)
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_INFO, "%s: got terminate signal", username);
|
1995-09-14 19:03:20 +00:00
|
|
|
terminate = 1;
|
|
|
|
}
|
|
|
|
|
1997-06-19 14:38:53 +00:00
|
|
|
int
|
1995-09-15 20:06:50 +00:00
|
|
|
getline(buf, size, fd, fintimeout)
|
1994-05-26 06:35:07 +00:00
|
|
|
char *buf;
|
1995-09-15 20:06:50 +00:00
|
|
|
int size, fd;
|
|
|
|
time_t fintimeout;
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
int ret;
|
1994-12-04 12:26:01 +00:00
|
|
|
fd_set readfds;
|
|
|
|
struct timeval tv;
|
1995-09-15 20:06:50 +00:00
|
|
|
time_t timeout;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
size--;
|
|
|
|
for (i = 0; i < size; i++) {
|
1995-09-14 19:03:20 +00:00
|
|
|
if (hup || terminate)
|
1994-05-26 06:35:07 +00:00
|
|
|
return (0);
|
1995-09-15 20:06:50 +00:00
|
|
|
if ((timeout = fintimeout - time(NULL)) <= 0)
|
|
|
|
goto tout;
|
1994-12-04 12:26:01 +00:00
|
|
|
FD_ZERO(&readfds);
|
|
|
|
FD_SET(fd, &readfds);
|
|
|
|
tv.tv_sec = timeout;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
if ((ret = select(fd + 1, &readfds, NULL, NULL, &tv)) < 0) {
|
1995-05-30 06:12:45 +00:00
|
|
|
if (errno != EINTR)
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: getline: select: %m", username);
|
1994-12-04 12:26:01 +00:00
|
|
|
} else {
|
|
|
|
if (! ret) {
|
1995-09-15 20:06:50 +00:00
|
|
|
tout:
|
1994-12-04 12:26:01 +00:00
|
|
|
printd("getline: timed out\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if ((ret = read(fd, &buf[i], 1)) == 1) {
|
|
|
|
buf[i] &= 0177;
|
1995-09-14 19:03:20 +00:00
|
|
|
if (buf[i] == '\r' || buf[i] == '\0') {
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
1994-12-04 12:26:01 +00:00
|
|
|
if (buf[i] != '\n' && buf[i] != ':')
|
|
|
|
continue;
|
|
|
|
buf[i + 1] = '\0';
|
1995-09-14 19:03:20 +00:00
|
|
|
printd("Got %d: %s", i + 1, buf);
|
1994-12-04 12:26:01 +00:00
|
|
|
return (i+1);
|
|
|
|
}
|
|
|
|
if (ret <= 0) {
|
|
|
|
if (ret < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: getline: read: %m", username);
|
1994-12-04 12:26:01 +00:00
|
|
|
} else
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: read returned 0", username);
|
1994-12-04 12:26:01 +00:00
|
|
|
buf[i] = '\0';
|
1995-09-14 19:03:20 +00:00
|
|
|
printd("returning %d after %d: %s\n", ret, i, buf);
|
1994-12-04 12:26:01 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-06-19 14:38:53 +00:00
|
|
|
int
|
1995-09-15 20:06:50 +00:00
|
|
|
carrier()
|
|
|
|
{
|
|
|
|
int comstate;
|
|
|
|
|
|
|
|
if (ioctl(fd, TIOCMGET, &comstate) < 0) {
|
1995-09-27 17:15:37 +00:00
|
|
|
syslog(LOG_ERR, "%s: ioctl (%s, TIOCMGET): %m",
|
|
|
|
username, devicename);
|
1995-09-15 20:06:50 +00:00
|
|
|
down(2);
|
|
|
|
}
|
|
|
|
return !!(comstate & TIOCM_CD);
|
|
|
|
}
|
|
|
|
|
1997-06-19 14:38:53 +00:00
|
|
|
void
|
1995-09-14 22:01:06 +00:00
|
|
|
down(code)
|
|
|
|
{
|
1995-09-19 03:37:07 +00:00
|
|
|
if (fd > -1)
|
|
|
|
close(fd);
|
1995-09-14 22:01:06 +00:00
|
|
|
if (pfd)
|
|
|
|
unlink(pidfile);
|
1995-09-20 04:56:09 +00:00
|
|
|
if (uucp_lock && locked)
|
1995-09-15 20:06:50 +00:00
|
|
|
uu_unlock(dvname);
|
1995-09-14 22:01:06 +00:00
|
|
|
exit(code);
|
|
|
|
}
|
|
|
|
|
1997-06-19 14:38:53 +00:00
|
|
|
static void
|
1994-05-26 06:35:07 +00:00
|
|
|
usage()
|
|
|
|
{
|
1997-06-19 14:38:53 +00:00
|
|
|
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
|
|
|
"usage: startslip [-d] [-b speed] [-s string1 [-s string2 [...]]] [-h] [-l]",
|
|
|
|
" [-L] [-A annexname] [-U upscript] [-D downscript]",
|
|
|
|
" [-t script_timeout] [-W maxtries] [-w retry_pause]",
|
|
|
|
" [-K keepalive] [-O outfill] [-S unit] device user passwd");
|
1994-05-26 06:35:07 +00:00
|
|
|
exit(1);
|
|
|
|
}
|