cryptospore / rpms / qemu-kvm

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