1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-10-17 19:33:10 +03:00

Compare commits

..

102 Commits

Author SHA1 Message Date
Valery Sinelnikov
1ed181e765 Cleaning up code and removing unnecessary parts 2024-02-27 15:21:34 +04:00
Valery Sinelnikov
532ca8a420 Changed package_applier_user launch keys 2024-02-26 13:23:08 +04:00
Valery Sinelnikov
3efde56398 Adapted check_enable_home_link to work with the new storage 2024-02-26 13:21:36 +04:00
Valery Sinelnikov
9567134ea0 Typo corrected 2024-02-26 12:02:20 +04:00
Valery Sinelnikov
5c7c8b4b63 Added use of profile forwarding in registry_factory 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
10515c2152 Corrected variable name 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
3013ddb1bd Added the ability to store envprofile status 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
ab8d0121f2 Improve code readability 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
45eaf0dffa In dconf_registry init was removed, the action performed in it was transferred to gpt 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
deea1d2891 Improved get_key_value and get_dconf_envprofile 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
1f224fe39c Added function to get profile for dconf 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
1f55115440 Adaptation to the new storage for pkcon_runner 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
62bcd9cbea Added use of username when get storage 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
4a416c9bee Added class field to store username 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
c306876b22 Added the ability to save username when get storage 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
a7e02f80eb Unnecessary line removed 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
3c5c68f65d Fix check_enabled in package_applier 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
5d7a33e67d Adapted to work with the new storage 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
ed4520c335 Adding forwarding policy_name and username to load_preg_dconf 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
673b94d350 Adding policy name to ReadQueue key values 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
34b8a7e0e6 Using a new argument when creating a gpt object 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
2f399f89ce Added username argument to gpt class constructor 2024-02-26 10:46:51 +04:00
ead238bbd2 Correcting logs in class methods 2024-02-26 10:46:51 +04:00
8ddf22466d Changing the log in the create_dconf_ini_file method 2024-02-26 10:46:51 +04:00
b4a2e35b8e Removing an empty key in a dictionary 2024-02-26 10:46:51 +04:00
8d715f4927 Added logs for the create_dconf_ini_file 2024-02-26 10:46:51 +04:00
390b1cf563 Added logs for the get_entry 2024-02-26 10:46:51 +04:00
135c54314b Added logs for the get_dictionary_from_dconf 2024-02-26 10:46:51 +04:00
b1f852046c Added logs for the apply_template 2024-02-26 10:46:51 +04:00
f9ef6a8b2c log correction 2024-02-26 10:46:51 +04:00
893ca07216 Added logs for the dconf_update 2024-02-26 10:46:51 +04:00
0cd33b361a Added logs for the get_key_value method 2024-02-26 10:46:51 +04:00
6f8541c3e0 Added logs for the get_matching_keys method 2024-02-26 10:46:51 +04:00
83fede7710 Updated get_key_values ​​method 2024-02-26 10:46:51 +04:00
dea7b7c301 Fixed error message and added logging module 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
87610cf90a Added extension with unique values 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
a0685322f9 Removed duplicate additions of objects 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
1e87993b66 Added search for a suitable .desktop file
and creation of a policy based on it
2024-02-26 10:46:51 +04:00
Valery Sinelnikov
994690b4a0 Added get_desktop_files_directory for .desktop path 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
36ea46168f Changed work with object_shortcut 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
3beee96ca2 Changed queries to the registry from systemd_applier 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
0ca6feee03 Fixed registry queries 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
93bb35ecef Changed interpretation method from new repository 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
cc2dac6619 Added local path processing 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
eba69dca1a Added check for empty value 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
d991e5cb00 Added processing of the key list request 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
2b4e79bd49 Added the ability to return registry keys with a list item value 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
deabadce4a Changes in requests to get a list of packages 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
4027a01605 Added the ability to get a class 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
ffef4fb3c4 Added fun for correct processing of branch requests 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
6c2fbb4d97 Added class method to get the key 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
b247e2ff73 Changed request method for ScrollSysvolDC 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
406e2149df Changed request method for UserPolicyMode 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
640fb9e0d0 Request method changed 2024-02-26 10:46:51 +04:00
Valery Sinelnikov
d60d1af36d Fixed adding a list of scripts 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
a3db43f872 Typos corrected 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
81423a3fe2 Processing module status changed 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
bcbe11a205 Removed unnecessary arguments 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
04836f8a04 Moved save_dconf 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
bf6c95bdd7 Added gpt status flags 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
2f5076cac0 Removed obsolete implementation 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
dec123f008 Added registry saving to dconf in the backend 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
87223d2a58 Removed obsolete implementation 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
ef67df2a31 Removed excess supply merge_polfile 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
26532d039a Added flag for data status 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
2843d5eaec Adaptation of gsettings for new storage 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
3898a838df Added handling of empty data 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
972450d870 Using the dconf registry 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
f75a1ae5f2 Added processing of various requests 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
410f08f43b Changed key request gsettings 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
8551f4f0ce Changes to the data source in the registry 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
524a6006ed Removed erroneous addition of objects 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
9648cca833 Fixed directory functionality 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
d82f687f29 Bugs fixed and return data wrapper added 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
2e0d735618 Added explicit conversion to string 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
fd3bc61e5d Added processing of different types of keys 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
24a9e30f10 Added the ability to query the Group Policy dictionary 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
f7c8491fe7 Added checking the fullness of the global registry key dictionary 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
a3e24f2693 Added the ability to query a dictionary across multiple dconf paths 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
a3c0eb8f68 Added class method for getting dconf keys 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
80003c556e Added semicolon handling when writing dconf 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
24d1c6a669 Added the ability to call methods through a class 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
1e82576ddb Refactor object initialization in init 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
a32238e174 Added saving the preference to dconf 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
1bc13bbd77 Added to gpupdate.spec req_skip storage.dconf_registry 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
069cd8f5b7 Fixed formation of the general list of scripts 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
cd617119f5 Added old storage functionality 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
714976dbac Added support for sqlite_registry API 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
e4369cd087 Added functions for verification and request in the dictionary 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
4aac338ecd Changed storage int 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
6c47a8c72e Added staticmethod for update dconf 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
9a84305b89 Added methods for mandatory_profile creation 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
9757d32d65 Added functions get_uid_by_username 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
52754f921d Added new fields to store preference 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
c66ba0f799 Added static methods to query dconf 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
c33f4cbad3 Added to the global_dict key ReadQueue and to able fill it 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
5f92df44c7 Use load_preg_dconf in merge_polfile 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
8993492b61 create_dconf_ini_file function moved 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
b1e947def1 Added functions for filling the dictionary 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
0fdc8c476f Added class to storing registry data for dconf 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
a6a4d60177 Add create_ini_file function 2024-02-26 10:46:50 +04:00
Valery Sinelnikov
64a78235f4 Add touch_file function 2024-02-26 10:46:50 +04:00
24 changed files with 82 additions and 287 deletions

