1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

frontend: All-in-one fixes for module switches

This commit is contained in:
Игорь Чудов 2020-06-29 12:59:22 +04:00
parent f680a3025e
commit 36d0a92247
Signed by untrusted user: nir
GPG Key ID: 0F3883600CAE7AAC
12 changed files with 141 additions and 73 deletions

View File

@ -20,7 +20,7 @@ from abc import ABC
def check_experimental_enabled(storage):
experimental_enable_flag = 'Software\\BaseALT\\Policies\\gpupdate\\global_experimental_enable'
experimental_enable_flag = 'Software\\BaseALT\\Policies\\GPUpdate\\GlobalExperimental'
flag = storage.get_hklm_entry(experimental_enable_flag)
if '1' == flag:
@ -28,8 +28,8 @@ def check_experimental_enabled(storage):
return False
def check_module_enabled(storage, module_name, default):
gpupdate_module_enable_branch = 'Software\\BaseALT\\Policies\\gpupdate'
def check_module_enabled(storage, module_name):
gpupdate_module_enable_branch = 'Software\\BaseALT\\Policies\\GPUpdate'
gpupdate_module_flag = '{}\\{}_enable'.format(gpupdate_module_enable_branch, module_name)
flag = storage.get_hklm_entry(gpupdate_module_flag)
@ -38,7 +38,21 @@ def check_module_enabled(storage, module_name, default):
if '0' == flag:
return True
return default
return None
def check_enabled(storage, module_name, is_experimental):
module_enabled = check_module_enabled(storage, module_name)
exp_enabled = check_experimental_enabled(storage)
result = False
if None == module_enabled:
if is_experimental and exp_enabled:
result = True
if not is_experimental:
result = True
else:
result = module_enabled
class applier_frontend(ABC):
@classmethod

View File

@ -18,7 +18,7 @@
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
import logging
@ -29,8 +29,8 @@ from util.logging import slogm
from util.util import is_machine_name
class chromium_applier(applier_frontend):
__module_name = 'chromium_applier'
__module_enabled = True
__module_name = 'ChromiumApplier'
__module_enabled = False
__module_experimental = True
__registry_branch = 'Software\\Policies\\Google\\Chrome'
__managed_policies_path = '/etc/chromium/policies/managed'
@ -45,7 +45,11 @@ class chromium_applier(applier_frontend):
self.username = username
self._is_machine_name = is_machine_name(self.username)
self.policies = dict()
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def get_hklm_string_entry(self, hive_subkey):
query_str = '{}\\{}'.format(self.__registry_branch, hive_subkey)

View File

@ -24,7 +24,7 @@ from pathlib import Path
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from gpt.drives import json2drive
from util.util import get_homedir
@ -56,7 +56,7 @@ class cifs_applier(applier_frontend):
pass
class cifs_applier_user(applier_frontend):
__module_name = 'cifs_applier_user'
__module_name = 'CIFSApplierUser'
__module_enabled = False
__module_experimental = True
__auto_file = '/etc/auto.master'
@ -96,7 +96,11 @@ class cifs_applier_user(applier_frontend):
self.template_indentity = self.template_env.get_template(self.__template_identity)
self.template_auto = self.template_env.get_template(self.__template_auto)
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def user_context_apply(self):

View File

@ -18,7 +18,7 @@
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from .appliers.control import control
from util.logging import slogm
@ -26,7 +26,7 @@ from util.logging import slogm
import logging
class control_applier(applier_frontend):
__module_name = 'control_applier'
__module_name = 'ControlApplier'
__module_experimental = False
__module_enabled = True
_registry_branch = 'Software\\BaseALT\\Policies\\Control'
@ -35,7 +35,11 @@ class control_applier(applier_frontend):
self.storage = storage
self.control_settings = self.storage.filter_hklm_entries('Software\\BaseALT\\Policies\\Control%')
self.controls = list()
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def run(self):
for setting in self.control_settings:

View File

