1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-01-09 17:18:17 +03:00

Added use of GpoInfoDconf object to save policy data

This commit is contained in:
Valery Sinelnikov 2024-06-20 16:54:52 +04:00
parent d3a316c1c0
commit cdcac9e4db
4 changed files with 21 additions and 19 deletions

View File

@ -26,6 +26,7 @@ except ImportError:
from .applier_backend import applier_backend
from storage import registry_factory
from gpt.gpt import gpt, get_local_gpt
from gpt.gpo_dconf_mapping import GpoInfoDconf
from util.util import (
get_machine_name,
is_machine_name
@ -176,16 +177,12 @@ 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, GpoInfoDconf(gpo))
else:
obj = gpt(gpt_abspath, sid, self.username, version=gpo_version)
obj = gpt(gpt_abspath, sid, self.username, GpoInfoDconf(gpo))
obj.set_name(gpo.display_name)
gpts.append(obj)
else:

View File

@ -153,13 +153,13 @@ 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', gpo_info=None):
self.path = gpt_path
self.username = username
self.sid = sid
self.storage = registry_factory()
self.storage._gpt_read_flag = True
self.version = version
self.gpo_info = gpo_info
self.name = ''
self.guid = self.path.rpartition('/')[2]
if 'default' == self.guid:
@ -217,7 +217,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, gpo_info=self.gpo_info)
# Merge machine preferences to registry if possible
for preference_name, preference_path in self.settings['machine'].items():
if preference_path:
@ -247,7 +247,7 @@ class gpt:
sid=self.sid,
policy_name=self.name,
username=self.username,
version=self.version)
gpo_info=self.gpo_info)
# Merge user preferences to registry if possible
for preference_name, preference_path in self.settings['user'].items():
if preference_path:

View File

@ -22,6 +22,7 @@ from util.util import string_to_literal_eval, touch_file, get_uid_by_username
from util.logging import log
import re
from collections import OrderedDict
import itertools
class PregDconf():
@ -63,6 +64,7 @@ class Dconf_registry():
list_keys = list()
_info = dict()
_counter_gpt = itertools.count(0)
shortcuts = list()
folders = list()
@ -87,6 +89,9 @@ class Dconf_registry():
def get_info(cls, key):
return cls._info.setdefault(key, None)
@staticmethod
def get_next_number():
return next(Dconf_registry._counter_gpt)
@staticmethod
def get_matching_keys(path):
@ -447,7 +452,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, gpo_info):
if username is None:
correct_path = '/'.join(string.split('/')[:-2])
machine= '{}/Machine'.format(Dconf_registry._ReadQueue)
@ -456,11 +461,11 @@ def add_to_dict(string, policy_name, username, version):
correct_path = '/'.join(string.split('/')[:-2])
user = '{}/User'.format(Dconf_registry._ReadQueue)
dictionary = Dconf_registry.global_registry_dict.setdefault(user, dict())
version = gpo_info.version if gpo_info else None
dictionary[len(dictionary)] = (policy_name, correct_path, version)
def load_preg_dconf(pregfile, pathfile, policy_name, username, version=None):
def load_preg_dconf(pregfile, pathfile, policy_name, username, gpo_info):
'''
Loads the configuration from preg registry into a dictionary
'''
@ -497,7 +502,7 @@ def load_preg_dconf(pregfile, pathfile, policy_name, username, version=None):
dd_target.setdefault(all_list_key[-1], []).append(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, gpo_info)
update_dict(Dconf_registry.global_registry_dict, dd)
@ -620,6 +625,6 @@ def add_preferences_to_global_registry_dict(username, is_machine):
preferences_global_dict[prefix] = dict()
for key, val in preferences_global:
preferences_global_dict[prefix].update({key:val})
preferences_global_dict[prefix].update({key:clean_data(str(val))})
update_dict(Dconf_registry.global_registry_dict, preferences_global_dict)

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', gpo_info=None):
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, gpo_info)
else:
load_preg_dconf(pregfile, preg, policy_name, username, version)
load_preg_dconf(pregfile, preg, policy_name, username, gpo_info)
logdata = dict({'pregfile': preg})
log('D32', logdata)
#log dconf