]> andersk Git - openssh.git/commitdiff
- markus@cvs.openbsd.org 2001/06/24 05:35:33
authormouring <mouring>
Mon, 25 Jun 2001 05:20:31 +0000 (05:20 +0000)
committermouring <mouring>
Mon, 25 Jun 2001 05:20:31 +0000 (05:20 +0000)
     [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

ChangeLog
readpass.c
readpass.h
ssh-add.c
ssh-keygen.c
sshconnect2.c

index 0a45afe34e89daf3b73ba4cb3c7f1534a48c11ae..fe6c857d18c6332e17369ff91b3f600fb089a907 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
    - markus@cvs.openbsd.org 2001/06/24 05:25:10
      [auth-options.c match.c match.h]
      move ip+hostname check to match.c
+   - 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
 
 20010622
  - (stevesk) handle systems without pw_expire and pw_change.
index 05883dfcd28b6712ce697e2635f423219075c602..3b6ed72babc48019bfa7d8d1364bee2bc6dd5dbb 100644 (file)
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: readpass.c,v 1.18 2001/06/23 15:12:19 itojun Exp $");
+RCSID("$OpenBSD: readpass.c,v 1.19 2001/06/24 05:35:33 markus Exp $");
+
+#include <readpassphrase.h>
 
 #include "xmalloc.h"
-#include "cli.h"
 #include "readpass.h"
 #include "pathnames.h"
 #include "log.h"
@@ -84,27 +85,24 @@ ssh_askpass(char *askpass, const char *msg)
        return pass;
 }
 
-
 /*
- * Reads a passphrase from /dev/tty with echo turned off.  Returns the
- * passphrase (allocated with xmalloc), being very careful to ensure that
- * no other userland buffer is storing the password.
- */
-/*
- * Note:  the funcationallity of this routing has been moved to
- * cli_read_passphrase().  This routing remains to maintain
- * compatibility with existing code.
+ * Reads a passphrase from /dev/tty with echo turned off/on.  Returns the
+ * passphrase (allocated with xmalloc).  Exits if EOF is encountered. If
+ * RP_ALLOW_STDIN is set, the passphrase will be read from stdin if no
+ * tty is available
  */
 char *
-read_passphrase(const char *prompt, int from_stdin)
+read_passphrase(const char *prompt, int flags)
 {
-       char *askpass = NULL;
-       int use_askpass = 0, ttyfd;
+       char *askpass = NULL, *ret, buf[1024];
+       int rppflags, use_askpass = 0, ttyfd;
 
-       if (from_stdin) {
+       rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF;
+       if (flags & RP_ALLOW_STDIN) {
                if (!isatty(STDIN_FILENO))
                        use_askpass = 1;
        } else {
+               rppflags |= RPP_REQUIRE_TTY;
                ttyfd = open("/dev/tty", O_RDWR);
                if (ttyfd >= 0)
                        close(ttyfd);
@@ -120,5 +118,10 @@ read_passphrase(const char *prompt, int from_stdin)
                return ssh_askpass(askpass, prompt);
        }
 
-       return cli_read_passphrase(prompt, from_stdin, 0);
+       if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL)
+               return NULL;
+
+       ret = xstrdup(buf);
+       memset(buf, 'x', sizeof buf);
+       return ret;
 }
index 55ed294da765ae77de479c2c74d33d8e1666ac51..37f85002b4073bdd12dc1d4582617c7159285e07 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: readpass.h,v 1.3 2001/05/06 17:52:08 mouring Exp $    */
+/*     $OpenBSD: readpass.h,v 1.4 2001/06/24 05:35:33 markus Exp $     */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -12,9 +12,6 @@
  * called by a name other than "ssh" or "Secure Shell".
  */
 
-/*
- * Reads a passphrase from /dev/tty with echo turned off.  Returns the
- * passphrase (allocated with xmalloc).  Exits if EOF is encountered. If
- * from_stdin is true, the passphrase will be read from stdin instead.
- */
-char   *read_passphrase(const char *prompt, int from_stdin);
+#define RP_ECHO                        0x0001
+#define RP_ALLOW_STDIN         0x0002
+char   *read_passphrase(const char *prompt, int flags);
index f03ce029ea4d00db1f23e5ce92af9a167b544d64..84a8c20f9648da4debd6bc75318545c5fee47237 100644 (file)
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -35,7 +35,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh-add.c,v 1.39 2001/06/23 15:12:20 itojun Exp $");
+RCSID("$OpenBSD: ssh-add.c,v 1.40 2001/06/24 05:35:33 markus Exp $");
 
 #include <openssl/evp.h>
 
