-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# doasudo | ||
sudo emulation for doas/opendoas | ||
|
||
Currently python only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import argparse | ||
has_args = False | ||
|
||
doas_exe = subprocess.getoutput('which doas') | ||
if not doas_exe: | ||
print("doasudo.py: doas: command not found.") | ||
exit(128) | ||
|
||
def parse_args(has_args=False): | ||
parser = argparse.ArgumentParser( | ||
prog='doasudo.py', | ||
description='Translate (most) of the sudo command to doas', | ||
epilog='do as sudo', | ||
) | ||
parser.add_argument('command', nargs="*") | ||
parser.add_argument('-S', '--stdin', '-n', '--non-interactive', | ||
help="Non interactive mode, fail if the matching rule doesn't have the nopass option.", | ||
action='store_true', | ||
) | ||
parser.add_argument('-s', '--shell', | ||
help="Execute the shell from SHELL or /etc/passwd.", | ||
action='store_true', | ||
) | ||
parser.add_argument('-u', '--user', | ||
help="Execute the command as user. The default is root.", | ||
) | ||
parser.add_argument('-T', '--command-timeout', | ||
help="No-op for compatability.", | ||
action='store_true' | ||
) | ||
parser.add_argument('-K', '--remove-timestamp', | ||
help="Clear any persisted authentications from previous invocations, then immediately exit.", | ||
action='store_const', | ||
const=3, | ||
dest='timestamp', | ||
) | ||
parser.add_argument('-k', '--reset-timestamp', | ||
help="Like -K, but a supplied command will be executed.", | ||
action='store_const', | ||
const=1, | ||
dest='timestamp', | ||
) | ||
return parser.parse_args() | ||
|
||
args = parse_args() | ||
|
||
doas_args = [] | ||
|
||
if args.user: | ||
doas_args.extend(('-u',args.user)) | ||
if args.shell: | ||
doas_args.extend('-s') | ||
if args.stdin: | ||
doas_args.extend('-n') | ||
args.timestamp = args.timestamp or 0 | ||
|
||
if not args.timestamp^2 and args.command != None: | ||
subprocess.run((doas_exe,) + tuple(doas_args) + ('--',) + tuple(command) ) | ||
|
||
if args.timestamp^1: | ||
os.system(doas_exe+' -L') |