Morganamilo / paru

Feature packed AUR helper
GNU General Public License v3.0
6.25k stars 237 forks source link

sudo: a password is required #332

Closed mindyourlifeguide closed 3 years ago

mindyourlifeguide commented 3 years ago

Affected Version

paru -V paru v1.5.1 - libalpm v12.0.2

Description

Extra password request after rejection of an operation

Peek 2021-04-16 18-33

KerfuffleV2 commented 3 years ago

paru spawns sudo but exits immediately when it gets SIGINT. sudo takes a second before it prints the second line. You can verify this by running and trying to abort sudo itself.

The commit that closed a similar issue on a different project has a solution, but it's not super simple: https://github.com/casey/just/issues/302

edit: That project has a permissive license. Could possibly just yoink interrupt_{handle,guard}.rs from it.

seragunn commented 3 years ago

Something like this would be the simplest solution:

static mut SIGINT_RECEIVED: bool = false;

#[no_mangle]
extern "C" fn sigint_handler(_: i32) {
    unsafe { SIGINT_RECEIVED = true };
    std::process::exit(0x82);
}

fn main() {
    // ...
    unsafe {
        signal(Signal::SIGINT, SigHandler::Handler(sigint_handler)).unwrap();
    }
    // ...
}
KerfuffleV2 commented 3 years ago

@trevorgunn Unless I'm misunderstanding, I don't think that would help. sudo isn't being run in async or anything, so there's no other thread or process to look at that SIGINT_RECEIVED flag.

seragunn commented 3 years ago

https://github.com/Morganamilo/paru/blob/be1cf8e7202c5d3711c30483fd2a2dd5c84c8ece/src/exec.rs#L51-L62

KerfuffleV2 commented 3 years ago

@trevorgunn This is behavior that occurs with SudoLoop disabled in the configuration.

KerfuffleV2 commented 3 years ago

This fixes it for me: https://github.com/KerfuffleV2/paru/commit/93db172c768d51394f42fb3f841c4dc17518ab94

@Morganamilo Any merit to that approach?

seragunn commented 3 years ago

Right, ok. So this is just how sudo works. One sees the same delay and message just running, for instance, sudo -i.

But is this something we should be trying to fix? Sudo captures SIGINT for a reason.

Edit: so does Pacman for that matter.

KerfuffleV2 commented 3 years ago

@trevorgunn Well, one way to fix it is to block SIGINT while running sudo as a child. Then paru will wait until sudo exits before exiting itself and random stuff won't end up on the terminal. See the commit I linked about your post ^^^^^

seragunn commented 3 years ago

You're right. Sorry, I was too focused on work that I did not read what linked to carefully enough.

Morganamilo commented 3 years ago

I'm not really interested in this because it's way to much code for what seems little benefit.

KerfuffleV2 commented 3 years ago

@mindyourlifeguide Alternative solution is to install something like doas instead (which I can confirm doesn't have the issue). Just be aware of the security implications of having multiple sudo-type programs installed and how that increases the surface area of potential exploits.

mindyourlifeguide commented 3 years ago

@KerfuffleV2, thanks for the advice! Perhaps I will return to yay - the potential in paru is clearly there, but for everyday use it does not suit me yet.

Thank you all for your help!

Morganamilo commented 3 years ago

But yay does the exact same thing.

mindyourlifeguide commented 3 years ago

no, in yay it works fine.

Morganamilo commented 3 years ago

Not for me

morganamilo@Octavia ~ % yay -R xterm
[sudo] password for morganamilo: 

morganamilo@Octavia ~ % sudo: a password is required
mindyourlifeguide commented 3 years ago

@Morganamilo , Indeed, I tried the same behavior. And I realized that on yay I did not notice this - I directly use the yay commands only for updating, namely yay, for the rest of the things I wrapped everything in commands with fzf and everything ends there correctly, most likely due to other utilities.

mindyourlifeguide commented 3 years ago

And can I edit the pkgfile right away? Will it apply my modifications?

soloturn commented 3 years ago

@Morganamilo would using "pkexec" instead of "sudo" help ?