From b4eb4fe03376b100258a3f4842cd44ef52fb631c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuncay=20=C3=87OLAK?= Date: Tue, 28 Aug 2018 12:51:59 +0300 Subject: [PATCH] added method to delete local users after registration ahenk --- src/base/registration/registration.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/base/registration/registration.py b/src/base/registration/registration.py index e30bd9d..d18448b 100644 --- a/src/base/registration/registration.py +++ b/src/base/registration/registration.py @@ -12,6 +12,7 @@ from base.messaging.anonymous_messenger import AnonymousMessenger from base.system.system import System from base.timer.setup_timer import SetupTimer from base.timer.timer import Timer +from base.util.util import Util class Registration: @@ -23,6 +24,7 @@ class Registration: self.messenger = scope.get_messenger() self.conf_manager = scope.get_configuration_manager() self.db_service = scope.get_db_service() + self.util = Util() self.event_manager.register_event('REGISTRATION_RESPONSE', self.registration_process) @@ -73,6 +75,7 @@ class Registration: with open('/etc/ahenk/ahenk.conf', 'w') as configfile: self.conf_manager.write(configfile) self.logger.debug('Registration configuration file is updated') + self.disable_local_users() def is_registered(self): @@ -180,3 +183,19 @@ class Registration: self.logger.error('Ahenk is shutting down...') print('Ahenk is shutting down...') System.Process.kill_by_pid(int(System.Ahenk.get_pid_number())) + + def disable_local_users(self): + command_users = 'awk -F: \'{print $1 ":" $6 ":" $7}\' /etc/passwd | grep /bin/bash' + command_user_disable = 'passwd -l {}' + command_logout_user = 'pkill -u {}' + result_code, p_out, p_err = self.util.execute(command_users) + lines = p_out.split('\n') + lines.pop() + for line in lines: + detail = line.split(':') + if detail[0] != 'root': + self.util.execute(command_user_disable.format(detail[0])) + self.util.execute(command_logout_user.format(detail[0])) + self.logger.debug('{0} has been disabled and killed all processes for {0}'.format(detail[0])) + else: + self.logger.info("machine has only root user")