View File

@@ -1,22 +0,0 @@
_gpoa()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
--dc)
_filedir
return
;;
--loglevel)
COMPREPLY=($(compgen -W '0 1 2 3 4 5' -- "$cur"))
return
;;
*)
COMPREPLY=($(compgen -W '--dc --nodomain --noupdate --noplugins --list-backends --loglevel --help' -- "$cur"))
return
;;
esac
}
complete -F _gpoa gpoa

View File

@@ -1,27 +0,0 @@
_gpupdate()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
-u|--user)
_filedir
return
;;
-t|--target)
COMPREPLY=($(compgen -W 'ALL USER COMPUTER' -- "$cur"))
return
;;
-l|--loglevel)
COMPREPLY=($(compgen -W '0 1 2 3 4 5' -- "$cur"))
return
;;
*)
COMPREPLY=($(compgen -W '--user --target --loglevel --system --help' -- "$cur"))
return
;;
esac
}
complete -F _gpupdate gpupdate

View File

@@ -1,18 +0,0 @@
_gpupdate-setup()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
set-backend)
COMPREPLY=($(compgen -W 'local samba' -- "$cur"))
return
;;
*)
COMPREPLY=($(compgen -W 'list list-backends status enable disable update write set-backend default-policy active-policy active-backend' -- "$cur"))
return
;;
esac
}
complete -F _gpupdate-setup gpupdate-setup

View File

