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
+29
-1
@@ -290,6 +290,11 @@ bool AppCore::hasSudoPassword() const {
|
||||
return m_pacman && m_pacman->hasPassword();
|
||||
}
|
||||
|
||||
bool AppCore::sudoRequiresPassword() const {
|
||||
return m_pacman && !m_pacman->hasPassword()
|
||||
&& !PacmanManager::sudoWorksWithoutPassword();
|
||||
}
|
||||
|
||||
AppCore::StartResult AppCore::credentialGate(
|
||||
const std::vector<IPackageManager*>& providers) const {
|
||||
bool privileged = false;
|
||||
@@ -309,6 +314,11 @@ AppCore::StartResult AppCore::credentialGate(
|
||||
}
|
||||
if (m_pacman->hasPassword()) return accepted();
|
||||
|
||||
// Nothing to ask when sudo accepts the session as it is — a NOPASSWD rule,
|
||||
// or an account with no password. Prompting there left the user with a
|
||||
// dialog whose empty field could never satisfy the gate.
|
||||
if (PacmanManager::sudoWorksWithoutPassword()) return accepted();
|
||||
|
||||
// The view prompts for the password and calls retryPendingRequest().
|
||||
return refused(tr("Mot de passe administrateur (sudo) requis."),
|
||||
/*needsPassword=*/true);
|
||||
@@ -595,7 +605,18 @@ AppCore::StartResult AppCore::releaseDatabaseLock() {
|
||||
|
||||
const PacmanManager::LockHolder holder = PacmanManager::detectLockHolder();
|
||||
const StartResult gate = credentialGate({m_pacman});
|
||||
if (!gate.started) return gate;
|
||||
if (!gate.started) {
|
||||
// The release itself now waits for the password, and the view replays
|
||||
// it through retryPendingRequest() once the user answered. A request
|
||||
// that was already pending wins: freeing the lock is meant to resume
|
||||
// that one, not to replace it.
|
||||
if (!m_pending) {
|
||||
Request request;
|
||||
request.action = QStringLiteral("release-lock");
|
||||
m_pending = request;
|
||||
}
|
||||
return gate;
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
emit statusMessage(tr("Libération de la base de données pacman..."));
|
||||
@@ -632,6 +653,10 @@ AppCore::StartResult AppCore::releaseDatabaseLock() {
|
||||
}
|
||||
LogManager::instance().endCommand(true);
|
||||
emit statusMessage(tr("Base libérée, reprise de l'opération..."));
|
||||
// A release waiting for its own password has nothing left to resume.
|
||||
if (m_pending && m_pending->action == QLatin1String("release-lock")) {
|
||||
m_pending.reset();
|
||||
}
|
||||
// Deferred so the status message paints before the replayed action
|
||||
// starts streaming its own progress.
|
||||
QTimer::singleShot(0, this, [this] { retryPendingRequest(); });
|
||||
@@ -1092,6 +1117,9 @@ AppCore::StartResult AppCore::retryPendingRequest() {
|
||||
|
||||
const Request request = *m_pending;
|
||||
m_pending.reset();
|
||||
// Releasing the lock is not a startRequest action: it has its own entry
|
||||
// point, which re-checks the credentials before running.
|
||||
if (request.action == QLatin1String("release-lock")) return releaseDatabaseLock();
|
||||
// A bulk removal is replayed with the groups it still has queued.
|
||||
const StartResult result = startRequest(request);
|
||||
if (!result.started && !result.needsPassword && !result.locked) {
|
||||
|
||||
Reference in new issue
Block a user