Package: sshpass
Version: 1.05

When remote key changes, sshpass hangs. This patch fixes the problem. It
seems the bug forum on Sourceforge for the upstream has been inactive for a
long time, I file the bug here. Hope someone can fix this.

This is another scenario which is similar to #506208, but not the same
thing.

Best Regards,
Yongzhi Pan
diff --git a/main.c b/main.c
index 652d4f8..31894f2 100644
--- a/main.c
+++ b/main.c
@@ -358,9 +358,10 @@ int handleoutput( int fd )
 {
     // We are looking for the string
     static int prevmatch=0; // If the "password" prompt is repeated, we have the wrong password.
-    static int state1, state2;
+    static int state1, state2, state3;
     static const char compare1[]="assword:"; // Asking for a password
     static const char compare2[]="The authenticity of host "; // Asks to authenticate host
+    static const char compare3[] = "Warning: the RSA host key for"; // Key changes
     // static const char compare3[]="WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"; // Warns about man in the middle attack
     // The remote identification changed error is sent to stderr, not the tty, so we do not handle it.
     // This is not a problem, as ssh exists immediately in such a case
@@ -389,6 +390,12 @@ int handleoutput( int fd )
         // Are we being prompted to authenticate the host?
         if( compare2[state2]=='\0' ) {
             ret=RETURN_HOST_KEY_UNKNOWN;
+        } else {
+            state3 = match( compare3, buffer, numread, state3 );
+            // Host key changed
+            if ( compare3[state3]=='\0' ) {
+                ret=RETURN_HOST_KEY_CHANGED;
+            }
         }
     }
 
diff --git a/sshpass.1 b/sshpass.1
index f6f1e26..e005c33 100644
--- a/sshpass.1
+++ b/sshpass.1
@@ -76,6 +76,9 @@ Invalid/incorrect password
 .TP
 6
 Host public key is unknown. sshpass exits without confirming the new key.
+.TP
+7
+Host public key changed. sshpass exits without confirming the new key.
 .P
 In addition, ssh might be complaining about a man in the middle attack. This
 complaint does not go to the tty. In other words, even with sshpass, the error

Reply via email to