@@ -40,7 +40,6 @@ from util.logging import log
class samba_backend(applier_backend):
__user_policy_mode_key = '/SOFTWARE/Policies/Microsoft/Windows/System/UserPolicyMode'
__user_policy_mode_key_win = '/Software/Policies/Microsoft/Windows/System/UserPolicyMode'
def __init__(self, sambacreds, username, domain, is_machine):
self.cache_path = '/var/cache/gpupdate/creds/krb5cc_{}'.format(os.getpid())
@@ -79,9 +78,7 @@ class samba_backend(applier_backend):
is possible to work with user's part of GPT. This value is
checked only if working for user's SID.
'''
upm_key = self.storage.get_key_value(self.__user_policy_mode_key)
upm_win_key = self.storage.get_key_value(self.__user_policy_mode_key_win)
upm = upm_key if upm_key else upm_win_key
upm = self.storage.get_key_value(self.__user_policy_mode_key)
if upm:
upm = int(upm)
if upm < 0 or upm > 2:
@@ -176,16 +173,10 @@ class samba_backend(applier_backend):
slogdata = dict({'sysvol_path': gpo.file_sys_path, 'gpo_name': gpo.display_name, 'gpo_path': path})
log('D30', slogdata)
gpt_abspath = os.path.join(self.cache_dir, 'gpo_cache', path)
gpo_version=None
try:
gpo_version=gpo.version
except:
log('D210')
if self._is_machine_username:
obj = gpt(gpt_abspath, sid, None, version=gpo_version)
obj = gpt(gpt_abspath, sid, None)
else:
obj = gpt(gpt_abspath, sid, self.username, version=gpo_version)
obj = gpt(gpt_abspath, sid, self.username)
obj.set_name(gpo.display_name)
gpts.append(obj)
else:

View File

@@ -36,8 +36,8 @@ def check_windows_mapping_enabled(storage):
flag = storage.get_key_value(windows_mapping_enable_flag)
result = True
flag = str(flag)
if flag and '0' == flag:
if flag and '0' == str(flag):
result = False
return result
@@ -48,9 +48,9 @@ def check_module_enabled(storage, module_name):
flag = storage.get_key_value(gpupdate_module_flag)
result = None
flag = str(flag)
if flag:
if '1' == flag:
if '1' == str(flag):
result = True
else:
result = False

View File

@@ -92,8 +92,6 @@ class Envvar:
value = value.replace('\\', '/')
exist_line = None
for line in lines:
if line == '\n':
continue
if line.split()[0] == name:
exist_line = line
break

View File

@@ -53,7 +53,7 @@ def str2bool(boolstr):
class Folder:
def __init__(self, folder_object, username=None):
folder_path = expand_windows_var(folder_object.path, username).replace('\\', '/').replace('//', '/')
folder_path = expand_windows_var(folder_object.path, username).replace('\\', '/')
if username:
folder_path = folder_path.replace(get_homedir(username), '')
self.folder_path = Path(get_homedir(username)).joinpath(folder_path if folder_path [0] != '/' else folder_path [1:])

View File

@@ -33,7 +33,7 @@ from .applier_frontend import (
, check_enabled
)
from util.logging import log
from util.util import is_machine_name, try_dict_to_literal_eval
from util.util import is_machine_name
class firefox_applier(applier_frontend):
__module_name = 'FirefoxApplier'
@@ -83,10 +83,6 @@ class firefox_applier(applier_frontend):
try:
if type(it_data.data) is bytes:
it_data.data = it_data.data.decode(encoding='utf-16').replace('\x00','')
json_data = try_dict_to_literal_eval(it_data.data)
if json_data:
it_data.data = json_data
it_data.type = 7
#Cases when it is necessary to create nested dictionaries
if it_data.valuename != it_data.data:
parts = self.get_parts(it_data.hive_key)
@@ -99,8 +95,6 @@ class firefox_applier(applier_frontend):
branch[parts[-1]] = int(it_data.data)
else:
branch[parts[-1]] = self.get_boolean(it_data.data)
elif it_data.type == 7:
branch[parts[-1]] = it_data.data
else:
branch[parts[-1]] = str(it_data.data).replace('\\', '/')
#Cases when it is necessary to create lists in a dictionary

View File

@@ -1,7 +1,7 @@
#
# GPOA - GPO Applier for Linux
#
# Copyright (C) 2019-2024 BaseALT Ltd.
# Copyright (C) 2019-2023 BaseALT Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -124,24 +124,10 @@ def create_dict(kde_settings, all_kde_settings, locks_settings, locks_dict, file
def apply(all_kde_settings, locks_dict, username = None):
logdata = dict()
if username is None:
system_path_settings = '/etc/xdg/'
system_files = [
"baloofilerc",
"kcminputrc",
"kded_device_automounterrc",
"kdeglobals",
"ksplashrc",
"kwinrc",
"plasma-localerc",
"plasmarc",
"powermanagementprofilesrc"
]
for file in system_files:
file_to_remove = f'{system_path_settings}{file}'
if os.path.exists(file_to_remove):
os.remove(file_to_remove)
for file_name, sections in all_kde_settings.items():
file_path = f'{system_path_settings}{file_name}'
file_path = f'/etc/xdg/{file_name}'
if os.path.exists(file_path):
os.remove(file_path)
with open(file_path, 'w') as file:
for section, keys in sections.items():
section = section.replace(')(', '][')
@@ -289,4 +275,4 @@ def get_id_desktop(path_to_wallpaper):
else:
return None
except:
return None
return None

View File

@@ -62,7 +62,8 @@ class package_applier(applier_frontend):
)
def run(self):
for flag in self.sync_packages_setting:
self.flagSync = bool(flag.data)
if flag.data:
self.flagSync = bool(int(flag.data))
if 0 < self.install_packages_setting.count() or 0 < self.remove_packages_setting.count():
if self.flagSync:

View File

@@ -26,8 +26,8 @@ from util.logging import log
class polkit_applier(applier_frontend):
__module_name = 'PolkitApplier'
__module_experimental = False
__module_enabled = True
__module_experimental = True
__module_enabled = False
__deny_all_win = 'Software\\Policies\\Microsoft\\Windows\\RemovableStorageDevices\\Deny_All'
__registry_branch = 'Software\\BaseALT\\Policies\\Polkit\\'
__registry_locks_branch = 'Software\\BaseALT\\Policies\\PolkitLocks\\'
@@ -106,8 +106,8 @@ class polkit_applier(applier_frontend):
class polkit_applier_user(applier_frontend):
__module_name = 'PolkitApplierUser'
__module_experimental = False
__module_enabled = True
__module_experimental = True
__module_enabled = False
__deny_all_win = 'Software\\Policies\\Microsoft\\Windows\\RemovableStorageDevices\\Deny_All'
__registry_branch = 'Software\\BaseALT\\Policies\\Polkit\\'
__polkit_map = {

View File

@@ -153,13 +153,12 @@ def get_merger(preference_type):
return mergers[preference_type]
class gpt:
def __init__(self, gpt_path, sid, username='Machine', version=None):
def __init__(self, gpt_path, sid, username='Machine'):
self.path = gpt_path
self.username = username
self.sid = sid
self.storage = registry_factory()
self.storage._gpt_read_flag = True
self.version = version
self.name = ''
self.guid = self.path.rpartition('/')[2]
if 'default' == self.guid:
@@ -217,7 +216,7 @@ class gpt:
if self.settings['machine']['regpol']:
mlogdata = dict({'polfile': self.settings['machine']['regpol']})
log('D34', mlogdata)
util.preg.merge_polfile(self.settings['machine']['regpol'], policy_name=self.name, version=self.version)
util.preg.merge_polfile(self.settings['machine']['regpol'], policy_name=self.name)
# Merge machine preferences to registry if possible
for preference_name, preference_path in self.settings['machine'].items():
if preference_path:
@@ -246,8 +245,7 @@ class gpt:
util.preg.merge_polfile(self.settings['user']['regpol'],
sid=self.sid,
policy_name=self.name,
username=self.username,
version=self.version)
username=self.username)
# Merge user preferences to registry if possible
for preference_name, preference_path in self.settings['user'].items():
if preference_path:

View File

@@ -149,7 +149,6 @@ class shortcut:
self.comment = ''
self.is_in_user_context = self.set_usercontext()
self.type = ttype
self.desktop_file_template = None
def replace_slashes(self, input_path):
if input_path.startswith('%'):
@@ -248,10 +247,11 @@ class shortcut:
if dest:
self.desktop_file = DesktopEntry(dest)
else:
self.desktop_file_template = find_desktop_entry(self.path)
self.desktop_file = DesktopEntry()
self.desktop_file.addGroup('Desktop Entry')
self.desktop_file.set('Version', '1.0')
self.desktop_file = find_desktop_entry(self.path)
if not self.desktop_file:
self.desktop_file = DesktopEntry()
self.desktop_file.addGroup('Desktop Entry')
self.desktop_file.set('Version', '1.0')
self._update_desktop()
return self.desktop_file
@@ -273,18 +273,13 @@ class shortcut:
if self.type == TargetType.URL:
self.desktop_file.set('URL', desktop_path)
else:
str2bool_lambda = (lambda boolstr: boolstr if isinstance(boolstr, bool)
else boolstr and boolstr.lower() in ['True', 'true', 'yes', '1'])
if self.desktop_file_template:
terminal_state = str2bool_lambda(self.desktop_file_template.get('Terminal'))
self.desktop_file.set('Terminal', 'true' if terminal_state else 'false')
terminal_state = bool(self.desktop_file.get('Terminal'))
self.desktop_file.set('Terminal', 'true' if terminal_state else 'false')
self.desktop_file.set('Exec', '{} {}'.format(desktop_path, self.arguments))
self.desktop_file.set('Comment', self.comment)
if self.icon:
self.desktop_file.set('Icon', self.icon)
elif self.desktop_file_template and self.desktop_file_template.get('Icon', False):
self.desktop_file.set('Icon', self.desktop_file_template.get('Icon'))
def _write_desktop(self, dest, create_only=False, read_firstly=False):
'''

