changeset 13585:411be0f9d82b

1332 ssh should use YESEXPR/NOEXPR Reviewed by: Garrett D'Amore <garrett@damore.org> Reviewed by: Albert Lee <trisk@opensolaris.org> Approved by: Garrett D'Amore <garrett@damore.org>
author Garrett D'Amore <garrett@damore.org>
date Tue, 31 Jan 2012 22:25:52 -0800
parents fc320b2833d3
children a42b5426edb4
files usr/src/cmd/ssh/ssh/sshconnect.c
diffstat 1 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/ssh/ssh/sshconnect.c	Sun Jan 22 05:35:33 2012 +0000
+++ b/usr/src/cmd/ssh/ssh/sshconnect.c	Tue Jan 31 22:25:52 2012 -0800
@@ -14,6 +14,8 @@
 /*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  */
 
 #include "includes.h"
@@ -37,6 +39,8 @@
 #include "misc.h"
 #include "readpass.h"
 #include <langinfo.h>
+#include <regex.h>
+#include <err.h>
 #include "engine.h"
 
 char *client_version_string = NULL;
@@ -545,6 +549,9 @@
 	const char *msg;
 	char *p, *again = NULL;
 	int n, ret = -1;
+	regex_t yesre, nore;
+	char *errstr;
+	int rerr, errlen;
 
 	if (options.batch_mode)
 		return 0;
@@ -552,20 +559,38 @@
 		nl_langinfo(YESSTR), nl_langinfo(NOSTR));
 	again = xmalloc(n + 1);
 	(void) snprintf(again, n + 1, gettext("Please type '%s' or '%s': "),
-		    nl_langinfo(YESSTR), nl_langinfo(NOSTR));
+	    nl_langinfo(YESSTR), nl_langinfo(NOSTR));
+
+	if ((rerr = regcomp(&yesre, nl_langinfo(YESEXPR), REG_EXTENDED)) != 0) {
+		errlen = regerror(rerr, &yesre, NULL, 0);
+		if ((errstr = malloc(errlen)) == NULL)
+			err(1, "malloc");
+		regerror(rerr, &yesre, errstr, errlen);
+		errx(1, "YESEXPR: %s: %s", nl_langinfo(YESEXPR), errstr);
+	}
+
+	if ((rerr = regcomp(&nore, nl_langinfo(NOEXPR), REG_EXTENDED)) != 0) {
+		errlen = regerror(rerr, &nore, NULL, 0);
+		if ((errstr = malloc(errlen)) == NULL)
+			err(1, "malloc");
+		regerror(rerr, &nore, errstr, errlen);
+		errx(1, "NOEXPR: %s: %s", nl_langinfo(NOEXPR), errstr);
+	}
 
 	for (msg = prompt;;msg = again) {
 		p = read_passphrase(msg, RP_ECHO);
-		if (p == NULL ||
-		    (p[0] == '\0') || (p[0] == '\n') ||
-		    strcasecmp(p, nl_langinfo(NOSTR)) == 0)
+		if (p == NULL || (p[0] == '\0') || (p[0] == '\n') ||
+		    regexec(&nore, p, 0, NULL, 0) == 0)
 			ret = 0;
-		if (p && strcasecmp(p, nl_langinfo(YESSTR)) == 0)
+		if (p && regexec(&yesre, p, 0, NULL, 0) == 0)
 			ret = 1;
 		if (p)
 			xfree(p);
-		if (ret != -1)
+		if (ret != -1) {
+			regfree(&yesre);
+			regfree(&nore);
 			return ret;
+		}
 	}
 }