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.
17 static char promptprog[PATH_MAX+1];
19 static option_t options[] = {
20 { "promptprog", o_string, promptprog,
21 "External PAP password prompting program",
22 OPT_STATIC, NULL, PATH_MAX },
26 static int promptpass(char *user, char *passwd)
33 if (promptprog[0] == 0 || access(promptprog, X_OK) < 0)
34 return -1; /* sorry, can't help */
40 warn("Can't make a pipe for %s", promptprog);
43 if ((kid = fork()) == (pid_t) -1) {
44 warn("Can't fork to run %s", promptprog);
50 /* we are the child, exec the program */
51 char *argv[4], fdstr[32];
59 argv[2] = remote_name;
60 sprintf(fdstr, "%d", p[1]);
67 /* we are the parent, read the password from the pipe */
71 red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
75 error("Can't read secret from %s: %m", promptprog);
80 } while (readgood < MAXSECRETLEN - 1);
84 /* now wait for child to exit */
85 while (waitpid(kid, &wstat, 0) < 0) {
87 warn("error waiting for %s: %m", promptprog);
94 if (!WIFEXITED(wstat))
95 warn("%s terminated abnormally", promptprog);
96 if (WEXITSTATUS(wstat))
97 warn("%s exited with code %d", promptprog, WEXITSTATUS(status));
102 void plugin_init(void)
104 add_options(options);
105 pap_passwd_hook = promptpass;