Changeset View
Changeset View
Standalone View
Standalone View
src/kpasswdserver/kpasswdserver.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
52 | static qlonglong getRequestId() | 52 | static qlonglong getRequestId() | ||
53 | { | 53 | { | ||
54 | static qlonglong nextRequestId = 0; | 54 | static qlonglong nextRequestId = 0; | ||
55 | return nextRequestId++; | 55 | return nextRequestId++; | ||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | bool KPasswdServer::AuthInfoContainer::Sorter::operator()(AuthInfoContainer *n1, AuthInfoContainer *n2) const | 58 | bool KPasswdServer::AuthInfoContainer::Sorter::operator()(AuthInfoContainer *n1, AuthInfoContainer *n2) const | ||
59 | { | 59 | { | ||
60 | if (!n1 || !n2) | 60 | if (!n1 || !n2) { | ||
61 | return 0; | 61 | return 0; | ||
62 | } | ||||
62 | 63 | | |||
63 | const int l1 = n1->directory.length(); | 64 | const int l1 = n1->directory.length(); | ||
64 | const int l2 = n2->directory.length(); | 65 | const int l2 = n2->directory.length(); | ||
65 | return l1 < l2; | 66 | return l1 < l2; | ||
66 | } | 67 | } | ||
67 | 68 | | |||
68 | KPasswdServer::KPasswdServer(QObject *parent, const QList<QVariant> &) | 69 | KPasswdServer::KPasswdServer(QObject *parent, const QList<QVariant> &) | ||
69 | : KDEDModule(parent) | 70 | : KDEDModule(parent) | ||
Show All 36 Lines | |||||
106 | { | 107 | { | ||
107 | return realm.isEmpty() ? key : key + QLatin1Char('-') + realm; | 108 | return realm.isEmpty() ? key : key + QLatin1Char('-') + realm; | ||
108 | } | 109 | } | ||
109 | 110 | | |||
110 | // Helper for storeInWallet/readFromWallet | 111 | // Helper for storeInWallet/readFromWallet | ||
111 | static QString makeMapKey(const char *key, int entryNumber) | 112 | static QString makeMapKey(const char *key, int entryNumber) | ||
112 | { | 113 | { | ||
113 | QString str = QLatin1String(key); | 114 | QString str = QLatin1String(key); | ||
114 | if (entryNumber > 1) | 115 | if (entryNumber > 1) { | ||
115 | str += QLatin1Char('-') + QString::number(entryNumber); | 116 | str += QLatin1Char('-') + QString::number(entryNumber); | ||
117 | } | ||||
116 | return str; | 118 | return str; | ||
117 | } | 119 | } | ||
118 | 120 | | |||
119 | static bool storeInWallet(KWallet::Wallet *wallet, const QString &key, const KIO::AuthInfo &info) | 121 | static bool storeInWallet(KWallet::Wallet *wallet, const QString &key, const KIO::AuthInfo &info) | ||
120 | { | 122 | { | ||
121 | if (!wallet->hasFolder(KWallet::Wallet::PasswordFolder())) | 123 | if (!wallet->hasFolder(KWallet::Wallet::PasswordFolder())) { | ||
122 | if (!wallet->createFolder(KWallet::Wallet::PasswordFolder())) | 124 | if (!wallet->createFolder(KWallet::Wallet::PasswordFolder())) { | ||
123 | return false; | 125 | return false; | ||
126 | } | ||||
127 | } | ||||
124 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | 128 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | ||
125 | // Before saving, check if there's already an entry with this login. | 129 | // Before saving, check if there's already an entry with this login. | ||
126 | // If so, replace it (with the new password). Otherwise, add a new entry. | 130 | // If so, replace it (with the new password). Otherwise, add a new entry. | ||
127 | typedef QMap<QString, QString> Map; | 131 | typedef QMap<QString, QString> Map; | ||
128 | int entryNumber = 1; | 132 | int entryNumber = 1; | ||
129 | Map map; | 133 | Map map; | ||
130 | QString walletKey = makeWalletKey(key, info.realmValue); | 134 | QString walletKey = makeWalletKey(key, info.realmValue); | ||
131 | qCDebug(category) << "walletKey =" << walletKey << " reading existing map"; | 135 | qCDebug(category) << "walletKey =" << walletKey << " reading existing map"; | ||
Show All 13 Lines | |||||
145 | qCDebug(category) << "writing to " << loginKey << "," << passwordKey; | 149 | qCDebug(category) << "writing to " << loginKey << "," << passwordKey; | ||
146 | // note the overwrite=true by default | 150 | // note the overwrite=true by default | ||
147 | map.insert(loginKey, info.username); | 151 | map.insert(loginKey, info.username); | ||
148 | map.insert(passwordKey, info.password); | 152 | map.insert(passwordKey, info.password); | ||
149 | wallet->writeMap(walletKey, map); | 153 | wallet->writeMap(walletKey, map); | ||
150 | return true; | 154 | return true; | ||
151 | } | 155 | } | ||
152 | 156 | | |||
153 | static bool readFromWallet(KWallet::Wallet *wallet, const QString &key, const QString &realm, QString &username, QString &password, bool userReadOnly, QMap<QString, QString> &knownLogins) | 157 | static bool readFromWallet(KWallet::Wallet *wallet, const QString &key, const QString &realm, QString &username, | ||
158 | QString &password, bool userReadOnly, QMap<QString, QString> &knownLogins) | ||||
154 | { | 159 | { | ||
155 | // qCDebug(category) << "key =" << key << " username =" << username << " password =" /*<< password*/ << " userReadOnly =" << userReadOnly << " realm =" << realm; | 160 | // qCDebug(category) << "key =" << key << " username =" << username << " password =" /*<< password*/ | ||
161 | // << " userReadOnly =" << userReadOnly << " realm =" << realm; | ||||
156 | if (wallet->hasFolder(KWallet::Wallet::PasswordFolder())) { | 162 | if (wallet->hasFolder(KWallet::Wallet::PasswordFolder())) { | ||
157 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | 163 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | ||
158 | 164 | | |||
159 | QMap<QString, QString> map; | 165 | QMap<QString, QString> map; | ||
160 | if (wallet->readMap(makeWalletKey(key, realm), map) == 0) { | 166 | if (wallet->readMap(makeWalletKey(key, realm), map) == 0) { | ||
161 | typedef QMap<QString, QString> Map; | 167 | typedef QMap<QString, QString> Map; | ||
162 | int entryNumber = 1; | 168 | int entryNumber = 1; | ||
163 | Map::ConstIterator end = map.constEnd(); | 169 | Map::ConstIterator end = map.constEnd(); | ||
164 | Map::ConstIterator it = map.constFind(QStringLiteral("login")); | 170 | Map::ConstIterator it = map.constFind(QStringLiteral("login")); | ||
165 | while (it != end) { | 171 | while (it != end) { | ||
166 | // qCDebug(category) << "found " << it.key() << "=" << it.value(); | 172 | // qCDebug(category) << "found " << it.key() << "=" << it.value(); | ||
167 | Map::ConstIterator pwdIter = map.constFind(makeMapKey("password", entryNumber)); | 173 | Map::ConstIterator pwdIter = map.constFind(makeMapKey("password", entryNumber)); | ||
168 | if (pwdIter != end) { | 174 | if (pwdIter != end) { | ||
169 | if (it.value() == username) | 175 | if (it.value() == username) { | ||
170 | password = pwdIter.value(); | 176 | password = pwdIter.value(); | ||
177 | } | ||||
171 | knownLogins.insert(it.value(), pwdIter.value()); | 178 | knownLogins.insert(it.value(), pwdIter.value()); | ||
172 | } | 179 | } | ||
173 | 180 | | |||
174 | it = map.constFind(QStringLiteral("login-") + QString::number(++entryNumber)); | 181 | it = map.constFind(QStringLiteral("login-") + QString::number(++entryNumber)); | ||
175 | } | 182 | } | ||
176 | // qCDebug(category) << knownLogins.count() << " known logins"; | 183 | // qCDebug(category) << knownLogins.count() << " known logins"; | ||
177 | 184 | | |||
178 | if (!userReadOnly && !knownLogins.isEmpty() && username.isEmpty()) { | 185 | if (!userReadOnly && !knownLogins.isEmpty() && username.isEmpty()) { | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 234 | if (hasPendingQuery(key, info)) { | |||
236 | m_authWait.append(pendingCheck); | 243 | m_authWait.append(pendingCheck); | ||
237 | return data; // return value will be ignored | 244 | return data; // return value will be ignored | ||
238 | } | 245 | } | ||
239 | 246 | | |||
240 | // qCDebug(category) << "key =" << key << "user =" << info.username << "windowId =" << windowId; | 247 | // qCDebug(category) << "key =" << key << "user =" << info.username << "windowId =" << windowId; | ||
241 | const AuthInfoContainer *result = findAuthInfoItem(key, info); | 248 | const AuthInfoContainer *result = findAuthInfoItem(key, info); | ||
242 | if (!result || result->isCanceled) { | 249 | if (!result || result->isCanceled) { | ||
243 | #ifdef HAVE_KF5WALLET | 250 | #ifdef HAVE_KF5WALLET | ||
244 | if (!result && !m_walletDisabled && (info.username.isEmpty() || info.password.isEmpty()) && | 251 | if (!result | ||
245 | !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), makeWalletKey(key, info.realmValue))) { | 252 | && !m_walletDisabled | ||
253 | && (info.username.isEmpty() || info.password.isEmpty()) | ||||
254 | && !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), | ||||
255 | makeWalletKey(key, info.realmValue))) { | ||||
246 | QMap<QString, QString> knownLogins; | 256 | QMap<QString, QString> knownLogins; | ||
247 | if (openWallet(windowId)) { | 257 | if (openWallet(windowId)) { | ||
248 | if (readFromWallet(m_wallet, key, info.realmValue, info.username, info.password, info.readOnly, knownLogins)) { | 258 | if (readFromWallet(m_wallet, key, info.realmValue, info.username, | ||
259 | info.password, info.readOnly, knownLogins)) { | ||||
249 | info.setModified(true); | 260 | info.setModified(true); | ||
250 | // fall through | 261 | // fall through | ||
251 | } | 262 | } | ||
252 | } | 263 | } | ||
253 | } else { | 264 | } else { | ||
254 | info.setModified(false); | 265 | info.setModified(false); | ||
255 | } | 266 | } | ||
256 | #else | 267 | #else | ||
Show All 36 Lines | 299 | if (hasPendingQuery(key, info)) { | |||
293 | pendingCheck->info = info; | 304 | pendingCheck->info = info; | ||
294 | m_authWait.append(pendingCheck); | 305 | m_authWait.append(pendingCheck); | ||
295 | return 0; // ignored as we already sent a reply | 306 | return 0; // ignored as we already sent a reply | ||
296 | } | 307 | } | ||
297 | 308 | | |||
298 | const AuthInfoContainer *result = findAuthInfoItem(key, info); | 309 | const AuthInfoContainer *result = findAuthInfoItem(key, info); | ||
299 | if (!result || result->isCanceled) { | 310 | if (!result || result->isCanceled) { | ||
300 | #ifdef HAVE_KF5WALLET | 311 | #ifdef HAVE_KF5WALLET | ||
301 | if (!result && !m_walletDisabled && (info.username.isEmpty() || info.password.isEmpty()) && | 312 | if (!result | ||
302 | !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), makeWalletKey(key, info.realmValue))) { | 313 | && !m_walletDisabled | ||
314 | && (info.username.isEmpty() || info.password.isEmpty()) | ||||
315 | && !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), | ||||
316 | makeWalletKey(key, info.realmValue))) { | ||||
303 | QMap<QString, QString> knownLogins; | 317 | QMap<QString, QString> knownLogins; | ||
304 | if (openWallet(windowId)) { | 318 | if (openWallet(windowId)) { | ||
305 | if (readFromWallet(m_wallet, key, info.realmValue, info.username, info.password, info.readOnly, knownLogins)) { | 319 | if (readFromWallet(m_wallet, key, info.realmValue, info.username, | ||
320 | info.password, info.readOnly, knownLogins)) { | ||||
306 | info.setModified(true); | 321 | info.setModified(true); | ||
307 | // fall through | 322 | // fall through | ||
308 | } | 323 | } | ||
309 | } | 324 | } | ||
310 | } else { | 325 | } else { | ||
311 | info.setModified(false); | 326 | info.setModified(false); | ||
312 | } | 327 | } | ||
313 | #else | 328 | #else | ||
314 | info.setModified(false); | 329 | info.setModified(false); | ||
315 | #endif | 330 | #endif | ||
316 | } else { | 331 | } else { | ||
317 | // qCDebug(category) << "Found cached authentication for" << key; | 332 | // qCDebug(category) << "Found cached authentication for" << key; | ||
318 | updateAuthExpire(key, result, windowId, false); | 333 | updateAuthExpire(key, result, windowId, false); | ||
319 | copyAuthInfo(result, info); | 334 | copyAuthInfo(result, info); | ||
320 | } | 335 | } | ||
321 | 336 | | |||
322 | emit checkAuthInfoAsyncResult(requestId, m_seqNr, info); | 337 | emit checkAuthInfoAsyncResult(requestId, m_seqNr, info); | ||
323 | return 0; // ignored | 338 | return 0; // ignored | ||
324 | } | 339 | } | ||
325 | 340 | | |||
326 | // deprecated method, not used anymore. TODO KF6: REMOVE | 341 | // deprecated method, not used anymore. TODO KF6: REMOVE | ||
327 | QByteArray KPasswdServer::queryAuthInfo(const QByteArray &data, const QString &errorMsg, qlonglong windowId, qlonglong seqNr, qlonglong usertime) | 342 | QByteArray KPasswdServer::queryAuthInfo(const QByteArray &data, const QString &errorMsg, | ||
343 | qlonglong windowId, qlonglong seqNr, qlonglong usertime) | ||||
328 | { | 344 | { | ||
329 | KIO::AuthInfo info; | 345 | KIO::AuthInfo info; | ||
330 | QDataStream stream(data); | 346 | QDataStream stream(data); | ||
331 | stream >> info; | 347 | stream >> info; | ||
332 | 348 | | |||
333 | qCDebug(category) << "User =" << info.username << ", WindowId =" << windowId << "seqNr =" << seqNr << ", errorMsg =" << errorMsg; | 349 | qCDebug(category) << "User =" << info.username << ", WindowId =" << windowId | ||
350 | << "seqNr =" << seqNr << ", errorMsg =" << errorMsg; | ||||
334 | 351 | | |||
335 | if (!info.password.isEmpty()) { // should we really allow the caller to pre-fill the password? | 352 | if (!info.password.isEmpty()) { // should we really allow the caller to pre-fill the password? | ||
336 | qCDebug(category) << "password was set by caller"; | 353 | qCDebug(category) << "password was set by caller"; | ||
337 | } | 354 | } | ||
338 | if (usertime != 0) { | 355 | if (usertime != 0) { | ||
339 | KUserTimestamp::updateUserTimestamp(usertime); | 356 | KUserTimestamp::updateUserTimestamp(usertime); | ||
340 | } | 357 | } | ||
341 | 358 | | |||
Show All 10 Lines | 368 | if (errorMsg == QLatin1String("<NoAuthPrompt>")) { | |||
352 | request->errorMsg.clear(); | 369 | request->errorMsg.clear(); | ||
353 | request->prompt = false; | 370 | request->prompt = false; | ||
354 | } else { | 371 | } else { | ||
355 | request->errorMsg = errorMsg; | 372 | request->errorMsg = errorMsg; | ||
356 | request->prompt = true; | 373 | request->prompt = true; | ||
357 | } | 374 | } | ||
358 | m_authPending.append(request); | 375 | m_authPending.append(request); | ||
359 | 376 | | |||
360 | if (m_authPending.count() == 1) | 377 | if (m_authPending.count() == 1) { | ||
361 | QTimer::singleShot(0, this, &KPasswdServer::processRequest); | 378 | QTimer::singleShot(0, this, &KPasswdServer::processRequest); | ||
379 | } | ||||
362 | 380 | | |||
363 | return QByteArray(); // return value is going to be ignored | 381 | return QByteArray(); // return value is going to be ignored | ||
364 | } | 382 | } | ||
365 | 383 | | |||
366 | qlonglong KPasswdServer::queryAuthInfoAsync(const KIO::AuthInfo &info, const QString &errorMsg, qlonglong windowId, qlonglong seqNr, qlonglong usertime) | 384 | qlonglong KPasswdServer::queryAuthInfoAsync(const KIO::AuthInfo &info, const QString &errorMsg, | ||
385 | qlonglong windowId,qlonglong seqNr, qlonglong usertime) | ||||
367 | { | 386 | { | ||
368 | qCDebug(category) << "User =" << info.username << ", WindowId =" << windowId << "seqNr =" << seqNr << ", errorMsg =" << errorMsg; | 387 | qCDebug(category) << "User =" << info.username << ", WindowId =" << windowId | ||
388 | << "seqNr =" << seqNr << ", errorMsg =" << errorMsg; | ||||
369 | 389 | | |||
370 | if (!info.password.isEmpty()) { | 390 | if (!info.password.isEmpty()) { | ||
371 | qCDebug(category) << "password was set by caller"; | 391 | qCDebug(category) << "password was set by caller"; | ||
372 | } | 392 | } | ||
373 | if (usertime != 0) { | 393 | if (usertime != 0) { | ||
374 | KUserTimestamp::updateUserTimestamp(usertime); | 394 | KUserTimestamp::updateUserTimestamp(usertime); | ||
375 | } | 395 | } | ||
376 | 396 | | |||
Show All 18 Lines | 414 | if (m_authPending.count() == 1) { | |||
395 | QTimer::singleShot(0, this, &KPasswdServer::processRequest); | 415 | QTimer::singleShot(0, this, &KPasswdServer::processRequest); | ||
396 | } | 416 | } | ||
397 | 417 | | |||
398 | return request->requestId; | 418 | return request->requestId; | ||
399 | } | 419 | } | ||
400 | 420 | | |||
401 | void KPasswdServer::addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId) | 421 | void KPasswdServer::addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId) | ||
402 | { | 422 | { | ||
403 | qCDebug(category) << "User =" << info.username << ", Realm =" << info.realmValue << ", WindowId =" << windowId; | 423 | qCDebug(category) << "User =" << info.username << ", Realm =" << info.realmValue | ||
424 | << ", WindowId =" << windowId; | ||||
404 | const QString key(createCacheKey(info)); | 425 | const QString key(createCacheKey(info)); | ||
405 | 426 | | |||
406 | m_seqNr++; | 427 | m_seqNr++; | ||
407 | 428 | | |||
408 | #ifdef HAVE_KF5WALLET | 429 | #ifdef HAVE_KF5WALLET | ||
409 | if (!m_walletDisabled && openWallet(windowId) && storeInWallet(m_wallet, key, info)) { | 430 | if (!m_walletDisabled && openWallet(windowId) && storeInWallet(m_wallet, key, info)) { | ||
410 | // Since storing the password in the wallet succeeded, make sure the | 431 | // Since storing the password in the wallet succeeded, make sure the | ||
411 | // password information is stored in memory only for the duration the | 432 | // password information is stored in memory only for the duration the | ||
Show All 21 Lines | |||||
433 | { | 454 | { | ||
434 | qCDebug(category) << protocol << host << user; | 455 | qCDebug(category) << protocol << host << user; | ||
435 | 456 | | |||
436 | QHashIterator<QString, AuthInfoContainerList *> dictIterator(m_authDict); | 457 | QHashIterator<QString, AuthInfoContainerList *> dictIterator(m_authDict); | ||
437 | while (dictIterator.hasNext()) { | 458 | while (dictIterator.hasNext()) { | ||
438 | dictIterator.next(); | 459 | dictIterator.next(); | ||
439 | 460 | | |||
440 | const AuthInfoContainerList *authList = dictIterator.value(); | 461 | const AuthInfoContainerList *authList = dictIterator.value(); | ||
441 | if (!authList) | 462 | if (!authList) { | ||
442 | continue; | 463 | continue; | ||
464 | } | ||||
443 | 465 | | |||
444 | for (const AuthInfoContainer *current : *authList) { | 466 | for (const AuthInfoContainer *current : *authList) { | ||
445 | qCDebug(category) << "Evaluating: " << current->info.url.scheme() << current->info.url.host() << current->info.username; | 467 | qCDebug(category) << "Evaluating: " << current->info.url.scheme() | ||
446 | if (current->info.url.scheme() == protocol && current->info.url.host() == host && (current->info.username == user || user.isEmpty())) { | 468 | << current->info.url.host() << current->info.username; | ||
469 | if (current->info.url.scheme() == protocol | ||||
470 | && current->info.url.host() == host | ||||
471 | && (current->info.username == user || user.isEmpty())) { | ||||
447 | qCDebug(category) << "Removing this entry"; | 472 | qCDebug(category) << "Removing this entry"; | ||
448 | removeAuthInfoItem(dictIterator.key(), current->info); | 473 | removeAuthInfoItem(dictIterator.key(), current->info); | ||
449 | } | 474 | } | ||
450 | } | 475 | } | ||
451 | } | 476 | } | ||
452 | } | 477 | } | ||
453 | 478 | | |||
454 | #ifdef HAVE_KF5WALLET | 479 | #ifdef HAVE_KF5WALLET | ||
455 | bool KPasswdServer::openWallet(qlonglong windowId) | 480 | bool KPasswdServer::openWallet(qlonglong windowId) | ||
456 | { | 481 | { | ||
457 | if (m_wallet && !m_wallet->isOpen()) { // forced closed | 482 | if (m_wallet && !m_wallet->isOpen()) { // forced closed | ||
458 | delete m_wallet; | 483 | delete m_wallet; | ||
459 | m_wallet = nullptr; | 484 | m_wallet = nullptr; | ||
460 | } | 485 | } | ||
461 | if (!m_wallet) | 486 | if (!m_wallet) { | ||
462 | m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), (WId)(windowId)); | 487 | m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), (WId)(windowId)); | ||
488 | } | ||||
463 | return m_wallet != nullptr; | 489 | return m_wallet != nullptr; | ||
464 | } | 490 | } | ||
465 | #endif | 491 | #endif | ||
466 | 492 | | |||
467 | void KPasswdServer::processRequest() | 493 | void KPasswdServer::processRequest() | ||
468 | { | 494 | { | ||
469 | if (m_authPending.isEmpty()) { | 495 | if (m_authPending.isEmpty()) { | ||
470 | return; | 496 | return; | ||
Show All 18 Lines | |||||
489 | // info.username to info.url.userName() to ensure proper caching. See | 515 | // info.username to info.url.userName() to ensure proper caching. See | ||
490 | // note passwordDialogDone. | 516 | // note passwordDialogDone. | ||
491 | if (info.username.isEmpty() && !info.url.userName().isEmpty()) { | 517 | if (info.username.isEmpty() && !info.url.userName().isEmpty()) { | ||
492 | info.username = info.url.userName(); | 518 | info.username = info.url.userName(); | ||
493 | } | 519 | } | ||
494 | const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool(); | 520 | const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool(); | ||
495 | 521 | | |||
496 | const AuthInfoContainer *result = findAuthInfoItem(request->key, request->info); | 522 | const AuthInfoContainer *result = findAuthInfoItem(request->key, request->info); | ||
497 | qCDebug(category) << "key=" << request->key << ", user=" << info.username << "seqNr: request=" << request->seqNr << ", result=" << (result ? result->seqNr : -1); | 523 | qCDebug(category) << "key=" << request->key << ", user=" << info.username | ||
524 | << "seqNr: request=" << request->seqNr | ||||
525 | <<", result=" << (result ? result->seqNr : -1); | ||||
498 | 526 | | |||
499 | if (!bypassCacheAndKWallet && result && (request->seqNr < result->seqNr)) { | 527 | if (!bypassCacheAndKWallet && result && (request->seqNr < result->seqNr)) { | ||
500 | qCDebug(category) << "auto retry!"; | 528 | qCDebug(category) << "auto retry!"; | ||
501 | if (result->isCanceled) { | 529 | if (result->isCanceled) { | ||
502 | info.setModified(false); | 530 | info.setModified(false); | ||
503 | } else { | 531 | } else { | ||
504 | updateAuthExpire(request->key, result, request->windowId, false); | 532 | updateAuthExpire(request->key, result, request->windowId, false); | ||
505 | copyAuthInfo(result, info); | 533 | copyAuthInfo(result, info); | ||
506 | } | 534 | } | ||
507 | } else { | 535 | } else { | ||
508 | m_seqNr++; | 536 | m_seqNr++; | ||
509 | if (result && !request->errorMsg.isEmpty()) { | 537 | if (result && !request->errorMsg.isEmpty()) { | ||
510 | const QString prompt = request->errorMsg.trimmed() + QLatin1Char('\n') + i18n("Do you want to retry?"); | 538 | const QString prompt = request->errorMsg.trimmed() + QLatin1Char('\n') + i18n("Do you want to retry?"); | ||
511 | 539 | | |||
512 | QDialog *dlg = new QDialog; | 540 | QDialog *dlg = new QDialog; | ||
513 | connect(dlg, &QDialog::finished, this, &KPasswdServer::retryDialogDone); | 541 | connect(dlg, &QDialog::finished, this, &KPasswdServer::retryDialogDone); | ||
514 | connect(this, &QObject::destroyed, dlg, &QObject::deleteLater); | 542 | connect(this, &QObject::destroyed, dlg, &QObject::deleteLater); | ||
515 | dlg->setWindowTitle(i18n("Retry Authentication")); | 543 | dlg->setWindowTitle(i18n("Retry Authentication")); | ||
516 | dlg->setWindowIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); | 544 | dlg->setWindowIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); | ||
517 | dlg->setObjectName(QStringLiteral("warningOKCancel")); | 545 | dlg->setObjectName(QStringLiteral("warningOKCancel")); | ||
518 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::Cancel); | 546 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::Cancel); | ||
519 | buttonBox->button(QDialogButtonBox::Yes)->setText(i18nc("@action:button filter-continue", "Retry")); | 547 | buttonBox->button(QDialogButtonBox::Yes)->setText(i18nc("@action:button filter-continue", "Retry")); | ||
520 | 548 | | |||
521 | KMessageBox::createKMessageBox(dlg, buttonBox, QMessageBox::Warning, prompt, QStringList(), QString(), nullptr, (KMessageBox::Notify | KMessageBox::NoExec)); | 549 | KMessageBox::createKMessageBox(dlg, buttonBox, QMessageBox::Warning, prompt, QStringList(), | ||
550 | QString(), nullptr, (KMessageBox::Notify | KMessageBox::NoExec)); | ||||
522 | 551 | | |||
523 | dlg->setAttribute(Qt::WA_NativeWindow, true); | 552 | dlg->setAttribute(Qt::WA_NativeWindow, true); | ||
524 | KWindowSystem::setMainWindow(dlg->windowHandle(), request->windowId); | 553 | KWindowSystem::setMainWindow(dlg->windowHandle(), request->windowId); | ||
525 | 554 | | |||
526 | qCDebug(category) << "Calling open on retry dialog" << dlg; | 555 | qCDebug(category) << "Calling open on retry dialog" << dlg; | ||
527 | m_authRetryInProgress.insert(dlg, request.take()); | 556 | m_authRetryInProgress.insert(dlg, request.take()); | ||
528 | dlg->open(); | 557 | dlg->open(); | ||
529 | return; | 558 | return; | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 605 | { | |||
577 | // qCDebug(category) << "key=" << key << ", user=" << info.username; | 606 | // qCDebug(category) << "key=" << key << ", user=" << info.username; | ||
578 | 607 | | |||
579 | AuthInfoContainerList *authList = m_authDict.value(key); | 608 | AuthInfoContainerList *authList = m_authDict.value(key); | ||
580 | if (authList) { | 609 | if (authList) { | ||
581 | QString path2 = info.url.path().left(info.url.path().indexOf(QLatin1Char('/')) + 1); | 610 | QString path2 = info.url.path().left(info.url.path().indexOf(QLatin1Char('/')) + 1); | ||
582 | auto it = authList->begin(); | 611 | auto it = authList->begin(); | ||
583 | while (it != authList->end()) { | 612 | while (it != authList->end()) { | ||
584 | AuthInfoContainer *current = (*it); | 613 | AuthInfoContainer *current = (*it); | ||
585 | if (current->expire == AuthInfoContainer::expTime && static_cast<qulonglong>(time(nullptr)) > current->expireTime) { | 614 | if (current->expire == AuthInfoContainer::expTime | ||
615 | && static_cast<qulonglong>(time(nullptr)) > current->expireTime) { | ||||
586 | delete current; | 616 | delete current; | ||
587 | it = authList->erase(it); | 617 | it = authList->erase(it); | ||
588 | continue; | 618 | continue; | ||
589 | } | 619 | } | ||
590 | 620 | | |||
591 | if (info.verifyPath) { | 621 | if (info.verifyPath) { | ||
592 | QString path1 = current->directory; | 622 | QString path1 = current->directory; | ||
593 | if (path2.startsWith(path1) && (info.username.isEmpty() || info.username == current->info.username)) | 623 | if (path2.startsWith(path1) | ||
624 | && (info.username.isEmpty() || info.username == current->info.username)) | ||||
594 | return current; | 625 | return current; | ||
595 | } else { | 626 | } else { | ||
596 | if (current->info.realmValue == info.realmValue && (info.username.isEmpty() || info.username == current->info.username)) | 627 | if (current->info.realmValue == info.realmValue | ||
628 | && (info.username.isEmpty() || info.username == current->info.username)) | ||||
597 | return current; // TODO: Update directory info, | 629 | return current; // TODO: Update directory info, | ||
598 | } | 630 | } | ||
599 | 631 | | |||
600 | ++it; | 632 | ++it; | ||
601 | } | 633 | } | ||
602 | } | 634 | } | ||
603 | return nullptr; | 635 | return nullptr; | ||
604 | } | 636 | } | ||
Show All 13 Lines | 649 | } else { | |||
618 | ++it; | 650 | ++it; | ||
619 | } | 651 | } | ||
620 | } | 652 | } | ||
621 | if (authList->isEmpty()) { | 653 | if (authList->isEmpty()) { | ||
622 | delete m_authDict.take(key); | 654 | delete m_authDict.take(key); | ||
623 | } | 655 | } | ||
624 | } | 656 | } | ||
625 | 657 | | |||
626 | void KPasswdServer::addAuthInfoItem(const QString &key, const KIO::AuthInfo &info, qlonglong windowId, qlonglong seqNr, bool canceled) | 658 | void KPasswdServer::addAuthInfoItem(const QString &key, const KIO::AuthInfo &info, | ||
659 | qlonglong windowId, qlonglong seqNr, bool canceled) | ||||
627 | { | 660 | { | ||
628 | qCDebug(category) << "key=" << key << "window-id=" << windowId << "username=" << info.username << "realm=" << info.realmValue << "seqNr=" << seqNr << "keepPassword?" << info.keepPassword << "canceled?" << canceled; | 661 | qCDebug(category) << "key=" << key << "window-id=" << windowId << "username=" << info.username | ||
662 | << "realm=" << info.realmValue << "seqNr=" << seqNr | ||||
663 | << "keepPassword?" << info.keepPassword << "canceled?" << canceled; | ||||
629 | AuthInfoContainerList *authList = m_authDict.value(key); | 664 | AuthInfoContainerList *authList = m_authDict.value(key); | ||
630 | if (!authList) { | 665 | if (!authList) { | ||
631 | authList = new AuthInfoContainerList; | 666 | authList = new AuthInfoContainerList; | ||
632 | m_authDict.insert(key, authList); | 667 | m_authDict.insert(key, authList); | ||
633 | } | 668 | } | ||
634 | AuthInfoContainer *authItem = nullptr; | 669 | AuthInfoContainer *authItem = nullptr; | ||
635 | auto it = authList->begin(); | 670 | auto it = authList->begin(); | ||
636 | while (it != authList->end()) { | 671 | while (it != authList->end()) { | ||
Show All 19 Lines | |||||
656 | 691 | | |||
657 | updateAuthExpire(key, authItem, windowId, (info.keepPassword && !canceled)); | 692 | updateAuthExpire(key, authItem, windowId, (info.keepPassword && !canceled)); | ||
658 | 693 | | |||
659 | // Insert into list, keep the list sorted "longest path" first. | 694 | // Insert into list, keep the list sorted "longest path" first. | ||
660 | authList->append(authItem); | 695 | authList->append(authItem); | ||
661 | std::sort(authList->begin(), authList->end(), AuthInfoContainer::Sorter()); | 696 | std::sort(authList->begin(), authList->end(), AuthInfoContainer::Sorter()); | ||
662 | } | 697 | } | ||
663 | 698 | | |||
664 | void KPasswdServer::updateAuthExpire(const QString &key, const AuthInfoContainer *auth, qlonglong windowId, bool keep) | 699 | void KPasswdServer::updateAuthExpire(const QString &key, const AuthInfoContainer *auth, | ||
700 | qlonglong windowId, bool keep) | ||||
665 | { | 701 | { | ||
666 | AuthInfoContainer *current = const_cast<AuthInfoContainer *>(auth); | 702 | AuthInfoContainer *current = const_cast<AuthInfoContainer *>(auth); | ||
667 | Q_ASSERT(current); | 703 | Q_ASSERT(current); | ||
668 | 704 | | |||
669 | qCDebug(category) << "key=" << key << "expire=" << current->expire << "window-id=" << windowId << "keep=" << keep; | 705 | qCDebug(category) << "key=" << key << "expire=" << current->expire | ||
706 | << "window-id=" << windowId << "keep=" << keep; | ||||
670 | 707 | | |||
671 | if (keep && !windowId) { | 708 | if (keep && !windowId) { | ||
672 | current->expire = AuthInfoContainer::expNever; | 709 | current->expire = AuthInfoContainer::expNever; | ||
673 | } else if (windowId && (current->expire != AuthInfoContainer::expNever)) { | 710 | } else if (windowId && (current->expire != AuthInfoContainer::expNever)) { | ||
674 | current->expire = AuthInfoContainer::expWindowClose; | 711 | current->expire = AuthInfoContainer::expWindowClose; | ||
675 | if (!current->windowList.contains(windowId)) | 712 | if (!current->windowList.contains(windowId)) { | ||
676 | current->windowList.append(windowId); | 713 | current->windowList.append(windowId); | ||
714 | } | ||||
677 | } else if (current->expire == AuthInfoContainer::expTime) { | 715 | } else if (current->expire == AuthInfoContainer::expTime) { | ||
678 | current->expireTime = time(nullptr) + 10; | 716 | current->expireTime = time(nullptr) + 10; | ||
679 | } | 717 | } | ||
680 | 718 | | |||
681 | // Update mWindowIdList | 719 | // Update mWindowIdList | ||
682 | if (windowId) { | 720 | if (windowId) { | ||
683 | QStringList &keysChanged = mWindowIdList[windowId]; // find or insert | 721 | QStringList &keysChanged = mWindowIdList[windowId]; // find or insert | ||
684 | if (!keysChanged.contains(key)) | 722 | if (!keysChanged.contains(key)) | ||
685 | keysChanged.append(key); | 723 | keysChanged.append(key); | ||
686 | } | 724 | } | ||
687 | } | 725 | } | ||
688 | 726 | | |||
689 | void KPasswdServer::removeAuthForWindowId(qlonglong windowId) | 727 | void KPasswdServer::removeAuthForWindowId(qlonglong windowId) | ||
690 | { | 728 | { | ||
691 | const QStringList keysChanged = mWindowIdList.value(windowId); | 729 | const QStringList keysChanged = mWindowIdList.value(windowId); | ||
692 | for (const QString &key : keysChanged) { | 730 | for (const QString &key : keysChanged) { | ||
693 | AuthInfoContainerList *authList = m_authDict.value(key); | 731 | AuthInfoContainerList *authList = m_authDict.value(key); | ||
694 | if (!authList) | 732 | if (!authList) { | ||
695 | continue; | 733 | continue; | ||
734 | } | ||||
696 | 735 | | |||
697 | QMutableListIterator<AuthInfoContainer *> it(*authList); | 736 | QMutableListIterator<AuthInfoContainer *> it(*authList); | ||
698 | while (it.hasNext()) { | 737 | while (it.hasNext()) { | ||
699 | AuthInfoContainer *current = it.next(); | 738 | AuthInfoContainer *current = it.next(); | ||
700 | if (current->expire == AuthInfoContainer::expWindowClose) { | 739 | if (current->expire == AuthInfoContainer::expWindowClose) { | ||
701 | if (current->windowList.removeAll(windowId) && current->windowList.isEmpty()) { | 740 | if (current->windowList.removeAll(windowId) && current->windowList.isEmpty()) { | ||
702 | delete current; | 741 | delete current; | ||
703 | it.remove(); | 742 | it.remove(); | ||
704 | } | 743 | } | ||
705 | } | 744 | } | ||
706 | } | 745 | } | ||
707 | } | 746 | } | ||
708 | } | 747 | } | ||
709 | 748 | | |||
710 | void KPasswdServer::showPasswordDialog(KPasswdServer::Request *request) | 749 | void KPasswdServer::showPasswordDialog(KPasswdServer::Request *request) | ||
711 | { | 750 | { | ||
712 | KIO::AuthInfo &info = request->info; | 751 | KIO::AuthInfo &info = request->info; | ||
713 | QString username = info.username; | 752 | QString username = info.username; | ||
714 | QString password = info.password; | 753 | QString password = info.password; | ||
715 | bool hasWalletData = false; | 754 | bool hasWalletData = false; | ||
716 | QMap<QString, QString> knownLogins; | 755 | QMap<QString, QString> knownLogins; | ||
717 | 756 | | |||
718 | #ifdef HAVE_KF5WALLET | 757 | #ifdef HAVE_KF5WALLET | ||
719 | const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool(); | 758 | const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool(); | ||
720 | if (!bypassCacheAndKWallet && (username.isEmpty() || password.isEmpty()) && !m_walletDisabled && | 759 | if (!bypassCacheAndKWallet | ||
721 | !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), makeWalletKey(request->key, info.realmValue))) { | 760 | && (username.isEmpty() || password.isEmpty()) | ||
761 | && !m_walletDisabled | ||||
762 | && !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), | ||||
763 | makeWalletKey(request->key, info.realmValue))) { | ||||
722 | // no login+pass provided, check if kwallet has one | 764 | // no login+pass provided, check if kwallet has one | ||
723 | if (openWallet(request->windowId)) | 765 | if (openWallet(request->windowId)) { | ||
724 | hasWalletData = readFromWallet(m_wallet, request->key, info.realmValue, username, password, info.readOnly, knownLogins); | 766 | hasWalletData = readFromWallet(m_wallet, request->key, info.realmValue, | ||
767 | username, password, info.readOnly, knownLogins); | ||||
768 | } | ||||
725 | } | 769 | } | ||
726 | #endif | 770 | #endif | ||
727 | 771 | | |||
728 | // assemble dialog-flags | 772 | // assemble dialog-flags | ||
729 | KPasswordDialog::KPasswordDialogFlags dialogFlags; | 773 | KPasswordDialog::KPasswordDialogFlags dialogFlags; | ||
730 | 774 | | |||
731 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).isValid()) { | 775 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).isValid()) { | ||
732 | dialogFlags |= KPasswordDialog::ShowDomainLine; | 776 | dialogFlags |= KPasswordDialog::ShowDomainLine; | ||
733 | if (info.getExtraFieldFlags(AUTHINFO_EXTRAFIELD_DOMAIN) & KIO::AuthInfo::ExtraFieldReadOnly) { | 777 | if (info.getExtraFieldFlags(AUTHINFO_EXTRAFIELD_DOMAIN) & KIO::AuthInfo::ExtraFieldReadOnly) { | ||
734 | dialogFlags |= KPasswordDialog::DomainReadOnly; | 778 | dialogFlags |= KPasswordDialog::DomainReadOnly; | ||
735 | } | 779 | } | ||
736 | } | 780 | } | ||
737 | 781 | | |||
738 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).isValid()) { | 782 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).isValid()) { | ||
739 | dialogFlags |= KPasswordDialog::ShowAnonymousLoginCheckBox; | 783 | dialogFlags |= KPasswordDialog::ShowAnonymousLoginCheckBox; | ||
740 | } | 784 | } | ||
741 | 785 | | |||
742 | if (!info.getExtraField(AUTHINFO_EXTRAFIELD_HIDE_USERNAME_INPUT).toBool()) { | 786 | if (!info.getExtraField(AUTHINFO_EXTRAFIELD_HIDE_USERNAME_INPUT).toBool()) { | ||
743 | dialogFlags |= KPasswordDialog::ShowUsernameLine; | 787 | dialogFlags |= KPasswordDialog::ShowUsernameLine; | ||
744 | } | 788 | } | ||
745 | 789 | | |||
746 | #ifdef HAVE_KF5WALLET | 790 | #ifdef HAVE_KF5WALLET | ||
747 | // If wallet is not enabled and the caller explicitly requested for it, | 791 | // If wallet is not enabled and the caller explicitly requested for it, | ||
748 | // do not show the keep password checkbox. | 792 | // do not show the keep password checkbox. | ||
749 | if (info.keepPassword && KWallet::Wallet::isEnabled()) | 793 | if (info.keepPassword && KWallet::Wallet::isEnabled()) { | ||
750 | dialogFlags |= KPasswordDialog::ShowKeepPassword; | 794 | dialogFlags |= KPasswordDialog::ShowKeepPassword; | ||
795 | } | ||||
751 | #endif | 796 | #endif | ||
752 | 797 | | |||
753 | // instantiate dialog | 798 | // instantiate dialog | ||
754 | qCDebug(category) << "Widget for" << request->windowId << QWidget::find(request->windowId); | 799 | qCDebug(category) << "Widget for" << request->windowId << QWidget::find(request->windowId); | ||
755 | 800 | | |||
756 | KPasswordDialog *dlg = new KPasswordDialog(nullptr, dialogFlags); | 801 | KPasswordDialog *dlg = new KPasswordDialog(nullptr, dialogFlags); | ||
757 | connect(dlg, &QDialog::finished, this, &KPasswdServer::passwordDialogDone); | 802 | connect(dlg, &QDialog::finished, this, &KPasswdServer::passwordDialogDone); | ||
758 | connect(this, &QObject::destroyed, dlg, &QObject::deleteLater); | 803 | connect(this, &QObject::destroyed, dlg, &QObject::deleteLater); | ||
759 | 804 | | |||
760 | dlg->setPrompt(info.prompt); | 805 | dlg->setPrompt(info.prompt); | ||
761 | dlg->setUsername(username); | 806 | dlg->setUsername(username); | ||
762 | if (info.caption.isEmpty()) | 807 | if (info.caption.isEmpty()) { | ||
763 | dlg->setWindowTitle(i18n("Authentication Dialog")); | 808 | dlg->setWindowTitle(i18n("Authentication Dialog")); | ||
764 | else | 809 | } else { | ||
765 | dlg->setWindowTitle(info.caption); | 810 | dlg->setWindowTitle(info.caption); | ||
811 | } | ||||
766 | 812 | | |||
767 | if (!info.comment.isEmpty()) | 813 | if (!info.comment.isEmpty()) { | ||
768 | dlg->addCommentLine(info.commentLabel, info.comment); | 814 | dlg->addCommentLine(info.commentLabel, info.comment); | ||
815 | } | ||||
769 | 816 | | |||
770 | if (!password.isEmpty()) | 817 | if (!password.isEmpty()) { | ||
771 | dlg->setPassword(password); | 818 | dlg->setPassword(password); | ||
819 | } | ||||
772 | 820 | | |||
773 | if (info.readOnly) | 821 | if (info.readOnly) { | ||
774 | dlg->setUsernameReadOnly(true); | 822 | dlg->setUsernameReadOnly(true); | ||
775 | else | 823 | } else { | ||
776 | dlg->setKnownLogins(knownLogins); | 824 | dlg->setKnownLogins(knownLogins); | ||
825 | } | ||||
777 | 826 | | |||
778 | if (hasWalletData) | 827 | if (hasWalletData) { | ||
779 | dlg->setKeepPassword(true); | 828 | dlg->setKeepPassword(true); | ||
829 | } | ||||
780 | 830 | | |||
781 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).isValid()) | 831 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).isValid()) { | ||
782 | dlg->setDomain(info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).toString()); | 832 | dlg->setDomain(info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).toString()); | ||
833 | } | ||||
783 | 834 | | |||
784 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).isValid() && password.isEmpty() && username.isEmpty()) | 835 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).isValid() | ||
836 | && password.isEmpty() | ||||
837 | && username.isEmpty()) { | ||||
785 | dlg->setAnonymousMode(info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).toBool()); | 838 | dlg->setAnonymousMode(info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).toBool()); | ||
839 | } | ||||
786 | 840 | | |||
787 | #ifndef Q_OS_MACOS | 841 | #ifndef Q_OS_MACOS | ||
788 | dlg->setAttribute(Qt::WA_NativeWindow, true); | 842 | dlg->setAttribute(Qt::WA_NativeWindow, true); | ||
789 | KWindowSystem::setMainWindow(dlg->windowHandle(), request->windowId); | 843 | KWindowSystem::setMainWindow(dlg->windowHandle(), request->windowId); | ||
790 | #else | 844 | #else | ||
791 | KWindowSystem::forceActiveWindow(dlg->winId(), 0); | 845 | KWindowSystem::forceActiveWindow(dlg->winId(), 0); | ||
792 | #endif | 846 | #endif | ||
793 | 847 | | |||
Show All 11 Lines | 854 | { | |||
805 | 859 | | |||
806 | qCDebug(category) << "key=" << request->key; | 860 | qCDebug(category) << "key=" << request->key; | ||
807 | if (request->isAsync) { | 861 | if (request->isAsync) { | ||
808 | emit queryAuthInfoAsyncResult(request->requestId, m_seqNr, request->info); | 862 | emit queryAuthInfoAsyncResult(request->requestId, m_seqNr, request->info); | ||
809 | } else { | 863 | } else { | ||
810 | QByteArray replyData; | 864 | QByteArray replyData; | ||
811 | QDataStream stream2(&replyData, QIODevice::WriteOnly); | 865 | QDataStream stream2(&replyData, QIODevice::WriteOnly); | ||
812 | stream2 << request->info; | 866 | stream2 << request->info; | ||
813 | QDBusConnection::sessionBus().send(request->transaction.createReply(QVariantList() << replyData << m_seqNr)); | 867 | QDBusConnection::sessionBus().send( | ||
868 | request->transaction.createReply(QVariantList() << replyData << m_seqNr)); | ||||
814 | } | 869 | } | ||
815 | 870 | | |||
816 | // Check all requests in the wait queue. | 871 | // Check all requests in the wait queue. | ||
817 | Request *waitRequest; | 872 | Request *waitRequest; | ||
818 | QMutableListIterator<Request *> it(m_authWait); | 873 | QMutableListIterator<Request *> it(m_authWait); | ||
819 | while (it.hasNext()) { | 874 | while (it.hasNext()) { | ||
820 | waitRequest = it.next(); | 875 | waitRequest = it.next(); | ||
821 | 876 | | |||
Show All 11 Lines | 887 | } else { | |||
833 | updateAuthExpire(waitRequest->key, result, waitRequest->windowId, false); | 888 | updateAuthExpire(waitRequest->key, result, waitRequest->windowId, false); | ||
834 | copyAuthInfo(result, rcinfo); | 889 | copyAuthInfo(result, rcinfo); | ||
835 | stream2 << rcinfo; | 890 | stream2 << rcinfo; | ||
836 | } | 891 | } | ||
837 | 892 | | |||
838 | if (waitRequest->isAsync) { | 893 | if (waitRequest->isAsync) { | ||
839 | emit checkAuthInfoAsyncResult(waitRequest->requestId, m_seqNr, rcinfo); | 894 | emit checkAuthInfoAsyncResult(waitRequest->requestId, m_seqNr, rcinfo); | ||
840 | } else { | 895 | } else { | ||
841 | QDBusConnection::sessionBus().send(waitRequest->transaction.createReply(QVariantList() << replyData << m_seqNr)); | 896 | QDBusConnection::sessionBus().send( | ||
897 | waitRequest->transaction.createReply(QVariantList() << replyData << m_seqNr)); | ||||
842 | } | 898 | } | ||
843 | 899 | | |||
844 | delete waitRequest; | 900 | delete waitRequest; | ||
845 | it.remove(); | 901 | it.remove(); | ||
846 | } | 902 | } | ||
847 | } | 903 | } | ||
848 | 904 | | |||
849 | // Re-enable password request processing for the current window id again. | 905 | // Re-enable password request processing for the current window id again. | ||
850 | m_authPrompted.removeAll(QString::number(request->windowId)); | 906 | m_authPrompted.removeAll(QString::number(request->windowId)); | ||
851 | m_authPrompted.removeAll(request->key); | 907 | m_authPrompted.removeAll(request->key); | ||
852 | 908 | | |||
853 | if (!m_authPending.isEmpty()) | 909 | if (!m_authPending.isEmpty()) { | ||
854 | QTimer::singleShot(0, this, &KPasswdServer::processRequest); | 910 | QTimer::singleShot(0, this, &KPasswdServer::processRequest); | ||
855 | } | 911 | } | ||
912 | } | ||||
856 | 913 | | |||
857 | void KPasswdServer::passwordDialogDone(int result) | 914 | void KPasswdServer::passwordDialogDone(int result) | ||
858 | { | 915 | { | ||
859 | KPasswordDialog *dlg = qobject_cast<KPasswordDialog *>(sender()); | 916 | KPasswordDialog *dlg = qobject_cast<KPasswordDialog *>(sender()); | ||
860 | Q_ASSERT(dlg); | 917 | Q_ASSERT(dlg); | ||
861 | 918 | | |||
862 | QScopedPointer<Request> request(m_authInProgress.take(dlg)); | 919 | QScopedPointer<Request> request(m_authInProgress.take(dlg)); | ||
863 | Q_ASSERT(request); // request should never be nullptr. | 920 | Q_ASSERT(request); // request should never be nullptr. | ||
864 | 921 | | |||
865 | if (request) { | 922 | if (request) { | ||
866 | KIO::AuthInfo &info = request->info; | 923 | KIO::AuthInfo &info = request->info; | ||
867 | const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool(); | 924 | const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool(); | ||
868 | 925 | | |||
869 | qCDebug(category) << "dialog result=" << result << ", bypassCacheAndKWallet?" << bypassCacheAndKWallet; | 926 | qCDebug(category) << "dialog result=" << result << ", bypassCacheAndKWallet?" << bypassCacheAndKWallet; | ||
870 | if (dlg && result == QDialog::Accepted) { | 927 | if (dlg && result == QDialog::Accepted) { | ||
871 | Q_ASSERT(dlg); | 928 | Q_ASSERT(dlg); | ||
872 | info.username = dlg->username(); | 929 | info.username = dlg->username(); | ||
873 | info.password = dlg->password(); | 930 | info.password = dlg->password(); | ||
874 | info.keepPassword = dlg->keepPassword(); | 931 | info.keepPassword = dlg->keepPassword(); | ||
875 | 932 | | |||
876 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).isValid()) | 933 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_DOMAIN).isValid()) { | ||
877 | info.setExtraField(AUTHINFO_EXTRAFIELD_DOMAIN, dlg->domain()); | 934 | info.setExtraField(AUTHINFO_EXTRAFIELD_DOMAIN, dlg->domain()); | ||
878 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).isValid()) | 935 | } | ||
936 | if (info.getExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS).isValid()) { | ||||
879 | info.setExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS, dlg->anonymousMode()); | 937 | info.setExtraField(AUTHINFO_EXTRAFIELD_ANONYMOUS, dlg->anonymousMode()); | ||
938 | } | ||||
880 | 939 | | |||
881 | // When the user checks "keep password", that means: | 940 | // When the user checks "keep password", that means: | ||
882 | // * if the wallet is enabled, store it there for long-term, and in kpasswdserver | 941 | // * if the wallet is enabled, store it there for long-term, and in kpasswdserver | ||
883 | // only for the duration of the window (#92928) | 942 | // only for the duration of the window (#92928) | ||
884 | // * otherwise store in kpasswdserver for the duration of the KDE session. | 943 | // * otherwise store in kpasswdserver for the duration of the KDE session. | ||
885 | if (!bypassCacheAndKWallet) { | 944 | if (!bypassCacheAndKWallet) { | ||
886 | /* | 945 | /* | ||
887 | NOTE: The following code changes the key under which the auth | 946 | NOTE: The following code changes the key under which the auth | ||
Show All 14 Lines | 957 | if (!info.url.userName().isEmpty() && info.username != info.url.userName()) { | |||
902 | request->key = createCacheKey(info); | 961 | request->key = createCacheKey(info); | ||
903 | updateCachedRequestKey(m_authPending, oldKey, request->key); | 962 | updateCachedRequestKey(m_authPending, oldKey, request->key); | ||
904 | updateCachedRequestKey(m_authWait, oldKey, request->key); | 963 | updateCachedRequestKey(m_authWait, oldKey, request->key); | ||
905 | } | 964 | } | ||
906 | 965 | | |||
907 | #ifdef HAVE_KF5WALLET | 966 | #ifdef HAVE_KF5WALLET | ||
908 | const bool skipAutoCaching = info.getExtraField(AUTHINFO_EXTRAFIELD_SKIP_CACHING_ON_QUERY).toBool(); | 967 | const bool skipAutoCaching = info.getExtraField(AUTHINFO_EXTRAFIELD_SKIP_CACHING_ON_QUERY).toBool(); | ||
909 | if (!skipAutoCaching && info.keepPassword && openWallet(request->windowId)) { | 968 | if (!skipAutoCaching && info.keepPassword && openWallet(request->windowId)) { | ||
910 | if (storeInWallet(m_wallet, request->key, info)) | 969 | if (storeInWallet(m_wallet, request->key, info)) { | ||
911 | // password is in wallet, don't keep it in memory after window is closed | 970 | // password is in wallet, don't keep it in memory after window is closed | ||
912 | info.keepPassword = false; | 971 | info.keepPassword = false; | ||
913 | } | 972 | } | ||
973 | } | ||||
914 | #endif | 974 | #endif | ||
915 | addAuthInfoItem(request->key, info, request->windowId, m_seqNr, false); | 975 | addAuthInfoItem(request->key, info, request->windowId, m_seqNr, false); | ||
916 | } | 976 | } | ||
917 | info.setModified(true); | 977 | info.setModified(true); | ||
918 | } else { | 978 | } else { | ||
919 | if (!bypassCacheAndKWallet && request->prompt) { | 979 | if (!bypassCacheAndKWallet && request->prompt) { | ||
920 | addAuthInfoItem(request->key, info, 0, m_seqNr, true); | 980 | addAuthInfoItem(request->key, info, 0, m_seqNr, true); | ||
921 | } | 981 | } | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 1043 | if (it.value()->windowId == windowId) { | |||
986 | it.remove(); | 1046 | it.remove(); | ||
987 | delete obj; | 1047 | delete obj; | ||
988 | delete request; | 1048 | delete request; | ||
989 | } | 1049 | } | ||
990 | } | 1050 | } | ||
991 | } | 1051 | } | ||
992 | } | 1052 | } | ||
993 | 1053 | | |||
994 | void KPasswdServer::updateCachedRequestKey(QList<KPasswdServer::Request *> &list, const QString &oldKey, const QString &newKey) | 1054 | void KPasswdServer::updateCachedRequestKey(QList<KPasswdServer::Request *> &list, | ||
1055 | const QString &oldKey, const QString &newKey) | ||||
995 | { | 1056 | { | ||
996 | QListIterator<Request *> it(list); | 1057 | QListIterator<Request *> it(list); | ||
997 | while (it.hasNext()) { | 1058 | while (it.hasNext()) { | ||
998 | Request *r = it.next(); | 1059 | Request *r = it.next(); | ||
999 | if (r->key == oldKey) { | 1060 | if (r->key == oldKey) { | ||
1000 | r->key = newKey; | 1061 | r->key = newKey; | ||
1001 | } | 1062 | } | ||
1002 | } | 1063 | } | ||
1003 | } | 1064 | } |