Simplified and cleaned up the radiusclient implementation, and
[mpls-ppp.git] / pppd / plugins / passwordfd.c
blobd718f3bdf81d74fd82d2d221e4b260d69d484040
2 /*
3 * Author: Arvin Schnell <arvin@suse.de>
5 * This plugin let's you pass the password to the pppd via
6 * a file descriptor. That's easy and secure - no fiddling
7 * with pap- and chap-secrets files.
8 */
10 #include <stdio.h>
11 #include <errno.h>
12 #include <string.h>
13 #include <unistd.h>
15 #include "pppd.h"
17 char pppd_version[] = VERSION;
19 static int passwdfd = -1;
20 static char save_passwd[MAXSECRETLEN];
22 static option_t options[] = {
23 { "passwordfd", o_int, &passwdfd,
24 "Receive password on this file descriptor" },
25 { NULL }
28 static int pwfd_check (void)
30 return 1;
33 static int pwfd_passwd (char *user, char *passwd)
35 int readgood, red;
37 if (passwdfd == -1)
38 return -1;
40 if (passwd == NULL)
41 return 1;
43 if (passwdfd == -2) {
44 strcpy (passwd, save_passwd);
45 return 1;
48 readgood = 0;
49 do {
50 red = read (passwdfd, passwd + readgood, MAXSECRETLEN - 1 - readgood);
51 if (red == 0)
52 break;
53 if (red < 0) {
54 error ("Can't read secret from fd\n");
55 readgood = -1;
56 break;
58 readgood += red;
59 } while (readgood < MAXSECRETLEN - 1);
61 close (passwdfd);
63 if (readgood < 0)
64 return 0;
66 passwd[readgood] = 0;
67 strcpy (save_passwd, passwd);
68 passwdfd = -2;
70 return 1;
73 void plugin_init (void)
75 add_options (options);
77 pap_check_hook = pwfd_check;
78 pap_passwd_hook = pwfd_passwd;
80 chap_check_hook = pwfd_check;
81 chap_passwd_hook = pwfd_passwd;