Blame SOURCES/0002-ssh-Improve-the-error-message-when-all-authenticatio.patch

0b2b05
From 916f90972af60576591dea4a4f1d07e4dae6d9cf Mon Sep 17 00:00:00 2001
0b2b05
From: "Richard W.M. Jones" <rjones@redhat.com>
0b2b05
Date: Thu, 5 Jan 2023 11:29:32 +0000
0b2b05
Subject: [PATCH] ssh: Improve the error message when all authentication
0b2b05
 methods fail
0b2b05
0b2b05
The current error message:
0b2b05
0b2b05
  nbdkit: ssh[1]: error: all possible authentication methods failed
0b2b05
0b2b05
is confusing and non-actionable.  It's hard even for experts to
0b2b05
understand the relationship between the authentication methods offered
0b2b05
by a server and what we require.
0b2b05
0b2b05
Try to improve the error message in some common situations, especially
0b2b05
where password authentication on the server side is disabled but the
0b2b05
client supplied a password=... parameter.  After this change, you will
0b2b05
see an actionable error:
0b2b05
0b2b05
  nbdkit: ssh[1]: error: the server does not offer password
0b2b05
  authentication but you tried to use a password; if you have root
0b2b05
  access to the server, try editing 'sshd_config' and setting
0b2b05
  'PasswordAuthentication yes'; otherwise try setting up public key
0b2b05
  authentication
0b2b05
0b2b05
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2158300
0b2b05
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
0b2b05
(cherry picked from commit bea88cff5ac9c42f1a068ad24d43d5ed0506edaa)
0b2b05
---
0b2b05
 plugins/ssh/ssh.c | 22 ++++++++++++++++++++++
0b2b05
 1 file changed, 22 insertions(+)
0b2b05
0b2b05
diff --git a/plugins/ssh/ssh.c b/plugins/ssh/ssh.c
0b2b05
index aaa7c2b9..5a132d8f 100644
0b2b05
--- a/plugins/ssh/ssh.c
0b2b05
+++ b/plugins/ssh/ssh.c
0b2b05
@@ -361,6 +361,28 @@ authenticate (struct ssh_handle *h)
0b2b05
     if (rc == SSH_AUTH_SUCCESS) return 0;
0b2b05
   }
0b2b05
 
0b2b05
+  /* All compatible methods were tried and none worked.  Come up with
0b2b05
+   * an actionable diagnostic message if we recognise the problem.
0b2b05
+   */
0b2b05
+  if (!(method & SSH_AUTH_METHOD_PUBLICKEY) && password == NULL) {
0b2b05
+    nbdkit_error ("the server does not offer public key authentication; "
0b2b05
+                  "try using the password=... parameter");
0b2b05
+    return -1;
0b2b05
+  }
0b2b05
+  if ((method & SSH_AUTH_METHOD_PASSWORD) && password != NULL) {
0b2b05
+    nbdkit_error ("password authentication failed, "
0b2b05
+                  "is the username and password correct?");
0b2b05
+    return -1;
0b2b05
+  }
0b2b05
+  if (!(method & SSH_AUTH_METHOD_PASSWORD) && password != NULL) {
0b2b05
+    nbdkit_error ("the server does not offer password authentication "
0b2b05
+                  "but you tried to use a password; if you have root access "
0b2b05
+                  "to the server, try editing 'sshd_config' and setting "
0b2b05
+                  "'PasswordAuthentication yes'; otherwise try setting up "
0b2b05
+                  "public key authentication");
0b2b05
+    return -1;
0b2b05
+  }
0b2b05
+
0b2b05
   nbdkit_error ("all possible authentication methods failed");
0b2b05
   return -1;
0b2b05
 }
0b2b05
-- 
0b2b05
2.31.1
0b2b05