Unverified Commit 78611c74 authored by Christian Schmitz's avatar Christian Schmitz Committed by Daniel Stenberg
Browse files

ssh: show libSSH2 error code when closing fails

Closes #2500
parent 36f0f478
Loading
Loading
Loading
Loading
+57 −22
Original line number Diff line number Diff line
@@ -839,7 +839,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
        state(conn, SSH_AUTH_DONE);
      }
      else {
        char *err_msg;
        char *err_msg = NULL;
        (void)libssh2_session_last_error(sshc->ssh_session,
                                         &err_msg, NULL, 0);
        infof(data, "SSH public key authentication failed: %s\n", err_msg);
@@ -1046,7 +1046,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
       */
      sshc->sftp_session = libssh2_sftp_init(sshc->ssh_session);
      if(!sshc->sftp_session) {
        char *err_msg;
        char *err_msg = NULL;
        if(libssh2_session_last_errno(sshc->ssh_session) ==
           LIBSSH2_ERROR_EAGAIN) {
          rc = LIBSSH2_ERROR_EAGAIN;
@@ -2276,7 +2276,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to close libssh2 file\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to close libssh2 file: %d %s\n", rc, err_msg);
        }
        sshc->sftp_handle = NULL;
      }
@@ -2310,7 +2313,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to close libssh2 file\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session, &err_msg,
                                           NULL, 0);
          infof(data, "Failed to close libssh2 file: %d %s\n", rc, err_msg);
        }
        sshc->sftp_handle = NULL;
      }
@@ -2365,7 +2371,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
                 data->state.infilesize);
      if(!sshc->ssh_channel) {
        int ssh_err;
        char *err_msg;
        char *err_msg = NULL;

        if(libssh2_session_last_errno(sshc->ssh_session) ==
           LIBSSH2_ERROR_EAGAIN) {
@@ -2438,7 +2444,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

      if(!sshc->ssh_channel) {
        int ssh_err;
        char *err_msg;
        char *err_msg = NULL;

        if(libssh2_session_last_errno(sshc->ssh_session) ==
           LIBSSH2_ERROR_EAGAIN) {
@@ -2491,7 +2497,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc) {
          infof(data, "Failed to send libssh2 channel EOF\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to send libssh2 channel EOF: %d %s\n",
                rc, err_msg);
        }
      }
      state(conn, SSH_SCP_WAIT_EOF);
@@ -2504,7 +2514,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc) {
          infof(data, "Failed to get channel EOF: %d\n", rc);
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to get channel EOF: %d %s\n", rc, err_msg);
        }
      }
      state(conn, SSH_SCP_WAIT_CLOSE);
@@ -2517,7 +2530,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc) {
          infof(data, "Channel failed to close: %d\n", rc);
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Channel failed to close: %d %s\n", rc, err_msg);
        }
      }
      state(conn, SSH_SCP_CHANNEL_FREE);
@@ -2530,7 +2546,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to free libssh2 scp subsystem\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to free libssh2 scp subsystem: %d %s\n",
                rc, err_msg);
        }
        sshc->ssh_channel = NULL;
      }
@@ -2552,7 +2572,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to free libssh2 scp subsystem\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to free libssh2 scp subsystem: %d %s\n",
                rc, err_msg);
        }
        sshc->ssh_channel = NULL;
      }
@@ -2563,7 +2587,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to disconnect libssh2 session\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to disconnect libssh2 session: %d %s\n",
                rc, err_msg);
        }
      }

@@ -2588,7 +2616,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to disconnect from libssh2 agent\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to disconnect from libssh2 agent: %d %s\n",
                rc, err_msg);
        }
        libssh2_agent_free(sshc->ssh_agent);
        sshc->ssh_agent = NULL;
@@ -2606,7 +2638,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
          break;
        }
        if(rc < 0) {
          infof(data, "Failed to free libssh2 session\n");
          char *err_msg = NULL;
          (void)libssh2_session_last_error(sshc->ssh_session,
                                           &err_msg, NULL, 0);
          infof(data, "Failed to free libssh2 session: %d %s\n", rc, err_msg);
        }
        sshc->ssh_session = NULL;
      }