elevate icon indicating copy to clipboard operation
elevate copied to clipboard

Add doas support

Open chambln opened this issue 2 years ago • 1 comments

Based on #18 by @wxllow.

I'm not aware of the intent behind or args[0] == "sudo" in the section reproduced below, so I may have broken something if that was important. All I know is that removing it prevented a raise that terminated the program before it could try doas instead of sudo.

def elevate(show_console=True, graphical=True):
    ...
    for args in commands:
        try:
            os.execlp(args[0], *args)
        except OSError as e:
            if e.errno != errno.ENOENT or args[0] == "sudo":
                raise

Another solution I had (shown below) was to catch the FileNotFoundError that is raised when sudo is not found on PATH.

def elevate(show_console=True, graphical=True):
    ...
    for args in commands:
        try:
            os.execlp(args[0], *args)
        except FileNotFoundError:
            raise               # sudo or doas not found 
        except OSError as e:
            if e.errno != errno.ENOENT or args[0] == "sudo":
                raise

This needs to be tested on a system which has only sudo (no doas) before being merged, so I've marked this PR as a draft.

chambln avatar Nov 06 '22 03:11 chambln

I am SOO late but i believe the purpose of args[0] == "sudo" is that since sudo was the last command being checked if it's not found then that means there are no available commands, so an exception is thrown. In my pull request, I made the mistake of adding commands.append(["doas"] + args) after commands.append(["sudo"] + args)

However, I think keeping the args[0] == "sudo" exactly as is and just moving the doas line to be before the sudo line would be the best solution. doas before sudo makes more sense because 99% of the people who have doas installed would prefer using it than sudo (otherwise they just wouldn't have installed doas)

wxllow avatar Jul 12 '23 17:07 wxllow