X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Foptions.c;h=482eab99e3274086d7c6b13aac4b7c1254045c27;hp=5c9d3a0d9534345460c7dc247521506d59bd630d;hb=3e451dfe42426b51e6ce1d66a3e04de43e055568;hpb=bf69479845b0dc57e75423be4dd2491cadda1f89 diff --git a/pppd/options.c b/pppd/options.c index 5c9d3a0..482eab9 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -40,7 +40,7 @@ * 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.102 2008/06/15 06:53:06 paulus Exp $" #include #include @@ -399,17 +399,19 @@ options_from_file(filename, must_exist, check_prot, priv) option_t *opt; int oldpriv, n; char *oldsource; + uid_t euid; 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(0) == -1) + if (check_prot && seteuid(euid) == -1) fatal("unable to regain privileges"); if (f == NULL) { errno = err; @@ -769,17 +771,20 @@ process_option(opt, cmd, argv) if (!(*parser)(argv)) return 0; if (opt->flags & OPT_A2LIST) { - struct option_value *ovp, **pp; + struct option_value *ovp, *pp; ovp = malloc(sizeof(*ovp) + strlen(*argv)); if (ovp != 0) { strcpy(ovp->value, *argv); ovp->source = option_source; ovp->next = NULL; - pp = (struct option_value **) &opt->addr2; - while (*pp != 0) - pp = &(*pp)->next; - *pp = ovp; + if (opt->addr2 == NULL) { + opt->addr2 = ovp; + } else { + for (pp = opt->addr2; pp->next != NULL; pp = pp->next) + ; + pp->next = ovp; + } } } break; @@ -791,6 +796,10 @@ process_option(opt, cmd, argv) break; } + /* + * If addr2 wasn't used by any flag (OPT_A2COPY, etc.) but is set, + * treat it as a bool and set/clear it based on the OPT_A2CLR bit. + */ if (opt->addr2 && (opt->flags & (OPT_A2COPY|OPT_ENABLE |OPT_A2PRINTER|OPT_A2STRVAL|OPT_A2LIST|OPT_A2OR)) == 0) *(bool *)(opt->addr2) = !(opt->flags & OPT_A2CLR); @@ -1512,7 +1521,9 @@ setlogfile(argv) 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; @@ -1521,7 +1532,7 @@ setlogfile(argv) 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;