o Explicitly set the close-on-exec flag of descriptor 3 before
exec()ing. Tidy up file dups in general prior to exec(). This prevents our tun device (fd 3) from staying open (and configured) despite handing off all it's links and exiting (because ``cat'' holds it open). o Don't bother SIG_DFL'ing signals before exec() as they're already trapped with specific handlers and will be handled correctly by the exec. o Use values from paths.h for "/dev/" and "/dev/tty". o Don't assert() in physical.c.
This commit is contained in:
parent
47723d29e5
commit
b762af4f95
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: bundle.c,v 1.1.2.65 1998/04/30 23:53:21 brian Exp $
|
||||
* $Id: bundle.c,v 1.1.2.66 1998/05/01 19:19:54 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -1196,6 +1196,7 @@ bundle_SendDatalink(struct datalink *dl, int ppp_fd)
|
||||
ppp_fd = fcntl(ppp_fd, F_DUPFD, 3);
|
||||
link_fd = fcntl(link_fd, F_DUPFD, 3);
|
||||
nfd = dup2(open(_PATH_DEVNULL, O_WRONLY), STDERR_FILENO);
|
||||
fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
|
||||
|
||||
setsid();
|
||||
setuid(geteuid());
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: chat.c,v 1.44.2.26 1998/04/28 01:25:09 brian Exp $
|
||||
* $Id: chat.c,v 1.44.2.27 1998/04/30 23:53:26 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -34,6 +34,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -728,25 +729,16 @@ ExecStr(struct physical *physical, char *command, char *out, int olen)
|
||||
}
|
||||
if ((pid = fork()) == 0) {
|
||||
TermTimerService();
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
signal(SIGALRM, SIG_DFL);
|
||||
/* XXX-ML This looks like it might need more encapsulation. */
|
||||
if (Physical_GetFD(physical) == 2) {
|
||||
Physical_DupAndClose(physical);
|
||||
}
|
||||
close(fids[0]);
|
||||
dup2(fids[1], 2);
|
||||
close(fids[1]);
|
||||
dup2(Physical_GetFD(physical), 0);
|
||||
dup2(Physical_GetFD(physical), 1);
|
||||
if ((nb = open("/dev/tty", O_RDWR)) > 3) {
|
||||
dup2(nb, 3);
|
||||
close(nb);
|
||||
|
||||
fids[1] = fcntl(fids[1], F_DUPFD, 4);
|
||||
dup2(Physical_GetFD(physical), STDIN_FILENO);
|
||||
dup2(STDIN_FILENO, STDOUT_FILENO);
|
||||
dup2(fids[1], STDERR_FILENO);
|
||||
close(3);
|
||||
if (open(_PATH_TTY, O_RDWR) == 3)
|
||||
fcntl(3, F_SETFD, 0); /* Clear close-on-exec flag */
|
||||
}
|
||||
else
|
||||
fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
|
||||
setuid(geteuid());
|
||||
execvp(vector[0], vector);
|
||||
fprintf(stderr, "execvp failed: %s: %s\n", vector[0], strerror(errno));
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: command.c,v 1.131.2.74 1998/04/30 23:53:29 brian Exp $
|
||||
* $Id: command.c,v 1.131.2.75 1998/05/01 19:19:58 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
@ -123,7 +123,7 @@
|
||||
#define NEG_DNS 50
|
||||
|
||||
const char Version[] = "2.0-beta";
|
||||
const char VersionDate[] = "$Date: 1998/04/30 23:53:29 $";
|
||||
const char VersionDate[] = "$Date: 1998/05/01 19:19:58 $";
|
||||
|
||||
static int ShowCommand(struct cmdargs const *);
|
||||
static int TerminalCommand(struct cmdargs const *);
|
||||
@ -317,11 +317,6 @@ ShellCommand(struct cmdargs const *arg, int bg)
|
||||
shell = _PATH_BSHELL;
|
||||
|
||||
TermTimerService();
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
signal(SIGALRM, SIG_DFL);
|
||||
|
||||
if (arg->prompt)
|
||||
fd = arg->prompt->fd_out;
|
||||
@ -333,6 +328,8 @@ ShellCommand(struct cmdargs const *arg, int bg)
|
||||
for (i = 0; i < 3; i++)
|
||||
dup2(fd, i);
|
||||
|
||||
fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
|
||||
|
||||
setuid(geteuid());
|
||||
if (arg->argc > arg->argn) {
|
||||
/* substitute pseudo args */
|
||||
|
@ -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.60 1998/04/30 23:53:49 brian Exp $
|
||||
* $Id: modem.c,v 1.77.2.61 1998/05/01 19:20:09 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -251,10 +251,12 @@ IntToSpeed(int nspeed)
|
||||
static void
|
||||
modem_SetDevice(struct physical *physical, const char *name)
|
||||
{
|
||||
int len = strlen(_PATH_DEV);
|
||||
|
||||
strncpy(physical->name.full, name, sizeof physical->name.full - 1);
|
||||
physical->name.full[sizeof physical->name.full - 1] = '\0';
|
||||
physical->name.base = strncmp(physical->name.full, "/dev/", 5) ?
|
||||
physical->name.full : physical->name.full + 5;
|
||||
physical->name.base = strncmp(physical->name.full, _PATH_DEV, len) ?
|
||||
physical->name.full : physical->name.full + len;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -16,13 +16,12 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: physical.c,v 1.1.2.27 1998/04/28 01:25:37 brian Exp $
|
||||
* $Id: physical.c,v 1.1.2.28 1998/04/30 23:53:53 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -104,21 +103,10 @@ Physical_SetSync(struct physical *phys) {
|
||||
|
||||
int
|
||||
Physical_SetRtsCts(struct physical *phys, int enable) {
|
||||
assert(enable == 0 || enable == 1);
|
||||
|
||||
phys->cfg.rts_cts = enable;
|
||||
phys->cfg.rts_cts = enable ? 1 : 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
Physical_DupAndClose(struct physical *phys) {
|
||||
int nmodem;
|
||||
|
||||
nmodem = dup(phys->fd);
|
||||
close(phys->fd);
|
||||
phys->fd = nmodem;
|
||||
}
|
||||
|
||||
/* Encapsulation for a read on the FD. Avoids some exposure, and
|
||||
concentrates control. */
|
||||
ssize_t
|
||||
|
@ -16,7 +16,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: physical.h,v 1.1.2.21 1998/04/10 23:51:33 brian Exp $
|
||||
* $Id: physical.h,v 1.1.2.22 1998/04/20 00:20:41 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -90,7 +90,6 @@ int /* Can this be set? (Might not be a relevant attribute for this
|
||||
device, for instance) */
|
||||
Physical_SetRtsCts(struct physical *, int);
|
||||
|
||||
void Physical_DupAndClose(struct physical *);
|
||||
ssize_t Physical_Read(struct physical *, void *, size_t);
|
||||
ssize_t Physical_Write(struct physical *, const void *, size_t);
|
||||
int Physical_UpdateSet(struct descriptor *, fd_set *, fd_set *, fd_set *,
|
||||
|
Loading…
Reference in New Issue
Block a user