]> andersk Git - openssh.git/blobdiff - readpass.c
[buildpkg.sh.in] Last minute fix didn't make it in the .in file. :-(
[openssh.git] / readpass.c
index b4421ade04dccb4b9eba43b06d54b823c3ed44cd..fc7629c37e6d3f51e8ad46aff2671bd66f81f371 100644 (file)
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: readpass.c,v 1.26 2002/02/13 00:39:15 markus Exp $");
+RCSID("$OpenBSD: readpass.c,v 1.29 2004/05/08 00:21:31 djm Exp $");
 
 #include "xmalloc.h"
-#include "readpass.h"
+#include "misc.h"
 #include "pathnames.h"
 #include "log.h"
 #include "ssh.h"
@@ -46,11 +46,11 @@ ssh_askpass(char *askpass, const char *msg)
                fatal("internal error: askpass undefined");
        if (pipe(p) < 0) {
                error("ssh_askpass: pipe: %s", strerror(errno));
-               return xstrdup("");
+               return NULL;
        }
        if ((pid = fork()) < 0) {
                error("ssh_askpass: fork: %s", strerror(errno));
-               return xstrdup("");
+               return NULL;
        }
        if (pid == 0) {
                seteuid(getuid());
@@ -79,6 +79,11 @@ ssh_askpass(char *askpass, const char *msg)
                if (errno != EINTR)
                        break;
 
+       if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+               memset(buf, 0, sizeof(buf));
+               return NULL;
+       }
+
        buf[strcspn(buf, "\r\n")] = '\0';
        pass = xstrdup(buf);
        memset(buf, 0, sizeof(buf));
@@ -115,11 +120,17 @@ read_passphrase(const char *prompt, int flags)
                        askpass = getenv(SSH_ASKPASS_ENV);
                else
                        askpass = _PATH_SSH_ASKPASS_DEFAULT;
-               return ssh_askpass(askpass, prompt);
+               if ((ret = ssh_askpass(askpass, prompt)) == NULL)
+                       if (!(flags & RP_ALLOW_EOF))
+                               return xstrdup("");
+               return ret;
        }
 
-       if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL)
+       if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) {
+               if (flags & RP_ALLOW_EOF)
+                       return NULL;
                return xstrdup("");
+       }
 
        ret = xstrdup(buf);
        memset(buf, 'x', sizeof buf);
This page took 0.071106 seconds and 4 git commands to generate.