summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--clientloop.c23
-rw-r--r--misc.h3
-rw-r--r--readpass.c28
-rw-r--r--ssh-agent.c20
5 files changed, 43 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 02892cc6..3847553d 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 009480ea..d77337b8 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 ec47a611..0290a2d6 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 <ylo@cs.hut.fi>
@@ -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 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);
+}
diff --git a/ssh-agent.c b/ssh-agent.c
index fffed134..dd7e22ad 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 <openssl/evp.h>
#include <openssl/md5.h>
@@ -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);
}