void KDEPrintd::processRequest() { if(m_requestsPending.count() == 0) return; Request *req = m_requestsPending.first(); KIO::AuthInfo info; QByteArray params, reply; QCString replyType; QString authString("::"); info.username = req->user; info.keepPassword = true; info.url = req->uri; info.comment = i18n("Printing system"); QDataStream input(params, IO_WriteOnly); input << info << i18n("Authentication failed (user name=%1)").arg(info.username) << 0L << (long int)req->seqNbr; if(callingDcopClient()->call("kded", "kpasswdserver", "queryAuthInfo(KIO::AuthInfo,QString,long int,long int)", params, replyType, reply)) { if(replyType == "KIO::AuthInfo") { QDataStream output(reply, IO_ReadOnly); KIO::AuthInfo result; int seqNbr; output >> result >> seqNbr; if(result.isModified()) authString = result.username + ":" + result.password + ":" + QString::number(seqNbr); } else
KIO::AuthInfo KPasswdServer::checkAuthInfo(KIO::AuthInfo info, long windowId, unsigned long usertime) { kdDebug(130) << "KPasswdServer::checkAuthInfo: User= "******", WindowId = " << windowId << endl; if( usertime != 0 ) kapp->updateUserTimestamp( usertime ); QString key = createCacheKey(info); Request *request = m_authPending.first(); QString path2 = info.url.directory(false, false); for(; request; request = m_authPending.next()) { if (request->key != key) continue; if (info.verifyPath) { QString path1 = request->info.url.directory(false, false); if (!path2.startsWith(path1)) continue; } request = new Request; request->client = callingDcopClient(); request->transaction = request->client->beginTransaction(); request->key = key; request->info = info; m_authWait.append(request); return info; } const AuthInfo *result = findAuthInfoItem(key, info); if (!result || result->isCanceled) { if (!result && (info.username.isEmpty() || info.password.isEmpty()) && !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), makeWalletKey(key, info.realmValue))) { QMap<QString, QString> knownLogins; if (openWallet(windowId)) { if (readFromWallet(m_wallet, key, info.realmValue, info.username, info.password, info.readOnly, knownLogins)) { info.setModified(true); return info; } } } info.setModified(false); return info; } updateAuthExpire(key, result, windowId, false); return copyAuthInfo(result); }
KIO::AuthInfo KPasswdServer::copyAuthInfo(const AuthInfo *i) { KIO::AuthInfo result; result.url = i->url; result.username = i->username; result.password = i->password; result.realmValue = i->realmValue; result.digestInfo = i->digestInfo; result.setModified(true); return result; }
bool Observer::openPassDlg(KIO::AuthInfo &info) { kdDebug(KDEBUG_OBSERVER) << "Observer::openPassDlg: User= "******", Message= " << info.prompt << endl; int result = KIO::PasswordDialog::getNameAndPassword(info.username, info.password, &info.keepPassword, info.prompt, info.readOnly, info.caption, info.comment, info.commentLabel); if(result == QDialog::Accepted) { info.setModified(true); return true; } return false; }
void simpleTest() { KPasswdServer server(this); server.setWalletDisabled(true); // Check that processRequest doesn't crash when it has nothing to do server.processRequest(); KIO::AuthInfo info; info.url = QUrl(QStringLiteral("http://www.example.com")); // Make a check for that host, should say "not found" QVERIFY(noCheckAuth(server, info)); // Now add auth to the cache const qlonglong windowId = 42; KIO::AuthInfo realInfo = info; realInfo.username = QStringLiteral("toto"); // you can see I'm french realInfo.password = QStringLiteral("foobar"); server.addAuthInfo(realInfo, windowId); // seqnr=2 // queryAuth without the ability to prompt, will just return info unmodified KIO::AuthInfo resultInfo; queryAuth(server, info, resultInfo); QCOMPARE(resultInfo.url, info.url); QCOMPARE(resultInfo.username, QString()); QCOMPARE(resultInfo.password, QString()); QCOMPARE(resultInfo.isModified(), false); // Check that checkAuth finds it QVERIFY(successCheckAuth(server, info, realInfo)); // Now remove auth server.removeAuthInfo(info.url.host(), info.url.scheme(), info.username); // Check we can't find that auth anymore QVERIFY(noCheckAuth(server, info)); }