]> git.ozlabs.org Git - ppp.git/commitdiff
Restore original EUID rather than 0 during option processing.
authorPaul Mackerras <paulus@samba.org>
Sun, 18 Jun 2006 11:26:00 +0000 (11:26 +0000)
committerPaul Mackerras <paulus@samba.org>
Sun, 18 Jun 2006 11:26:00 +0000 (11:26 +0000)
When dropping and regaining privileges during option processing,
the seteuid to regain privileges is now the original EUID rather
than a constant zero.  This means that `pppd --version' run without
root privilege prints the version number and exits rather than
giving an "unable to regain privileges" error.

pppd/auth.c
pppd/options.c

index 8180927c6dd56afa773cb56b6bebe7efd460c89f..cd0477780cf2111c604eaebd102fa9b0b81fa78a 100644 (file)
@@ -68,7 +68,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: auth.c,v 1.111 2006/06/04 21:56:31 paulus Exp $"
+#define RCSID  "$Id: auth.c,v 1.112 2006/06/18 11:26:00 paulus Exp $"
 
 #include <stdio.h>
 #include <stddef.h>
 
 #include <stdio.h>
 #include <stddef.h>
@@ -409,6 +409,7 @@ setupapfile(argv)
 {
     FILE *ufile;
     int l;
 {
     FILE *ufile;
     int l;
+    uid_t euid;
     char u[MAXNAMELEN], p[MAXSECRETLEN];
     char *fname;
 
     char u[MAXNAMELEN], p[MAXSECRETLEN];
     char *fname;
 
@@ -418,12 +419,13 @@ setupapfile(argv)
     fname = strdup(*argv);
     if (fname == NULL)
        novm("+ua file name");
     fname = strdup(*argv);
     if (fname == NULL)
        novm("+ua file name");
+    euid = geteuid();
     if (seteuid(getuid()) == -1) {
        option_error("unable to reset uid before opening %s: %m", fname);
        return 0;
     }
     ufile = fopen(fname, "r");
     if (seteuid(getuid()) == -1) {
        option_error("unable to reset uid before opening %s: %m", fname);
        return 0;
     }
     ufile = fopen(fname, "r");
-    if (seteuid(0) == -1)
+    if (seteuid(euid) == -1)
        fatal("unable to regain privileges: %m");
     if (ufile == NULL) {
        option_error("unable to open user login data file %s", fname);
        fatal("unable to regain privileges: %m");
     if (ufile == NULL) {
        option_error("unable to open user login data file %s", fname);
index 5c9d3a0d9534345460c7dc247521506d59bd630d..a85239abb0c523908e2e51d69d2b296b79754fb2 100644 (file)
@@ -40,7 +40,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: options.c,v 1.99 2006/06/04 07:04:57 paulus Exp $"
+#define RCSID  "$Id: options.c,v 1.100 2006/06/18 11:26:00 paulus Exp $"
 
 #include <ctype.h>
 #include <stdio.h>
 
 #include <ctype.h>
 #include <stdio.h>
@@ -399,17 +399,19 @@ options_from_file(filename, must_exist, check_prot, priv)
     option_t *opt;
     int oldpriv, n;
     char *oldsource;
     option_t *opt;
     int oldpriv, n;
     char *oldsource;
+    uid_t euid;
     char *argv[MAXARGS];
     char args[MAXARGS][MAXWORDLEN];
     char cmd[MAXWORDLEN];
 
     char *argv[MAXARGS];
     char args[MAXARGS][MAXWORDLEN];
     char cmd[MAXWORDLEN];
 
+    euid = geteuid();
     if (check_prot && seteuid(getuid()) == -1) {
        option_error("unable to drop privileges to open %s: %m", filename);
        return 0;
     }
     f = fopen(filename, "r");
     err = errno;
     if (check_prot && seteuid(getuid()) == -1) {
        option_error("unable to drop privileges to open %s: %m", filename);
        return 0;
     }
     f = fopen(filename, "r");
     err = errno;
-    if (check_prot && seteuid(0) == -1)
+    if (check_prot && seteuid(euid) == -1)
        fatal("unable to regain privileges");
     if (f == NULL) {
        errno = err;
        fatal("unable to regain privileges");
     if (f == NULL) {
        errno = err;
@@ -1512,7 +1514,9 @@ setlogfile(argv)
     char **argv;
 {
     int fd, err;
     char **argv;
 {
     int fd, err;
+    uid_t euid;
 
 
+    euid = geteuid();
     if (!privileged_option && seteuid(getuid()) == -1) {
        option_error("unable to drop permissions to open %s: %m", *argv);
        return 0;
     if (!privileged_option && seteuid(getuid()) == -1) {
        option_error("unable to drop permissions to open %s: %m", *argv);
        return 0;
@@ -1521,7 +1525,7 @@ setlogfile(argv)
     if (fd < 0 && errno == EEXIST)
        fd = open(*argv, O_WRONLY | O_APPEND);
     err = errno;
     if (fd < 0 && errno == EEXIST)
        fd = open(*argv, O_WRONLY | O_APPEND);
     err = errno;
-    if (!privileged_option && seteuid(0) == -1)
+    if (!privileged_option && seteuid(euid) == -1)
        fatal("unable to regain privileges: %m");
     if (fd < 0) {
        errno = err;
        fatal("unable to regain privileges: %m");
     if (fd < 0) {
        errno = err;