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 char pppd_version[] = VERSION;
19 static char promptprog[PATH_MAX+1];
21 static option_t options[] = {
22 { "promptprog", o_string, promptprog,
23 "External PAP password prompting program",
24 OPT_STATIC, NULL, PATH_MAX },
28 static int promptpass(char *user, char *passwd)
35 if (promptprog[0] == 0 || access(promptprog, X_OK) < 0)
36 return -1; /* sorry, can't help */
42 warn("Can't make a pipe for %s", promptprog);
45 if ((kid = fork()) == (pid_t) -1) {
46 warn("Can't fork to run %s", promptprog);
52 /* we are the child, exec the program */
53 char *argv[4], fdstr[32];
61 argv[2] = remote_name;
62 sprintf(fdstr, "%d", p[1]);
69 /* we are the parent, read the password from the pipe */
73 red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
79 error("Can't read secret from %s: %m", promptprog);
84 } while (readgood < MAXSECRETLEN - 1);
88 /* now wait for child to exit */
89 while (waitpid(kid, &wstat, 0) < 0) {
91 warn("error waiting for %s: %m", promptprog);
98 if (!WIFEXITED(wstat))
99 warn("%s terminated abnormally", promptprog);
100 if (WEXITSTATUS(wstat))
101 warn("%s exited with code %d", promptprog, WEXITSTATUS(status));
106 void plugin_init(void)
108 add_options(options);
109 pap_passwd_hook = promptpass;