X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fmain.c;h=092195471e35c730287e5b80e9cf3e0f80e890c1;hb=0875ace97fd7efe9a109a282a2f30c20872c78aa;hp=2141879090fc378c770119c08e03c41700ef3b20;hpb=ef6f6d62459620b334457a58cb17e40f450814dc;p=ppp.git diff --git a/pppd/main.c b/pppd/main.c index 2141879..0921954 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: main.c,v 1.54 1999/03/02 05:36:42 paulus Exp $"; +static char rcsid[] = "$Id: main.c,v 1.57 1999/03/08 05:34:43 paulus Exp $"; #endif #include @@ -448,7 +448,16 @@ main(argc, argv) hungup = 0; kill_link = 0; sigprocmask(SIG_UNBLOCK, &mask, NULL); - while ((ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0)) < 0) { + for (;;) { + /* If the user specified the device name, become the + user before opening it. */ + if (!devnam_info.priv) + seteuid(uid); + ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0); + if (!devnam_info.priv) + seteuid(0); + if (ttyfd >= 0) + break; if (errno != EINTR) syslog(LOG_ERR, "Failed to open %s: %m", devnam); if (!persist || errno != EINTR) @@ -504,7 +513,14 @@ main(argc, argv) /* reopen tty if necessary to wait for carrier */ if (connector == NULL && modem) { - while ((i = open(devnam, O_RDWR)) < 0) { + for (;;) { + if (!devnam_info.priv) + seteuid(uid); + i = open(devnam, O_RDWR); + if (!devnam_info.priv) + seteuid(0); + if (i >= 0) + break; if (errno != EINTR) syslog(LOG_ERR, "Failed to reopen %s: %m", devnam); if (!persist || errno != EINTR || hungup || kill_link) @@ -838,6 +854,15 @@ close_tty() ttyfd = -1; } +/* + * hangup_modem - hang up the modem by clearing DTR. + */ +void hangup_modem(ttyfd) + int ttyfd; +{ + setdtr(ttyfd, 0); +} + struct callout { struct timeval c_time; /* time at which to call routine */ @@ -1145,7 +1170,7 @@ device_script(program, in, out) close(errfd); } } - setuid(getuid()); + setuid(uid); setgid(getgid()); execl("/bin/sh", "sh", "-c", program, (char *)0); syslog(LOG_ERR, "could not exec /bin/sh: %m"); @@ -1224,10 +1249,10 @@ run_program(prog, args, must_exist, done, arg) int new_fd; /* Leave the current location */ - (void) setsid(); /* No controlling tty. */ + (void) setsid(); /* No controlling tty. */ (void) umask (S_IRWXG|S_IRWXO); - (void) chdir ("/"); /* no current directory. */ - setuid(geteuid()); + (void) chdir ("/"); /* no current directory. */ + setuid(0); /* set real UID = root */ setgid(getegid()); /* Ensure that nothing of our device environment is inherited. */