]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/tty.c
Check the result of seteuid(), just to be paranoid.
[ppp.git] / pppd / tty.c
index 1ef8a52eacae3bf8a6560005c2659214e1186622..c356483d1974ee9358010cc585049eddcc1de569 100644 (file)
@@ -68,7 +68,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: tty.c,v 1.24 2005/07/12 01:09:05 paulus Exp $"
+#define RCSID  "$Id: tty.c,v 1.25 2006/06/04 07:04:57 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -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;