Changeset View
Changeset View
Standalone View
Standalone View
kded/secretagent.cpp
Show All 29 Lines | |||||
30 | #include <NetworkManagerQt/Settings> | 30 | #include <NetworkManagerQt/Settings> | ||
31 | #include <NetworkManagerQt/ConnectionSettings> | 31 | #include <NetworkManagerQt/ConnectionSettings> | ||
32 | #include <NetworkManagerQt/GenericTypes> | 32 | #include <NetworkManagerQt/GenericTypes> | ||
33 | #include <NetworkManagerQt/GsmSetting> | 33 | #include <NetworkManagerQt/GsmSetting> | ||
34 | #include <NetworkManagerQt/Security8021xSetting> | 34 | #include <NetworkManagerQt/Security8021xSetting> | ||
35 | #include <NetworkManagerQt/VpnSetting> | 35 | #include <NetworkManagerQt/VpnSetting> | ||
36 | #include <NetworkManagerQt/WirelessSecuritySetting> | 36 | #include <NetworkManagerQt/WirelessSecuritySetting> | ||
37 | #include <NetworkManagerQt/WirelessSetting> | 37 | #include <NetworkManagerQt/WirelessSetting> | ||
38 | #include <NetworkManagerQt/WireguardSetting> | ||||
38 | 39 | | |||
39 | #include <QStringBuilder> | 40 | #include <QStringBuilder> | ||
40 | #include <QDialog> | 41 | #include <QDialog> | ||
41 | 42 | | |||
42 | #include <KLocalizedString> | 43 | #include <KLocalizedString> | ||
43 | #include <KPluginFactory> | 44 | #include <KPluginFactory> | ||
44 | #include <KWindowSystem> | 45 | #include <KWindowSystem> | ||
45 | #include <KConfig> | 46 | #include <KConfig> | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 68 | { | |||
87 | request.connection_path = connection_path; | 88 | request.connection_path = connection_path; | ||
88 | request.flags = static_cast<NetworkManager::SecretAgent::GetSecretsFlags>(flags); | 89 | request.flags = static_cast<NetworkManager::SecretAgent::GetSecretsFlags>(flags); | ||
89 | request.hints = hints; | 90 | request.hints = hints; | ||
90 | request.setting_name = setting_name; | 91 | request.setting_name = setting_name; | ||
91 | request.message = message(); | 92 | request.message = message(); | ||
92 | m_calls << request; | 93 | m_calls << request; | ||
93 | 94 | | |||
94 | processNext(); | 95 | processNext(); | ||
95 | | ||||
96 | return NMVariantMapMap(); | 96 | return NMVariantMapMap(); | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | void SecretAgent::SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) | 99 | void SecretAgent::SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) | ||
100 | { | 100 | { | ||
101 | qCDebug(PLASMA_NM) << Q_FUNC_INFO; | 101 | qCDebug(PLASMA_NM) << Q_FUNC_INFO; | ||
102 | qCDebug(PLASMA_NM) << "Path:" << connection_path.path(); | 102 | qCDebug(PLASMA_NM) << "Path:" << connection_path.path(); | ||
103 | // qCDebug(PLASMA_NM) << "Setting:" << connection; | 103 | // qCDebug(PLASMA_NM) << "Setting:" << connection; | ||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Line(s) | 351 | { | |||
355 | 355 | | |||
356 | NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); | 356 | NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); | ||
357 | NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); | 357 | NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); | ||
358 | 358 | | |||
359 | const bool requestNew = request.flags & RequestNew; | 359 | const bool requestNew = request.flags & RequestNew; | ||
360 | const bool userRequested = request.flags & UserRequested; | 360 | const bool userRequested = request.flags & UserRequested; | ||
361 | const bool allowInteraction = request.flags & AllowInteraction; | 361 | const bool allowInteraction = request.flags & AllowInteraction; | ||
362 | const bool isVpn = (setting->type() == NetworkManager::Setting::Vpn); | 362 | const bool isVpn = (setting->type() == NetworkManager::Setting::Vpn); | ||
363 | const bool isWireGuard = (setting->type() == NetworkManager::Setting::WireGuard); | ||||
363 | 364 | | |||
364 | if (isVpn) { | 365 | if (isVpn) { | ||
365 | NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>(); | 366 | NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>(); | ||
366 | if (vpnSetting->serviceType() == QLatin1String("org.freedesktop.NetworkManager.ssh") && vpnSetting->data()["auth-type"] == QLatin1String("ssh-agent")) { | 367 | if (vpnSetting->serviceType() == QLatin1String("org.freedesktop.NetworkManager.ssh") && vpnSetting->data()["auth-type"] == QLatin1String("ssh-agent")) { | ||
367 | QString authSock = qgetenv("SSH_AUTH_SOCK"); | 368 | QString authSock = qgetenv("SSH_AUTH_SOCK"); | ||
368 | qCDebug(PLASMA_NM) << Q_FUNC_INFO << "Sending SSH auth socket" << authSock; | 369 | qCDebug(PLASMA_NM) << Q_FUNC_INFO << "Sending SSH auth socket" << authSock; | ||
369 | 370 | | |||
370 | if (authSock.isEmpty()) { | 371 | if (authSock.isEmpty()) { | ||
Show All 23 Lines | 389 | if (!requestNew && useWallet()) { | |||
394 | } else { | 395 | } else { | ||
395 | qCDebug(PLASMA_NM) << Q_FUNC_INFO << "Waiting for the wallet to open"; | 396 | qCDebug(PLASMA_NM) << Q_FUNC_INFO << "Waiting for the wallet to open"; | ||
396 | return false; | 397 | return false; | ||
397 | } | 398 | } | ||
398 | } | 399 | } | ||
399 | 400 | | |||
400 | if (!secretsMap.isEmpty()) { | 401 | if (!secretsMap.isEmpty()) { | ||
401 | setting->secretsFromStringMap(secretsMap); | 402 | setting->secretsFromStringMap(secretsMap); | ||
402 | if (!isVpn && setting->needSecrets(requestNew).isEmpty()) { | 403 | if (!(isVpn || isWireGuard) && setting->needSecrets(requestNew).isEmpty()) { | ||
403 | // Enough secrets were retrieved from storage | 404 | // Enough secrets were retrieved from storage | ||
404 | request.connection[request.setting_name] = setting->secretsToMap(); | 405 | request.connection[request.setting_name] = setting->secretsToMap(); | ||
405 | sendSecrets(request.connection, request.message); | 406 | sendSecrets(request.connection, request.message); | ||
406 | return true; | 407 | return true; | ||
407 | } | 408 | } | ||
408 | } | 409 | } | ||
409 | 410 | | |||
410 | if (!Configuration::showPasswordDialog()) { | 411 | if (!Configuration::showPasswordDialog()) { | ||
411 | sendError(SecretAgent::NoSecrets, "Cannot authenticate", request.message); | 412 | sendError(SecretAgent::NoSecrets, "Cannot authenticate", request.message); | ||
412 | emit secretsError(request.connection_path.path(), i18n("Authentication to %1 failed. Wrong password?", request.connection.value("connection").value("id").toString())); | 413 | emit secretsError(request.connection_path.path(), i18n("Authentication to %1 failed. Wrong password?", request.connection.value("connection").value("id").toString())); | ||
413 | return true; | 414 | return true; | ||
415 | } else if (isWireGuard && userRequested) { // Just return what we have | ||||
416 | NMVariantMapMap result; | ||||
417 | NetworkManager::WireGuardSetting::Ptr wireGuardSetting; | ||||
418 | wireGuardSetting = connectionSettings->setting(NetworkManager::Setting::WireGuard).dynamicCast<NetworkManager::WireGuardSetting>(); | ||||
419 | //FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it | ||||
420 | // won't ask for additional secrets with AllowInteraction flag which would display the authentication dialog | ||||
421 | if (wireGuardSetting->secretsToMap().isEmpty()) { | ||||
422 | // Insert an empty secrets map as it was before I fixed it in NetworkManagerQt to make sure NM will ask again | ||||
423 | // with flags we need | ||||
424 | QVariantMap secretsMap; | ||||
425 | secretsMap.insert(QLatin1String("secrets"), QVariant::fromValue<NMStringMap>(NMStringMap())); | ||||
426 | result.insert("wireguard", secretsMap); | ||||
427 | } else { | ||||
428 | result.insert("wireguard", wireGuardSetting->secretsToMap()); | ||||
429 | } | ||||
430 | sendSecrets(result, request.message); | ||||
431 | return true; | ||||
414 | } else if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) || (isVpn && allowInteraction)) { | 432 | } else if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) || (isVpn && allowInteraction)) { | ||
433 | | ||||
415 | m_dialog = new PasswordDialog(connectionSettings, request.flags, request.setting_name); | 434 | m_dialog = new PasswordDialog(connectionSettings, request.flags, request.setting_name); | ||
416 | connect(m_dialog, &PasswordDialog::accepted, this, &SecretAgent::dialogAccepted); | 435 | connect(m_dialog, &PasswordDialog::accepted, this, &SecretAgent::dialogAccepted); | ||
417 | connect(m_dialog, &PasswordDialog::rejected, this, &SecretAgent::dialogRejected); | 436 | connect(m_dialog, &PasswordDialog::rejected, this, &SecretAgent::dialogRejected); | ||
418 | 437 | | |||
419 | if (m_dialog->hasError()) { | 438 | if (m_dialog->hasError()) { | ||
420 | sendError(m_dialog->error(), | 439 | sendError(m_dialog->error(), | ||
421 | m_dialog->errorMessage(), | 440 | m_dialog->errorMessage(), | ||
422 | request.message); | 441 | request.message); | ||
423 | delete m_dialog; | 442 | delete m_dialog; | ||
424 | m_dialog = nullptr; | 443 | m_dialog = nullptr; | ||
425 | return true; | 444 | return true; | ||
426 | } else { | 445 | } else { | ||
427 | request.dialog = m_dialog; | 446 | request.dialog = m_dialog; | ||
428 | request.saveSecretsWithoutReply = !connectionSettings->permissions().isEmpty(); | 447 | request.saveSecretsWithoutReply = !connectionSettings->permissions().isEmpty(); | ||
429 | m_dialog->show(); | 448 | m_dialog->show(); | ||
430 | KWindowSystem::setState(m_dialog->winId(), NET::KeepAbove); | 449 | KWindowSystem::setState(m_dialog->winId(), NET::KeepAbove); | ||
jgrulich: Shouldn't it be
```
(isVpn && !isWireguard) && allowInteraction
```
You don't want to display… | |||||
Actually what I did is move the WireGuard handling above this 'else if' so it shouldn't get to this point if it is WireGuard so I simply returned the logic to what it was originally. andersonbruce: Actually what I did is move the WireGuard handling above this 'else if' so it shouldn't get to… | |||||
431 | KWindowSystem::forceActiveWindow(m_dialog->winId()); | 450 | KWindowSystem::forceActiveWindow(m_dialog->winId()); | ||
432 | return false; | 451 | return false; | ||
433 | } | 452 | } | ||
434 | } else if (isVpn && userRequested) { // just return what we have | 453 | } else if (isVpn && userRequested) { // just return what we have | ||
435 | NMVariantMapMap result; | 454 | NMVariantMapMap result; | ||
436 | NetworkManager::VpnSetting::Ptr vpnSetting; | 455 | NetworkManager::VpnSetting::Ptr vpnSetting; | ||
437 | vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>(); | 456 | vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>(); | ||
438 | //FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it | 457 | //FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it | ||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |
Shouldn't it be
You don't want to display password dialog in case it's a WG connection.
Or maybe it should stay and instead we should return true and send error (like we do when a dialog has an error) if it's a WG connection, to let NetworkManager know we cannot handle that.