summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sliplogin
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1995-09-22 10:04:33 +0000
committerache <ache@FreeBSD.org>1995-09-22 10:04:33 +0000
commitc44c62580b76404924dc11cc82b1ef6db2dde98e (patch)
treec71295027b8aa746153e172b2fd38f70e41da0b2 /usr.sbin/sliplogin
parent78e8883c280269b4cc0774adab2c0ab68a005c59 (diff)
downloadFreeBSD-src-c44c62580b76404924dc11cc82b1ef6db2dde98e.zip
FreeBSD-src-c44c62580b76404924dc11cc82b1ef6db2dde98e.tar.gz
Additionly parse /etc/sliphome/slip.slparms* to set keepalive,
outfill and slunit. Make it more POSIXed. Describe undocumented stuff.
Diffstat (limited to 'usr.sbin/sliplogin')
-rw-r--r--usr.sbin/sliplogin/pathnames.h1
-rw-r--r--usr.sbin/sliplogin/sliplogin.857
-rw-r--r--usr.sbin/sliplogin/sliplogin.c172
3 files changed, 143 insertions, 87 deletions
diff --git a/usr.sbin/sliplogin/pathnames.h b/usr.sbin/sliplogin/pathnames.h
index 9e792a3..3bee951 100644
--- a/usr.sbin/sliplogin/pathnames.h
+++ b/usr.sbin/sliplogin/pathnames.h
@@ -40,6 +40,7 @@
#endif
#define _PATH_ACCESS "/etc/sliphome/slip.hosts"
+#define _PATH_SLPARMS "/etc/sliphome/slip.slparms"
#define _PATH_LOGIN "/etc/sliphome/slip.login"
#define _PATH_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
index 1c71988..6f8a993 100644
--- a/usr.sbin/sliplogin/sliplogin.8
+++ b/usr.sbin/sliplogin/sliplogin.8
@@ -39,11 +39,12 @@
.Nd attach a serial line network interface
.Sh SYNOPSIS
.Nm sliplogin
-.Op Ar loginname
+.Op Ar loginname Op Ar device
.Sh DESCRIPTION
.Nm Sliplogin
-is used to turn the terminal line on standard input into
-a Serial Line IP
+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
@@ -55,12 +56,52 @@ 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. Then a shell script is invoked to initialize the slip
+discipline.
+.Pp
+The additional SLIP configuration file (if even present) is
+.Pa /etc/sliphome/slip.slparms
+but, if particular hosts need different configuration, 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 not received in this
+timeout,
+.Nm startslip
+close line and exit.
+Active "out fill" timeout expected from other
+side.
+Default value is no timeout (zero).
+.It Ar outfill
+Set SLIP "out fill" timeout in seconds. It cause at least one FRAME_END
+will be sended during this timeout.
+Needed for "keep alive" timeout on other side.
+Default value is no timeout (zero).
+.It Ar slunit
+Set SLIP unit number directly. Use with caution, no check for two
+interfaces with same number made.
+Default is dynamic assignment.
+.El
+.Pp
+If last two or one parameters ommited, they not affect corresponding SLIP
+configuration.
+If any of first two parameters is equal to zero, it does not affect
+corresponding SLIP configuration.
+.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
@@ -94,7 +135,8 @@ 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 are ignored.
+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
@@ -212,7 +254,8 @@ was successfully attached.
.El
.Sh SEE ALSO
.Xr slattach 8 ,
-.Xr syslogd 8
+.Xr syslogd 8 ,
+.Pa /usr/share/examples/sliplogin
.Sh HISTORY
The
.Nm
diff --git a/usr.sbin/sliplogin/sliplogin.c b/usr.sbin/sliplogin/sliplogin.c
index f873631..4cc2537 100644
--- a/usr.sbin/sliplogin/sliplogin.c
+++ b/usr.sbin/sliplogin/sliplogin.c
@@ -69,32 +69,30 @@ static char sccsid[] = "@(#)sliplogin.c 8.2 (Berkeley) 2/1/94";
#include <sys/param.h>
#include <sys/socket.h>
-#include <sys/signal.h>
#include <sys/file.h>
-#include <sys/syslog.h>
+#include <sys/stat.h>
+#include <syslog.h>
#include <netdb.h>
-#if BSD >= 199006
-#define POSIX
-#endif
-#ifdef POSIX
-#include <sys/termios.h>
+#include <termios.h>
#include <sys/ioctl.h>
-#include <ttyent.h>
-#else
-#include <sgtty.h>
-#endif
#include <net/slip.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
#include "pathnames.h"
int unit;
-int speed;
+speed_t speed;
int uid;
+int keepal;
+int outfill;
+int slunit;
char loginargs[BUFSIZ];
char loginfile[MAXPATHLEN];
char loginname[BUFSIZ];
@@ -108,27 +106,34 @@ findid(name)
static char laddr[16];
static char raddr[16];
static char mask[16];
+ char slparmsfile[MAXPATHLEN];
char user[16];
+ char buf[128];
int i, j, n;
(void)strcpy(loginname, name);
if ((fp = fopen(_PATH_ACCESS, "r")) == NULL) {
- (void)fprintf(stderr, "sliplogin: %s: %s\n",
- _PATH_ACCESS, strerror(errno));
+ accfile_err:
syslog(LOG_ERR, "%s: %m\n", _PATH_ACCESS);
exit(1);
}
while (fgets(loginargs, sizeof(loginargs) - 1, fp)) {
if (ferror(fp))
- break;
+ 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 (user[0] == '#' || isspace(user[0]))
- continue;
+ if (n < 4) {
+ syslog(LOG_ERR, "%s: wrong format\n", _PATH_ACCESS);
+ exit(1);
+ }
if (strcmp(user, name) != 0)
continue;
+ (void) fclose(fp);
+
/*
* we've found the guy we're looking for -- see if
* there's a login file we can use. First check for
@@ -139,19 +144,47 @@ findid(name)
if (access(loginfile, R_OK|X_OK) != 0) {
(void)strcpy(loginfile, _PATH_LOGIN);
if (access(loginfile, R_OK|X_OK)) {
- fputs("access denied - no login file\n",
- stderr);
syslog(LOG_ERR,
"access denied for %s - no %s\n",
name, _PATH_LOGIN);
exit(5);
}
}
+ (void)sprintf(slparmsfile, "%s.%s", _PATH_SLPARMS, name);
+ if (access(slparmsfile, R_OK|X_OK) != 0) {
+ (void)strcpy(slparmsfile, _PATH_SLPARMS);
+ 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;
+ }
- (void) fclose(fp);
return;
}
- (void)fprintf(stderr, "SLIP access denied for %s\n", name);
syslog(LOG_ERR, "SLIP access denied for %s\n", name);
exit(4);
/* NOTREACHED */
@@ -208,6 +241,7 @@ hup_handler(s)
{
char logoutfile[MAXPATHLEN];
+ (void) close(0);
seteuid(0);
(void)sprintf(logoutfile, "%s.%s", _PATH_LOGOUT, loginname);
if (access(logoutfile, R_OK|X_OK) != 0)
@@ -215,11 +249,10 @@ hup_handler(s)
if (access(logoutfile, R_OK|X_OK) == 0) {
char logincmd[2*MAXPATHLEN+32];
- (void) sprintf(logincmd, "%s %d %d %s", logoutfile, unit, speed,
+ (void) sprintf(logincmd, "%s %d %ld %s", logoutfile, unit, speed,
loginargs);
(void) system(logincmd);
}
- (void) close(0);
syslog(LOG_INFO, "closed %s slip unit %d (%s)\n", loginname, unit,
sigstr(s));
exit(1);
@@ -230,13 +263,9 @@ main(argc, argv)
int argc;
char *argv[];
{
- int fd, s, ldisc, odisc;
+ int fd, s, ldisc;
char *name;
-#ifdef POSIX
struct termios tios, otios;
-#else
- struct sgttyb tty, otty;
-#endif
char logincmd[2*BUFSIZ+32];
extern uid_t getuid();
@@ -245,7 +274,7 @@ main(argc, argv)
s = getdtablesize();
for (fd = 3 ; fd < s ; fd++)
(void) close(fd);
- openlog(name, LOG_PID, LOG_DAEMON);
+ openlog(name, LOG_PID|LOG_PERROR, LOG_DAEMON);
uid = getuid();
if (argc > 1) {
findid(argv[1]);
@@ -254,50 +283,37 @@ main(argc, argv)
* Disassociate from current controlling terminal, if any,
* and ensure that the slip line is our controlling terminal.
*/
-#ifdef POSIX
- if (fork() > 0)
- exit(0);
- if (setsid() == -1)
- perror("setsid");
-#else
- if ((fd = open("/dev/tty", O_RDONLY, 0)) >= 0) {
- extern char *ttyname();
-
- (void) ioctl(fd, TIOCNOTTY, (caddr_t)0);
- (void) close(fd);
- /* open slip tty again to acquire as controlling tty? */
- fd = open(ttyname(0), O_RDWR, 0);
- if (fd >= 0)
- (void) close(fd);
+ if (daemon(1, 1)) {
+ syslog(LOG_ERR, "daemon(1, 1): %m");
+ exit(1);
}
- (void) setpgrp(0, getpid());
-#endif
if (argc > 2) {
if ((fd = open(argv[2], O_RDWR)) == -1) {
- perror(argv[2]);
+ syslog(LOG_ERR, "open %s: %m", argv[2]);
exit(2);
}
(void) dup2(fd, 0);
if (fd > 2)
close(fd);
}
-#ifdef TIOCSCTTY
- if (ioctl(0, TIOCSCTTY, (caddr_t)0) == -1)
- perror("ioctl (TIOCSCTTY)");
-#endif
+ 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 {
- extern char *getlogin();
-
if ((name = getlogin()) == NULL) {
- (void) fprintf(stderr, "access denied - no username\n");
- syslog(LOG_ERR, "access denied - getlogin returned 0\n");
+ 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);
-#ifdef POSIX
+
/* set up the line parameters */
if (tcgetattr(0, &tios) < 0) {
syslog(LOG_ERR, "tcgetattr: %m");
@@ -305,46 +321,43 @@ main(argc, argv)
}
otios = tios;
cfmakeraw(&tios);
- tios.c_iflag &= ~IMAXBEL;
if (tcsetattr(0, TCSAFLUSH, &tios) < 0) {
syslog(LOG_ERR, "tcsetattr: %m");
exit(1);
}
speed = cfgetispeed(&tios);
-#else
- /* set up the line parameters */
- if (ioctl(0, TIOCGETP, (caddr_t)&tty) < 0) {
- syslog(LOG_ERR, "ioctl (TIOCGETP): %m");
- exit(1);
- }
- otty = tty;
- speed = tty.sg_ispeed;
- tty.sg_flags = RAW | ANYP;
- if (ioctl(0, TIOCSETP, (caddr_t)&tty) < 0) {
- syslog(LOG_ERR, "ioctl (TIOCSETP): %m");
- exit(1);
- }
-#endif
- /* find out what ldisc we started with */
- if (ioctl(0, TIOCGETD, (caddr_t)&odisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCGETD) (1): %m");
- exit(1);
- }
+
ldisc = SLIPDISC;
- if (ioctl(0, TIOCSETD, (caddr_t)&ldisc) < 0) {
+ 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, (caddr_t)&unit) < 0) {
+ 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);
+ }
+
syslog(LOG_INFO, "attaching slip unit %d for %s\n", unit, loginname);
- (void)sprintf(logincmd, "%s %d %d %s", loginfile, unit, speed,
+ (void)sprintf(logincmd, "%s %d %ld %s", loginfile, unit, speed,
loginargs);
/*
* aim stdout and errout at /dev/null so logincmd output won't
@@ -370,7 +383,6 @@ main(argc, argv)
if (s = system(logincmd)) {
syslog(LOG_ERR, "%s login failed: exit status %d from %s",
loginname, s, loginfile);
- (void) ioctl(0, TIOCSETD, (caddr_t)&odisc);
exit(6);
}
OpenPOWER on IntegriCloud