From 6a0c42f86ba1df0d071cd6124342eefb994c1946 Mon Sep 17 00:00:00 2001 From: quackerd Date: Fri, 19 Feb 2021 18:41:39 -0500 Subject: [PATCH] change example --- add-user-group.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/add-user-group.py b/add-user-group.py index aed3b7b..4d98da4 100644 --- a/add-user-group.py +++ b/add-user-group.py @@ -19,8 +19,10 @@ def main(): if (len(elements) != 2): print("Skipping invalid group config string \"" + group + "\"") continue - subprocess.check_call(shlex.join(["addgroup", "-g", elements[1], elements[0]]), shell=True) - print("Added group " + elements[0] + " with gid " + elements[1]) + gid = elements[1] + gname = elements[0] + subprocess.check_call("addgroup -g" + shlex.quote(gid) + " " + shlex.quote(gname), shell=True) + print("Added group " + gname + " with gid " + gid) # username,uid,password,[group] @@ -29,13 +31,17 @@ def main(): if (len(elements) != 3 and len(elements) != 4): print("Skipping invalid user config string \"" + user + "\"") continue - subprocess.check_call(shlex.join(["adduser", "-D", "-H", "-u", elements[1], elements[0]]), shell=True) - print("Added user " + elements[0] + " with uid " + elements[1]) + uname = elements[0] + uid = elements[1] + passwd = elements[2] + subprocess.check_call("adduser -D -H -u ", shlex.quote(uid), shlex.quote(uname), shell=True) + print("Added user " + uname + " with uid " + uid) if (len(elements) == 4): - subprocess.check_call(shlex.join(["addgroup", elements[0], elements[3]]), shell=True) - print("Added user " + elements[0] + " to group " + elements[3]) + gname = elements[3] + subprocess.check_call("addgroup " + shlex.quote(uname) + " " + shlex.quote(gname), shell=True) + print("Added user " + uname + " to group " + gname) # set passwd - subprocess.check_call(shlex.join(["echo", "-ne", "\"" + elements[2] + "\n" + elements[2] + "\n\""]) + " | " + shlex.join(["smbpasswd", "-a", "-U", elements[0]]), shell=True) - print("Set user " + elements[0] + " password to " + elements[2]) + subprocess.check_call("echo -ne " + shlex.quote("\n" + passwd + "\n" + passwd + "\n") + " | smbpasswd -a -U " + shlex.quote(uname), shell=True) + print("Set user " + uname + " password to " + passwd) main() \ No newline at end of file