summaryrefslogtreecommitdiff
path: root/usr/src/cmd/ssh/libssh/common/readpass.c
diff options
context:
space:
mode:
authorHuie-Ying Lee <Huie-Ying.Lee@Sun.COM>2009-08-12 17:10:27 -0700
committerHuie-Ying Lee <Huie-Ying.Lee@Sun.COM>2009-08-12 17:10:27 -0700
commitef4d27fba69298571e509867dd27ea8bca349ec9 (patch)
tree1eee7aef2eab935482e13bd99c0600c139c91e4f /usr/src/cmd/ssh/libssh/common/readpass.c
parent2e7d9b4283515cc94f4e29f4b76204b1c108c307 (diff)
downloadillumos-joyent-ef4d27fba69298571e509867dd27ea8bca349ec9.tar.gz
PSARC 2009/408 resync ssh-agent command with OpenSSH
6860042 resync ssh-agent(1) with OpenSSH 6228970 ssh-agent cannot tolerate stdin being closed
Diffstat (limited to 'usr/src/cmd/ssh/libssh/common/readpass.c')
-rw-r--r--usr/src/cmd/ssh/libssh/common/readpass.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/usr/src/cmd/ssh/libssh/common/readpass.c b/usr/src/cmd/ssh/libssh/common/readpass.c
index 8e7fd9e239..fa1f1a4982 100644
--- a/usr/src/cmd/ssh/libssh/common/readpass.c
+++ b/usr/src/cmd/ssh/libssh/common/readpass.c
@@ -1,4 +1,9 @@
/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -25,13 +30,12 @@
#include "includes.h"
RCSID("$OpenBSD: readpass.c,v 1.27 2002/03/26 15:58:46 markus Exp $");
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include "xmalloc.h"
#include "readpass.h"
#include "pathnames.h"
#include "log.h"
#include "ssh.h"
+#include <langinfo.h>
static char *
ssh_askpass(char *askpass, const char *msg)
@@ -130,3 +134,30 @@ 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;
+ char *yeschar = nl_langinfo(YESSTR);
+
+ 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' ||
+ strncasecmp(p, yeschar, 1) == 0)
+ allowed = 1;
+ xfree(p);
+ }
+
+ return (allowed);
+}