Fix subprocess.run calls and replace libc crypt with crypt module

This commit is contained in:
Robert Miles 2018-09-21 14:29:21 -04:00
parent e97a2b17f3
commit 6a85c918fc
1 changed files with 5 additions and 7 deletions

View File

@ -1,8 +1,6 @@
#!/usr/bin/python3
import subprocess,argparse,random,string
from ctypes import cdll,c_char_p
libc = cdll.LoadLibrary("libc.so.6")
import subprocess,argparse,random,string,crypt
parser = argparse.ArgumentParser(prog="makeuser",description="A user adding script.")
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()
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("echo '{}' | sudo tee /home/{}/.ssh/authorized_keys".format(args.key,args.user))
subprocess.run("sed -e 's/username/{}/' -e 's/password/{}/' email.tmpl | sendmail {} sudoers@tilde.team")
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.username),shell=True)
subprocess.run("sed -e 's/username/{}/' -e 's/password/{}/' email.tmpl | sendmail {} sudoers@tilde.team",shell=True)