From f6b9f3524dd6785b88c3b0594a6700fde03766fc Mon Sep 17 00:00:00 2001 From: Kara <33235324+kro-cat@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:24:38 -0500 Subject: [PATCH 1/3] fix(distroutils): add **kwargs to FreeBSDDistro.chpasswd() When operating FreeBSD, the argument crypt_id is passed to an overridden method chpasswd() in the FreeBSDDistro class. The definition of this method does not contain an argument for 'crypt_id' or 'salt_len'. To address this issue, add **kwargs to the definition of chpasswd() in the FreeBSDDistro class. --- Utils/distroutils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utils/distroutils.py b/Utils/distroutils.py index 23359e5ec..990955b5d 100644 --- a/Utils/distroutils.py +++ b/Utils/distroutils.py @@ -280,7 +280,7 @@ def __init__(self, config): # noinspection PyMethodOverriding - def chpasswd(self, user, password): + def chpasswd(self, user, password, **kwargs): return ext_utils.run_send_stdin(['pw', 'usermod', 'user', '-h', '0'], password, log_cmd=False) def create_account(self, user, password, expiration, thumbprint, enable_nopasswd): @@ -554,4 +554,4 @@ def restart_ssh_service(self): retcode = ext_utils.run(ssh_restart_cmd) if retcode > 0: logger.error("Failed to restart SSH service with return code:" + str(retcode)) - return retcode \ No newline at end of file + return retcode From b22c688945ecc89d60abdea10040d3649c793a23 Mon Sep 17 00:00:00 2001 From: Kara <33235324+kro-cat@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:25:37 -0500 Subject: [PATCH 2/3] fix(distroutils): encode cmd_input argument for ext_utils.run_send_stdin() The method ext_utils.run_send_stdin() (in extensionutils.py) requires the second argument, cmd_input, to be a bytes object, not a string object. This is due to the usage of: subprocess.Popen().communicate(). Encode the password as utf-8 when passing to ext_utils.run_send_stdin(). --- Utils/distroutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utils/distroutils.py b/Utils/distroutils.py index 990955b5d..c664f6fb7 100644 --- a/Utils/distroutils.py +++ b/Utils/distroutils.py @@ -281,7 +281,7 @@ def __init__(self, config): # noinspection PyMethodOverriding def chpasswd(self, user, password, **kwargs): - return ext_utils.run_send_stdin(['pw', 'usermod', 'user', '-h', '0'], password, log_cmd=False) + return ext_utils.run_send_stdin(['pw', 'usermod', 'user', '-h', '0'], password.encode('utf-8'), log_cmd=False) def create_account(self, user, password, expiration, thumbprint, enable_nopasswd): """ From 245cc506c97b5f1fc7c0c2ff3244e68a082b5460 Mon Sep 17 00:00:00 2001 From: Kara <33235324+kro-cat@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:10:38 -0500 Subject: [PATCH 3/3] fix(distroutils): use /etc/pw.conf to discern accounting information. /etc/user.defs is the shadow configuration file. FreeBSD user management uses the pw utility. --- Utils/distroutils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Utils/distroutils.py b/Utils/distroutils.py index c664f6fb7..be06ed2f1 100644 --- a/Utils/distroutils.py +++ b/Utils/distroutils.py @@ -13,7 +13,7 @@ def get_my_distro(config, os_name=None): if 'FreeBSD' in platform.system(): return FreeBSDDistro(config) - + if os_name is None: if os.path.isfile(constants.os_release): os_name = ext_utils.get_line_starting_with("NAME", constants.os_release) @@ -296,8 +296,8 @@ def create_account(self, user, password, expiration, thumbprint, enable_nopasswd pass uidmin = None try: - if os.path.isfile("/etc/login.defs"): - uidmin = int(ext_utils.get_line_starting_with("UID_MIN", "/etc/login.defs").split()[1]) + if os.path.isfile("/etc/pw.conf"): + uidmin = int(ext_utils.get_line_starting_with("minuid", "/etc/pw.conf").split('=')[1].strip(' "')) except (ValueError, KeyError, AttributeError, EnvironmentError): pass pass @@ -374,9 +374,8 @@ def delete_account(self, user): return uidmin = None try: - if os.path.isfile("/etc/login.defs"): - uidmin = int( - ext_utils.get_line_starting_with("UID_MIN", "/etc/login.defs").split()[1]) + if os.path.isfile("/etc/pw.conf"): + uidmin = int(ext_utils.get_line_starting_with("minuid", "/etc/pw.conf").split('=')[1].strip(' "')) except (ValueError, KeyError, AttributeError, EnvironmentError): pass if uidmin is None: