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
@@ -132,6 +132,20 @@ public:
|
||||
void clearPassword();
|
||||
bool hasPassword() const;
|
||||
|
||||
// Whether sudo accepts this session without asking for anything (a
|
||||
// passwordless sudo such as NOPASSWD, or an account with no password at
|
||||
// all). Asked of sudo itself with `sudo -n true`, so it reflects what the
|
||||
// next command will really get rather than the account's passwd entry.
|
||||
static bool sudoWorksWithoutPassword();
|
||||
|
||||
// The shell command that runs `command` as root: the password is piped to
|
||||
// `sudo -S`, or `sudo -n` is used when there is none. Without a password,
|
||||
// a passwordless setup therefore still works, and a password-requiring one
|
||||
// fails fast instead of waiting on a prompt nobody can answer. Exposed as
|
||||
// static so both branches can be unit-tested without invoking sudo.
|
||||
static std::string privilegedCommand(const std::string& command,
|
||||
const std::string& password);
|
||||
|
||||
std::vector<PackageInfo> search(const std::string& query) override;
|
||||
bool install(const std::string& packageName,
|
||||
ProgressCallback progressCallback) override;
|
||||
@@ -157,8 +171,8 @@ private:
|
||||
bool isPackageInstalled(const std::string& name);
|
||||
|
||||
// Run a one-off command (kill, rm) and return its exit status, through sudo
|
||||
// with the session password when asked. Used by the lock recovery, which
|
||||
// needs the status rather than the output.
|
||||
// when asked (with the session password, or passwordless). Used by the lock
|
||||
// recovery, which needs the status rather than the output.
|
||||
int runCommand(const std::string& command, bool withSudo) const;
|
||||
bool terminateProcess(int pid, const char* signal) const;
|
||||
bool removeLockFile() const;
|
||||
|
||||
Reference in new issue
Block a user