summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2004-10-29 22:53:57 +0000
committerDamien Miller <djm@cvs.openbsd.org>2004-10-29 22:53:57 +0000
commit45681a89596cc85d74d0a6297295eb2653f0367d (patch)
tree03cc86f7b2df7564a83f24dd8ed079f4bc65d891 /usr.bin/ssh
parenta442ed804762d8b605eb1ddfed148a91c4ace07e (diff)
factor out common permission-asking code to separate function; ok markus@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/clientloop.c23
-rw-r--r--usr.bin/ssh/misc.h3
-rw-r--r--usr.bin/ssh/readpass.c28
-rw-r--r--usr.bin/ssh/ssh-agent.c20
4 files changed, 39 insertions, 35 deletions
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c
index 009480ea187..d77337b826b 100644
--- a/usr.bin/ssh/clientloop.c
+++ b/usr.bin/ssh/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/usr.bin/ssh/misc.h b/usr.bin/ssh/misc.h
index ec47a611d48..0290a2d6488 100644
--- a/usr.bin/ssh/misc.h
+++ b/usr.bin/ssh/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/usr.bin/ssh/readpass.c b/usr.bin/ssh/readpass.c
index 1a8397c4a8c..29e9342adcd 100644
--- a/usr.bin/ssh/readpass.c
+++ b/usr.bin/ssh/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 <readpassphrase.h>
@@ -143,3 +143,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/usr.bin/ssh/ssh-agent.c b/usr.bin/ssh/ssh-agent.c
index 18dc1db12d5..63b59a55d7b 100644
--- a/usr.bin/ssh/ssh-agent.c
+++ b/usr.bin/ssh/ssh-agent.c
@@ -35,7 +35,7 @@
#include "includes.h"
#include <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>
@@ -164,23 +164,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);
}