From: Paul Mackerras Date: Wed, 17 Nov 1999 03:49:28 +0000 (+0000) Subject: add passprompt plugin X-Git-Tag: ppp-2.4.7~598 X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=95d719f47943c479df4d7bf13eb928567392166d add passprompt plugin --- diff --git a/pppd/plugins/Makefile.linux b/pppd/plugins/Makefile.linux index b33ab27..1c99dc0 100644 --- a/pppd/plugins/Makefile.linux +++ b/pppd/plugins/Makefile.linux @@ -2,7 +2,10 @@ CC = gcc CFLAGS = -g -O2 -I.. -I../../include LDFLAGS = -shared -all: minconn.so +all: minconn.so passprompt.so minconn.so: minconn.c $(CC) -o $@ $(LDFLAGS) $(CFLAGS) minconn.c + +passprompt.so: passprompt.c + $(CC) -o $@ $(LDFLAGS) $(CFLAGS) passprompt.c diff --git a/pppd/plugins/Makefile.sol2 b/pppd/plugins/Makefile.sol2 index c1d02e5..ee04761 100644 --- a/pppd/plugins/Makefile.sol2 +++ b/pppd/plugins/Makefile.sol2 @@ -1,7 +1,7 @@ # # Makefile for plugins on Solaris 2 # -# $Id: Makefile.sol2,v 1.1 1999/09/16 01:17:00 masputra Exp $ +# $Id: Makefile.sol2,v 1.2 1999/11/17 03:49:27 paulus Exp $ # include ../../svr4/Makedefs @@ -17,5 +17,11 @@ minconn.so: minconn.o minconn.o: minconn.c $(CC) $(CFLAGS) -c $? +passprompt.so: passprompt.o + ld -o $@ $(LDFLAGS) -h $@ passprompt.o + +passprompt.o: passprompt.c + $(CC) $(CFLAGS) -c $? + clean: rm -f *.o *.so diff --git a/pppd/plugins/passprompt.c b/pppd/plugins/passprompt.c new file mode 100644 index 0000000..a579b91 --- /dev/null +++ b/pppd/plugins/passprompt.c @@ -0,0 +1,106 @@ +/* + * passprompt.c - pppd plugin to invoke an external PAP password prompter + * + * Copyright 1999 Paul Mackerras, Alan Curry. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * 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 "pppd.h" + +static char promptprog[PATH_MAX+1]; + +static option_t options[] = { + { "promptprog", o_string, promptprog, + "External PAP password prompting program", + OPT_STATIC, NULL, PATH_MAX }, + { NULL } +}; + +static int promptpass(char *user, char *passwd) +{ + int p[2]; + pid_t kid; + int readgood, wstat; + size_t red; + + if (promptprog[0] == 0 || access(promptprog, X_OK) < 0) + return -1; /* sorry, can't help */ + + if (!passwd) + return 1; + + if (pipe(p)) { + warn("Can't make a pipe for %s", promptprog); + return 0; + } + if ((kid = fork()) == (pid_t) -1) { + warn("Can't fork to run %s", promptprog); + close(p[0]); + close(p[1]); + return 0; + } + if (!kid) { + /* we are the child, exec the program */ + char *argv[4], fdstr[32]; + sys_close(); + closelog(); + close(p[0]); + seteuid(getuid()); + setegid(getgid()); + argv[0] = promptprog; + argv[1] = user; + argv[2] = remote_name; + sprintf(fdstr, "%d", p[1]); + argv[3] = fdstr; + argv[4] = 0; + execv(*argv, argv); + _exit(127); + } + + /* we are the parent, read the password from the pipe */ + close(p[1]); + readgood = 0; + do { + red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood); + if (red == 0) + break; + if (red < 0) { + 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) { + warn("error waiting for %s: %m", promptprog); + break; + } + } + + if (readgood < 0) + return 0; + if (!WIFEXITED(wstat)) + warn("%s terminated abnormally", promptprog); + if (WEXITSTATUS(wstat)) + warn("%s exited with code %d", promptprog, WEXITSTATUS(status)); + + return 1; +} + +void plugin_init(void) +{ + add_options(options); + pap_passwd_hook = promptpass; +}