mirror of
https://github.com/ThunixdotNet/makeuser.git
synced 2026-01-24 13:40:17 +00:00
Fix subprocess.run calls and replace libc crypt with crypt module
This commit is contained in:
12
makeuser
12
makeuser
@@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import subprocess,argparse,random,string
|
import subprocess,argparse,random,string,crypt
|
||||||
from ctypes import cdll,c_char_p
|
|
||||||
libc = cdll.LoadLibrary("libc.so.6")
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog="makeuser",description="A user adding script.")
|
parser = argparse.ArgumentParser(prog="makeuser",description="A user adding script.")
|
||||||
parser.add_argument("username",help="Username of user.")
|
parser.add_argument("username",help="Username of user.")
|
||||||
@@ -11,8 +9,8 @@ parser.add_argument("key",help="The user's SSH pubkey.")
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
pw = "".join(random.sample(string.ascii_letters+string.digits,20))
|
pw = "".join(random.sample(string.ascii_letters+string.digits,20))
|
||||||
cr = libc.crypt(pw)
|
cr = crypt.crypt(pw)
|
||||||
|
|
||||||
subprocess.run("sudo useradd -m -g 100 -p {} -s /bin/bash {}".format(cr,args.user)
|
subprocess.run("sudo useradd -m -g 100 -p {} -s /bin/bash {}".format(cr,args.username),shell=True)
|
||||||
subprocess.run("echo '{}' | sudo tee /home/{}/.ssh/authorized_keys".format(args.key,args.user))
|
subprocess.run("echo '{}' | sudo tee /home/{}/.ssh/authorized_keys".format(args.key,args.username),shell=True)
|
||||||
subprocess.run("sed -e 's/username/{}/' -e 's/password/{}/' email.tmpl | sendmail {} sudoers@tilde.team")
|
subprocess.run("sed -e 's/username/{}/' -e 's/password/{}/' email.tmpl | sendmail {} sudoers@tilde.team",shell=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user