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 eb4f6fdb6..c2bacdcd4 100644
--- a/readpass.c
+++ b/readpass.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: readpass.c,v 1.30 2004/06/17 15:10:14 djm Exp $"); 26RCSID("$OpenBSD: readpass.c,v 1.31 2004/10/29 22:53:56 djm Exp $");
27 27
28#include "xmalloc.h" 28#include "xmalloc.h"
29#include "misc.h" 29#include "misc.h"
@@ -141,3 +141,29 @@ read_passphrase(const char *prompt, int flags)
141 memset(buf, 'x', sizeof buf); 141 memset(buf, 'x', sizeof buf);
142 return ret; 142 return ret;
143} 143}
144
145int
146ask_permission(const char *fmt, ...)
147{
148 va_list args;
149 char *p, prompt[1024];
150 int allowed = 0;
151
152 va_start(args, fmt);
153 vsnprintf(prompt, sizeof(prompt), fmt, args);
154 va_end(args);
155
156 p = read_passphrase(prompt, RP_USE_ASKPASS|RP_ALLOW_EOF);
157 if (p != NULL) {
158 /*
159 * Accept empty responses and responses consisting
160 * of the word "yes" as affirmative.
161 */
162 if (*p == '\0' || *p == '\n' ||
163 strcasecmp(p, "yes") == 0)
164 allowed = 1;
165 xfree(p);
166 }
167
168 return (allowed);
169}