PEP8: One Import per line... -.-

Add TODO statements and foremost return False on error. Missed that
pull/4/head
Darksider3 5 years ago
parent c43cad73fa
commit a6d63fee42

@ -1,8 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from lib.sqlitedb import SQLitedb import ListUsers
import csv
import io
import lib.CFG as CFG import lib.CFG as CFG
import ListUsers, csv, os, io
if __name__ == "__main__": if __name__ == "__main__":
try: try:

@ -1,4 +1,7 @@
import configparser, logging, argparse, os import argparse
import configparser
import logging
import os
cwd = os.environ.get('TILDE_CONF') cwd = os.environ.get('TILDE_CONF')
if cwd is None: if cwd is None:

@ -1,4 +1,7 @@
import sys, os, subprocess, pwd import sys
import os
import subprocess
import pwd
class System: class System:
@ -41,15 +44,16 @@ class System:
except OSError as e: except OSError as e:
print(f"Could not create {ssh_dir}: Exception: {e}", file=sys.stderr) print(f"Could not create {ssh_dir}: Exception: {e}", file=sys.stderr)
return False return False
try:
with open(ssh_dir + "authorized_keys", "w") as f: with open(ssh_dir + "authorized_keys", "w") as f:
print(pubkey, file=f) print(pubkey, file=f)
f.close() f.close()
try:
os.chmod(ssh_dir + "authorized_keys", 0o700) # directory is already 777? os.chmod(ssh_dir + "authorized_keys", 0o700) # directory is already 777?
os.chmod(ssh_dir, 0o700) # directory is already 777? os.chmod(ssh_dir, 0o700) # directory is already 777?
except OSError as e: except OSError as e:
print(f"Could not chmod 0700 {ssh_dir} or {ssh_dir}/authorized_keys, Exception: {e}", file=sys.stderr) print(f"Could not write and/or chmod 0700 {ssh_dir} or {ssh_dir}/authorized_keys, Exception: {e}",
return False file=sys.stderr)
return False # @TODO Exception in Log
try: try:
pwdnam = pwd.getpwnam(username) pwdnam = pwd.getpwnam(username)
os.chown(ssh_dir, pwdnam[2], pwdnam[3]) # 2=>uid, 3=>gid os.chown(ssh_dir, pwdnam[2], pwdnam[3]) # 2=>uid, 3=>gid
@ -57,7 +61,7 @@ class System:
except OSError as e: except OSError as e:
print(f"Could not chown {ssh_dir} and/or authorized_keys to {username} and their group, Exception: {e}", print(f"Could not chown {ssh_dir} and/or authorized_keys to {username} and their group, Exception: {e}",
file=sys.stderr) file=sys.stderr)
return False return False # @TODO Exception in Log
return True return True
def lock_user_pw(self, username: str, cc: tuple = tuple(["usermod", "--lock"])): def lock_user_pw(self, username: str, cc: tuple = tuple(["usermod", "--lock"])):
@ -70,6 +74,8 @@ class System:
rt = subprocess.call(cc) rt = subprocess.call(cc)
if rt != 0: if rt != 0:
print(f"Could not lock user '{username}'; '{cc}' returned '{rt}'", file=sys.stderr) print(f"Could not lock user '{username}'; '{cc}' returned '{rt}'", file=sys.stderr)
return False
# @TODO Exception in Log
def add_to_usergroup(self, username: str, group: str = "tilde", cc: tuple = tuple(["usermod", "-a", "-G"])): def add_to_usergroup(self, username: str, group: str = "tilde", cc: tuple = tuple(["usermod", "-a", "-G"])):
add_command = cc add_command = cc
@ -81,7 +87,8 @@ class System:
rt = subprocess.call(cc) rt = subprocess.call(cc)
if rt != 0: if rt != 0:
print(f"Could not add user '{username}' to group '{group}' with command '{cc}', returned '{rt}'", print(f"Could not add user '{username}' to group '{group}' with command '{cc}', returned '{rt}'",
file=sys.stderr) file=sys.stderr) # @TODO Exception in Log
return False
def printTuple(self, tup: tuple): def printTuple(self, tup: tuple):
pp = "" pp = ""

Loading…
Cancel
Save