Commit 5fdf4d9f authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Add UiUtils::setConnectionDefaultPermissions

This sets up default permissions correctly for a connection. When either
configuration indicates we should prefer system connections, KWallet
isn't enabled or we're running a live image we'll try to create a system
connection. However, if we're not allowed to create system connections,
then fall back to creating user connections.

Additionally, this sets the default password storage to store passwords
system-wide if we're creating system-wide connections, since storing
those passwords locally leads to awkward behaviour where a system
connection can't really be reused since the password is not available.
parent 4efbe8a9
......@@ -15,8 +15,11 @@
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KUser>
#include <KWallet>
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/Security8021xSetting>
#include <ModemManagerQt/Manager>
......@@ -703,3 +706,30 @@ bool UiUtils::isLiveImage()
liveImage = false;
return false;
void UiUtils::setConnectionDefaultPermissions(NetworkManager::ConnectionSettings::Ptr &settings)
auto wifiSecurity = settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
auto security8021x = settings->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
if (!wifiSecurity || !security8021x) {
if (Configuration::self().systemConnectionsByDefault() || !KWallet::Wallet::isEnabled() || isLiveImage()) {
auto modifySystem = NetworkManager::permissions().value(QStringLiteral("org.freedesktop.NetworkManager.settings.modify.system"));
if (modifySystem == QLatin1String("yes")) {
settings->addToPermissions(KUser().loginName(), QString());
......@@ -121,6 +121,21 @@ public:
static bool isLiveImage();
* Setup default permissions for a new connection.
* This determines whether we should use system connections or user
* connections by default and sets the default permissions accordingly.
* System connections are preferred if either the preference for that is
* set, KWallet is not enabled or we're running in a live image. However, if
* we do not have permissions to create system connections, we fall back to
* user connections.
* @param settings The connection settings to setup.
* @param liveSession Whether we are running a session from a live disk image.
static void setConnectionDefaultPermissions(NetworkManager::ConnectionSettings::Ptr &settings);
static QString convertAllowedModeToString(ModemManager::Modem::ModemModes mode);
static QString convertAccessTechnologyToString(ModemManager::Modem::AccessTechnologies tech);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment