Changeset View
Changeset View
Standalone View
Standalone View
src/kmanagesieve/sessionthread.cpp
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Line(s) | 165 | { | |||
---|---|---|---|---|---|
206 | } | 206 | } | ||
207 | } | 207 | } | ||
208 | 208 | | |||
209 | // Called in secondary thread | 209 | // Called in secondary thread | ||
210 | void SessionThread::slotSocketError() | 210 | void SessionThread::slotSocketError() | ||
211 | { | 211 | { | ||
212 | Q_ASSERT(QThread::currentThread() == thread()); | 212 | Q_ASSERT(QThread::currentThread() == thread()); | ||
213 | 213 | | |||
214 | qCWarning(KMANAGERSIEVE_LOG) << Q_FUNC_INFO << m_socket->errorString(); | 214 | qCWarning(KMANAGERSIEVE_LOG) << Q_FUNC_INFO << m_socket->error() << m_socket->errorString(); | ||
215 | Q_EMIT error(KIO::buildErrorString(KIO::ERR_COULD_NOT_CONNECT, m_socket->errorString())); | 215 | | ||
216 | Q_EMIT error(m_socket->error(), m_socket->errorString()); | ||||
216 | doDisconnectFromHost(false); | 217 | doDisconnectFromHost(false); | ||
217 | } | 218 | } | ||
218 | 219 | | |||
219 | // Called in main thread | 220 | // Called in main thread | ||
220 | void SessionThread::startAuthentication() | 221 | void SessionThread::startAuthentication() | ||
221 | { | 222 | { | ||
222 | QMetaObject::invokeMethod(this, &SessionThread::doStartAuthentication, Qt::QueuedConnection); | 223 | QMetaObject::invokeMethod(this, &SessionThread::doStartAuthentication, Qt::QueuedConnection); | ||
223 | } | 224 | } | ||
224 | 225 | | |||
225 | // Called in secondary thread | 226 | // Called in secondary thread | ||
227 | void SessionThread::handleSaslAuthError() | ||||
228 | { | ||||
229 | Q_EMIT error(KTcpSocket::UnknownError, KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, QString::fromUtf8(sasl_errdetail(m_sasl_conn)))); | ||||
230 | doDisconnectFromHost(true); | ||||
231 | } | ||||
232 | | ||||
233 | // Called in secondary thread | ||||
226 | void SessionThread::doStartAuthentication() | 234 | void SessionThread::doStartAuthentication() | ||
227 | { | 235 | { | ||
228 | Q_ASSERT(QThread::currentThread() == thread()); | 236 | Q_ASSERT(QThread::currentThread() == thread()); | ||
229 | 237 | | |||
230 | int result; | 238 | int result; | ||
231 | m_sasl_conn = nullptr; | 239 | m_sasl_conn = nullptr; | ||
232 | m_sasl_client_interact = nullptr; | 240 | m_sasl_client_interact = nullptr; | ||
233 | const char *out = nullptr; | 241 | const char *out = nullptr; | ||
234 | uint outlen; | 242 | uint outlen; | ||
235 | const char *mechusing = nullptr; | 243 | const char *mechusing = nullptr; | ||
236 | 244 | | |||
237 | result = sasl_client_new("sieve", m_url.host().toLatin1().constData(), nullptr, nullptr, callbacks, 0, &m_sasl_conn); | 245 | result = sasl_client_new("sieve", m_url.host().toLatin1().constData(), nullptr, nullptr, callbacks, 0, &m_sasl_conn); | ||
238 | if (result != SASL_OK) { | 246 | if (result != SASL_OK) { | ||
239 | Q_EMIT error(KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, QString::fromUtf8(sasl_errdetail(m_sasl_conn)))); | 247 | handleSaslAuthError(); | ||
240 | doDisconnectFromHost(true); | | |||
241 | return; | 248 | return; | ||
242 | } | 249 | } | ||
243 | 250 | | |||
244 | do { | 251 | do { | ||
245 | result = sasl_client_start(m_sasl_conn, m_session->requestedSaslMethod().join(QLatin1Char(' ')).toLatin1().constData(), &m_sasl_client_interact, &out, &outlen, &mechusing); | 252 | result = sasl_client_start(m_sasl_conn, m_session->requestedSaslMethod().join(QLatin1Char(' ')).toLatin1().constData(), &m_sasl_client_interact, &out, &outlen, &mechusing); | ||
246 | if (result == SASL_INTERACT) { | 253 | if (result == SASL_INTERACT) { | ||
247 | if (!saslInteract(m_sasl_client_interact)) { | 254 | if (!saslInteract(m_sasl_client_interact)) { | ||
248 | Q_EMIT error(KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, QString::fromUtf8(sasl_errdetail(m_sasl_conn)))); | 255 | handleSaslAuthError(); | ||
249 | sasl_dispose(&m_sasl_conn); | 256 | sasl_dispose(&m_sasl_conn); | ||
250 | doDisconnectFromHost(true); | | |||
251 | return; | 257 | return; | ||
252 | } | 258 | } | ||
253 | } | 259 | } | ||
254 | } while (result == SASL_INTERACT); | 260 | } while (result == SASL_INTERACT); | ||
255 | 261 | | |||
256 | if (result != SASL_CONTINUE && result != SASL_OK) { | 262 | if (result != SASL_CONTINUE && result != SASL_OK) { | ||
257 | Q_EMIT error(KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, QString::fromUtf8(sasl_errdetail(m_sasl_conn)))); | 263 | handleSaslAuthError(); | ||
258 | sasl_dispose(&m_sasl_conn); | 264 | sasl_dispose(&m_sasl_conn); | ||
259 | doDisconnectFromHost(true); | | |||
260 | return; | 265 | return; | ||
261 | } | 266 | } | ||
262 | 267 | | |||
263 | qCDebug(KMANAGERSIEVE_LOG) << "Preferred authentication method is " << mechusing << "."; | 268 | qCDebug(KMANAGERSIEVE_LOG) << "Preferred authentication method is " << mechusing << "."; | ||
264 | 269 | | |||
265 | QByteArray authCommand = "AUTHENTICATE \"" + QByteArray(mechusing) + QByteArray("\""); | 270 | QByteArray authCommand = "AUTHENTICATE \"" + QByteArray(mechusing) + QByteArray("\""); | ||
266 | const QByteArray challenge = QByteArray::fromRawData(out, outlen).toBase64(); | 271 | const QByteArray challenge = QByteArray::fromRawData(out, outlen).toBase64(); | ||
267 | if (!challenge.isEmpty()) { | 272 | if (!challenge.isEmpty()) { | ||
Show All 15 Lines | |||||
283 | 288 | | |||
284 | // Called in secondary thread | 289 | // Called in secondary thread | ||
285 | void SessionThread::doContinueAuthentication(const Response &response, const QByteArray &data) | 290 | void SessionThread::doContinueAuthentication(const Response &response, const QByteArray &data) | ||
286 | { | 291 | { | ||
287 | Q_ASSERT(QThread::currentThread() == thread()); | 292 | Q_ASSERT(QThread::currentThread() == thread()); | ||
288 | 293 | | |||
289 | if (response.operationResult() == Response::Other) { | 294 | if (response.operationResult() == Response::Other) { | ||
290 | if (!saslClientStep(data)) { | 295 | if (!saslClientStep(data)) { | ||
291 | Q_EMIT error(KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, QString::fromUtf8(sasl_errdetail(m_sasl_conn)))); | 296 | handleSaslAuthError(); | ||
292 | doDisconnectFromHost(true); | | |||
293 | return; | 297 | return; | ||
294 | } | 298 | } | ||
295 | } else { | 299 | } else { | ||
296 | sasl_dispose(&m_sasl_conn); | 300 | sasl_dispose(&m_sasl_conn); | ||
297 | if (response.operationSuccessful()) { | 301 | if (response.operationSuccessful()) { | ||
298 | qCDebug(KMANAGERSIEVE_LOG) << "Authentication complete."; | 302 | qCDebug(KMANAGERSIEVE_LOG) << "Authentication complete."; | ||
299 | Q_EMIT authenticationDone(); | 303 | Q_EMIT authenticationDone(); | ||
300 | } else { | 304 | } else { | ||
301 | Q_EMIT error(KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, | 305 | Q_EMIT error(KTcpSocket::UnknownError, KIO::buildErrorString(KIO::ERR_COULD_NOT_AUTHENTICATE, | ||
302 | i18n("Authentication failed.\nMost likely the password is wrong.\nThe server responded:\n%1", QString::fromLatin1(response.action())))); | 306 | i18n("Authentication failed.\nMost likely the password is wrong.\nThe server responded:\n%1", QString::fromLatin1(response.action())))); | ||
303 | doDisconnectFromHost(true); | 307 | doDisconnectFromHost(true); | ||
304 | } | 308 | } | ||
305 | } | 309 | } | ||
306 | } | 310 | } | ||
307 | 311 | | |||
308 | // Called in secondary thread | 312 | // Called in secondary thread | ||
309 | bool SessionThread::saslInteract(void *in) | 313 | bool SessionThread::saslInteract(void *in) | ||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |