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 /usr.sbin/sliplogin | |
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 'usr.sbin/sliplogin')
-rw-r--r-- | usr.sbin/sliplogin/Makefile | 11 | ||||
-rw-r--r-- | usr.sbin/sliplogin/pathnames.h | 44 | ||||
-rw-r--r-- | usr.sbin/sliplogin/sliplogin.8 | 317 | ||||
-rw-r--r-- | usr.sbin/sliplogin/sliplogin.c | 544 |
4 files changed, 0 insertions, 916 deletions
diff --git a/usr.sbin/sliplogin/Makefile b/usr.sbin/sliplogin/Makefile deleted file mode 100644 index 0236f1e..0000000 --- a/usr.sbin/sliplogin/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 7/19/93 -# $FreeBSD$ - -PROG= sliplogin -MAN= sliplogin.8 -BINOWN= root -BINGRP= network -BINMODE=4550 -PRECIOUSPROG= - -.include <bsd.prog.mk> diff --git a/usr.sbin/sliplogin/pathnames.h b/usr.sbin/sliplogin/pathnames.h deleted file mode 100644 index e318f92..0000000 --- a/usr.sbin/sliplogin/pathnames.h +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * Copyright (c) 1990, 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. - * - * From: @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD$ - */ - -#ifndef COMPAT -#include <paths.h> -#else -#define _PATH_DEVNULL "/dev/null" -#endif - -#define _PATH_ACCESS "/etc/sliphome/slip.hosts" -#define _PATH_SLPARMS "/etc/sliphome/slip.slparms" -#define _PATH_SLIP_LOGIN "/etc/sliphome/slip.login" -#define _PATH_SLIP_LOGOUT "/etc/sliphome/slip.logout" -#define _PATH_DEBUG "/tmp/sliplogin.XXXXXX" - diff --git a/usr.sbin/sliplogin/sliplogin.8 b/usr.sbin/sliplogin/sliplogin.8 deleted file mode 100644 index 1f6960b..0000000 --- a/usr.sbin/sliplogin/sliplogin.8 +++ /dev/null @@ -1,317 +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. -.\" -.\" @(#)sliplogin.8 8.2 (Berkeley) 1/5/94 -.\" $FreeBSD$ -.\" -.Dd January 5, 1994 -.Dt SLIPLOGIN 8 -.Os -.Sh NAME -.Nm sliplogin -.Nd attach a serial line network interface -.Sh SYNOPSIS -.Nm -.Op Ar loginname Op Ar device -.Sh DESCRIPTION -The -.Nm -utility is used to turn the terminal line on standard input (or -.Ar device ) -into a Serial Line IP -.Pq Tn SLIP -link to a remote host. -To do this, the program -searches the file -.Pa /etc/sliphome/slip.hosts -for an entry matching -.Ar loginname -(which defaults to the current login name if omitted). -If a matching entry is found, the line is configured appropriately -for slip (8-bit transparent i/o) and converted to -.Tn SLIP -line discipline using the optional line discipline parameters. -.Pp -The optional line discipline parameters consist of one or more of -the following; -.Sq normal , -.Sq compress , -.Sq noicmp , -or -.Sq autocomp -which correspond respectively to -.Sq use normal line discipline -(no header compression), -.Sq enable VJ header compression , -.Sq throw away ICMP packets , -and -.Sq auto enable VJ header compression -(only if the remote end of the link also supports it). -.Pp -Then a shell script is invoked to initialize the slip -interface with the appropriate local and remote -.Tn IP -address, -netmask, etc. -.Pp -The usual initialization script is -.Pa /etc/sliphome/slip.login -but, if particular hosts need special initialization, the file -.Pa /etc/sliphome/slip.login. Ns Ar loginname -will be executed instead if it exists. -The script is invoked with the parameters -.Bl -tag -width slipunit -.It Em slipunit -The unit number of the slip interface assigned to this line. -E.g., -.Sy 0 -for -.Sy sl0 . -.It Em speed -The speed of the line. -.It Em args -The arguments from the -.Pa /etc/sliphome/slip.hosts -entry, in order starting with -.Ar loginname . -.El -.Pp -Only the super-user may attach a network interface. -The interface is -automatically detached when the other end hangs up or the -.Nm -process dies. -If the kernel slip -module has been configured for it, all routes through that interface will -also disappear at the same time. -If there is other processing a site -would like done on hangup, the file -.Pa /etc/sliphome/slip.logout -or -.Pa /etc/sliphome/slip.logout. Ns Ar loginname -is executed if it exists. -It is given the same arguments as the login script. -.Ss Format of /etc/sliphome/slip.hosts -Comments (lines starting with a `#') and blank lines (or started -with space) are ignored. -Other lines must start with a -.Ar loginname -but the remaining arguments can be whatever is appropriate for the -.Pa slip.login -file that will be executed for that name. -Arguments are separated by white space and follow normal -.Xr sh 1 -quoting conventions (however, -.Ar loginname -cannot be quoted). -Usually, lines have the form -.Bd -literal -offset indent -loginname local-address remote-address netmask opt-args -.Ed -.Pp -where -.Em local-address -and -.Em remote-address -are the IP host names or addresses of the local and remote ends of the -slip line and -.Em netmask -is the appropriate IP netmask. -These arguments are passed -directly to -.Xr ifconfig 8 . -.Em Opt-args -are optional arguments used to configure the line. -.Sh FreeBSD Additions -An additional SLIP configuration file (if present) is -.Pa /etc/sliphome/slip.slparms . -If particular hosts need different configurations, the file -.Pa /etc/sliphome/slip.slparms. Ns Ar loginname -will be parsed instead if it exists. -.Ss Format of /etc/sliphome/slip.slparms* -Comments (lines starting with a `#') and blank lines (or started with -space) are ignored. -This file contains from one to three numeric parameters separated with spaces, -in order: -.Ar keepalive , -.Ar outfill -and -.Ar slunit . -.Bl -tag -width keepalive -.It Ar keepalive -Set SLIP "keep alive" timeout in seconds. -If FRAME_END is not received in -this amount of time, -.Nm -closes the line and exits. -The default value is no timeout (zero). -.It 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 (zero). -.It Ar slunit -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. -.El -.Pp -If latter two parameters are omitted, they will not affect the -corresponding SLIP configuration. -If any of first two parameters is equal to zero, it will not affect -the corresponding SLIP configuration. -.Sh FILES -.Bl -tag -width indent -.It Pa /etc/sliphome/slip.hosts -list of host login names and parameters. -.It Pa /etc/sliphome/slip.login -script executed when a connection is made. -.It Pa /etc/sliphome/slip.login. Ns Ar loginname -script executed when a connection is made by -.Ar loginname . -.It Pa /etc/sliphome/slip.logout -script executed when a connection is lost. -.It Pa /etc/sliphome/slip.logout. Ns Ar loginname -script executed when a connection is lost by -.Ar loginname . -.It Pa /etc/sliphome/slip.slparms -extra parameters file. -.It Pa /etc/sliphome/slip.slparms. Ns Ar loginname -extra parameters file for -.Ar loginname . -.It Pa /var/run/ Ns Ar ttyXn Ns Pa .if -contains the name of the network interface used by the sliplogin process on -.Ar ttyXn . -.It Pa /var/run/ Ns Ar slX Ns Pa .pid -contains the PID of the sliplogin process which is using interface -.Ar slX . -.El -.Sh EXAMPLES -The normal use of -.Nm -is to create a -.Pa /etc/passwd -entry for each legal, remote slip site with -.Nm -as the shell for that entry. -E.g., -.Bd -literal -Sfoo:ikhuy6:2010:1:slip line to foo:/tmp:/usr/sbin/sliplogin -.Ed -.Pp -(Our convention is to name the account used by remote host -.Ar hostname -as -.Em Shostname . ) -Then an entry is added to -.Pa slip.hosts -that looks like: -.Pp -.Bd -literal -offset indent -compact -Sfoo `hostname` foo netmask -.Ed -.Pp -where -.Em `hostname` -will be evaluated by -.Xr sh 1 -to the local host name and -.Em netmask -is the local host IP netmask. -.Pp -Note that -.Nm -must be setuid to root and, while not a security hole, moral defectives -can use it to place terminal lines in an unusable state and/or deny -access to legitimate users of a remote slip line. -To prevent this, -.Nm -is installed as user -.Em root , -group -.Em network -and mode 4550 so that only members of group -.Em network -may run -.Nm . -The system administrator should make sure that all legitimate users -are a member of the correct group. -.Sh DIAGNOSTICS -The -.Nm -utility logs various information to the system log daemon, -.Xr syslogd 8 , -with a facility code of -.Em daemon . -The messages are listed here, grouped by severity level. -.Pp -.Sy Error Severity -.Bl -tag -width Ds -compact -.It Sy ioctl (TCGETS): Em reason -A -.Dv TCGETS -.Fn ioctl -to get the line parameters failed. -.Pp -.It Sy ioctl (TCSETS): Em reason -A -.Dv TCSETS -.Fn ioctl -to set the line parameters failed. -.Pp -.It Sy /etc/sliphome/slip.hosts: Em reason -The -.Pa /etc/sliphome/slip.hosts -file could not be opened. -.Pp -.It Sy access denied for Em user -No entry for -.Em user -was found in -.Pa /etc/sliphome/slip.hosts . -.El -.Pp -.Sy Notice Severity -.Bl -tag -width Ds -compact -.It Sy "attaching slip unit" Em unit Sy for Ar loginname -.Tn SLIP -unit -.Em unit -was successfully attached. -.El -.Sh SEE ALSO -.Xr slattach 8 , -.Xr syslogd 8 -.Pp -.Pa /usr/share/examples/sliplogin -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.3 Reno . diff --git a/usr.sbin/sliplogin/sliplogin.c b/usr.sbin/sliplogin/sliplogin.c deleted file mode 100644 index dafdfd4..0000000 --- a/usr.sbin/sliplogin/sliplogin.c +++ /dev/null @@ -1,544 +0,0 @@ -/*- - * Copyright (c) 1990, 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 char copyright[] = -"@(#) Copyright (c) 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)sliplogin.c 8.2 (Berkeley) 2/1/94"; -static char rscid[] = "@(#)$FreeBSD$"; -#endif /* not lint */ - -/* - * sliplogin.c - * [MUST BE RUN SUID, SLOPEN DOES A SUSER()!] - * - * This program initializes its own tty port to be an async TCP/IP interface. - * It sets the line discipline to slip, invokes a shell script to initialize - * the network interface, then pauses forever waiting for hangup. - * - * It is a remote descendant of several similar programs with incestuous ties: - * - Kirk Smith's slipconf, modified by Richard Johnsson @ DEC WRL. - * - slattach, probably by Rick Adams but touched by countless hordes. - * - the original sliplogin for 4.2bsd, Doug Kingston the mover behind it. - * - * There are two forms of usage: - * - * "sliplogin" - * Invoked simply as "sliplogin", the program looks up the username - * in the file /etc/slip.hosts. - * If an entry is found, the line on fd0 is configured for SLIP operation - * as specified in the file. - * - * "sliplogin IPhostlogin </dev/ttyb" - * Invoked by root with a username, the name is looked up in the - * /etc/slip.hosts file and if found fd0 is configured as in case 1. - */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <syslog.h> -#include <netdb.h> - -#include <termios.h> -#include <sys/ioctl.h> -#include <net/slip.h> -#include <net/if.h> -#include <netinet/in.h> - -#include <stdio.h> -#include <errno.h> -#include <ctype.h> -#include <paths.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <signal.h> -#include "pathnames.h" - -extern char **environ; - -static char *restricted_environ[] = { - "PATH=" _PATH_STDPATH, - NULL -}; - -int unit; -int slip_mode; -speed_t speed; -int uid; -int keepal; -int outfill; -int slunit; -char loginargs[BUFSIZ]; -char loginfile[MAXPATHLEN]; -char loginname[BUFSIZ]; -static char raddr[32]; /* remote address */ -char ifname[IFNAMSIZ]; /* interface name */ -static char pidfilename[MAXPATHLEN]; /* name of pid file */ -static char iffilename[MAXPATHLEN]; /* name of if file */ -static pid_t pid; /* our pid */ - -char * -make_ipaddr(void) -{ -static char address[20] =""; -struct hostent *he; -unsigned long ipaddr; - -address[0] = '\0'; -if ((he = gethostbyname(raddr)) != NULL) { - ipaddr = ntohl(*(long *)he->h_addr_list[0]); - sprintf(address, "%lu.%lu.%lu.%lu", - ipaddr >> 24, - (ipaddr & 0x00ff0000) >> 16, - (ipaddr & 0x0000ff00) >> 8, - (ipaddr & 0x000000ff)); - } - -return address; -} - -struct slip_modes { - char *sm_name; - int sm_or_flag; - int sm_and_flag; -} modes[] = { - "normal", 0 , 0 , - "compress", IFF_LINK0, IFF_LINK2, - "noicmp", IFF_LINK1, 0 , - "autocomp", IFF_LINK2, IFF_LINK0, -}; - -void -findid(name) - char *name; -{ - FILE *fp; - static char slopt[5][16]; - static char laddr[16]; - static char mask[16]; - char slparmsfile[MAXPATHLEN]; - char user[16]; - char buf[128]; - int i, j, n; - - environ = restricted_environ; /* minimal protection for system() */ - - (void)strncpy(loginname, name, sizeof(loginname)-1); - loginname[sizeof(loginname)-1] = '\0'; - - if ((fp = fopen(_PATH_ACCESS, "r")) == NULL) { - accfile_err: - syslog(LOG_ERR, "%s: %m\n", _PATH_ACCESS); - exit(1); - } - while (fgets(loginargs, sizeof(loginargs) - 1, fp)) { - if (ferror(fp)) - goto accfile_err; - if (loginargs[0] == '#' || isspace(loginargs[0])) - continue; - n = sscanf(loginargs, "%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s\n", - user, laddr, raddr, mask, slopt[0], slopt[1], - slopt[2], slopt[3], slopt[4]); - if (n < 4) { - syslog(LOG_ERR, "%s: wrong format\n", _PATH_ACCESS); - exit(1); - } - if (strcmp(user, name) != 0) - continue; - - (void) fclose(fp); - - slip_mode = 0; - for (i = 0; i < n - 4; i++) { - for (j = 0; j < sizeof(modes)/sizeof(struct slip_modes); - j++) { - if (strcmp(modes[j].sm_name, slopt[i]) == 0) { - slip_mode |= (modes[j].sm_or_flag); - slip_mode &= ~(modes[j].sm_and_flag); - break; - } - } - } - - /* - * we've found the guy we're looking for -- see if - * there's a login file we can use. First check for - * one specific to this host. If none found, try for - * a generic one. - */ - (void)snprintf(loginfile, sizeof(loginfile), "%s.%s", - _PATH_SLIP_LOGIN, name); - if (access(loginfile, R_OK|X_OK) != 0) { - (void)strncpy(loginfile, _PATH_SLIP_LOGIN, - sizeof(loginfile) - 1); - loginfile[sizeof(loginfile) - 1] = '\0'; - if (access(loginfile, R_OK|X_OK)) { - syslog(LOG_ERR, - "access denied for %s - no %s\n", - name, _PATH_SLIP_LOGIN); - exit(5); - } - } - (void)snprintf(slparmsfile, sizeof(slparmsfile), "%s.%s", _PATH_SLPARMS, name); - if (access(slparmsfile, R_OK|X_OK) != 0) { - (void)strncpy(slparmsfile, _PATH_SLPARMS, sizeof(slparmsfile)-1); - slparmsfile[sizeof(slparmsfile)-1] = '\0'; - if (access(slparmsfile, R_OK|X_OK)) - *slparmsfile = '\0'; - } - keepal = outfill = 0; - slunit = -1; - if (*slparmsfile) { - if ((fp = fopen(slparmsfile, "r")) == NULL) { - slfile_err: - syslog(LOG_ERR, "%s: %m\n", slparmsfile); - exit(1); - } - n = 0; - while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { - if (ferror(fp)) - goto slfile_err; - if (buf[0] == '#' || isspace(buf[0])) - continue; - n = sscanf(buf, "%d %d %d", &keepal, &outfill, &slunit); - if (n < 1) { - slwrong_fmt: - syslog(LOG_ERR, "%s: wrong format\n", slparmsfile); - exit(1); - } - (void) fclose(fp); - break; - } - if (n == 0) - goto slwrong_fmt; - } - - return; - } - syslog(LOG_ERR, "SLIP access denied for %s\n", name); - exit(4); - /* NOTREACHED */ -} - -char * -sigstr(s) - int s; -{ - static char buf[32]; - - switch (s) { - case SIGHUP: return("HUP"); - case SIGINT: return("INT"); - case SIGQUIT: return("QUIT"); - case SIGILL: return("ILL"); - case SIGTRAP: return("TRAP"); - case SIGIOT: return("IOT"); - case SIGEMT: return("EMT"); - case SIGFPE: return("FPE"); - case SIGKILL: return("KILL"); - case SIGBUS: return("BUS"); - case SIGSEGV: return("SEGV"); - case SIGSYS: return("SYS"); - case SIGPIPE: return("PIPE"); - case SIGALRM: return("ALRM"); - case SIGTERM: return("TERM"); - case SIGURG: return("URG"); - case SIGSTOP: return("STOP"); - case SIGTSTP: return("TSTP"); - case SIGCONT: return("CONT"); - case SIGCHLD: return("CHLD"); - case SIGTTIN: return("TTIN"); - case SIGTTOU: return("TTOU"); - case SIGIO: return("IO"); - case SIGXCPU: return("XCPU"); - case SIGXFSZ: return("XFSZ"); - case SIGVTALRM: return("VTALRM"); - case SIGPROF: return("PROF"); - case SIGWINCH: return("WINCH"); -#ifdef SIGLOST - case SIGLOST: return("LOST"); -#endif - case SIGUSR1: return("USR1"); - case SIGUSR2: return("USR2"); - } - (void)snprintf(buf, sizeof(buf), "sig %d", s); - return(buf); -} - -void -hup_handler(s) - int s; -{ - char logoutfile[MAXPATHLEN]; - - (void) close(0); - seteuid(0); - (void)snprintf(logoutfile, sizeof(logoutfile), "%s.%s", - _PATH_SLIP_LOGOUT, loginname); - if (access(logoutfile, R_OK|X_OK) != 0) { - (void)strncpy(logoutfile, _PATH_SLIP_LOGOUT, - sizeof(logoutfile) - 1); - logoutfile[sizeof(logoutfile) - 1] = '\0'; - } - if (access(logoutfile, R_OK|X_OK) == 0) { - char logincmd[2*MAXPATHLEN+32]; - - (void) snprintf(logincmd, sizeof(logincmd), "%s %d %ld %s", logoutfile, unit, speed, loginargs); - (void) system(logincmd); - } - syslog(LOG_INFO, "closed %s slip unit %d (%s)\n", loginname, unit, - sigstr(s)); - if (unlink(pidfilename) < 0 && errno != ENOENT) - syslog(LOG_WARNING, "unable to delete pid file: %m"); - if (unlink(iffilename) < 0 && errno != ENOENT) - syslog(LOG_WARNING, "unable to delete if file: %m"); - exit(1); - /* NOTREACHED */ -} - - -/* Modify the slip line mode and add any compression or no-icmp flags. */ -void line_flags(unit) - int unit; -{ - struct ifreq ifr; - int s; - - /* 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(1); - } - sprintf(ifr.ifr_name, "sl%d", unit); - - /* get the flags for the interface */ - if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { - syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); - exit(1); - } - - /* Assert any compression or no-icmp flags. */ -#define SLMASK (~(IFF_LINK0 | IFF_LINK1 | IFF_LINK2)) - ifr.ifr_flags &= SLMASK; - ifr.ifr_flags |= slip_mode; - if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) { - syslog(LOG_ERR, "ioctl (SIOCSIFFLAGS): %m"); - exit(1); - } - close(s); -} - - -int -main(argc, argv) - int argc; - char *argv[]; -{ - int fd, s, ldisc; - char *name; - struct termios tios; - char logincmd[2*BUFSIZ+32]; - - FILE *pidfile; /* pid file */ - FILE *iffile; /* interfaces file */ - char *p; - int n; - char devnam[MAXPATHLEN] = _PATH_TTY; /* Device name */ - - if ((name = strrchr(argv[0], '/')) == NULL) - name = argv[0]; - s = getdtablesize(); - for (fd = 3 ; fd < s ; fd++) - (void) close(fd); - openlog(name, LOG_PID|LOG_PERROR, LOG_DAEMON); - uid = getuid(); - if (argc > 1) { - findid(argv[1]); - - /* - * Disassociate from current controlling terminal, if any, - * and ensure that the slip line is our controlling terminal. - */ - if (daemon(1, 1)) { - syslog(LOG_ERR, "daemon(1, 1): %m"); - exit(1); - } - if (argc > 2) { - if ((fd = open(argv[2], O_RDWR)) == -1) { - syslog(LOG_ERR, "open %s: %m", argv[2]); - exit(2); - } - (void) dup2(fd, 0); - if (fd > 2) - close(fd); - } - if (ioctl(0, TIOCSCTTY, 0) == -1) { - syslog(LOG_ERR, "ioctl (TIOCSCTTY): %m"); - exit(1); - } - if (tcsetpgrp(0, getpid()) < 0) { - syslog(LOG_ERR, "tcsetpgrp failed: %m"); - exit(1); - } - } else { - if ((name = getlogin()) == NULL) { - syslog(LOG_ERR, "access denied - login name not found\n"); - exit(1); - } - findid(name); - } - (void) fchmod(0, 0600); - (void) fprintf(stderr, "starting slip login for %s\n", loginname); - (void) fprintf(stderr, "your address is %s\n\n", make_ipaddr()); - - (void) fflush(stderr); - sleep(1); - - /* set up the line parameters */ - if (tcgetattr(0, &tios) < 0) { - syslog(LOG_ERR, "tcgetattr: %m"); - exit(1); - } - cfmakeraw(&tios); - if (tcsetattr(0, TCSAFLUSH, &tios) < 0) { - syslog(LOG_ERR, "tcsetattr: %m"); - exit(1); - } - speed = cfgetispeed(&tios); - - ldisc = SLIPDISC; - if (ioctl(0, TIOCSETD, &ldisc) < 0) { - syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); - exit(1); - } - if (slunit >= 0 && ioctl(0, SLIOCSUNIT, &slunit) < 0) { - syslog(LOG_ERR, "ioctl (SLIOCSUNIT): %m"); - exit(1); - } - /* find out what unit number we were assigned */ - if (ioctl(0, SLIOCGUNIT, &unit) < 0) { - syslog(LOG_ERR, "ioctl (SLIOCGUNIT): %m"); - exit(1); - } - (void) signal(SIGHUP, hup_handler); - (void) signal(SIGTERM, hup_handler); - - if (keepal > 0) { - (void) signal(SIGURG, hup_handler); - if (ioctl(0, SLIOCSKEEPAL, &keepal) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCSKEEPAL): %m"); - exit(1); - } - } - if (outfill > 0 && ioctl(0, SLIOCSOUTFILL, &outfill) < 0) { - syslog(LOG_ERR, "ioctl(SLIOCSOUTFILL): %m"); - exit(1); - } - - /* write pid to file */ - pid = getpid(); - (void) sprintf(ifname, "sl%d", unit); - (void) sprintf(pidfilename, "%s%s.pid", _PATH_VARRUN, ifname); - if ((pidfile = fopen(pidfilename, "w")) != NULL) { - fprintf(pidfile, "%d\n", pid); - (void) fclose(pidfile); - } else { - syslog(LOG_ERR, "Failed to create pid file %s: %m", - pidfilename); - pidfilename[0] = 0; - } - - /* write interface unit number to file */ - p = ttyname(0); - if (p) - strcpy(devnam, p); - for (n = strlen(devnam); n > 0; n--) - if (devnam[n] == '/') { - n++; - break; - } - (void) sprintf(iffilename, "%s%s.if", _PATH_VARRUN, &devnam[n]); - if ((iffile = fopen(iffilename, "w")) != NULL) { - fprintf(iffile, "sl%d\n", unit); - (void) fclose(iffile); - } else { - syslog(LOG_ERR, "Failed to create if file %s: %m", iffilename); - iffilename[0] = 0; - } - - - syslog(LOG_INFO, "attaching slip unit %d for %s\n", unit, loginname); - (void)snprintf(logincmd, sizeof(logincmd), "%s %d %ld %s", loginfile, unit, speed, - loginargs); - /* - * aim stdout and errout at /dev/null so logincmd output won't - * babble into the slip tty line. - */ - (void) close(1); - if ((fd = open(_PATH_DEVNULL, O_WRONLY)) != 1) { - if (fd < 0) { - syslog(LOG_ERR, "open %s: %m", _PATH_DEVNULL); - exit(1); - } - (void) dup2(fd, 1); - (void) close(fd); - } - (void) dup2(1, 2); - - /* - * Run login and logout scripts as root (real and effective); - * current route(8) is setuid root, and checks the real uid - * to see whether changes are allowed (or just "route get"). - */ - (void) setuid(0); - if (s = system(logincmd)) { - syslog(LOG_ERR, "%s login failed: exit status %d from %s", - loginname, s, loginfile); - exit(6); - } - - /* Handle any compression or no-icmp flags. */ - line_flags(unit); - - /* reset uid to users' to allow the user to give a signal. */ - seteuid(uid); - /* twiddle thumbs until we get a signal */ - while (1) - sigpause(0); - - /* NOTREACHED */ -} |