X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Fpassprompt.c;h=dae326867fcdea9b2f6190d6e01fd24fff056352;hb=75f1f5fde9fa6a64d0c35af6dfac5086a0739334;hp=a579b912e70cfec5140b5396192b0e05ae3c4eb2;hpb=95d719f47943c479df4d7bf13eb928567392166d;p=ppp.git diff --git a/pppd/plugins/passprompt.c b/pppd/plugins/passprompt.c index a579b91..dae3268 100644 --- a/pppd/plugins/passprompt.c +++ b/pppd/plugins/passprompt.c @@ -8,13 +8,21 @@ * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include #include #include "pppd.h" +char pppd_version[] = VERSION; + static char promptprog[PATH_MAX+1]; +static int promptprog_refused = 0; static option_t options[] = { { "promptprog", o_string, promptprog, @@ -28,9 +36,9 @@ static int promptpass(char *user, char *passwd) int p[2]; pid_t kid; int readgood, wstat; - size_t red; + ssize_t red; - if (promptprog[0] == 0 || access(promptprog, X_OK) < 0) + if (promptprog_refused || promptprog[0] == 0 || access(promptprog, X_OK) < 0) return -1; /* sorry, can't help */ if (!passwd) @@ -48,7 +56,7 @@ static int promptpass(char *user, char *passwd) } if (!kid) { /* we are the child, exec the program */ - char *argv[4], fdstr[32]; + char *argv[5], fdstr[32]; sys_close(); closelog(); close(p[0]); @@ -72,18 +80,19 @@ static int promptpass(char *user, char *passwd) if (red == 0) break; if (red < 0) { + if (errno == EINTR && !got_sigterm) + continue; error("Can't read secret from %s: %m", promptprog); readgood = -1; break; } readgood += red; } while (readgood < MAXSECRETLEN - 1); - passwd[readgood] = 0; close(p[0]); /* now wait for child to exit */ while (waitpid(kid, &wstat, 0) < 0) { - if (errno != EINTR) { + if (errno != EINTR || got_sigterm) { warn("error waiting for %s: %m", promptprog); break; } @@ -91,11 +100,17 @@ static int promptpass(char *user, char *passwd) if (readgood < 0) return 0; + passwd[readgood] = 0; if (!WIFEXITED(wstat)) warn("%s terminated abnormally", promptprog); - if (WEXITSTATUS(wstat)) - warn("%s exited with code %d", promptprog, WEXITSTATUS(status)); - + if (WEXITSTATUS(wstat)) { + warn("%s exited with code %d", promptprog, WEXITSTATUS(wstat)); + /* code when cancel was hit in the prompt prog */ + if (WEXITSTATUS(wstat) == 128) { + promptprog_refused = 1; + } + return -1; + } return 1; } @@ -103,4 +118,7 @@ void plugin_init(void) { add_options(options); pap_passwd_hook = promptpass; +#ifdef USE_EAPTLS + eaptls_passwd_hook = promptpass; +#endif }