From b4d4fd9ad42a73daf8389ccfee1431a827612f37 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Wed, 23 Oct 2019 15:02:21 +0200 Subject: [PATCH] System: Improved return calls at remove_user --- private/lib/System.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/private/lib/System.py b/private/lib/System.py index 311e693..25cc861 100644 --- a/private/lib/System.py +++ b/private/lib/System.py @@ -50,6 +50,7 @@ class System: :raises: lib.UserExceptions.UserExistsAlready: when username specified already exists on the system """ + create_command = cc cc = create_command + tuple([username]) if self.dry: @@ -128,6 +129,7 @@ class System: :type ssh_dir: str :return: None """ + with open(ssh_dir + "authorized_keys", "w") as f: print(key, file=f) f.close() @@ -218,10 +220,13 @@ class System: self.printTuple(cc) return True else: - ret = subprocess.call(cc) - if ret != 0 and ret != 6: + ret = subprocess.Popen(cc, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + ret.wait() # wait for cc + stdio, err_io = ret.communicate() # get stdout as well as stderr + if ret.returncode != 0 and ret.returncode != 6: # userdel returns 6 when no mail dir was found but success raise lib.UserExceptions.UnknownReturnCode( - f"Could not delete user with command {cc}. Return code: {ret}") + f"Could not delete user with command {cc}. Return code: {ret.returncode}," + f" stdout/stderr: {stdio+err_io}") return True