diff options
Diffstat (limited to 'readpass.c')
-rw-r--r-- | readpass.c | 28 |
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" |
26 | RCSID("$OpenBSD: readpass.c,v 1.30 2004/06/17 15:10:14 djm Exp $"); | 26 | RCSID("$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 | |||
145 | int | ||
146 | ask_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 | } | ||