diff --git a/src/ssh_terminal.cpp b/src/ssh_terminal.cpp index fdcb1b3..a3c317a 100644 --- a/src/ssh_terminal.cpp +++ b/src/ssh_terminal.cpp @@ -146,29 +146,38 @@ bool SshTerminal::connect(const std::string& host, int port, const std::string& g_message("Connecting to %s:%d as %s ...", host.c_str(), port, user.c_str()); + g_message("ssh_new..."); session_ = ssh_new(); if (!session_) { g_warning("ssh_new() failed"); return false; } + g_message("ssh_options_set host..."); ssh_options_set(session_, SSH_OPTIONS_HOST, host.c_str()); unsigned int p = port; + g_message("ssh_options_set port..."); ssh_options_set(session_, SSH_OPTIONS_PORT, &p); + g_message("ssh_options_set user..."); ssh_options_set(session_, SSH_OPTIONS_USER, user.c_str()); int strict = 0; + g_message("ssh_options_set stricthostkeycheck..."); ssh_options_set(session_, SSH_OPTIONS_STRICTHOSTKEYCHECK, &strict); + g_message("ssh_connect..."); if (ssh_connect(session_) != SSH_OK) { std::string err = ssh_get_error(session_); g_warning("ssh_connect failed: %s", err.c_str()); - /* Manually free since cleanup_done_ is still true */ ssh_free(session_); session_ = nullptr; if (on_status_change) on_status_change(false, "Connection failed: " + err); return false; } + g_message("ssh_connect OK"); + g_message("ssh_session_update_known_hosts..."); ssh_session_update_known_hosts(session_); + g_message("known_hosts OK"); if (!keyfile.empty()) { + g_message("Trying keyfile auth..."); ssh_key key = nullptr; if (ssh_pki_import_privkey_file(keyfile.c_str(), nullptr, nullptr, nullptr, &key) == SSH_OK) { if (ssh_userauth_publickey(session_, nullptr, key) == SSH_AUTH_SUCCESS) { @@ -180,7 +189,9 @@ bool SshTerminal::connect(const std::string& host, int port, const std::string& } { + g_message("ssh_userauth_password..."); int rc = ssh_userauth_password(session_, nullptr, password.c_str()); + g_message("auth result: %d", rc); if (rc != SSH_AUTH_SUCCESS) { std::string err = ssh_get_error(session_); g_warning("Auth failed: %s", err.c_str()); @@ -193,16 +204,13 @@ bool SshTerminal::connect(const std::string& host, int port, const std::string& } auth_done: + g_message("ssh_channel_new..."); channel_ = ssh_channel_new(session_); - if (!channel_) { - ssh_disconnect(session_); - ssh_free(session_); - session_ = nullptr; - if (on_status_change) on_status_change(false, "Channel creation failed"); - return false; - } + if (!channel_) { g_warning("ssh_channel_new() failed"); return false; } + g_message("ssh_channel_open_session..."); if (ssh_channel_open_session(channel_) != SSH_OK) { + g_warning("ssh_channel_open_session failed"); ssh_channel_free(channel_); channel_ = nullptr; ssh_disconnect(session_); @@ -211,10 +219,13 @@ auth_done: if (on_status_change) on_status_change(false, "Session open failed"); return false; } + g_message("channel open OK"); guint cols = vte_terminal_get_column_count(terminal_); guint rows = vte_terminal_get_row_count(terminal_); + g_message("requesting PTY %dx%d...", cols, rows); if (ssh_channel_request_pty_size(channel_, "xterm-256color", cols, rows) != SSH_OK) { + g_warning("PTY request failed"); ssh_channel_free(channel_); channel_ = nullptr; ssh_disconnect(session_); @@ -224,7 +235,9 @@ auth_done: return false; } + g_message("requesting shell..."); if (ssh_channel_request_shell(channel_) != SSH_OK) { + g_warning("Shell request failed"); ssh_channel_free(channel_); channel_ = nullptr; ssh_disconnect(session_); @@ -233,9 +246,12 @@ auth_done: if (on_status_change) on_status_change(false, "Shell request failed"); return false; } + g_message("shell OK"); + g_message("openpty..."); pty_master_ = openpty(&pty_slave_, nullptr, nullptr, nullptr, nullptr); if (pty_master_ < 0) { + g_warning("openpty failed"); ssh_channel_free(channel_); channel_ = nullptr; ssh_disconnect(session_); @@ -244,9 +260,12 @@ auth_done: if (on_status_change) on_status_change(false, "PTY creation failed"); return false; } + g_message("openpty OK (master=%d, slave=%d)", pty_master_, pty_slave_); + g_message("vte_pty_new_foreign_sync..."); vte_pty_ = vte_pty_new_foreign_sync(pty_master_, nullptr, nullptr); if (vte_pty_) { + g_message("setting VTE pty..."); vte_terminal_set_pty(terminal_, vte_pty_); } else { close(pty_slave_); pty_slave_ = -1;