Add support for devices beginning with ``!'', where we execute

the given program, using stdin/stdout/stderr as our link
descriptor.
This commit is contained in:
Brian Somers 1998-05-13 19:06:27 +00:00
parent 318fd42fb1
commit a36e970919
2 changed files with 77 additions and 15 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.68 1998/05/08 01:15:14 brian Exp $
* $Id: modem.c,v 1.77.2.69 1998/05/12 17:34:29 brian Exp $
*
* TODO:
*/
@ -39,6 +39,7 @@
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <unistd.h>
#ifdef __OpenBSD__
#include <util.h>
@ -515,7 +516,7 @@ modem_Open(struct physical *modem, struct bundle *bundle)
if (modem_lock(modem, bundle->unit) != -1) {
modem->fd = ID0open(modem->name.full, O_RDWR | O_NONBLOCK);
if (modem->fd < 0) {
log_Printf(LogERROR, "%s: Open(\"%s\"): %s\n",
log_Printf(LogPHASE, "%s: Open(\"%s\"): %s\n",
modem->link.name, modem->name.full, strerror(errno));
modem_Unlock(modem);
} else {
@ -524,6 +525,55 @@ modem_Open(struct physical *modem, struct bundle *bundle)
modem->link.name, modem->name.full);
}
}
} else if (*modem->name.full == '!') {
/* PPP via an external program */
/*
* XXX: Fix me - this should be another sort of link (similar to a
* physical
*/
int fids[2];
modem->name.base = modem->name.full + 1;
if (pipe(fids) < 0)
log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
strerror(errno));
else {
int stat;
pid_t pid;
stat = fcntl(fids[0], F_GETFL, 0);
if (stat > 0) {
stat |= O_NONBLOCK;
fcntl(fids[0], F_SETFL, stat);
}
switch ((pid = fork())) {
case -1:
log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
strerror(errno));
break;
case 0:
close(fids[0]);
timer_TermService();
fids[1] = fcntl(fids[1], F_DUPFD, 3);
dup2(fids[1], STDIN_FILENO);
dup2(fids[1], STDOUT_FILENO);
dup2(fids[1], STDERR_FILENO);
setuid(geteuid());
if (fork())
exit(127);
execlp(modem->name.base, modem->name.base, NULL);
fprintf(stderr, "execvp failed: %s: %s\n", modem->name.base,
strerror(errno));
exit(127);
break;
default:
close(fids[1]);
modem->fd = fids[0];
waitpid(pid, &stat, 0);
break;
}
}
} else {
/* PPP over TCP */
/*
@ -538,21 +588,20 @@ modem_Open(struct physical *modem, struct bundle *bundle)
if (*host && *port) {
modem->fd = OpenConnection(modem->link.name, host, port);
*cp = ':'; /* Don't destroy name.full */
if (modem->fd < 0)
return (-1);
modem_Found(modem, bundle);
log_Printf(LogDEBUG, "%s: Opened socket %s\n", modem->link.name,
modem->name.full);
if (modem->fd >= 0) {
modem_Found(modem, bundle);
log_Printf(LogDEBUG, "%s: Opened socket %s\n", modem->link.name,
modem->name.full);
}
} else {
*cp = ':'; /* Don't destroy name.full */
log_Printf(LogERROR, "%s: Invalid host:port: \"%s\"\n",
modem->link.name, modem->name.full);
return (-1);
}
} else {
log_Printf(LogERROR, "%s: Device (%s) must begin with a '/' or be a"
" host:port pair\n", modem->link.name, modem->name.full);
return (-1);
log_Printf(LogERROR, "%s: Device (%s) must begin with a '/',"
" a '!' or be a host:port pair\n", modem->link.name,
modem->name.full);
}
}
}

View File

@ -1,4 +1,4 @@
.\" $Id: ppp.8,v 1.97.2.30 1998/05/08 18:50:24 brian Exp $
.\" $Id: ppp.8,v 1.97.2.31 1998/05/10 09:26:21 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -2321,9 +2321,20 @@ If
.Dq value
does not begin with
.Pa /dev/ ,
it must be of the format
it must either begin with an exclaimation mark
.Pq Dq \&!
or be of the format
.Dq host:port .
If this is the case,
.Pp
If it begins with an exclaimation mark, the rest of the device name is
treated as a program name, and that program is executed when the device
is opened. Standard input, output and error are fed back to
.Nm
and are read and written as if they were a regular device.
.Pp
If a
.Dq host:port
pair is given,
.Nm
will attempt to connect to the given
.Dq host
@ -2331,7 +2342,9 @@ on the given
.Dq port .
Refer to the section on
.Em PPP OVER TCP
above for further details. If multiple
above for further details.
.Pp
If multiple
.Dq values
are specified,
.Nm