shithub: riscv

Download patch

ref: ef7b42883242ec39eb4be18c2c5c49b03e5ceaf1
parent: fbf64184dff33adc9dec19db243f0eaba3594140
author: aiju <devnull@localhost>
date: Mon Apr 24 19:16:59 EDT 2017

ssh: loop keyboard-interactive on failure

--- a/sys/src/cmd/ssh.c
+++ b/sys/src/cmd/ssh.c
@@ -52,6 +52,10 @@
 	WinPackets = 8,		// (1<<15) * 8 = 256K
 };
 
+enum {
+	MaxPwTries = 3 // retry this often for keyboard-interactive
+};
+
 typedef struct
 {
 	u32int		seq;
@@ -859,15 +863,21 @@
 kbintauth(void)
 {
 	static char authmeth[] = "keyboard-interactive";
+	int tries;
 
 	char *name, *inst, *s, *a;
 	int fd, i, n, m;
 	int nquest, echo;
 	uchar *ans, *answ;
+	tries = 0;
 
 	if(!authok(authmeth))
 		return -1;
 
+Loop:
+	if(++tries > MaxPwTries)
+		return -1;
+		
 	sendpkt("bsssss", MSG_USERAUTH_REQUEST,
 		user, strlen(user),
 		service, strlen(service),
@@ -880,8 +890,10 @@
 		dispatch();
 		goto Next0;
 	case MSG_USERAUTH_FAILURE:
-		authfailure(authmeth);
-		return -1;
+		werrstr("keyboard-interactive failed");
+		if(authfailure(authmeth))
+			return -1;
+		goto Loop;
 	case MSG_USERAUTH_SUCCESS:
 		return 0;
 	case MSG_USERAUTH_INFO_REQUEST:
@@ -940,8 +952,10 @@
 	case MSG_USERAUTH_INFO_REQUEST:
 		goto Retry;
 	case MSG_USERAUTH_FAILURE:
-		authfailure(authmeth);
-		return -1;
+		werrstr("keyboard-interactive failed");
+		if(authfailure(authmeth))
+			return -1;
+		goto Loop;
 	case MSG_USERAUTH_SUCCESS:
 		return 0;
 	}