diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2001-06-25 05:20:31 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2001-06-25 05:20:31 +0000 |
commit | 949974bbdb057202a429036a18fe36de5a7b6eac (patch) | |
tree | d5777e395808237422b323998888d1595d62c28b /readpass.c | |
parent | f0c50293dddf8b36e9511fdf1c2f3f443800e51c (diff) |
- markus@cvs.openbsd.org 2001/06/24 05:35:33
[readpass.c readpass.h ssh-add.c sshconnect2.c ssh-keygen.c]
switch to readpassphrase(3)
2.7/8-stable needs readpassphrase.[ch] from libc
Diffstat (limited to 'readpass.c')
-rw-r--r-- | readpass.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/readpass.c b/readpass.c index 05883dfcd..3b6ed72ba 100644 --- a/readpass.c +++ b/readpass.c | |||
@@ -32,10 +32,11 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include "includes.h" | 34 | #include "includes.h" |
35 | RCSID("$OpenBSD: readpass.c,v 1.18 2001/06/23 15:12:19 itojun Exp $"); | 35 | RCSID("$OpenBSD: readpass.c,v 1.19 2001/06/24 05:35:33 markus Exp $"); |
36 | |||
37 | #include <readpassphrase.h> | ||
36 | 38 | ||
37 | #include "xmalloc.h" | 39 | #include "xmalloc.h" |
38 | #include "cli.h" | ||
39 | #include "readpass.h" | 40 | #include "readpass.h" |
40 | #include "pathnames.h" | 41 | #include "pathnames.h" |
41 | #include "log.h" | 42 | #include "log.h" |
@@ -84,27 +85,24 @@ ssh_askpass(char *askpass, const char *msg) | |||
84 | return pass; | 85 | return pass; |
85 | } | 86 | } |
86 | 87 | ||
87 | |||
88 | /* | 88 | /* |
89 | * Reads a passphrase from /dev/tty with echo turned off. Returns the | 89 | * Reads a passphrase from /dev/tty with echo turned off/on. Returns the |
90 | * passphrase (allocated with xmalloc), being very careful to ensure that | 90 | * passphrase (allocated with xmalloc). Exits if EOF is encountered. If |
91 | * no other userland buffer is storing the password. | 91 | * RP_ALLOW_STDIN is set, the passphrase will be read from stdin if no |
92 | */ | 92 | * tty is available |
93 | /* | ||
94 | * Note: the funcationallity of this routing has been moved to | ||
95 | * cli_read_passphrase(). This routing remains to maintain | ||
96 | * compatibility with existing code. | ||
97 | */ | 93 | */ |
98 | char * | 94 | char * |
99 | read_passphrase(const char *prompt, int from_stdin) | 95 | read_passphrase(const char *prompt, int flags) |
100 | { | 96 | { |
101 | char *askpass = NULL; | 97 | char *askpass = NULL, *ret, buf[1024]; |
102 | int use_askpass = 0, ttyfd; | 98 | int rppflags, use_askpass = 0, ttyfd; |
103 | 99 | ||
104 | if (from_stdin) { | 100 | rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF; |
101 | if (flags & RP_ALLOW_STDIN) { | ||
105 | if (!isatty(STDIN_FILENO)) | 102 | if (!isatty(STDIN_FILENO)) |
106 | use_askpass = 1; | 103 | use_askpass = 1; |
107 | } else { | 104 | } else { |
105 | rppflags |= RPP_REQUIRE_TTY; | ||
108 | ttyfd = open("/dev/tty", O_RDWR); | 106 | ttyfd = open("/dev/tty", O_RDWR); |
109 | if (ttyfd >= 0) | 107 | if (ttyfd >= 0) |
110 | close(ttyfd); | 108 | close(ttyfd); |
@@ -120,5 +118,10 @@ read_passphrase(const char *prompt, int from_stdin) | |||
120 | return ssh_askpass(askpass, prompt); | 118 | return ssh_askpass(askpass, prompt); |
121 | } | 119 | } |
122 | 120 | ||
123 | return cli_read_passphrase(prompt, from_stdin, 0); | 121 | if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) |
122 | return NULL; | ||
123 | |||
124 | ret = xstrdup(buf); | ||
125 | memset(buf, 'x', sizeof buf); | ||
126 | return ret; | ||
124 | } | 127 | } |