From ce327b62ac28cb6a605fd827a97d978ea31e2860 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 5 Nov 2004 20:38:03 +1100 Subject: [PATCH] - 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@ --- ChangeLog | 5 ++++- clientloop.c | 23 ++++------------------- misc.h | 3 ++- readpass.c | 28 +++++++++++++++++++++++++++- ssh-agent.c | 20 ++++++-------------- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 02892cc61..3847553dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -51,6 +51,9 @@ were not being updated if they had changed after ~^Z suspends and SIGWINCH was not being processed unless the first connection had requested a tty; ok markus + - 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@ 20041102 - (dtucker) [configure.ac includes.h] Bug #947: Fix compile error on HP-UX @@ -1830,4 +1833,4 @@ - (djm) Trim deprecated options from INSTALL. Mention UsePAM - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu -$Id: ChangeLog,v 1.3575 2004/11/05 09:35:44 dtucker Exp $ +$Id: ChangeLog,v 1.3576 2004/11/05 09:38:03 dtucker Exp $ diff --git a/clientloop.c b/clientloop.c index 009480ea1..d77337b82 100644 --- a/clientloop.c +++ b/clientloop.c @@ -59,7 +59,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: clientloop.c,v 1.132 2004/10/29 21:47:15 djm Exp $"); +RCSID("$OpenBSD: clientloop.c,v 1.133 2004/10/29 22:53:56 djm Exp $"); #include "ssh.h" #include "ssh1.h" @@ -592,24 +592,9 @@ client_process_control(fd_set * readset) } allowed = 1; - if (options.control_master == 2) { - char *p, prompt[1024]; - - allowed = 0; - snprintf(prompt, sizeof(prompt), - "Allow shared connection to %s? ", host); - 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); - } - } + if (options.control_master == 2) + allowed = ask_permission("Allow shared connection to %s? ", + host); unset_nonblock(client_fd); diff --git a/misc.h b/misc.h index ec47a611d..0290a2d64 100644 --- a/misc.h +++ b/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.17 2004/08/11 21:43:05 avsm Exp $ */ +/* $OpenBSD: misc.h,v 1.18 2004/10/29 22:53:56 djm Exp $ */ /* * Author: Tatu Ylonen @@ -46,3 +46,4 @@ char *tilde_expand_filename(const char *, uid_t); #define RP_USE_ASKPASS 0x0008 char *read_passphrase(const char *, int); +int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); diff --git a/readpass.c b/readpass.c index eb4f6fdb6..c2bacdcd4 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); +} diff --git a/ssh-agent.c b/ssh-agent.c index fffed1342..dd7e22ad5 100644 --- a/ssh-agent.c +++ b/ssh-agent.c @@ -35,7 +35,7 @@ #include "includes.h" #include "openbsd-compat/sys-queue.h" -RCSID("$OpenBSD: ssh-agent.c,v 1.121 2004/10/07 10:12:36 djm Exp $"); +RCSID("$OpenBSD: ssh-agent.c,v 1.122 2004/10/29 22:53:56 djm Exp $"); #include #include @@ -168,23 +168,15 @@ lookup_identity(Key *key, int version) static int confirm_key(Identity *id) { - char *p, prompt[1024]; + char *p; int ret = -1; p = key_fingerprint(id->key, SSH_FP_MD5, SSH_FP_HEX); - snprintf(prompt, sizeof(prompt), "Allow use of key %s?\n" - "Key fingerprint %s.", id->comment, p); + if (ask_permission("Allow use of key %s?\nKey fingerprint %s.", + id->comment, p)) + ret = 0; xfree(p); - p = read_passphrase(prompt, 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) - ret = 0; - xfree(p); - } + return (ret); }