From ce327b62ac28cb6a605fd827a97d978ea31e2860 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 5 Nov 2004 20:38:03 +1100 Subject: - 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@ --- readpass.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'readpass.c') 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); +} -- cgit v1.2.1