]> andersk Git - openssh.git/blobdiff - readpass.c
- (tim) [configure.ac] test for egrep (AC_PROG_EGREP) before first
[openssh.git] / readpass.c
index eb4f6fdb6d903aa29b533e42b315b150a2f9a3ca..7914799a4965ce37f23aca67ad5c12f9e20bbcd8 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: readpass.c,v 1.30 2004/06/17 15:10:14 djm Exp $");
+RCSID("$OpenBSD: readpass.c,v 1.33 2005/05/02 21:13:22 markus Exp $");
 
 #include "xmalloc.h"
 #include "misc.h"
@@ -106,15 +106,20 @@ read_passphrase(const char *prompt, int flags)
        if (flags & RP_USE_ASKPASS)
                use_askpass = 1;
        else if (flags & RP_ALLOW_STDIN) {
-               if (!isatty(STDIN_FILENO))
+               if (!isatty(STDIN_FILENO)) {
+                       debug("read_passphrase: stdin is not a tty");
                        use_askpass = 1;
+               }
        } else {
                rppflags |= RPP_REQUIRE_TTY;
                ttyfd = open(_PATH_TTY, O_RDWR);
                if (ttyfd >= 0)
                        close(ttyfd);
-               else
+               else {
+                       debug("read_passphrase: can't open %s: %s", _PATH_TTY,
+                           strerror(errno));
                        use_askpass = 1;
+               }
        }
 
        if ((flags & RP_USE_ASKPASS) && getenv("DISPLAY") == NULL)
@@ -141,3 +146,29 @@ read_passphrase(const char *prompt, int flags)
        memset(buf, 'x', sizeof buf);
        return ret;
 }
+
+int
+ask_permission(const char *fmt, ...)
+{
+       va_list args;
+       char *p, prompt[1024];
+       int allowed = 0;
+
+       va_start(args, fmt);
+       vsnprintf(prompt, sizeof(prompt), fmt, args);
+       va_end(args);
+
+       p = read_passphrase(prompt, RP_USE_ASKPASS|RP_ALLOW_EOF);
+       if (p != NULL) {
+               /*
+                * Accept empty responses and responses consisting
+                * of the word "yes" as affirmative.
+                */
+               if (*p == '\0' || *p == '\n' ||
+                   strcasecmp(p, "yes") == 0)
+                       allowed = 1;
+               xfree(p);
+       }
+
+       return (allowed);
+}
This page took 0.162629 seconds and 4 git commands to generate.