X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Ftty.c;h=d571b111d7e34755d9304104c075dcbcc16f4e44;hp=c11d039364420c97093f00bc370649f550610f7e;hb=7a7ed0a1a26961a165fd17183fd161c36a4b088f;hpb=3c9d53d98102887698af1c1b3655274207e7c941 diff --git a/pppd/tty.c b/pppd/tty.c index c11d039..d571b11 100644 --- a/pppd/tty.c +++ b/pppd/tty.c @@ -68,12 +68,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: tty.c,v 1.23 2004/12/31 11:49:22 paulus Exp $" +#define RCSID "$Id: tty.c,v 1.27 2008/07/01 12:27:56 paulus Exp $" #include #include #include #include +#include #include #include #include @@ -553,7 +554,6 @@ int connect_tty() * out and we want to use the modem lines, we reopen it later * in order to wait for the carrier detect signal from the modem. */ - hungup = 0; got_sigterm = 0; connector = doing_callback? callback_script: connect_script; if (devnam[0] != 0) { @@ -563,12 +563,16 @@ int connect_tty() int err, prio; prio = privopen? OPRIO_ROOT: tty_options[0].priority; - if (prio < OPRIO_ROOT) - seteuid(uid); + if (prio < OPRIO_ROOT && seteuid(uid) == -1) { + error("Unable to drop privileges before opening %s: %m\n", + devnam); + status = EXIT_OPEN_FAILED; + goto errret; + } real_ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0); err = errno; - if (prio < OPRIO_ROOT) - seteuid(0); + if (prio < OPRIO_ROOT && seteuid(0) == -1) + fatal("Unable to regain privileges"); if (real_ttyfd >= 0) break; errno = err; @@ -684,11 +688,11 @@ int connect_tty() if (device_script(initializer, ttyfd, ttyfd, 0) < 0) { error("Initializer script failed"); status = EXIT_INIT_FAILED; - goto errret; + goto errretf; } if (got_sigterm) { disconnect_tty(); - goto errret; + goto errretf; } info("Serial port initialized."); } @@ -697,11 +701,11 @@ int connect_tty() if (device_script(connector, ttyfd, ttyfd, 0) < 0) { error("Connect script failed"); status = EXIT_CONNECT_FAILED; - goto errret; + goto errretf; } if (got_sigterm) { disconnect_tty(); - goto errret; + goto errretf; } info("Serial connection established."); } @@ -750,6 +754,9 @@ int connect_tty() return ttyfd; + errretf: + if (real_ttyfd >= 0) + tcflush(real_ttyfd, TCIOFLUSH); errret: if (pty_master >= 0) { close(pty_master); @@ -773,6 +780,7 @@ void disconnect_tty() } else { info("Serial link disconnected."); } + stop_charshunt(NULL, 0); } void tty_close_fds() @@ -936,8 +944,7 @@ start_charshunt(ifd, ofd) exit(0); } charshunt_pid = cpid; - add_notifier(&sigreceived, stop_charshunt, 0); - record_child(cpid, "pppd (charshunt)", charshunt_done, NULL); + record_child(cpid, "pppd (charshunt)", charshunt_done, NULL, 1); return 1; }