From b6ad6d80d59e6b9382153e389c4e530b0e83ff2a Mon Sep 17 00:00:00 2001 From: Alexander Burmatov Date: Wed, 17 May 2023 15:26:02 +0300 Subject: [PATCH] Add operation for leave from the domain --- actor/src/udsactor/linux/operations.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/actor/src/udsactor/linux/operations.py b/actor/src/udsactor/linux/operations.py index cbfc2015c..9de35d555 100644 --- a/actor/src/udsactor/linux/operations.py +++ b/actor/src/udsactor/linux/operations.py @@ -231,6 +231,30 @@ def joinDomain( # pylint: disable=unused-argument, too-many-arguments except Exception as e: logger.error(f'Error join machine to domain {name}: {e}') +def leaveDomain( + domain: str, + account: str, + password: str, + client_software: str, + server_software: str, + ) -> None: + if server_software == 'ipa': + try: + command = f'hostnamectl set-hostname {getComputerName()}' + subprocess.run(command, shell=True) + except Exception as e: + logger.error(f'Error set hostname for leave freeeipa domain: {e}') + try: + command = f'realm leave -U {account} ' + if client_software and client_software != 'automatically': + command += f'--client-software={client_software} ' + if server_software: + command += f'--server-software={server_software} ' + command += domain + subprocess.run(command, input=password.encode(), shell=True) + except Exception as e: + logger.error(f'Error leave machine from domain {domain}: {e}') + def changeUserPassword(user: str, oldPassword: str, newPassword: str) -> None: ''' Simple password change for user using command line