2 Support to pass the password via a pipe to the pppd
3 ---------------------------------------------------
5 Arvin Schnell <arvin@suse.de>
12 Normally programs like wvdial or kppp read the online password from their
13 config file and store them in the pap- and chap-secrets before they start the
14 pppd and remove them afterwards. Sure they need special privileges to do so.
16 The passwordfd feature offers a simpler and more secure solution. The program
17 that starts the pppd opens a pipe and writes the password into it. The pppd
18 simply reads the password from that pipe.
20 This methods is used for quiet a while on SuSE Linux by the programs wvdial,
27 Here is a short C program that uses the passwordfd feature. It starts the pppd
28 to buildup a pppoe connection.
41 #define _PATH_PPPD "/usr/sbin/pppd"
45 // Of course these values can be read from a configuration file or
46 // entered in a graphical dialog.
47 char *device = "eth0";
48 char *username = "1122334455661122334455660001@t-online.de";
49 char *password = "hello";
57 fprintf (stderr, "Sending signal %d to pid %d\n", src, pid);
66 fprintf (stderr, "Daemon died\n");
74 signal (SIGINT, &sigproc);
75 signal (SIGTERM, &sigproc);
76 signal (SIGCHLD, &sigchild);
80 fprintf (stderr, "unable to fork() for pppd: %m\n");
91 for (i = 0; i < 20; i++)
94 pppd_argv[pppd_argc++] = "pppd";
96 pppd_argv[pppd_argc++] = "call";
97 pppd_argv[pppd_argc++] = "pwfd-test";
99 // The device must be after the call, since the call loads the plugin.
100 pppd_argv[pppd_argc++] = device;
102 pppd_argv[pppd_argc++] = "user";
103 pppd_argv[pppd_argc++] = username;
105 // Open a pipe to pass the password to pppd.
106 if (pipe (pppd_passwdfd) == -1) {
107 fprintf (stderr, "pipe failed: %m\n");
111 // Of course this only works it the password is shorter
112 // than the pipe buffer. Otherwise you have to fork to
113 // prevent that your main program blocks.
114 write (pppd_passwdfd[1], password, strlen (password));
115 close (pppd_passwdfd[1]);
117 // Tell the pppd to read the password from the fd.
118 pppd_argv[pppd_argc++] = "passwordfd";
119 snprintf (buffer, 32, "%d", pppd_passwdfd[0]);
120 pppd_argv[pppd_argc++] = buffer;
122 if (execv (_PATH_PPPD, (char **) pppd_argv) < 0) {
123 fprintf (stderr, "cannot execl %s: %m\n", _PATH_PPPD);
135 main (int argc, char **argv)
146 Copy this file to /etc/ppp/peers/pwfd-test. The plugins can't be loaded on the
147 command line (unless you are root) since the plugin option is privileged.
153 # PPPoE plugin for kernel 2.4
158 # This plugin enables us to pipe the password to pppd, thus we don't have
159 # to fiddle with pap-secrets and chap-secrets. The user is also passed
160 # on the command line.