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
@@ -190,6 +190,25 @@ static void testAuthFailed_ignoresPacmanErrors() {
|
||||
assert(!PacmanManager::authFailed("warning: firefox is up to date"));
|
||||
}
|
||||
|
||||
// A captured password goes to `sudo -S` on stdin, quoted so it stays data.
|
||||
static void testPrivilegedCommand_pipesThePassword() {
|
||||
assert(PacmanManager::privilegedCommand("pacman -S firefox", "secret")
|
||||
== "printf '%s\\n' 'secret' | sudo -S pacman -S firefox");
|
||||
assert(PacmanManager::privilegedCommand("true", "a'b")
|
||||
== "printf '%s\\n' 'a'\\''b' | sudo -S true");
|
||||
}
|
||||
|
||||
// No password is not a missing one: the command runs through `sudo -n`, which
|
||||
// keeps a passwordless setup working and fails fast on a password-requiring
|
||||
// one instead of waiting on a prompt nobody can answer.
|
||||
static void testPrivilegedCommand_withoutPasswordUsesSudoN() {
|
||||
const std::string command =
|
||||
PacmanManager::privilegedCommand("pacman -S firefox", std::string());
|
||||
assert(command == "sudo -n pacman -S firefox");
|
||||
assert(command.find("sudo -S") == std::string::npos);
|
||||
assert(command.find("printf") == std::string::npos);
|
||||
}
|
||||
|
||||
// The lock dialog names the process that holds pacman's database, so the
|
||||
// description has to cover the three states the detection can report.
|
||||
static void testDescribeLockHolder() {
|
||||
@@ -300,6 +319,9 @@ int main() {
|
||||
testAuthFailed_detectsMissingPassword();
|
||||
testAuthFailed_ignoresPacmanErrors();
|
||||
|
||||
testPrivilegedCommand_pipesThePassword();
|
||||
testPrivilegedCommand_withoutPasswordUsesSudoN();
|
||||
|
||||
testDescribeLockHolder();
|
||||
testLockHolderPid_findsTheHolder();
|
||||
|
||||
|
||||
Reference in new issue
Block a user