Fix assertion error when noWallet used

Krfb fails to startup if "noWallet" is in the config since
`walletOpened()` is called without a wallet, triggering the `Q_ASSERT`
at the beginning of the function.

Fix this by adding function to read passwords from the config directly
rather than reusing the `walletOpened()` slot.
This commit is contained in:
Guillaume Champagne
2024-03-26 17:39:47 -04:00
committed by Alexey Min
parent 3ae94343e4
commit 7a0c0bd6e1
2 changed files with 23 additions and 17 deletions

View File

@@ -58,7 +58,7 @@ void InvitationsRfbServer::init()
instance->m_wallet = nullptr;
if (KrfbConfig::noWallet()) {
instance->walletOpened(false);
instance->readPasswordFromConfig();
} else {
instance->openKWallet();
}
@@ -181,23 +181,8 @@ void InvitationsRfbServer::walletOpened(bool opened)
}
} else {
qCDebug(KRFB) << "Could not open KWallet, Falling back to config file";
KConfigGroup krfbConfig(KSharedConfig::openConfig(),QStringLiteral("Security"));
desktopPassword = KStringHandler::obscure(krfbConfig.readEntry(
"desktopPassword", QString()));
if(!desktopPassword.isEmpty()) {
m_desktopPassword = desktopPassword;
Q_EMIT passwordChanged(m_desktopPassword);
}
unattendedPassword = KStringHandler::obscure(krfbConfig.readEntry(
"unattendedPassword", QString()));
if(!unattendedPassword.isEmpty()) {
m_unattendedPassword = unattendedPassword;
}
readPasswordFromConfig();
}
}
@@ -258,3 +243,23 @@ void InvitationsRfbServer::saveSecuritySettings()
}
KrfbConfig::self()->save();
}
void InvitationsRfbServer::readPasswordFromConfig()
{
QString desktopPassword;
QString unattendedPassword;
KConfigGroup krfbConfig(KSharedConfig::openConfig(),QStringLiteral("Security"));
desktopPassword = KStringHandler::obscure(krfbConfig.readEntry(
"desktopPassword", QString()));
if(!desktopPassword.isEmpty()) {
m_desktopPassword = desktopPassword;
Q_EMIT passwordChanged(m_desktopPassword);
}
unattendedPassword = KStringHandler::obscure(krfbConfig.readEntry(
"unattendedPassword", QString()));
if(!unattendedPassword.isEmpty()) {
m_unattendedPassword = unattendedPassword;
}
}

View File

@@ -70,6 +70,7 @@ private:
KWallet::Wallet *m_wallet = nullptr;
QString readableRandomString(int);
void readPasswordFromConfig();
Q_DISABLE_COPY(InvitationsRfbServer)
};