Пример #1
0
    def change_permissions_for_local_users(self):
        if self.disable_local_users is False:
            content = Util.read_file('/etc/passwd')
            change_permisson = "chmod -R 700 {}"
            for p in pwd.getpwall():
                self.logger.info(
                    "User: '******' will change home directory of username".
                    format(p.pw_name))
                if not sysx.shell_is_interactive(p.pw_shell):
                    continue
                if p.pw_uid == 0:
                    continue
                if p.pw_name in content:
                    Util.execute(change_permisson.format(p.pw_dir))

        add_user_conf_file = "/etc/adduser.conf"
        file_dir_mode = open(add_user_conf_file, 'r')
        file_data = file_dir_mode.read()
        file_data = file_data.replace("DIR_MODE=0755", "DIR_MODE=0700")
        file_dir_mode.close()

        file_dir_mode = open(add_user_conf_file, 'w')
        file_dir_mode.write(file_data)
        file_dir_mode.close()
        self.logger.info("add user mode changed to 0700 in file {}".format(
            add_user_conf_file))
Пример #2
0
 def enable_local_users(self):
     passwd_cmd = 'passwd -u {}'
     change_home = 'usermod -m -d {0} {1}'
     change_username = '******'
     content = self.util.read_file('/etc/passwd')
     for p in pwd.getpwall():
         if not sysx.shell_is_interactive(p.pw_shell):
             continue
         if p.pw_uid == 0:
             continue
         if p.pw_name in content:
             new_home_dir = p.pw_dir.rstrip('-local/') + '/'
             new_username = p.pw_name.rstrip('-local')
             self.util.execute(passwd_cmd.format(p.pw_name))
             self.util.execute(
                 change_username.format(new_username, p.pw_name))
             self.util.execute(
                 change_home.format(new_home_dir, new_username))
             self.logger.debug(
                 "User: '******' will be enabled and changed username and home directory of username"
                 .format(p.pw_name))
Пример #3
0
 def disable_local_users(self):
     passwd_cmd = 'passwd -l {}'
     change_home = 'usermod -m -d {0} {1}'
     change_username = '******'
     content = Util.read_file('/etc/passwd')
     kill_all_process = 'killall -KILL -u {}'
     for p in pwd.getpwall():
         self.logger.info(
             "User: '******' will be disabled and changed username and home directory of username"
             .format(p.pw_name))
         if not sysx.shell_is_interactive(p.pw_shell):
             continue
         if p.pw_uid == 0:
             continue
         if p.pw_name in content:
             new_home_dir = p.pw_dir.rstrip('/') + '-local/'
             new_username = p.pw_name + '-local'
             Util.execute(kill_all_process.format(p.pw_name))
             Util.execute(passwd_cmd.format(p.pw_name))
             Util.execute(change_username.format(new_username, p.pw_name))
             Util.execute(change_home.format(new_home_dir, new_username))
Пример #4
0
    def disable_local_users(self):
        passwd_cmd = 'passwd -l {}'
        change_home = 'usermod -m -d {0} {1}'
        change_username = '******'
        content = Util.read_file('/etc/passwd')
        kill_all_process = 'killall -KILL -u {}'
        change_permisson = "chmod -R 700 {}"

        add_user_conf_file = "/etc/adduser.conf"
        file_dir_mode = open(add_user_conf_file, 'r')
        file_data = file_dir_mode.read()
        file_data = file_data.replace("DIR_MODE=0755", "DIR_MODE=0700")
        file_dir_mode.close()

        file_dir_mode = open(add_user_conf_file, 'w')
        file_dir_mode.write(file_data)
        file_dir_mode.close()

        self.logger.info("add user mode changed to 0700 in file {}".format(
            add_user_conf_file))

        for p in pwd.getpwall():
            self.logger.info(
                "User: '******' will be disabled and changed username and home directory of username"
                .format(p.pw_name))
            if not sysx.shell_is_interactive(p.pw_shell):
                continue
            if p.pw_uid == 0:
                continue
            if p.pw_name in content:
                new_home_dir = p.pw_dir.rstrip('/') + '-local/'
                new_username = p.pw_name + '-local'
                Util.execute(kill_all_process.format(p.pw_name))
                Util.execute(passwd_cmd.format(p.pw_name))
                Util.execute(change_username.format(new_username, p.pw_name))
                Util.execute(change_home.format(new_home_dir, new_username))
                Util.execute(change_permisson.format(new_home_dir))