summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh/readpass.c
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2004-10-29 22:53:56 +0000
committerdjm <djm@openbsd.org>2004-10-29 22:53:56 +0000
commit4ec46a0eba55cca735e43b61bb86efdcda561d15 (patch)
tree13c6a539951b17a4006d87e97e4d2c999d154ba7 /usr.bin/ssh/readpass.c
parentfix some window size change bugs for multiplexed connections: windows sizes (diff)
downloadwireguard-openbsd-4ec46a0eba55cca735e43b61bb86efdcda561d15.tar.xz
wireguard-openbsd-4ec46a0eba55cca735e43b61bb86efdcda561d15.zip
factor out common permission-asking code to separate function; ok markus@
Diffstat (limited to 'usr.bin/ssh/readpass.c')
-rw-r--r--usr.bin/ssh/readpass.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/usr.bin/ssh/readpass.c b/usr.bin/ssh/readpass.c
index 1a8397c4a8c..29e9342adcd 100644
--- a/usr.bin/ssh/readpass.c
+++ b/usr.bin/ssh/readpass.c
@@ -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.31 2004/10/29 22:53:56 djm Exp $");
#include <readpassphrase.h>
@@ -143,3 +143,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);
+}