fix(credentials): run sudo without a password when the account has none
A passwordless sudo setup (NOPASSWD, or an account without a password) was still asked for a password: leaving the field empty never satisfied the gate, so the dialog reopened and the operation could not run at all. The gate now asks sudo itself (`sudo -n true`) and lets the request through when it needs nothing, privileged commands fall back to `sudo -n` when no password is held, and an empty field cancels instead of looping. Releasing the lock records its own pending request so an answered prompt is replayed rather than lost.
This commit is contained in:
9 files changed
+131
-24
No files matched your search
+12
-5
@@ -465,8 +465,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
updateStatusBar();
|
||||
|
||||
// With per-session credentials, ask for the sudo password once, right
|
||||
// after the window is shown (so the dialog has a visible parent).
|
||||
if (m_core->credentialMode() == AppCore::CredentialMode::AtLaunch) {
|
||||
// after the window is shown (so the dialog has a visible parent) — unless
|
||||
// sudo needs none on this machine.
|
||||
if (m_core->credentialMode() == AppCore::CredentialMode::AtLaunch
|
||||
&& m_core->sudoRequiresPassword()) {
|
||||
QTimer::singleShot(0, this, [this] { promptForSudoPassword(); });
|
||||
}
|
||||
|
||||
@@ -1350,7 +1352,9 @@ void MainWindow::changeEvent(QEvent* event) {
|
||||
// The core knows *when* a password is needed (it owns the credential state and
|
||||
// the sudo pipeline); the frame only owns the dialog.
|
||||
bool MainWindow::promptForSudoPassword() {
|
||||
if (m_core->hasSudoPassword()) return true;
|
||||
// Nothing to ask when the session already holds a password or when sudo
|
||||
// works without one (passwordless rule, account with no password).
|
||||
if (m_core->hasSudoPassword() || !m_core->sudoRequiresPassword()) return true;
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
@@ -1361,11 +1365,14 @@ bool MainWindow::promptForSudoPassword() {
|
||||
this, "Authentification",
|
||||
tr("Mot de passe administrateur (sudo) :"),
|
||||
QLineEdit::Password, QString(), &ok);
|
||||
if (!ok) {
|
||||
if (!ok || password.isEmpty()) {
|
||||
// An empty field is not a password: replaying the request would land on
|
||||
// this very dialog again, so it is cancelled instead of looping.
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
tr("mot de passe refusé par l'utilisateur"));
|
||||
statusBar()->showMessage(tr("Opération annulée : identifiants requis."));
|
||||
statusBar()->showMessage(ok ? tr("Mot de passe administrateur (sudo) requis.")
|
||||
: tr("Opération annulée : identifiants requis."));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user