Changeset View
Changeset View
Standalone View
Standalone View
vnc/vncsshtunnelthread.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
61 | // This is called by the main thread, but from a slot connected to our signal via BlockingQueuedConnection | 61 | // This is called by the main thread, but from a slot connected to our signal via BlockingQueuedConnection | ||
62 | // so this is safe even without a mutex, the semaphore in BlockingQueuedConnection takes care of the synchronization. | 62 | // so this is safe even without a mutex, the semaphore in BlockingQueuedConnection takes care of the synchronization. | ||
63 | void VncSshTunnelThread::setPassword(const QString &password, PasswordOrigin origin) | 63 | void VncSshTunnelThread::setPassword(const QString &password, PasswordOrigin origin) | ||
64 | { | 64 | { | ||
65 | m_password = password; | 65 | m_password = password; | ||
66 | m_passwordOrigin = origin; | 66 | m_passwordOrigin = origin; | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | // This is called by the main thread, but from a slot connected to our signal via BlockingQueuedConnection | ||||
70 | // so this is safe even without a mutex, the semaphore in BlockingQueuedConnection takes care of the synchronization. | ||||
71 | void VncSshTunnelThread::userCanceledPasswordRequest() | ||||
72 | { | ||||
73 | m_passwordRequestCanceledByUser = true; | ||||
74 | } | ||||
75 | | ||||
69 | void VncSshTunnelThread::run() | 76 | void VncSshTunnelThread::run() | ||
70 | { | 77 | { | ||
71 | struct CleanupHelper | 78 | struct CleanupHelper | ||
72 | { | 79 | { | ||
73 | int server_sock = -1; | 80 | int server_sock = -1; | ||
74 | int client_sock = -1; | 81 | int client_sock = -1; | ||
75 | ssh_session session = nullptr; | 82 | ssh_session session = nullptr; | ||
76 | ssh_channel forwarding_channel = nullptr; | 83 | ssh_channel forwarding_channel = nullptr; | ||
Show All 30 Lines | |||||
107 | { | 114 | { | ||
108 | emit errorMessage(i18n("Error connecting to %1: %2", QString::fromUtf8(m_host), QString::fromLocal8Bit(ssh_get_error(session)))); | 115 | emit errorMessage(i18n("Error connecting to %1: %2", QString::fromUtf8(m_host), QString::fromLocal8Bit(ssh_get_error(session)))); | ||
109 | return; | 116 | return; | ||
110 | } | 117 | } | ||
111 | 118 | | |||
112 | // First try authenticating via ssh agent | 119 | // First try authenticating via ssh agent | ||
113 | res = ssh_userauth_agent(session, NULL); | 120 | res = ssh_userauth_agent(session, NULL); | ||
114 | 121 | | |||
122 | m_passwordRequestCanceledByUser = false; | ||||
115 | if (res != SSH_AUTH_SUCCESS) { | 123 | if (res != SSH_AUTH_SUCCESS) { | ||
116 | // If ssh agent didn't work, try with password | 124 | // If ssh agent didn't work, try with password | ||
117 | emit passwordRequest(NoFlags); // This calls blockingly to the main thread which will call setPassword | 125 | emit passwordRequest(NoFlags); // This calls blockingly to the main thread which will call setPassword | ||
118 | res = ssh_userauth_password(session, NULL, m_password.toUtf8().constData()); | 126 | res = ssh_userauth_password(session, NULL, m_password.toUtf8().constData()); | ||
119 | 127 | | |||
120 | // If password didn't work but came from the wallet, ask the user for the password | 128 | // If password didn't work but came from the wallet, ask the user for the password | ||
121 | if (res != SSH_AUTH_SUCCESS && m_passwordOrigin == PasswordFromWallet) { | 129 | if (!m_passwordRequestCanceledByUser && res != SSH_AUTH_SUCCESS && m_passwordOrigin == PasswordFromWallet) { | ||
122 | emit passwordRequest(IgnoreWallet); // This calls blockingly to the main thread which will call setPassword | 130 | emit passwordRequest(IgnoreWallet); // This calls blockingly to the main thread which will call setPassword | ||
123 | res = ssh_userauth_password(session, NULL, m_password.toUtf8().constData()); | 131 | res = ssh_userauth_password(session, NULL, m_password.toUtf8().constData()); | ||
124 | } | 132 | } | ||
125 | } | 133 | } | ||
126 | 134 | | |||
135 | if (m_passwordRequestCanceledByUser) { | ||||
136 | return; | ||||
137 | } | ||||
138 | | ||||
127 | if (res != SSH_AUTH_SUCCESS) { | 139 | if (res != SSH_AUTH_SUCCESS) { | ||
128 | emit errorMessage(i18n("Error authenticating with password: %1", QString::fromLocal8Bit(ssh_get_error(session)))); | 140 | emit errorMessage(i18n("Error authenticating with password: %1", QString::fromLocal8Bit(ssh_get_error(session)))); | ||
129 | return; | 141 | return; | ||
130 | } | 142 | } | ||
131 | 143 | | |||
132 | const int server_sock = socket(AF_INET, SOCK_STREAM, 0); | 144 | const int server_sock = socket(AF_INET, SOCK_STREAM, 0); | ||
133 | if (server_sock == -1) { | 145 | if (server_sock == -1) { | ||
134 | emit errorMessage(i18n("Error creating tunnel socket")); | 146 | emit errorMessage(i18n("Error creating tunnel socket")); | ||
▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines |