1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
https://github.com/ppp-project/ppp/pull/420
From df35ecb4ab63e8f89f57aa5d593441765a96ed62 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alin=20N=C4=83stac?= <mrness@gentoo.org>
Date: Fri, 20 Jun 2008 18:34:06 +0000
Subject: [PATCH] passwordfd: read password early
Bug: https://bugs.gentoo.org/209294
Bug: https://bugs.gentoo.org/905112
---
pppd/plugins/passwordfd.c | 54 ++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 29 deletions(-)
diff --git a/pppd/plugins/passwordfd.c b/pppd/plugins/passwordfd.c
index c1f782e..13aec56 100644
--- a/pppd/plugins/passwordfd.c
+++ b/pppd/plugins/passwordfd.c
@@ -24,11 +24,11 @@
char pppd_version[] = PPPD_VERSION;
-static int passwdfd = -1;
static char save_passwd[MAXSECRETLEN];
+static int readpassword (char **);
static struct option options[] = {
- { "passwordfd", o_int, &passwdfd,
+ { "passwordfd", o_special, (void *)readpassword,
"Receive password on this file descriptor" },
{ NULL }
};
@@ -38,43 +38,39 @@ static int pwfd_check (void)
return 1;
}
-static int pwfd_passwd (char *user, char *passwd)
+static int readpassword(char **argv)
{
- int readgood, red;
-
- if (passwdfd == -1)
- return -1;
+ char *arg = *argv;
+ int passwdfd = -1;
+ int chunk, len;
- if (passwd == NULL)
- return 1;
-
- if (passwdfd == -2) {
- strcpy (passwd, save_passwd);
- return 1;
+ if (sscanf(arg, "%d", &passwdfd) != 1 || passwdfd < 0)
+ {
+ error ("\"%s\" is not a valid file descriptor number", arg);
+ return 0;
}
- readgood = 0;
+ len = 0;
do {
- red = read (passwdfd, passwd + readgood, MAXSECRETLEN - 1 - readgood);
- if (red == 0)
- break;
- if (red < 0) {
- error ("Can't read secret from fd\n");
- readgood = -1;
+ chunk = read (passwdfd, save_passwd + len, MAXSECRETLEN - 1 - len);
+ if (chunk == 0)
break;
+ if (chunk < 0) {
+ error ("Can't read secret from fd %d", passwdfd);
+ return 0;
}
- readgood += red;
- } while (readgood < MAXSECRETLEN - 1);
-
+ len += chunk;
+ } while (len < MAXSECRETLEN - 1);
+ save_passwd[len] = 0;
close (passwdfd);
- if (readgood < 0)
- return 0;
-
- passwd[readgood] = 0;
- strcpy (save_passwd, passwd);
- passwdfd = -2;
+ return 1;
+}
+static int pwfd_passwd (char *user, char *passwd)
+{
+ if (passwd != NULL)
+ strcpy (passwd, save_passwd);
return 1;
}
--
2.40.1
|