9ae3a8
From aa59c26b76954860b4c7f7e57d1d4b8b99ccfa6f Mon Sep 17 00:00:00 2001
9ae3a8
From: Richard Jones <rjones@redhat.com>
9ae3a8
Date: Mon, 8 Jun 2015 11:56:57 +0200
9ae3a8
Subject: [PATCH 04/30] block/ssh: Propagate errors through authenticate()
9ae3a8
9ae3a8
Message-id: <1433764620-20506-4-git-send-email-rjones@redhat.com>
9ae3a8
Patchwork-id: 65478
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH 3/6] block/ssh: Propagate errors through authenticate()
9ae3a8
Bugzilla: 1226683
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
Upstream-status: 4618e658e6dadd1ba53585157984eac71cb706c6
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/ssh.c | 23 ++++++++++++++---------
9ae3a8
 1 file changed, 14 insertions(+), 9 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/ssh.c b/block/ssh.c
9ae3a8
index 6ffcff1..5908e6d 100644
9ae3a8
--- a/block/ssh.c
9ae3a8
+++ b/block/ssh.c
9ae3a8
@@ -434,7 +434,7 @@ static int check_host_key(BDRVSSHState *s, const char *host, int port,
9ae3a8
     return -EINVAL;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int authenticate(BDRVSSHState *s, const char *user)
9ae3a8
+static int authenticate(BDRVSSHState *s, const char *user, Error **errp)
9ae3a8
 {
9ae3a8
     int r, ret;
9ae3a8
     const char *userauthlist;
9ae3a8
@@ -445,7 +445,8 @@ static int authenticate(BDRVSSHState *s, const char *user)
9ae3a8
     userauthlist = libssh2_userauth_list(s->session, user, strlen(user));
9ae3a8
     if (strstr(userauthlist, "publickey") == NULL) {
9ae3a8
         ret = -EPERM;
9ae3a8
-        error_report("remote server does not support \"publickey\" authentication");
9ae3a8
+        error_setg(errp,
9ae3a8
+                "remote server does not support \"publickey\" authentication");
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -453,17 +454,18 @@ static int authenticate(BDRVSSHState *s, const char *user)
9ae3a8
     agent = libssh2_agent_init(s->session);
9ae3a8
     if (!agent) {
9ae3a8
         ret = -EINVAL;
9ae3a8
-        session_error_report(s, "failed to initialize ssh-agent support");
9ae3a8
+        session_error_setg(errp, s, "failed to initialize ssh-agent support");
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
     if (libssh2_agent_connect(agent)) {
9ae3a8
         ret = -ECONNREFUSED;
9ae3a8
-        session_error_report(s, "failed to connect to ssh-agent");
9ae3a8
+        session_error_setg(errp, s, "failed to connect to ssh-agent");
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
     if (libssh2_agent_list_identities(agent)) {
9ae3a8
         ret = -EINVAL;
9ae3a8
-        session_error_report(s, "failed requesting identities from ssh-agent");
9ae3a8
+        session_error_setg(errp, s,
9ae3a8
+                           "failed requesting identities from ssh-agent");
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -474,7 +476,8 @@ static int authenticate(BDRVSSHState *s, const char *user)
9ae3a8
         }
9ae3a8
         if (r < 0) {
9ae3a8
             ret = -EINVAL;
9ae3a8
-            session_error_report(s, "failed to obtain identity from ssh-agent");
9ae3a8
+            session_error_setg(errp, s,
9ae3a8
+                               "failed to obtain identity from ssh-agent");
9ae3a8
             goto out;
9ae3a8
         }
9ae3a8
         r = libssh2_agent_userauth(agent, user, identity);
9ae3a8
@@ -488,8 +491,8 @@ static int authenticate(BDRVSSHState *s, const char *user)
9ae3a8
     }
9ae3a8
 
9ae3a8
     ret = -EPERM;
9ae3a8
-    error_report("failed to authenticate using publickey authentication "
9ae3a8
-                 "and the identities held by your ssh-agent");
9ae3a8
+    error_setg(errp, "failed to authenticate using publickey authentication "
9ae3a8
+               "and the identities held by your ssh-agent");
9ae3a8
 
9ae3a8
  out:
9ae3a8
     if (agent != NULL) {
9ae3a8
@@ -577,8 +580,10 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Authenticate. */
9ae3a8
-    ret = authenticate(s, user);
9ae3a8
+    ret = authenticate(s, user, &err;;
9ae3a8
     if (ret < 0) {
9ae3a8
+        qerror_report_err(err);
9ae3a8
+        error_free(err);
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8