summaryrefslogtreecommitdiff
path: root/readpass.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2004-11-05 20:38:03 +1100
committerDarren Tucker <dtucker@zip.com.au>2004-11-05 20:38:03 +1100
commitce327b62ac28cb6a605fd827a97d978ea31e2860 (patch)
tree4238303b22083a2e00cef74ab894efb852e23685 /readpass.c
parent5d78de628376f55fd2fc5acad14733cf90867425 (diff)
- djm@cvs.openbsd.org 2004/10/29 22:53:56
[clientloop.c misc.h readpass.c ssh-agent.c] factor out common permission-asking code to separate function; ok markus@
Diffstat (limited to 'readpass.c')
-rw-r--r--readpass.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/readpass.c b/readpass.c
index eb4f6fdb..c2bacdcd 100644
--- a/readpass.c
+++ b/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 "xmalloc.h"
#include "misc.h"
@@ -141,3 +141,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);
+}