diff options
author | ed <ed@FreeBSD.org> | 2009-04-05 22:08:18 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-04-05 22:08:18 +0000 |
commit | 36d960175a8cfcbccee2d24424dc7677bbf9954a (patch) | |
tree | 8a97b6bb04afecdfb70c99fe4302c043d6d240e0 /sbin | |
parent | 18eefdb2b28b2ccc1394a40d490c6b1b0c80086d (diff) | |
download | FreeBSD-src-36d960175a8cfcbccee2d24424dc7677bbf9954a.zip FreeBSD-src-36d960175a8cfcbccee2d24424dc7677bbf9954a.tar.gz |
Remove if_ppp(4) and if_sl(4).
Not only did these two drivers depend on IFF_NEEDSGIANT, they were
broken 7 months ago during the MPSAFE TTY import. if_ppp(4) has been
replaced by ppp(8). There is no replacement for if_sl(4).
If we see regressions in for example the ports tree, we should just use
__FreeBSD_version 800045 to check whether if_ppp(4) and if_sl(4) are
present. Version 800045 is used to denote the import of MPSAFE TTY.
Discussed with: rwatson, but also rwatson's IFF_NEEDSGIANT emails on the
lists.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/Makefile | 6 | ||||
-rw-r--r-- | sbin/slattach/Makefile | 12 | ||||
-rw-r--r-- | sbin/slattach/slattach.8 | 271 | ||||
-rw-r--r-- | sbin/slattach/slattach.c | 599 | ||||
-rw-r--r-- | sbin/startslip/Makefile | 9 | ||||
-rw-r--r-- | sbin/startslip/startslip.1 | 213 | ||||
-rw-r--r-- | sbin/startslip/startslip.c | 595 |
7 files changed, 0 insertions, 1705 deletions
diff --git a/sbin/Makefile b/sbin/Makefile index 0b6bc02..649f4a2 100644 --- a/sbin/Makefile +++ b/sbin/Makefile @@ -82,9 +82,7 @@ SUBDIR= adjkerntz \ ${_sconfig} \ setkey \ shutdown \ - slattach \ spppcontrol \ - ${_startslip} \ ${_sunlabel} \ swapon \ sysctl \ @@ -130,10 +128,6 @@ _quotacheck= quotacheck _routed= routed .endif -.if ${MK_SLIP} != "no" -_startslip= startslip -.endif - .if ${MACHINE_ARCH} == "i386" .if ${MACHINE} == "i386" _fdisk= fdisk diff --git a/sbin/slattach/Makefile b/sbin/slattach/Makefile deleted file mode 100644 index 84b0c12..0000000 --- a/sbin/slattach/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# @(#)Makefile 5.4 (Berkeley) 5/11/90 -# -# $FreeBSD$ - -PROG= slattach -WARNS?= 0 -MAN= slattach.8 -MLINKS= slattach.8 slip.8 -LDADD= -lutil -DPADD= ${LIBUTIL} - -.include <bsd.prog.mk> diff --git a/sbin/slattach/slattach.8 b/sbin/slattach/slattach.8 deleted file mode 100644 index a359dd2..0000000 --- a/sbin/slattach/slattach.8 +++ /dev/null @@ -1,271 +0,0 @@ -.\" Copyright (c) 1986, 1991 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. -.\" 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. -.\" -.\" @(#)slattach.8 6.4 (Berkeley) 3/16/91 -.\" -.\" $FreeBSD$ -.\" -.Dd April 4, 1993 -.Dt SLATTACH 8 -.Os -.Sh NAME -.Nm slattach -.Nd attach serial lines as network interfaces -.Sh SYNOPSIS -.Nm -.Op Fl acfhLlnz -.Op Fl e Ar exit-command -.Op Fl K Ar keepalive -.Op Fl O Ar outfill -.Op Fl r Ar redial-command -.Op Fl S Ar unit -.Op Fl s Ar baudrate -.Op Fl u Ar unit-command -.Ar ttyname -.Sh DESCRIPTION -The -.Nm -utility is used to assign a tty line to a network interface, -and to define the network source and destination addresses. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl a -Autoenable the VJ header compression option, if the other end of the link -is capable of VJ header compression then it will be used otherwise normal -headers will be used. -.It Fl c -Enable the VJ header compression option. -Note that both ends of the link -must be able to use VJ header compression for this to work. -.It Fl e Ar exit-command -Specify a command to be invoked within a shell -.Ql sh \-c Ar exit-command -before -.Nm -exits. -.It Fl f -Disable the invocation of daemon() to run -.Nm -in the background. -.It Fl h -Turn on cts/rts style flow control on the slip port, by default no flow -control is done. -.It Fl l -Disable modem control (CLOCAL) and ignore carrier detect on the slip -port. -By default the -.Ar redial-command -is invoked upon carrier drop and -.Nm -aborts if no -.Ar redial-command -is specified. -.It Fl n -Throw away ICMP packets. -The slip interface will ignore ICMP packets -to prevent slow lines being saturated by ICMP responses. -.It Fl r Ar redial-command -Specify a command to be invoked within a shell -.Ql sh \-c Ar redial-command -whenever carrier is lost on the modem line. -Empty -.Ar redial-command -(i.e.\& -.Fl r Qq "" ) -cause connection reestablishing on leased line -without any external command invoked. -.It Fl s Ar baudrate -Specify the speed of the connection. -If not specified, the -default of 9600 is used. -.It Fl u Ar unit-command -When the line is switched to slip discipline, run -.Dq Nm "sh -c" Ar unit-command old new -where -.Ar old -and -.Ar new -are the slip unit numbers when the line was -last opened and the unit number of the current slip connection -respectively. -The unit number can change after redialing if you are -using more than one slip line. -When -.Nm -is connected for the first time, -.Dq Nm "sh -c" Ar unit-command \-1 new -is run. -When -.Nm -is disconnected, -.Dq Nm "sh -c" Ar unit-command old \-1 -is run. -The -.Nm -utility will abort if the unit number -changes and -.Dq Fl u Ar \%unit-command -was not specified. -.It Fl z -Force redial -.Ar redial-command -upon startup irrespective of carrier. -.It Fl L -Use uucp-style device locking. -You need it unless you start -.Nm -from external program which already does uucp locking. -Default case is no uucp locking to satisfy such programs. -.It Fl K Ar keepalive -Set SLIP "keep alive" timeout in seconds. -If FRAME_END is not received in -this amount of time, re-connect occurs. -The default value is no timeout. -.It Fl O Ar outfill -Set SLIP "out fill" timeout in seconds. -It forces at least one FRAME_END -to be sent during this time period, which is necessary for the "keep alive" -timeout on the remote side. -The default value is no timeout. -.It Fl S Ar unit -Set the SLIP unit number directly. -Use with caution, because no check is made -for two interfaces with same number. -By default sliplogin dynamically assigns the unit number. -.It Ar ttyname -Specify the name of the tty device. -.Ar Ttyname -should be a string of the form -.Ql ttyXX -or -.Ql /dev/ttyXX . -.El -.Pp -Only the super-user may attach a network interface. -.Pp -To detach the interface, use -.Dq Li ifconfig interface-name down -after killing off the -.Nm -process using -.Ql kill -INT . -.Ar Interface-name -is the name that is shown by -.Xr netstat 1 . -.Pp -To setup -.Nm -to redial the phone when carrier is lost, use the -.Fl r Ar redial-command -option to specify a script or executable that will reconnect the -serial line to the slip server. -For example, the script could redial -the server and log in, etc. -.Pp -To reconfigure the network interface in case the slip unit number -changes, use the -.Fl u Ar unit-command -option to specify a script or executable that will be invoked as -.Ql sh \-c Ar unit-command old new -where -.Ar old -and -.Ar new -are the slip unit numbers before and after -reconnecting the line. -The unit number can change if you have more -than one line disconnect at the same time. -The first to succeed in -reconnecting will get the lowest unit number. -.Pp -To kill -.Nm -use -.Ql kill -INT -(SIGINT) which causes it to close the tty and exit. -.Pp -To force a redial, use -.Ql kill -HUP -(SIGHUP) which causes -.Nm -to think carrier was lost and thus invoke -.Ql sh \-c Ar redial-command -to reconnect to the server. -.Pp -If you use a hard-wired connection rather than a modem, invoke -.Nm -with the -.Fl l -option in order to ignore carrier on the slip line. -.Sh FILES -.Bl -tag -width /usr/share/examples/slattach/* -compact -.It Pa /var/run/slattach.<tty>.pid -with -.Ar tty -replaced by the terminal path name component of -.Ar ttyname . -This file contains the numerical process ID of the -.Nm -process and can be examined by scripts in order to send a signal to -.Nm -.It Pa /usr/share/examples/slattach/* -.El -.Sh EXAMPLES -.Bd -literal -offset indent -compact -slattach ttyd8 -slattach \-s 4800 /dev/ttyd1 -slattach \-c \-s 38400 /dev/cuad1 -slattach \-r 'kermit -y dial.script >kermit.log 2>&1' -.Ed -.Sh DIAGNOSTICS -Look for error messages in -.Pa /var/log/messages -.No ( Nm -is a daemon). -Messages indicating the specified interface does not exit, the -requested address is unknown, the user is not privileged and tried to -alter an interface's configuration are logged there. -The -.Nm -utility -also logs failure to set the controlling terminal or failure to install -signal handlers. -Upon connection and redial the ttyname and baud rate -are logged and on shutdown the ttyname is logged. -.Sh SEE ALSO -.Xr netstat 1 , -.Xr startslip 1 , -.Xr netintro 4 , -.Xr ifconfig 8 , -.Xr rc 8 , -.Xr sliplogin 8 -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.3 . diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c deleted file mode 100644 index afdfce8..0000000 --- a/sbin/slattach/slattach.c +++ /dev/null @@ -1,599 +0,0 @@ -/* - * Copyright (c) 1988 Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Rick Adams. - * - * 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. - * 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 -static const char copyright[] = -"@(#) Copyright (c) 1988 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)slattach.c 4.6 (Berkeley) 6/1/90"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/socket.h> - -#include <err.h> -#include <fcntl.h> -#include <libutil.h> -#include <paths.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <termios.h> -#include <unistd.h> - -#include <net/if.h> -#include <net/slip.h> - -#define DEFAULT_BAUD 9600 - -void sighup_handler(); /* SIGHUP handler */ -void sigint_handler(); /* SIGINT handler */ -void sigterm_handler(); /* SIGTERM handler */ -void sigurg_handler(); /* SIGURG handler */ -void exit_handler(int ret); /* run exit_cmd iff specified upon exit. */ -void setup_line(int cflag); /* configure terminal settings */ -void slip_discipline(); /* switch to slip line discipline */ -void configure_network(); /* configure slip interface */ -void acquire_line(); /* get tty device as controlling terminal */ -static void usage(void); - -int fd = -1; -char *dev = (char *)0; /* path name of the tty (e.g. /dev/tty01) */ -char *dvname; /* basename of dev */ -int locked = 0; /* uucp lock active */ -int flow_control = 0; /* non-zero to enable hardware flow control. */ -int modem_control = HUPCL; /* !CLOCAL+HUPCL iff we watch carrier. */ -int comstate; /* TIOCMGET current state of serial driver */ -int redial_on_startup = 0; /* iff non-zero execute redial_cmd on startup */ -speed_t speed = DEFAULT_BAUD; /* baud rate of tty */ -int slflags = 0; /* compression flags */ -int unit = -1; /* slip device unit number */ -int foreground = 0; /* act as daemon if zero, else don't fork. */ -int keepal = 0; /* keepalive timeout */ -int outfill = 0; /* outfill timeout */ -int sl_unit = -1; /* unit number */ -int uucp_lock = 0; /* do uucp locking */ -int exiting = 0; /* already running exit_handler */ - -struct termios tty; /* tty configuration/state */ - -char tty_path[32]; /* path name of the tty (e.g. /dev/tty01) */ -char pidfilename[40]; /* e.g. /var/run/slattach.tty01.pid */ -char *redial_cmd = 0; /* command to exec upon shutdown. */ -char *config_cmd = 0; /* command to exec if slip unit changes. */ -char *exit_cmd = 0; /* command to exec before exiting. */ - -static void -usage() -{ - fprintf(stderr, "%s\n%s\n%s\n", -"usage: slattach [-acfhLlnz] [-e exit-command] [-K keepalive] [-O outfill]", -" [-r redial-command] [-S unit] [-s baudrate] [-u unit-command]", -" ttyname"); - /* do not exit here */ -} - -int -main(int argc, char **argv) -{ - int option; - - while ((option = getopt(argc, argv, "ace:fhlnr:s:u:zLK:O:S:")) != -1) { - switch (option) { - case 'a': - slflags |= IFF_LINK2; - slflags &= ~IFF_LINK0; - break; - case 'c': - slflags |= IFF_LINK0; - slflags &= ~IFF_LINK2; - break; - case 'e': - exit_cmd = strdup (optarg); - break; - case 'f': - foreground = 1; - break; - case 'h': - flow_control |= CRTSCTS; - break; - case 'l': - modem_control = CLOCAL; /* clear HUPCL too */ - break; - case 'n': - slflags |= IFF_LINK1; - break; - case 'r': - redial_cmd = strdup (optarg); - break; - case 's': - speed = atoi(optarg); - break; - case 'u': - config_cmd = strdup (optarg); - break; - case 'z': - redial_on_startup = 1; - break; - case 'L': - uucp_lock = 1; - break; - case 'K': - keepal = atoi(optarg); - break; - case 'O': - outfill = atoi(optarg); - break; - case 'S': - sl_unit = atoi(optarg); - break; - case '?': - default: - usage(); - exit_handler(1); - } - } - - if (optind == argc - 1) - dev = argv[optind]; - - if (optind < (argc - 1)) - warnx("too many args, first='%s'", argv[optind]); - if (optind > (argc - 1)) - warnx("not enough args"); - if (dev == (char *)0) { - usage(); - exit_handler(2); - } - if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { - strcpy(tty_path, _PATH_DEV); - strcat(tty_path, "/"); - strncat(tty_path, dev, 10); - dev = tty_path; - } - dvname = strrchr(dev, '/'); /* always succeeds */ - dvname++; /* trailing tty pathname component */ - snprintf(pidfilename, sizeof(pidfilename), - "%sslattach.%s.pid", _PATH_VARRUN, dvname); - printf("%s\n",pidfilename); - - if (!foreground) - daemon(0,0); /* fork, setsid, chdir /, and close std*. */ - /* daemon() closed stderr, so log errors from here on. */ - openlog("slattach",LOG_CONS|LOG_PID,LOG_DAEMON); - - acquire_line(); /* get tty device as controlling terminal */ - setup_line(0); /* configure for slip line discipline */ - slip_discipline(); /* switch to slip line discipline */ - - /* upon INT log a timestamp and exit. */ - if (signal(SIGINT,sigint_handler) == SIG_ERR) - syslog(LOG_NOTICE,"cannot install SIGINT handler: %m"); - /* upon TERM log a timestamp and exit. */ - if (signal(SIGTERM,sigterm_handler) == SIG_ERR) - syslog(LOG_NOTICE,"cannot install SIGTERM handler: %m"); - /* upon HUP redial and reconnect. */ - if (signal(SIGHUP,sighup_handler) == SIG_ERR) - syslog(LOG_NOTICE,"cannot install SIGHUP handler: %m"); - - if (redial_on_startup) - sighup_handler(); - else if (!(modem_control & CLOCAL)) { - if (ioctl(fd, TIOCMGET, &comstate) < 0) - syslog(LOG_NOTICE,"cannot get carrier state: %m"); - if (!(comstate & TIOCM_CD)) { /* check for carrier */ - /* force a redial if no carrier */ - kill (getpid(), SIGHUP); - } else - configure_network(); - } else - configure_network(); /* configure the network if needed. */ - - for (;;) { - sigset_t mask; - sigemptyset(&mask); - sigsuspend(&mask); - } -} - -/* Close all FDs, fork, reopen tty port as 0-2, and make it the - controlling terminal for our process group. */ -void acquire_line() -{ - int ttydisc = TTYDISC; - int oflags; - FILE *pidfile; - - /* reset to tty discipline */ - if (fd >= 0 && ioctl(fd, TIOCSETD, &ttydisc) < 0) { - syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); - exit_handler(1); - } - - (void)close(STDIN_FILENO); /* close FDs before forking. */ - (void)close(STDOUT_FILENO); - (void)close(STDERR_FILENO); - if (fd > 2) - (void)close(fd); - - signal(SIGHUP, SIG_IGN); /* ignore HUP signal when parent dies. */ - if (daemon(0,0)) { /* fork, setsid, chdir /, and close std*. */ - syslog(LOG_ERR, "daemon(0,0): %m"); - exit_handler(1); - } - - while (getppid () != 1) - sleep (1); /* Wait for parent to die. */ - - /* create PID file */ - if((pidfile = fopen(pidfilename, "w"))) { - fprintf(pidfile, "%ld\n", (long)getpid()); - fclose(pidfile); - } - - if (signal(SIGHUP,sighup_handler) == SIG_ERR) /* Re-enable HUP signal */ - syslog(LOG_NOTICE,"cannot install SIGHUP handler: %m"); - - if (uucp_lock) { - /* unlock not needed here, always re-lock with new pid */ - int res; - if ((res = uu_lock(dvname)) != UU_LOCK_OK) { - if (res != UU_LOCK_INUSE) - syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res)); - syslog(LOG_ERR, "can't lock %s", dev); - exit_handler(1); - } - locked = 1; - } - - if ((fd = open(dev, O_RDWR | O_NONBLOCK, 0)) < 0) { - syslog(LOG_ERR, "open(%s) %m", dev); - exit_handler(1); - } - /* Turn off O_NONBLOCK for dumb redialers, if any. */ - if ((oflags = fcntl(fd, F_GETFL)) == -1) { - syslog(LOG_ERR, "fcntl(F_GETFL) failed: %m"); - exit_handler(1); - } - if (fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK) == -1) { - syslog(LOG_ERR, "fcntl(F_SETFL) failed: %m"); - exit_handler(1); - } - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close (fd); - fd = STDIN_FILENO; - - /* acquire the serial line as a controlling terminal. */ - if (ioctl(fd, TIOCSCTTY, 0) < 0) { - syslog(LOG_ERR,"ioctl(TIOCSCTTY): %m"); - exit_handler(1); - } - /* Make us the foreground process group associated with the - slip line which is our controlling terminal. */ - if (tcsetpgrp(fd, getpid()) < 0) - syslog(LOG_NOTICE,"tcsetpgrp failed: %m"); -} - -/* Set the tty flags and set DTR. */ -/* Call as setup_line(CLOCAL) to force clocal assertion. */ -void setup_line(int cflag) -{ - tty.c_lflag = tty.c_iflag = tty.c_oflag = 0; - tty.c_cflag = CREAD | CS8 | flow_control | modem_control | cflag; - cfsetispeed(&tty, speed); - cfsetospeed(&tty, speed); - /* set the line speed and flow control */ - if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) { - syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m"); - exit_handler(1); - } - /* set data terminal ready */ - if (ioctl(fd, TIOCSDTR) < 0) { - syslog(LOG_ERR, "ioctl(TIOCSDTR): %m"); - exit_handler(1); - } -} - -/* Put the line in slip discipline. */ -void slip_discipline() -{ - struct ifreq ifr; - int slipdisc = SLIPDISC; - int s, tmp_unit = -1; - - /* Switch to slip line discipline. */ - if (ioctl(fd, TIOCSETD, &slipdisc) < 0) { - syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); - exit_handler(1); - } - - if (sl_unit >= 0 && ioctl(fd, SLIOCSUNIT, &sl_unit) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCSUNIT): %m"); - exit_handler(1); - } - - /* find out what unit number we were assigned */ - if (ioctl(fd, SLIOCGUNIT, (caddr_t)&tmp_unit) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m"); - exit_handler(1); - } - - if (tmp_unit < 0) { - syslog(LOG_ERR, "bad unit (%d) from ioctl(SLIOCGUNIT)",tmp_unit); - exit_handler(1); - } - - if (keepal > 0) { - signal(SIGURG, sigurg_handler); - if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCSKEEPAL): %m"); - exit_handler(1); - } - } - if (outfill > 0 && ioctl(fd, SLIOCSOUTFILL, &outfill) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCSOUTFILL): %m"); - exit_handler(1); - } - - /* open a socket as the handle to the interface */ - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s < 0) { - syslog(LOG_ERR, "socket: %m"); - exit_handler(1); - } - sprintf(ifr.ifr_name, "sl%d", tmp_unit); - - /* get the flags for the interface */ - if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { - syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); - exit_handler(1); - } - - /* Assert any compression or no-icmp flags. */ -#define SLMASK (~(IFF_LINK0 | IFF_LINK1 | IFF_LINK2)) - ifr.ifr_flags &= SLMASK; - ifr.ifr_flags |= slflags; - if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) { - syslog(LOG_ERR, "ioctl (SIOCSIFFLAGS): %m"); - exit_handler(1); - } - close(s); -} - -/* configure the interface, e.g. by passing the unit number to a script. */ -void configure_network() -{ - int new_unit; - - /* find out what unit number we were assigned */ - if (ioctl(fd, SLIOCGUNIT, (caddr_t)&new_unit) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m"); - exit_handler(1); - } - /* iff the unit number changes either invoke config_cmd or punt. */ - if (config_cmd) { - char *s; - s = (char*) malloc(strlen(config_cmd) + 32); - if (s == NULL) { - syslog(LOG_ERR, "malloc failed"); - exit(1); - } - sprintf (s, "%s %d %d", config_cmd, unit, new_unit); - syslog(LOG_NOTICE, "configuring %s (sl%d):", dev, unit); - syslog(LOG_NOTICE, " '%s'", s); - system(s); - free (s); - unit = new_unit; - } else { - /* don't compare unit numbers if this is the first time to attach. */ - if (unit < 0) - unit = new_unit; - if (new_unit != unit) { - syslog(LOG_ERR, - "slip unit changed from sl%d to sl%d, but no -u CMD was specified!", - unit, new_unit); - exit_handler(1); - } - syslog(LOG_NOTICE,"sl%d connected to %s at %d baud",unit,dev,speed); - } -} - -/* sighup_handler() is invoked when carrier drops, eg. before redial. */ -void sighup_handler() -{ - if(exiting) return; - - if (redial_cmd == NULL) { - syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); exiting", dev, unit); - exit_handler(1); - } -again: - /* invoke a shell for redial_cmd or punt. */ - if (*redial_cmd) { /* Non-empty redial command */ - syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); running '%s'", - dev, unit, redial_cmd); - acquire_line(); /* reopen dead line */ - setup_line(CLOCAL); - if (locked) { - if (uucp_lock) - uu_unlock(dvname); /* for redial */ - locked = 0; - } - if (system(redial_cmd)) - goto again; - if (uucp_lock) { - int res; - if ((res = uu_lock(dvname)) != UU_LOCK_OK) { - if (res != UU_LOCK_INUSE) - syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res)); - syslog(LOG_ERR, "can't relock %s after %s, aborting", - dev, redial_cmd); - exit_handler(1); - } - locked = 1; - } - /* Now check again for carrier (dial command is done): */ - if (!(modem_control & CLOCAL)) { - tty.c_cflag &= ~CLOCAL; - if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) { - syslog(LOG_ERR, "tcsetattr(TCSAFLUSH): %m"); - exit_handler(1); - } - ioctl(fd, TIOCMGET, &comstate); - if (!(comstate & TIOCM_CD)) { /* check for carrier */ - /* force a redial if no carrier */ - goto again; - } - } else - setup_line(0); - } else { /* Empty redial command */ - syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); reestablish connection", - dev, unit); - acquire_line(); /* reopen dead line */ - setup_line(0); /* restore ospeed from hangup (B0) */ - /* If modem control, just wait for carrier before attaching. - If no modem control, just fall through immediately. */ - if (!(modem_control & CLOCAL)) { - int carrier = 0; - - syslog(LOG_NOTICE, "waiting for carrier on %s (sl%d)", - dev, unit); - /* Now wait for carrier before attaching line. */ - /* We must poll since CLOCAL prevents signal. */ - while (! carrier) { - sleep(2); - ioctl(fd, TIOCMGET, &comstate); - if (comstate & TIOCM_CD) - carrier = 1; - } - syslog(LOG_NOTICE, "carrier now present on %s (sl%d)", - dev, unit); - } - } - slip_discipline(); - configure_network(); -} -/* Signal handler for SIGINT. We just log and exit. */ -void sigint_handler() -{ - if(exiting) return; - syslog(LOG_NOTICE,"SIGINT on %s (sl%d); exiting",dev,unit); - exit_handler(0); -} -/* Signal handler for SIGURG. */ -void sigurg_handler() -{ - int ttydisc = TTYDISC; - - signal(SIGURG, SIG_IGN); - if(exiting) return; - syslog(LOG_NOTICE,"SIGURG on %s (sl%d); hangup",dev,unit); - if (ioctl(fd, TIOCSETD, &ttydisc) < 0) { - syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); - exit_handler(1); - } - cfsetospeed(&tty, B0); - if (tcsetattr(fd, TCSANOW, &tty) < 0) { - syslog(LOG_ERR, "tcsetattr(TCSANOW): %m"); - exit_handler(1); - } - /* Need to go to sighup handler in any case */ - if (modem_control & CLOCAL) - kill (getpid(), SIGHUP); - -} -/* Signal handler for SIGTERM. We just log and exit. */ -void sigterm_handler() -{ - if(exiting) return; - syslog(LOG_NOTICE,"SIGTERM on %s (sl%d); exiting",dev,unit); - exit_handler(0); -} -/* Run config_cmd if specified before exiting. */ -void exit_handler(int ret) -{ - if(exiting) return; - exiting = 1; - /* - * First close the slip line in case exit_cmd wants it (like to hang - * up a modem or something). - */ - if (fd != -1) - close(fd); - if (uucp_lock && locked) - uu_unlock(dvname); - - /* Remove the PID file */ - (void)unlink(pidfilename); - - if (config_cmd) { - char *s; - s = (char*) malloc(strlen(config_cmd) + 32); - if (s == NULL) { - syslog(LOG_ERR, "malloc failed"); - exit(1); - } - sprintf (s, "%s %d -1", config_cmd, unit); - syslog(LOG_NOTICE, "deconfiguring %s (sl%d):", dev, unit); - syslog(LOG_NOTICE, " '%s'", s); - system(s); - free (s); - } - /* invoke a shell for exit_cmd. */ - if (exit_cmd) { - syslog(LOG_NOTICE,"exiting after running %s", exit_cmd); - system(exit_cmd); - } - exit(ret); -} - -/* local variables: */ -/* c-indent-level: 8 */ -/* c-argdecl-indent: 0 */ -/* c-label-offset: -8 */ -/* c-continued-statement-offset: 8 */ -/* c-brace-offset: 0 */ -/* comment-column: 32 */ -/* end: */ diff --git a/sbin/startslip/Makefile b/sbin/startslip/Makefile deleted file mode 100644 index 1bf91dd..0000000 --- a/sbin/startslip/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/5/93 -# $FreeBSD$ - -PROG= startslip -WARNS?= 3 -DPADD= ${LIBUTIL} -LDADD= -lutil - -.include <bsd.prog.mk> diff --git a/sbin/startslip/startslip.1 b/sbin/startslip/startslip.1 deleted file mode 100644 index 2d6f43b..0000000 --- a/sbin/startslip/startslip.1 +++ /dev/null @@ -1,213 +0,0 @@ -.\" 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. -.\" 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. -.\" -.\" @(#)startslip.1 8.1 (Berkeley) 6/5/93 -.\" $FreeBSD$ -.\" -.Dd June 5, 1993 -.Dt STARTSLIP 1 -.Os -.Sh NAME -.Nm startslip -.Nd dial up and login to a slip server -.Sh SYNOPSIS -.Nm -.Op Fl d -.Op Fl b Ar speed -.Oo -.Fl s Ar string1 -.Op Fl s Ar string2 Op Ar ...\& -.Oc -.Op Fl h -.Op Fl l -.Op Fl L -.Op Fl A Ar annexname -.Op Fl U Ar upscript -.Op Fl D Ar downscript -.Op Fl t Ar script_timeout -.Op Fl W Ar maxtries -.Op Fl w Ar retry_pause -.Op Fl K Ar keepalive -.Op Fl O Ar outfill -.Op Fl S Ar unit -.Ar device user password -.Sh DESCRIPTION -The -.Nm -utility opens the specified -.Ar device . -Once carrier is asserted (if modem control is enabled) -.Nm -attempts to login as the specified -.Ar user -with the given -.Ar password . -Standard login: & Password: scheme assumed unless Annex option -specified (see -.Fl A ) . -If successful, it puts the device into the slip line discipline, -calls -.Ar upscript -and goes to wait mode. -If carrier drops (modem control enabled) or a -.Dv SIGHUP -is sent to -.Nm , -it closes the device, calls -.Ar downscript -and attempts to repeat the dialup and login sequence. -If a -.Dv SIGTERM -is send to -.Nm , -it closes the device, calls -.Ar downscript -and exits. -When -.Nm -called twice on the same device, previous copy killed by a -.Dv SIGTERM -before any operation. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl d -Print out debugging information. -.It Fl b Ar speed -Determine the baud rate used for -.Ar device , -default value is 9600. -.It Fl t Ar script_timeout -Set login script timeout in seconds, default value is 90. -.It Fl w Ar retry_pause -Set connecting retry pause in seconds (increased from one retry to another), -default value is 60. -.It Fl W Ar maxtries -Set maximum number of connection retries for one session, -default value is 6. -Value 0 means infinite count. -.It Fl s Ar stringN -The optional -.Ar stringN -is written to -.Ar device . -Return character is added automatically. -For a dialup modem, -the string is used to specify a dial sequence. -No string written by default. -You can specify several -.Fl s Ar stringN -arguments to use with each try, f.e. -several host phone numbers. -.It Fl A Ar annexname -The -.Nm -utility assumes it is connecting to a Xylogics Annex box and engages in an -appropriate dialog using the -.Ar user -and -.Ar password -arguments. -The -.Ar annexname -argument is a string that is used to match against the Annex prompt -to determine when a connection has been established. -.It Fl h -Use hardware (CTS/RTS) flow control for -.Ar device . -Default value is no flow control. -.It Fl l -Disable modem control (waiting for carrier and carrier drop sense) for -.Ar device . -Modem control is enabled by default. -.It Fl U Ar upscript -Specify a script to run when a SLIP interface becomes connected. -This may -contain -.Xr ifconfig 8 , -.Xr route 8 , -and other appropriate commands. -The arguments that -are passed to the script are "slX up". -Default value is -.Pa /sbin/ifconfig . -Dial sequence number (see -.Fl s ) -passed via -.Ev LINE -environment variable. -.It Fl D Ar downscript -Specify a script to run when a SLIP connection goes away. -The arguments that -are passed to the script are "slX down". -Default value is -.Pa /sbin/ifconfig . -Dial sequence number (see -.Fl s ) -passed via -.Ev LINE -environment variable. -.It Fl K Ar keepalive -Set SLIP "keep alive" timeout in seconds. -If FRAME_END not received during this -time period, a reconnect will occur. -Active "out fill" timeout expected from other -side. -Default value is no timeout. -.It Fl O Ar outfill -Set SLIP "out fill" timeout in seconds. -It causes at least one FRAME_END -to be sent during this timeout. -Needed for "keep alive" timeout on other side. -Default value is no timeout. -.It Fl S Ar unit -Set SLIP unit number directly. -Use with caution, no check for two -interfaces with same number made. -Default is dynamic assignment. -.It Fl L -Use uucp-style device locking. -You need it unless you start -.Nm -from external program which already does uucp locking. -Default case is no uucp locking to satisfy such programs. -.El -.Sh FILES -.Bl -tag -width /var/run/startslip.<device>.pid -compact -.It Pa /var/run/startslip.<device>.pid -pid stored here -.It Pa /usr/share/examples/startslip/* -.El -.Sh SEE ALSO -.Xr uustat 1 Pq Pa ports/net/freebsd-uucp , -.Xr slattach 8 , -.Xr sliplogin 8 -.Sh HISTORY -The -.Nm -appeared in -.Bx 4.4 . diff --git a/sbin/startslip/startslip.c b/sbin/startslip/startslip.c deleted file mode 100644 index 2d4d3bf..0000000 --- a/sbin/startslip/startslip.c +++ /dev/null @@ -1,595 +0,0 @@ -/*- - * 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. - * 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 -static const char copyright[] = -"@(#) Copyright (c) 1990, 1991, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)startslip.c 8.1 (Berkeley) 6/5/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/time.h> - -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <libutil.h> -#include <paths.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <termios.h> -#include <unistd.h> - -#include <net/slip.h> - -#define DEFAULT_BAUD B9600 -int speed = DEFAULT_BAUD; -#define FC_NONE 0 /* flow control: none */ -#define FC_HW 1 /* flow control: hardware (RTS/CTS) */ -int flowcontrol = FC_NONE; -int modem_control = 1; /* !CLOCAL+HUPCL iff we watch carrier. */ -int sl_unit = -1; -int uucp_lock = 0; /* uucp locking */ -char *annex; -char *username; -int hup; -int terminate; -int locked = 0; /* uucp lock active */ -int logged_in = 0; -int wait_time = 60; /* then back off */ -int script_timeout = 90; /* connect script default timeout */ -time_t conn_time, start_time; -int MAXTRIES = 6; /* w/60 sec and doubling, takes an hour */ -#define PIDFILE "%sstartslip.%s.pid" - -#define MAXDIALS 20 -char *dials[MAXDIALS]; -int diali, dialc; - -int fd = -1; -FILE *pfd; -char *dvname, *devicename; -char pidfile[80]; - -#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 - -int carrier(void); -void down(int); -int getline(char *, int, int, time_t); -void sighup(int); -void sigterm(int); -void sigurg(int); -static void usage(void); - -int -main(int argc, char **argv) -{ - char *cp, **ap; - int ch, disc; - FILE *wfd = NULL; - char *dialerstring = 0, buf[BUFSIZ]; - int unitnum, keepal = 0, outfill = 0; - char unitname[32]; - char *password; - char *upscript = NULL, *downscript = NULL; - int first = 1, tries = 0; - time_t fintimeout; - long lpid; - pid_t pid; - struct termios t; - - while ((ch = getopt(argc, argv, "dhlb:s:t:w:A:U:D:W:K:O:S:L")) != -1) - switch (ch) { - case 'd': - debug = 1; - break; - case 'b': - speed = atoi(optarg); - break; - case 's': - if (diali >= MAXDIALS) - errx(1, "max dial strings number (%d) exceeded", MAXDIALS); - dials[diali++] = strdup(optarg); - break; - case 't': - script_timeout = atoi(optarg); - break; - case 'w': - wait_time = atoi(optarg); - break; - case 'W': - MAXTRIES = atoi(optarg); - break; - case 'A': - annex = strdup(optarg); - break; - case 'U': - upscript = strdup(optarg); - break; - case 'D': - downscript = strdup(optarg); - break; - case 'L': - uucp_lock = 1; - break; - case 'l': - modem_control = 0; - break; - case 'h': - flowcontrol = FC_HW; - break; - case 'K': - keepal = atoi(optarg); - break; - case 'O': - outfill = atoi(optarg); - break; - case 'S': - sl_unit = atoi(optarg); - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc != 3) - usage(); - - /* - * 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'; - - openlog("startslip", LOG_PID|LOG_PERROR, LOG_DAEMON); - - if (debug) - setbuf(stdout, NULL); - - signal(SIGTERM, sigterm); - if ((dvname = strrchr(devicename, '/')) == NULL) - dvname = devicename; - else - dvname++; - if (snprintf(pidfile, sizeof(pidfile), PIDFILE, _PATH_VARRUN, dvname) - >= (int)sizeof(pidfile)) - usage(); - - if ((pfd = fopen(pidfile, "r")) != NULL) { - if (fscanf(pfd, "%ld\n", &lpid) == 1) { - pid = lpid; - if (pid == lpid && pid > 0) - kill(pid, SIGTERM); - } - fclose(pfd); - pfd = NULL; /* not remove pidfile yet */ - sleep(5); /* allow down script to be completed */ - } else -restart: - signal(SIGHUP, SIG_IGN); - signal(SIGURG, SIG_IGN); - hup = 0; - if (wfd) { - printd("fclose, "); - fclose(wfd); - conn_time = time(NULL) - start_time; - if (uucp_lock) - uu_unlock(dvname); - locked = 0; - wfd = NULL; - fd = -1; - sleep(5); - } else if (fd >= 0) { - printd("close, "); - close(fd); - conn_time = time(NULL) - start_time; - if (uucp_lock) - uu_unlock(dvname); - locked = 0; - fd = -1; - sleep(5); - } - if (logged_in) { - syslog(LOG_INFO, "%s: connection time elapsed: %ld secs", - username, (long)conn_time); - sprintf(buf, "LINE=%d %s %s down", - diali ? (dialc - 1) % diali : 0, - downscript ? downscript : _PATH_IFCONFIG , unitname); - (void) system(buf); - logged_in = 0; - } - if (terminate) - down(0); - tries++; - if (MAXTRIES > 0 && tries > MAXTRIES) { - syslog(LOG_ERR, "%s: exiting login after %d tries", username, tries); - /* ??? - if (first) - */ - down(3); - } - if (tries > 1) { - syslog(LOG_INFO, "%s: sleeping %d seconds (%d tries)", - username, wait_time * (tries - 1), tries); - sleep(wait_time * (tries - 1)); - if (terminate) - goto restart; - } - - if (daemon(1, debug) < 0) { - syslog(LOG_ERR, "%s: daemon: %m", username); - down(2); - } - - pid = getpid(); - printd("restart: pid %ld: ", (long)pid); - if ((pfd = fopen(pidfile, "w")) != NULL) { - fprintf(pfd, "%ld\n", (long)pid); - fclose(pfd); - } - printd("open"); - if (uucp_lock) { - int res; - if ((res = uu_lock(dvname)) != UU_LOCK_OK) { - if (res != UU_LOCK_INUSE) - syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res)); - syslog(LOG_ERR, "%s: can't lock %s", username, devicename); - goto restart; - } - locked = 1; - } - if ((fd = open(devicename, O_RDWR | O_NONBLOCK)) < 0) { - syslog(LOG_ERR, "%s: open %s: %m", username, devicename); - if (first) - down(1); - else { - if (uucp_lock) - uu_unlock(dvname); - locked = 0; - goto restart; - } - } - printd(" %d", fd); - signal(SIGHUP, sighup); - if (ioctl(fd, TIOCSCTTY, 0) < 0) { - syslog(LOG_ERR, "%s: ioctl (TIOCSCTTY): %m", username); - down(2); - } - if (tcsetpgrp(fd, getpid()) < 0) { - syslog(LOG_ERR, "%s: tcsetpgrp failed: %m", username); - down(2); - } - printd(", ioctl\n"); - if (tcgetattr(fd, &t) < 0) { - syslog(LOG_ERR, "%s: tcgetattr(%s): %m", username, devicename); - down(2); - } - 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; - } - if (modem_control) - t.c_cflag |= HUPCL; - else - t.c_cflag &= ~(HUPCL); - t.c_cflag |= CLOCAL; /* until modem commands passes */ - cfsetispeed(&t, speed); - cfsetospeed(&t, speed); - if (tcsetattr(fd, TCSAFLUSH, &t) < 0) { - syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename); - down(2); - } - sleep(2); /* wait for flakey line to settle */ - if (hup || terminate) - goto restart; - - wfd = fdopen(fd, "w+"); - if (wfd == NULL) { - syslog(LOG_ERR, "%s: can't fdopen %s: %m", username, devicename); - down(2); - } - setbuf(wfd, NULL); - - if (diali > 0) - dialerstring = dials[dialc++ % diali]; - if (dialerstring) { - syslog(LOG_INFO, "%s: dialer string: %s\\r", username, dialerstring); - fprintf(wfd, "%s\r", dialerstring); - } - printd("\n"); - - 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) { - syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename); - down(2); - } - /* Only now we able to receive HUP on carrier drop! */ - } - - /* - * Log in - */ - printd("look for login: "); - for (;;) { - if (getline(buf, BUFSIZ, fd, fintimeout) == 0 || hup || terminate) - 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) { - fprintf(wfd, "%s\r", username); - printd("Sent login: %s\n", username); - continue; - } - if (bcmp(&buf[1], "assword:", 8) == 0) { - fprintf(wfd, "%s\r", password); - printd("Sent password: %s\n", password); - break; - } - } else { - if (strstr(&buf[1], "ogin:") != NULL) { - fprintf(wfd, "%s\r", username); - printd("Sent login: %s\n", username); - continue; - } - if (strstr(&buf[1], "assword:") != NULL) { - fprintf(wfd, "%s\r", password); - printd("Sent password: %s\n", password); - break; - } - } - } - - sleep(5); /* Wait until login completed */ - if (hup || terminate) - goto restart; - start_time = time(NULL); - /* - * Attach - */ - printd("setd"); - disc = SLIPDISC; - if (ioctl(fd, TIOCSETD, &disc) < 0) { - syslog(LOG_ERR, "%s: ioctl (%s, TIOCSETD): %m", - username, devicename); - down(2); - } - if (sl_unit >= 0 && ioctl(fd, SLIOCSUNIT, &sl_unit) < 0) { - syslog(LOG_ERR, "%s: ioctl(SLIOCSUNIT): %m", username); - down(2); - } - if (ioctl(fd, SLIOCGUNIT, &unitnum) < 0) { - syslog(LOG_ERR, "%s: ioctl(SLIOCGUNIT): %m", username); - down(2); - } - sprintf(unitname, "sl%d", unitnum); - - if (keepal > 0) { - signal(SIGURG, sigurg); - if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) { - syslog(LOG_ERR, "%s: ioctl(SLIOCSKEEPAL): %m", username); - down(2); - } - } - if (outfill > 0 && ioctl(fd, SLIOCSOUTFILL, &outfill) < 0) { - syslog(LOG_ERR, "%s: ioctl(SLIOCSOUTFILL): %m", username); - down(2); - } - - sprintf(buf, "LINE=%d %s %s up", - diali ? (dialc - 1) % diali : 0, - upscript ? upscript : _PATH_IFCONFIG , unitname); - (void) system(buf); - - printd(", ready\n"); - if (!first) - syslog(LOG_INFO, "%s: reconnected on %s (%d tries)", username, unitname, tries); - else - syslog(LOG_INFO, "%s: connected on %s", username, unitname); - first = 0; - tries = 0; - logged_in = 1; - while (hup == 0 && terminate == 0) { - sigpause(0L); - printd("sigpause return\n"); - } - goto restart; - return(0); /* not reached */ -} - -void -sighup(int sig __unused) -{ - - printd("hup\n"); - if (hup == 0 && logged_in) - syslog(LOG_INFO, "%s: got hangup signal", username); - hup = 1; -} - -void -sigurg(int sig __unused) -{ - - printd("urg\n"); - if (hup == 0 && logged_in) - syslog(LOG_INFO, "%s: got dead line signal", username); - hup = 1; -} - -void -sigterm(int sig __unused) -{ - - printd("terminate\n"); - if (terminate == 0 && logged_in) - syslog(LOG_INFO, "%s: got terminate signal", username); - terminate = 1; -} - -int -getline(char *buf, int size, int fd, time_t fintimeout) -{ - int i; - int ret; - fd_set readfds; - struct timeval tv; - time_t timeout; - - size--; - for (i = 0; i < size; i++) { - if (hup || terminate) - return (0); - if ((timeout = fintimeout - time(NULL)) <= 0) - goto tout; - 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) { - if (errno != EINTR) - syslog(LOG_ERR, "%s: getline: select: %m", username); - } else { - if (! ret) { - tout: - printd("getline: timed out\n"); - return (0); - } - if ((ret = read(fd, &buf[i], 1)) == 1) { - buf[i] &= 0177; - if (buf[i] == '\r' || buf[i] == '\0') { - i--; - continue; - } - if (buf[i] != '\n' && buf[i] != ':') - continue; - buf[i + 1] = '\0'; - printd("Got %d: %s", i + 1, buf); - return (i+1); - } - if (ret <= 0) { - if (ret < 0) { - syslog(LOG_ERR, "%s: getline: read: %m", username); - } else - syslog(LOG_ERR, "%s: read returned 0", username); - buf[i] = '\0'; - printd("returning %d after %d: %s\n", ret, i, buf); - return (0); - } - } - } - return (0); -} - -int -carrier(void) -{ - int comstate; - - if (ioctl(fd, TIOCMGET, &comstate) < 0) { - syslog(LOG_ERR, "%s: ioctl (%s, TIOCMGET): %m", - username, devicename); - down(2); - } - return !!(comstate & TIOCM_CD); -} - -void -down(int code) -{ - if (fd > -1) - close(fd); - if (pfd) - unlink(pidfile); - if (uucp_lock && locked) - uu_unlock(dvname); - exit(code); -} - -static void -usage(void) -{ - (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 password"); - exit(1); -} |