@@ -128,7 +128,7 @@ add_file(AuthenticationConnection *ac, const char *filename)
                snprintf(msg, sizeof msg, "Enter passphrase for %.200s: ",
                   comment);
                for (;;) {
-                       pass = read_passphrase(msg, 1);
+                       pass = read_passphrase(msg, RP_ALLOW_STDIN);
                        if (strcmp(pass, "") == 0) {
                                clear_pass();
                                xfree(comment);
index 51b0034057367d3aba88a2ec96c8d05213a45daf..95fcd6521b77b91b5695a653222eea28d8f52462 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh-keygen.c,v 1.64 2001/06/23 17:05:22 markus Exp $");
+RCSID("$OpenBSD: ssh-keygen.c,v 1.65 2001/06/24 05:35:33 markus Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/pem.h>
@@ -123,7 +123,8 @@ load_identity(char *filename)
                if (identity_passphrase)
                        pass = xstrdup(identity_passphrase);
                else
-                       pass = read_passphrase("Enter passphrase: ", 1);
+                       pass = read_passphrase("Enter passphrase: ",
+                           RP_ALLOW_STDIN);
                prv = key_load_private(filename, pass, NULL);
                memset(pass, 0, strlen(pass));
                xfree(pass);
@@ -491,8 +492,11 @@ do_change_passphrase(struct passwd *pw)
                if (identity_passphrase)
                        old_passphrase = xstrdup(identity_passphrase);
                else
-                       old_passphrase = read_passphrase("Enter old passphrase: ", 1);
-               private = key_load_private(identity_file, old_passphrase , &comment);
+                       old_passphrase =
+                           read_passphrase("Enter old passphrase: ",
+                           RP_ALLOW_STDIN);
+               private = key_load_private(identity_file, old_passphrase,
+                   &comment);
                memset(old_passphrase, 0, strlen(old_passphrase));
                xfree(old_passphrase);
                if (private == NULL) {
@@ -508,8 +512,10 @@ do_change_passphrase(struct passwd *pw)
                passphrase2 = NULL;
        } else {
                passphrase1 =
-                       read_passphrase("Enter new passphrase (empty for no passphrase): ", 1);
-               passphrase2 = read_passphrase("Enter same passphrase again: ", 1);
+                       read_passphrase("Enter new passphrase (empty for no "
+                           "passphrase): ", RP_ALLOW_STDIN);
+               passphrase2 = read_passphrase("Enter same passphrase again: ",
+                    RP_ALLOW_STDIN);
 
                /* Verify that they are the same. */
                if (strcmp(passphrase1, passphrase2) != 0) {
@@ -570,7 +576,8 @@ do_change_comment(struct passwd *pw)
                else if (identity_new_passphrase)
                        passphrase = xstrdup(identity_new_passphrase);
                else
-                       passphrase = read_passphrase("Enter passphrase: ", 1);
+                       passphrase = read_passphrase("Enter passphrase: ",
+                           RP_ALLOW_STDIN);
                /* Try to load using the passphrase. */
                private = key_load_private(identity_file, passphrase, &comment);
                if (private == NULL) {
@@ -830,10 +837,15 @@ main(int ac, char **av)
        else {
 passphrase_again:
                passphrase1 =
-                       read_passphrase("Enter passphrase (empty for no passphrase): ", 1);
-               passphrase2 = read_passphrase("Enter same passphrase again: ", 1);
+                       read_passphrase("Enter passphrase (empty for no "
+                           "passphrase): ", RP_ALLOW_STDIN);
+               passphrase2 = read_passphrase("Enter same passphrase again: ",
+                   RP_ALLOW_STDIN);
                if (strcmp(passphrase1, passphrase2) != 0) {
-                       /* The passphrases do not match.  Clear them and retry. */
+                       /*
+                        * The passphrases do not match.  Clear them and
+                        * retry.
+                        */
                        memset(passphrase1, 0, strlen(passphrase1));
                        memset(passphrase2, 0, strlen(passphrase2));
                        xfree(passphrase1);
index 1f57c3a9f5da40ce7f602cdc94a08024e4f340a6..5f4943ba80faadefddb8c0b19f42f46481d00b80 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sshconnect2.c,v 1.76 2001/06/23 15:12:21 itojun Exp $");
+RCSID("$OpenBSD: sshconnect2.c,v 1.77 2001/06/24 05:35:34 markus Exp $");
 
 #include <openssl/bn.h>
 #include <openssl/md5.h>
@@ -45,7 +45,6 @@ RCSID("$OpenBSD: sshconnect2.c,v 1.76 2001/06/23 15:12:21 itojun Exp $");
 #include "key.h"
 #include "sshconnect.h"
 #include "authfile.h"
-#include "cli.h"
 #include "dh.h"
 #include "authfd.h"
 #include "log.h"
@@ -770,9 +769,9 @@ input_userauth_info_req(int type, int plen, void *ctxt)
        inst = packet_get_string(NULL);
        lang = packet_get_string(NULL);
        if (strlen(name) > 0)
-               cli_mesg(name);
+               log(name);
        if (strlen(inst) > 0)
-               cli_mesg(inst);
+               log(inst);
        xfree(name);
        xfree(inst);
        xfree(lang);
@@ -792,7 +791,7 @@ input_userauth_info_req(int type, int plen, void *ctxt)
                prompt = packet_get_string(NULL);
                echo = packet_get_char();
 
-               response = cli_prompt(prompt, echo);
+               response = read_passphrase(prompt, echo ? RP_ECHO : 0);
 
                packet_put_cstring(response);
                memset(response, 0, strlen(response));
This page took 0.097419 seconds and 5 git commands to generate.