Changeset View
Changeset View
Standalone View
Standalone View
kded/secretagent.cpp
Show First 20 Lines • Show All 344 Lines • ▼ Show 20 Line(s) | |||||
345 | } | 345 | } | ||
346 | 346 | | |||
347 | bool SecretAgent::processGetSecrets(SecretsRequest &request) const | 347 | bool SecretAgent::processGetSecrets(SecretsRequest &request) const | ||
348 | { | 348 | { | ||
349 | if (m_dialog) { | 349 | if (m_dialog) { | ||
350 | return false; | 350 | return false; | ||
351 | } | 351 | } | ||
352 | 352 | | |||
353 | NetworkManager::ConnectionSettings connectionSettings(request.connection); | 353 | NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); | ||
354 | 354 | NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); | |||
355 | NetworkManager::Setting::Ptr setting = connectionSettings.setting(request.setting_name); | | |||
356 | 355 | | |||
357 | const bool requestNew = request.flags & RequestNew; | 356 | const bool requestNew = request.flags & RequestNew; | ||
358 | const bool userRequested = request.flags & UserRequested; | 357 | const bool userRequested = request.flags & UserRequested; | ||
359 | const bool allowInteraction = request.flags & AllowInteraction; | 358 | const bool allowInteraction = request.flags & AllowInteraction; | ||
360 | const bool isVpn = (setting->type() == NetworkManager::Setting::Vpn); | 359 | const bool isVpn = (setting->type() == NetworkManager::Setting::Vpn); | ||
361 | 360 | | |||
362 | NMStringMap secretsMap; | 361 | NMStringMap secretsMap; | ||
363 | if (!requestNew && useWallet()) { | 362 | if (!requestNew && useWallet()) { | ||
364 | if (m_wallet->isOpen()) { | 363 | if (m_wallet->isOpen()) { | ||
365 | if (m_wallet->hasFolder("Network Management") && m_wallet->setFolder("Network Management")) { | 364 | if (m_wallet->hasFolder("Network Management") && m_wallet->setFolder("Network Management")) { | ||
366 | QString key = QLatin1Char('{') % connectionSettings.uuid() % QLatin1Char('}') % QLatin1Char(';') % request.setting_name; | 365 | QString key = QLatin1Char('{') % connectionSettings->uuid() % QLatin1Char('}') % QLatin1Char(';') % request.setting_name; | ||
367 | m_wallet->readMap(key, secretsMap); | 366 | m_wallet->readMap(key, secretsMap); | ||
368 | } | 367 | } | ||
369 | } else { | 368 | } else { | ||
370 | qCDebug(PLASMA_NM) << Q_FUNC_INFO << "Waiting for the wallet to open"; | 369 | qCDebug(PLASMA_NM) << Q_FUNC_INFO << "Waiting for the wallet to open"; | ||
371 | return false; | 370 | return false; | ||
372 | } | 371 | } | ||
373 | } | 372 | } | ||
374 | 373 | | |||
375 | if (!secretsMap.isEmpty()) { | 374 | if (!secretsMap.isEmpty()) { | ||
376 | setting->secretsFromStringMap(secretsMap); | 375 | setting->secretsFromStringMap(secretsMap); | ||
377 | if (!isVpn && setting->needSecrets(requestNew).isEmpty()) { | 376 | if (!isVpn && setting->needSecrets(requestNew).isEmpty()) { | ||
378 | // Enough secrets were retrieved from storage | 377 | // Enough secrets were retrieved from storage | ||
379 | request.connection[request.setting_name] = setting->secretsToMap(); | 378 | request.connection[request.setting_name] = setting->secretsToMap(); | ||
380 | sendSecrets(request.connection, request.message); | 379 | sendSecrets(request.connection, request.message); | ||
381 | return true; | 380 | return true; | ||
382 | } | 381 | } | ||
383 | } | 382 | } | ||
384 | 383 | | |||
385 | if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) || (isVpn && allowInteraction)) { | 384 | if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) || (isVpn && allowInteraction)) { | ||
386 | m_dialog = new PasswordDialog(request.connection, request.flags, request.setting_name); | 385 | m_dialog = new PasswordDialog(connectionSettings, request.flags, request.setting_name); | ||
387 | connect(m_dialog, &PasswordDialog::accepted, this, &SecretAgent::dialogAccepted); | 386 | connect(m_dialog, &PasswordDialog::accepted, this, &SecretAgent::dialogAccepted); | ||
388 | connect(m_dialog, &PasswordDialog::rejected, this, &SecretAgent::dialogRejected); | 387 | connect(m_dialog, &PasswordDialog::rejected, this, &SecretAgent::dialogRejected); | ||
389 | if (isVpn) { | | |||
390 | m_dialog->setupVpnUi(connectionSettings); | | |||
391 | } else { | | |||
392 | m_dialog->setupGenericUi(connectionSettings); | | |||
393 | } | | |||
394 | 388 | | |||
395 | if (m_dialog->hasError()) { | 389 | if (m_dialog->hasError()) { | ||
396 | sendError(m_dialog->error(), | 390 | sendError(m_dialog->error(), | ||
397 | m_dialog->errorMessage(), | 391 | m_dialog->errorMessage(), | ||
398 | request.message); | 392 | request.message); | ||
399 | delete m_dialog; | 393 | delete m_dialog; | ||
400 | m_dialog = 0; | 394 | m_dialog = 0; | ||
401 | return true; | 395 | return true; | ||
402 | } else { | 396 | } else { | ||
403 | request.dialog = m_dialog; | 397 | request.dialog = m_dialog; | ||
404 | request.saveSecretsWithoutReply = !connectionSettings.permissions().isEmpty(); | 398 | request.saveSecretsWithoutReply = !connectionSettings->permissions().isEmpty(); | ||
405 | m_dialog->show(); | 399 | m_dialog->show(); | ||
406 | KWindowSystem::setState(m_dialog->winId(), NET::KeepAbove); | 400 | KWindowSystem::setState(m_dialog->winId(), NET::KeepAbove); | ||
407 | KWindowSystem::forceActiveWindow(m_dialog->winId()); | 401 | KWindowSystem::forceActiveWindow(m_dialog->winId()); | ||
408 | return false; | 402 | return false; | ||
409 | } | 403 | } | ||
410 | } else if (isVpn && userRequested) { // just return what we have | 404 | } else if (isVpn && userRequested) { // just return what we have | ||
411 | NMVariantMapMap result; | 405 | NMVariantMapMap result; | ||
412 | NetworkManager::VpnSetting::Ptr vpnSetting; | 406 | NetworkManager::VpnSetting::Ptr vpnSetting; | ||
413 | vpnSetting = connectionSettings.setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>(); | 407 | vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>(); | ||
414 | //FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it | 408 | //FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it | ||
415 | // won't ask for additional secrets with AllowInteraction flag which would display the authentication dialog | 409 | // won't ask for additional secrets with AllowInteraction flag which would display the authentication dialog | ||
416 | if (vpnSetting->secretsToMap().isEmpty()) { | 410 | if (vpnSetting->secretsToMap().isEmpty()) { | ||
417 | // Insert an empty secrets map as it was before I fixed it in NetworkManagerQt to make sure NM will ask again | 411 | // Insert an empty secrets map as it was before I fixed it in NetworkManagerQt to make sure NM will ask again | ||
418 | // with flags we need | 412 | // with flags we need | ||
419 | QVariantMap secretsMap; | 413 | QVariantMap secretsMap; | ||
420 | secretsMap.insert(QLatin1String("secrets"), QVariant::fromValue<NMStringMap>(NMStringMap())); | 414 | secretsMap.insert(QLatin1String("secrets"), QVariant::fromValue<NMStringMap>(NMStringMap())); | ||
421 | result.insert("vpn", secretsMap); | 415 | result.insert("vpn", secretsMap); | ||
▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines |