]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/passwordfd.c
pppd.8: Document netmask option
[ppp.git] / pppd / plugins / passwordfd.c
index d718f3bdf81d74fd82d2d221e4b260d69d484040..be3088c532206f7bd06f8c6b29b87ad9e05aeb16 100644 (file)
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/time.h>
 
-#include "pppd.h"
+#include <pppd/pppd.h>
+#include <pppd/upap.h>
+#include <pppd/chap.h>
+#include <pppd/eap.h>
+#include <pppd/options.h>
 
-char pppd_version[] = VERSION;
+char pppd_version[] = PPPD_VERSION;
 
-static int passwdfd = -1;
 static char save_passwd[MAXSECRETLEN];
 
-static option_t options[] = {
-    { "passwordfd", o_int, &passwdfd,
-      "Receive password on this file descriptor" },
-    { NULL }
-};
-
-static int pwfd_check (void)
-{
-    return 1;
-}
-
-static int pwfd_passwd (char *user, char *passwd)
+static int pwfd_read_password(char **argv)
 {
-    int readgood, red;
-
-    if (passwdfd == -1)
-       return -1;
+    ssize_t readgood, red;
+    int passwdfd;
+    char passwd[MAXSECRETLEN];
 
-    if (passwd == NULL)
-       return 1;
-
-    if (passwdfd == -2) {
-       strcpy (passwd, save_passwd);
-       return 1;
-    }
+    if (!ppp_int_option(argv[0], &passwdfd))
+       return 0;
 
     readgood = 0;
     do {
@@ -65,18 +55,39 @@ static int pwfd_passwd (char *user, char *passwd)
 
     passwd[readgood] = 0;
     strcpy (save_passwd, passwd);
-    passwdfd = -2;
 
     return 1;
 }
 
+static struct option options[] = {
+    { "passwordfd", o_special, pwfd_read_password,
+      "Receive password on this file descriptor" },
+    { NULL }
+};
+
+static int pwfd_check (void)
+{
+    return 1;
+}
+
+static int pwfd_passwd (char *user, char *passwd)
+{
+    if (passwd != NULL)
+       strcpy(passwd, save_passwd);
+    return 1;
+}
+
 void plugin_init (void)
 {
-    add_options (options);
+    ppp_add_options (options);
 
     pap_check_hook = pwfd_check;
     pap_passwd_hook = pwfd_passwd;
 
     chap_check_hook = pwfd_check;
     chap_passwd_hook = pwfd_passwd;
+
+#ifdef PPP_WITH_EAPTLS
+    eaptls_passwd_hook = pwfd_passwd;
+#endif
 }