2 * passprompt.c - pppd plugin to invoke an external PAP password prompter
4 * Copyright 1999 Paul Mackerras, Alan Curry.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
22 char pppd_version[] = VERSION;
24 static char promptprog[PATH_MAX+1];
25 static int promptprog_refused = 0;
27 static option_t options[] = {
28 { "promptprog", o_string, promptprog,
29 "External PAP password prompting program",
30 OPT_STATIC, NULL, PATH_MAX },
34 static int promptpass(char *user, char *passwd)
38 int readgood, wstat, ret;
41 if (promptprog_refused || promptprog[0] == 0 || access(promptprog, X_OK) < 0)
42 return -1; /* sorry, can't help */
48 warn("Can't make a pipe for %s", promptprog);
51 if ((kid = fork()) == (pid_t) -1) {
52 warn("Can't fork to run %s", promptprog);
58 /* we are the child, exec the program */
59 char *argv[5], fdstr[32];
63 ret = seteuid(getuid());
65 warn("Couldn't set effective user id");
67 ret = setegid(getgid());
69 warn("Couldn't set effective user id");
73 argv[2] = remote_name;
74 sprintf(fdstr, "%d", p[1]);
81 /* we are the parent, read the password from the pipe */
85 red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
89 if (errno == EINTR && !got_sigterm)
91 error("Can't read secret from %s: %m", promptprog);
96 } while (readgood < MAXSECRETLEN - 1);
99 /* now wait for child to exit */
100 while (waitpid(kid, &wstat, 0) < 0) {
101 if (errno != EINTR || got_sigterm) {
102 warn("error waiting for %s: %m", promptprog);
109 passwd[readgood] = 0;
110 if (!WIFEXITED(wstat))
111 warn("%s terminated abnormally", promptprog);
112 if (WEXITSTATUS(wstat)) {
113 warn("%s exited with code %d", promptprog, WEXITSTATUS(wstat));
114 /* code when cancel was hit in the prompt prog */
115 if (WEXITSTATUS(wstat) == 128) {
116 promptprog_refused = 1;
123 void plugin_init(void)
125 add_options(options);
126 pap_passwd_hook = promptpass;
128 eaptls_passwd_hook = promptpass;