@ -24,7 +24,7 @@ import cups
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from gpt.printers import json2printer
from util.rpm import is_rpm_installed
@ -65,13 +65,17 @@ def connect_printer(connection, prn):
)
class cups_applier(applier_frontend):
__module_name = 'cups_applier'
__module_name = 'CUPSApplier'
__module_experimantal = True
__module_enabled = False
def __init__(self, storage):
self.storage = storage
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def run(self):
if not is_rpm_installed('cups'):
@ -93,7 +97,7 @@ class cups_applier(applier_frontend):
self.run()
class cups_applier_user(applier_frontend):
__module_name = 'cups_applier_user'
__module_name = 'CUPSApplierUser'
__module_experimental = True
__module_enabled = False
@ -101,7 +105,11 @@ class cups_applier_user(applier_frontend):
self.storage = storage
self.sid = sid
self.username = username
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_enabled
)
def user_context_apply(self):
'''

View File

@ -32,15 +32,15 @@ import configparser
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from util.logging import slogm
from util.util import is_machine_name
class firefox_applier(applier_frontend):
__module_name = 'firefox_applier'
__module_name = 'FirefoxApplier'
__module_experimental = True
__module_enabled = True
__module_enabled = False
__registry_branch = 'Software\\Policies\\Mozilla\\Firefox'
__firefox_installdir = '/usr/lib64/firefox/distribution'
__user_settings_dir = '.mozilla/firefox'
@ -52,7 +52,11 @@ class firefox_applier(applier_frontend):
self._is_machine_name = is_machine_name(self.username)
self.policies = dict()
self.policies_json = dict({ 'policies': self.policies })
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def get_profiles(self):
'''

View File

@ -20,7 +20,7 @@ from pathlib import Path
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from .appliers.folder import Folder
from util.logging import slogm
@ -28,7 +28,7 @@ from util.logging import slogm
import logging
class folder_applier(applier_frontend):
__module_name = 'folder_applier'
__module_name = 'FoldersApplier'
__module_experimental = False
__module_enabled = True
@ -44,7 +44,7 @@ class folder_applier(applier_frontend):
fld.action()
class folder_applier_user(applier_frontend):
__module_name = 'folder_applier_user'
__module_name = 'FoldersApplierUser'
__module_experimental = False
__module_enabled = True
@ -53,7 +53,11 @@ class folder_applier_user(applier_frontend):
self.sid = sid
self.username = username
self.folders = self.storage.get_folders(self.sid)
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def run(self):
for directory_obj in self.folders:

View File

