X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Fpassprompt.c;h=7779d511d8e4a203775c286397bbefc795eb09fc;hb=ba7f7e053daae846a54a1d08d3d133a5f1266ace;hp=2091f1361f0c863b5a26c09c77e3f18bdda9b803;hpb=0314df4b46a815922139ded9a2632015ddf260a7;p=ppp.git diff --git a/pppd/plugins/passprompt.c b/pppd/plugins/passprompt.c index 2091f13..7779d51 100644 --- a/pppd/plugins/passprompt.c +++ b/pppd/plugins/passprompt.c @@ -8,18 +8,30 @@ * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ + #include #include #include +#include +#include +#include #include -#include "pppd.h" +#include +#include +#include +#include + +#include +#include +#include +#include -char pppd_version[] = VERSION; +char pppd_version[] = PPPD_VERSION; static char promptprog[PATH_MAX+1]; static int promptprog_refused = 0; -static option_t options[] = { +static struct option options[] = { { "promptprog", o_string, promptprog, "External PAP password prompting program", OPT_STATIC, NULL, PATH_MAX }, @@ -30,7 +42,7 @@ static int promptpass(char *user, char *passwd) { int p[2]; pid_t kid; - int readgood, wstat; + int readgood, wstat, ret; ssize_t red; if (promptprog_refused || promptprog[0] == 0 || access(promptprog, X_OK) < 0) @@ -52,15 +64,21 @@ static int promptpass(char *user, char *passwd) if (!kid) { /* we are the child, exec the program */ char *argv[5], fdstr[32]; - sys_close(); + ppp_sys_close(); closelog(); close(p[0]); - seteuid(getuid()); - setegid(getgid()); - argv[0] = promptprog; - argv[1] = user; - argv[2] = remote_name; + ret = seteuid(getuid()); + if (ret != 0) { + warn("Couldn't set effective user id"); + } + ret = setegid(getgid()); + if (ret != 0) { + warn("Couldn't set effective user id"); + } sprintf(fdstr, "%d", p[1]); + argv[0] = promptprog; + argv[1] = strdup(user); + argv[2] = strdup(ppp_remote_name()); argv[3] = fdstr; argv[4] = 0; execv(*argv, argv); @@ -75,7 +93,7 @@ static int promptpass(char *user, char *passwd) if (red == 0) break; if (red < 0) { - if (errno == EINTR && !got_sigterm) + if (errno == EINTR && !ppp_signaled(SIGTERM)) continue; error("Can't read secret from %s: %m", promptprog); readgood = -1; @@ -87,7 +105,7 @@ static int promptpass(char *user, char *passwd) /* now wait for child to exit */ while (waitpid(kid, &wstat, 0) < 0) { - if (errno != EINTR || got_sigterm) { + if (errno != EINTR || ppp_signaled(SIGTERM)) { warn("error waiting for %s: %m", promptprog); break; } @@ -111,6 +129,9 @@ static int promptpass(char *user, char *passwd) void plugin_init(void) { - add_options(options); + ppp_add_options(options); pap_passwd_hook = promptpass; +#ifdef PPP_WITH_EAPTLS + eaptls_passwd_hook = promptpass; +#endif }