File relax-ssh-password-prompt-recognition-some-more.patch of Package lftp.18123

Index: lftp-4.8.4/src/SSH_Access.cc
===================================================================
--- lftp-4.8.4.orig/src/SSH_Access.cc	2021-01-20 11:39:08.275521449 +0000
+++ lftp-4.8.4/src/SSH_Access.cc	2021-01-20 11:39:49.849368781 +0000
@@ -1,7 +1,7 @@
 /*
  * lftp - file transfer program
  *
- * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net)
+ * Copyright (c) 1996-2020 by Alexander V. Lukyanov (lav@yars.free.net)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
 #include <config.h>
 #include "SSH_Access.h"
 #include "misc.h"
+#include "ascii_ctype.h"
 #include <algorithm>
 #include <cctype>
 #include <string>
@@ -47,16 +48,35 @@ static bool begins_with(const char *b,co
    return (e-b>=len && !strncasecmp(b,suffix,len));
 }
 
-static bool contains(char const * begin, char const * end, std::string const & needle)
+struct nocase_eq
 {
-   struct nocase_eq
-   {
       inline bool operator() (char lhs, char rhs) const
       {
-         return std::tolower(lhs) == std::tolower(rhs);
-      };
+      return c_tolower(lhs) == c_tolower(rhs);
    };
-   return std::search(begin, end, needle.begin(), needle.end(), nocase_eq()) != end;
+};
+
+static bool contains(char const *begin, char const *end, char const *needle)
+{
+   return std::search(begin, end, needle, needle+strlen(needle), nocase_eq()) != end;
+}
+
+static bool IsPasswordPrompt(const char *b,const char *e)
+{
+   if(b==e)
+      return false;
+   if(ends_with(b,e,"'s password"))
+      return true;
+   if(e[-1]==':')
+      return contains(b,e,"password") || contains(b,e,"passphrase");
+   return false;
+}
+
+static bool IsConfirmPrompt(const char *b,const char *e)
+{
+   if(b==e)
+      return false;
+   return e[-1]=='?' && contains(b,e,"yes/no");
 }
 
 int SSH_Access::HandleSSHMessage()
@@ -70,7 +90,7 @@ int SSH_Access::HandleSSHMessage()
    {
       if(s>0 && b[s-1]==' ')
 	 s--;
-      if((contains(b,b+s,"password") && b[s-1]==':'))
+      if(IsPasswordPrompt(b,b+s))
       {
 	 if(!pass)
 	 {
@@ -88,7 +108,7 @@ int SSH_Access::HandleSSHMessage()
 	 password_sent++;
 	 return m;
       }
-      if(ends_with(b,b+s,"(yes/no)?"))
+      if(IsConfirmPrompt(b,b+s))
       {
 	 const char *answer=QueryBool("auto-confirm",hostname)?"yes\n":"no\n";
 	 pty_recv_buf->Put(answer);
openSUSE Build Service is sponsored by