@ -22,7 +22,7 @@ import subprocess
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from .appliers.gsettings import (
system_gsetting,
@ -31,7 +31,7 @@ from .appliers.gsettings import (
from util.logging import slogm
class gsettings_applier(applier_frontend):
__module_name = 'gsettings_applier'
__module_name = 'GSettingsApplier'
__module_experimental = True
__module_enabled = False
__registry_branch = 'Software\\BaseALT\\Policies\\gsettings'
@ -43,7 +43,11 @@ class gsettings_applier(applier_frontend):
self.gsettings_keys = self.storage.filter_hklm_entries(gsettings_filter)
self.gsettings = list()
self.override_file = os.path.join(self.__global_schema, '0_policy.gschema.override')
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def apply(self):
# Cleanup settings from previous run
@ -70,7 +74,7 @@ class gsettings_applier(applier_frontend):
logging.debug(slogm('Error recompiling global GSettings schemas'))
class gsettings_applier_user(applier_frontend):
__module_name = 'gsettings_applier_user'
__module_name = 'GSettingsApplierUser'
__module_experimental = True
__module_enabled = False
__registry_branch = 'Software\\BaseALT\\Policies\\gsettings'

View File

@ -26,11 +26,11 @@ from util.rpm import (
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
class package_applier(applier_frontend):
__module_name = 'package_applier'
__module_name = 'PackagesApplier'
__module_experimental = True
__module_enabled = False
__install_key_name = 'Install'
@ -46,27 +46,34 @@ class package_applier(applier_frontend):
self.install_packages_setting = self.storage.filter_hklm_entries(install_branch)
self.remove_packages_setting = self.storage.filter_hklm_entries(remove_branch)
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def run(self):
if 0 < len(self.install_packages_setting) or 0 < len(self.remove_packages_setting):
update()
for package in self.install_packages_setting:
try:
install_rpm(package.data)
except Exception as exc:
logging.error(exc)
for package in self.remove_packages_setting:
try:
remove_rpm(package.data)
except Exception as exc:
logging.error(exc)
def apply(self):
if self.__module_enabled:
if 0 < len(self.install_packages_setting) or 0 < len(self.remove_packages_setting):
update()
for package in self.install_packages_setting:
try:
install_rpm(package.data)
except Exception as exc:
logging.error(exc)
for package in self.remove_packages_setting:
try:
remove_rpm(package.data)
except Exception as exc:
logging.error(exc)
self.run()
class package_applier_user(applier_frontend):
__module_name = 'package_applier_user'
__module_name = 'PackagesApplierUser'
__module_experimental = True
__module_enabled = False
__install_key_name = 'Install'
@ -92,23 +99,26 @@ class package_applier_user(applier_frontend):
'''
pass
def run(self):
if 0 < len(self.install_packages_setting) or 0 < len(self.remove_packages_setting):
update()
for package in self.install_packages_setting:
try:
install_rpm(package.data)
except Exception as exc:
logging.debug(exc)
for package in self.remove_packages_setting:
try:
remove_rpm(package.data)
except Exception as exc:
logging.debug(exc)
def admin_context_apply(self):
'''
Install software assigned to specified username regardless
which computer he uses to log into system.
'''
if self.__module_enabled:
if 0 < len(self.install_packages_setting) or 0 < len(self.remove_packages_setting):
update()
for package in self.install_packages_setting:
try:
install_rpm(package.data)
except Exception as exc:
logging.debug(exc)
for package in self.remove_packages_setting:
try:
remove_rpm(package.data)
except Exception as exc:
logging.debug(exc)
self.run()

View File

@ -18,7 +18,7 @@
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from .appliers.polkit import polkit
from util.logging import slogm
@ -26,7 +26,7 @@ from util.logging import slogm
import logging
class polkit_applier(applier_frontend):
__module_name = 'polkit_applier'
__module_name = 'PolkitApplier'
__module_experimental = False
__module_enabled = True
__deny_all = 'Software\\Policies\\Microsoft\\Windows\\RemovableStorageDevices\\Deny_All'
@ -47,7 +47,11 @@ class polkit_applier(applier_frontend):
logging.debug(slogm('Deny_All setting not found'))
self.policies = []
self.policies.append(polkit(template_file, template_vars))
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def apply(self):
'''
@ -58,7 +62,7 @@ class polkit_applier(applier_frontend):
policy.generate()
class polkit_applier_user(applier_frontend):
__module_name = 'polkit_applier_user'
__module_name = 'PolkitApplierUser'
__module_experimental = False
__module_enabled = True
__deny_all = 'Software\\Policies\\Microsoft\\Windows\\RemovableStorageDevices\\Deny_All'

View File

@ -21,7 +21,7 @@ import subprocess
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from gpt.shortcuts import json2sc
from util.windows import expand_windows_var
@ -82,13 +82,17 @@ def write_shortcut(shortcut, username=None):
shortcut.write_desktop(dest_abspath)
class shortcut_applier(applier_frontend):
__module_name = 'shortcut_applier'
__module_name = 'ShortcutsApplier'
__module_experimental = False
__module_enabled = True
def __init__(self, storage):
self.storage = storage
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def run(self):
shortcuts = storage_get_shortcuts(self.storage, self.storage.get_info('machine_sid'))
@ -108,7 +112,7 @@ class shortcut_applier(applier_frontend):
self.run()
class shortcut_applier_user(applier_frontend):
__module_name = 'shortcut_applier_user'
__module_name = 'ShortcutsApplierUser'
__module_experimental = False
__module_enabled = True

View File

@ -18,7 +18,7 @@
from .applier_frontend import (
applier_frontend
, check_module_enabled
, check_enabled
)
from .appliers.systemd import systemd_unit
from util.logging import slogm
@ -26,7 +26,7 @@ from util.logging import slogm
import logging
class systemd_applier(applier_frontend):
__module_name = 'systemd_applier'
__module_name = 'SystemdApplier'
__module_experimental = False
__module_enabled = True
__registry_branch = 'Software\\BaseALT\\Policies\\SystemdUnits'
@ -35,7 +35,11 @@ class systemd_applier(applier_frontend):
self.storage = storage
self.systemd_unit_settings = self.storage.filter_hklm_entries('Software\\BaseALT\\Policies\\SystemdUnits%')
self.units = []
self.__module_enabled = check_module_enabled(self.storage, self.__module_name, self.__module_enabled)
self.__module_enabled = check_enabled(
self.storage
, self.__module_name
, self.__module_experimental
)
def run(self):
for setting in self.systemd_unit_settings:
@ -59,7 +63,7 @@ class systemd_applier(applier_frontend):
self.run()
class systemd_applier_user(applier_frontend):
__module_name = 'systemd_applier_user'
__module_name = 'SystemdApplierUser'
__module_experimental = False
__module_enabled = True
__registry_branch = 'Software\\BaseALT\\Policies\\SystemdUnits'