View File

@@ -865,10 +865,7 @@ msgid "No entry found for the specified path"
msgstr "Не найдено записей по указанному пути"
msgid "Creating an ini file with policies for dconf"
msgstr "Создание ini-файла с политиками для dconf"
msgid "GPO version was not found"
msgstr "Версия GPO не найдена"
msgstr "Создание ini-фала с политиками для dconf"
# Debug_end

View File

@@ -320,7 +320,6 @@ def debug_code(code):
debug_ids[207] = 'Creating a dictionary with keys and values from the dconf database'
debug_ids[208] = 'No entry found for the specified path'
debug_ids[209] = 'Creating an ini file with policies for dconf'
debug_ids[210] = 'GPO version was not found'
return debug_ids.get(code, 'Unknown debug code')

View File

@@ -21,8 +21,6 @@ import subprocess
import argparse
import os
from pathlib import Path
import psutil
import time
class Scripts_runner:
'''
@@ -106,39 +104,12 @@ class Scripts_runner:
def run_cmd_subprocess(self, cmd):
try:
subprocess.run(cmd)
subprocess.Popen(cmd)
return 'Script run: {}'.format(cmd)
except Exception as exc:
return exc
def find_process_by_name_and_script(name, script_path):
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
try:
# Check if the process name matches and the script path is in the command line arguments
if proc.info['name'] == name and script_path in proc.info['cmdline']:
return proc
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
continue
return None
def wait_for_process(name, script_path, check_interval=1):
process = find_process_by_name_and_script(name, script_path)
if not process:
print(f"Process with name {name} and script path {script_path} not found.")
return
try:
# Loop to wait for the process to finish
while process.is_running():
print(f"Waiting for process {name} with PID {process.pid} to finish...")
time.sleep(check_interval)
print(f"Process {name} with PID {process.pid} has finished.")
return
except (psutil.NoSuchProcess, psutil.AccessDenied):
print(f"Process {name} with PID {process.pid} is no longer accessible.")
return
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Scripts runner')
@@ -146,9 +117,6 @@ if __name__ == '__main__':
parser.add_argument('--user', type = str, help = 'User name ', nargs = '?', default = None)
parser.add_argument('--action', type = str, help = 'MACHINE : [STARTUP or SHUTDOWN], USER : [LOGON or LOGOFF]', nargs = '?', default = None)
process_name = "python3"
script_path = "/usr/sbin/gpoa"
wait_for_process(process_name, script_path)
args = parser.parse_args()
try:
Scripts_runner(args.mode, args.user, args.action)

View File

@@ -22,10 +22,11 @@ from storage.dconf_registry import Dconf_registry
def registry_factory(registry_name='', envprofile=None , username=None):
if username:
Dconf_registry._username = username
else:
Dconf_registry._envprofile = 'system'
if envprofile:
Dconf_registry._envprofile = envprofile
if envprofile == 'local':
Dconf_registry._local_envprofile = True
elif envprofile == 'default':
Dconf_registry._default_envprofile = True
if registry_name == 'dconf':
return Dconf_registry()

View File

@@ -58,7 +58,8 @@ class Dconf_registry():
__dconf_dict_flag = False
__dconf_dict = dict()
_username = None
_envprofile = None
_default_envprofile = None
_local_envprofile = None
list_keys = list()
_info = dict()
@@ -92,7 +93,9 @@ class Dconf_registry():
if path[0] != '/':
path = '/' + path
logdata = dict()
envprofile = get_dconf_envprofile()
envprofile = get_dconf_envprofile(Dconf_registry._username,
Dconf_registry._default_envprofile,
Dconf_registry._local_envprofile)
try:
process = subprocess.Popen(['dconf', 'list', path],
env=envprofile, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
@@ -123,7 +126,9 @@ class Dconf_registry():
@staticmethod
def get_key_value(key):
logdata = dict()
envprofile = get_dconf_envprofile()
envprofile = get_dconf_envprofile(Dconf_registry._username,
Dconf_registry._default_envprofile,
Dconf_registry._local_envprofile)
try:
process = subprocess.Popen(['dconf', 'read', key],
env=envprofile, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
@@ -446,7 +451,7 @@ def update_dict(dict1, dict2):
dict1[key] = value
def add_to_dict(string, policy_name, username, version):
def add_to_dict(string, policy_name, username):
if username is None:
correct_path = '/'.join(string.split('/')[:-2])
machine= '{}/Machine'.format(Dconf_registry._ReadQueue)
@@ -456,47 +461,40 @@ def add_to_dict(string, policy_name, username, version):
user = '{}/User'.format(Dconf_registry._ReadQueue)
dictionary = Dconf_registry.global_registry_dict.setdefault(user, dict())
dictionary[len(dictionary)] = (policy_name, correct_path, version)
dictionary[len(dictionary)] = (policy_name, correct_path)
def load_preg_dconf(pregfile, pathfile, policy_name, username, version=None):
def load_preg_dconf(pregfile, pathfile, policy_name, username):
'''
Loads the configuration from preg registry into a dictionary
'''
dd = dict()
dd_win_style = dict()
for i in pregfile.entries:
# Skip this entry if the valuename starts with '**del'
if i.valuename.startswith('**del'):
continue
valuename = convert_string_dconf(i.valuename)
data = check_data(i.data, i.type)
if i.valuename != i.data and i.valuename:
if i.valuename != i.data:
if i.keyname.replace('\\', '/') in dd:
# If the key exists in dd, update its value with the new key-value pair
dd[i.keyname.replace('\\', '/')].update({valuename.replace('\\', '/'):data})
dd[i.keyname.replace('\\', '/')].update({valuename.replace('\\', '/'):i.data})
dd_win_style[i.keyname].update({valuename:i.data})
else:
# If the key does not exist in dd, create a new key-value pair
dd[i.keyname.replace('\\', '/')] = {valuename.replace('\\', '/'):data}
elif not i.valuename:
keyname_tmp = i.keyname.replace('\\', '/').split('/')
keyname = '/'.join(keyname_tmp[:-1])
if keyname in dd:
# If the key exists in dd, update its value with the new key-value pair
dd[keyname].update({keyname_tmp[-1]:data})
else:
# If the key does not exist in dd, create a new key-value pair
dd[keyname] = {keyname_tmp[-1]:data}
dd[i.keyname.replace('\\', '/')] = {valuename.replace('\\', '/'):i.data}
dd_win_style[i.keyname] = {valuename:i.data}
else:
# If the value name is the same as the data,
# split the keyname and add the data to the appropriate location in dd.
all_list_key = i.keyname.split('\\')
dd_target = dd.setdefault('/'.join(all_list_key[:-1]),{})
dd_target.setdefault(all_list_key[-1], []).append(data)
dd_target.setdefault(all_list_key[-1], []).append(i.data)
dd_target_win = dd_win_style.setdefault('\\'.join(all_list_key[:-1]),{})
dd_target_win.setdefault(all_list_key[-1], []).append(i.data)
# Update the global registry dictionary with the contents of dd
add_to_dict(pathfile, policy_name, username, version)
add_to_dict(pathfile, policy_name, username)
update_dict(Dconf_registry.global_registry_dict, dd)
@@ -525,36 +523,14 @@ def create_dconf_ini_file(filename, data):
log('D209', logdata)
Dconf_registry.dconf_update()
def clean_data(data):
try:
cleaned_string = data.replace('\n', '').replace('\r', '')
cleaned_string = cleaned_string.replace('"', "'")
return cleaned_string
except:
return None
def check_data(data, t_data):
if isinstance(data, bytes):
if t_data == 7:
return clean_data(data.decode('utf-16').replace('\x00',''))
else:
return None
elif t_data == 4:
return data
return clean_data(data)
def convert_string_dconf(input_string):
macros = {
'#': '%sharp%',
';': '%semicolon%',
'//': '%doubleslash%'
}
output_string = input_string
for key, value in macros.items():
if key in input_string:
output_string = input_string.replace(key, value)
elif value in input_string:
output_string = input_string.replace(value, key)
# Check if the input string contains '%semicolon%'
if '%semicolon%' in input_string:
# If it contains, replace '%semicolon%' with ';'
output_string = input_string.replace('%semicolon%', ';')
else:
# If it doesn't contain, replace ';' with '%semicolon%'
output_string = input_string.replace(';', '%semicolon%')
return output_string
@@ -575,17 +551,15 @@ def flatten_dictionary(input_dict, result=None, current_key=''):
return result
def get_dconf_envprofile():
dconf_envprofile = {'default': {'DCONF_PROFILE': 'default'},
'local': {'DCONF_PROFILE': 'local'},
'system': {'DCONF_PROFILE': 'system'}
}
def get_dconf_envprofile(user=None, default=None, local=None):
if default:
return {'DCONF_PROFILE': 'default'}
if Dconf_registry._envprofile:
return dconf_envprofile.get(Dconf_registry._envprofile, dconf_envprofile['system'])
if local:
return {'DCONF_PROFILE': 'local'}
if not Dconf_registry._username:
return dconf_envprofile['system']
if not user:
return {'DCONF_PROFILE': 'system'}
profile = '/run/dconf/user/{}'.format(get_uid_by_username(Dconf_registry._username))
profile = '/run/dconf/user/{}'.format(get_uid_by_username(user))
return {'DCONF_PROFILE': profile}

View File

@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% if Deny_All == 1 %}
{% if Deny_All == '1' %}
polkit.addRule(function (action, subject) {
if ((action.id == "org.freedesktop.udisks2.filesystem-mount" ||
action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||

View File

@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% if Deny_All == 1 %}
{% if Deny_All == '1' %}
polkit.addRule(function (action, subject) {
if (action.id == "org.freedesktop.udisks2.filesystem-mount" ||
action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||

View File

@@ -81,12 +81,12 @@ def preg_keymap(preg):
return keymap
def merge_polfile(preg, sid=None, reg_name='registry', reg_path=None, policy_name='Unknown', username='Machine', version=None):
def merge_polfile(preg, sid=None, reg_name='registry', reg_path=None, policy_name='Unknown', username='Machine'):
pregfile = load_preg(preg)
if sid is None and username == 'Machine':
load_preg_dconf(pregfile, preg, policy_name, None, version)
load_preg_dconf(pregfile, preg, policy_name, None)
else:
load_preg_dconf(pregfile, preg, policy_name, username, version)
load_preg_dconf(pregfile, preg, policy_name, username)
logdata = dict({'pregfile': preg})
log('D32', logdata)
#log dconf

View File

@@ -175,16 +175,6 @@ def string_to_literal_eval(string):
literaleval = string
return literaleval
def try_dict_to_literal_eval(string):
try:
literaleval = ast.literal_eval(string)
if isinstance(literaleval ,dict):
return literaleval
else:
return None
except:
return None
def touch_file(filename):
path = Path(filename)
path.parent.mkdir(parents=True, exist_ok=True)

View File

@@ -317,7 +317,7 @@ def expand_windows_var(text, username=None):
for var in variables.keys():
result = result.replace('%{}%'.format(var),
variables[var] if variables[var][-1] == '/'
else variables[var] +'/')
else variables[var] +'/').replace('//','/')
return result

View File

@@ -33,7 +33,7 @@
%add_python3_req_skip util.gpoa_ini_parsing
Name: gpupdate
Version: 0.10.3
Version: 0.9.13.8
Release: alt1
Summary: GPT applier
@@ -54,7 +54,6 @@ Requires: libnss-role >= 0.5.0
Requires: local-policy >= 0.4.9
Requires: pam-config >= 1.9.0
Requires: autofs
Requires: dconf-profile
# This is needed by shortcuts_applier
Requires: desktop-file-utils
# This is needed for smb file cache support
@@ -121,9 +120,6 @@ install -Dm0644 dist/%name-remote-policy %buildroot%_sysconfdir/pam.d/%name-remo
install -Dm0644 dist/%name.ini %buildroot%_sysconfdir/%name/%name.ini
install -Dm0644 doc/gpoa.1 %buildroot/%_man1dir/gpoa.1
install -Dm0644 doc/gpupdate.1 %buildroot/%_man1dir/gpupdate.1
install -Dm0644 completions/gpoa %buildroot/%_datadir/bash-completion/completions/gpoa
install -Dm0644 completions/gpupdate %buildroot/%_datadir/bash-completion/completions/gpupdate
install -Dm0644 completions/gpupdate-setup %buildroot/%_datadir/bash-completion/completions/gpupdate-setup
for i in gpupdate-localusers \
gpupdate-group-users \
@@ -170,12 +166,9 @@ fi
%_unitdir/%name.timer
%_man1dir/gpoa.1.*
%_man1dir/gpupdate.1.*
%_datadir/bash-completion/completions/gpoa
%_datadir/bash-completion/completions/gpupdate
%_datadir/bash-completion/completions/gpupdate-setup
%_user_unitdir/%name-user.service
%_user_unitdir/%name-user.timer
%_user_unitdir/%name-scripts-run-user.service
/usr/lib/systemd/user/%name-user.service
/usr/lib/systemd/user/%name-user.timer
/usr/lib/systemd/user/%name-scripts-run-user.service
%dir %_sysconfdir/%name
%_sysconfdir/control.d/facilities/*
%config(noreplace) %_sysconfdir/%name/environment
@@ -191,29 +184,6 @@ fi
%exclude %python3_sitelibdir/gpoa/test
%changelog
* Wed Jun 19 2024 Valery Sinelnikov <greh@altlinux.org> 0.10.3-alt1
- Added autocompletion for gpoa, gpupdate, gpupdate-setup
- Added correct work with json data in keys for the Firefox browser
- Polkit_appliers changed to non-experimental
- Fixed bug of not clearing kde applier settings (closes: 50336)
- Fixed registry key reading (closes: 50553)
- Added waiting for data generation for scripts (closes: 50667)
* Fri Jun 07 2024 Valery Sinelnikov <greh@altlinux.org> 0.10.2-alt1
- Added some fixes to dconf_registry and scripts
- Fixed windows registry key reading for loopback
* Tue Jun 04 2024 Valery Sinelnikov <greh@altlinux.org> 0.10.1-alt1
- Added handling of unexpected data types when writing to dconf
* Mon May 13 2024 Valery Sinelnikov <greh@altlinux.org> 0.10.0-alt1
- A method for storing registry keys obtained from GPOs (Group Policy Objects)
has undergone significant repairs. We have switched from using SQLite
to using Dconf to improve data storage efficiency
* Wed Mar 13 2024 Valery Sinelnikov <greh@altlinux.org> 0.9.13.9-alt1
- Fixed premature removal of double slash
* Thu Feb 22 2024 Valery Sinelnikov <greh@altlinux.org> 0.9.13.8-alt1
- Added search for dc on the site
- Added compatibility support for the oldest versions of SQLAlchemy