mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43896 from twangboy/win_fix_lgpo_scom
Fix win_lgpo execution module
This commit is contained in:
commit
1d16ae8ba7
1 changed files with 67 additions and 24 deletions
|
@ -34,16 +34,19 @@ Current known limitations
|
|||
- pywin32 Python module
|
||||
- lxml
|
||||
- uuid
|
||||
- codecs
|
||||
- struct
|
||||
- salt.modules.reg
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import io
|
||||
import os
|
||||
import logging
|
||||
import re
|
||||
import locale
|
||||
import ctypes
|
||||
import time
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
|
@ -90,7 +93,6 @@ try:
|
|||
import win32net
|
||||
import win32security
|
||||
import uuid
|
||||
import codecs
|
||||
import lxml
|
||||
import struct
|
||||
from lxml import etree
|
||||
|
@ -117,6 +119,16 @@ try:
|
|||
ADMX_DISPLAYNAME_SEARCH_XPATH = etree.XPath('//*[local-name() = "policy" and @*[local-name() = "displayName"] = $display_name and (@*[local-name() = "class"] = "Both" or @*[local-name() = "class"] = $registry_class) ]')
|
||||
PRESENTATION_ANCESTOR_XPATH = etree.XPath('ancestor::*[local-name() = "presentation"]')
|
||||
TEXT_ELEMENT_XPATH = etree.XPath('.//*[local-name() = "text"]')
|
||||
# Get the System Install Language
|
||||
# https://msdn.microsoft.com/en-us/library/dd318123(VS.85).aspx
|
||||
# local.windows_locale is a dict
|
||||
# GetSystemDefaultUILanguage() returns a 4 digit language code that
|
||||
# corresponds to an entry in the dict
|
||||
# Not available in win32api, so we have to use ctypes
|
||||
# Default to `en-US` (1033)
|
||||
windll = ctypes.windll.kernel32
|
||||
INSTALL_LANGUAGE = locale.windows_locale.get(
|
||||
windll.GetSystemDefaultUILanguage(), 1033).replace('_', '-')
|
||||
except ImportError:
|
||||
HAS_WINDOWS_MODULES = False
|
||||
|
||||
|
@ -2709,7 +2721,8 @@ def _processPolicyDefinitions(policy_def_path='c:\\Windows\\PolicyDefinitions',
|
|||
helper function to process all ADMX files in the specified policy_def_path
|
||||
and build a single XML doc that we can search/use for ADMX policy processing
|
||||
'''
|
||||
display_language_fallback = 'en-US'
|
||||
# Fallback to the System Install Language
|
||||
display_language_fallback = INSTALL_LANGUAGE
|
||||
t_policy_definitions = lxml.etree.Element('policyDefinitions')
|
||||
t_policy_definitions.append(lxml.etree.Element('categories'))
|
||||
t_policy_definitions.append(lxml.etree.Element('policies'))
|
||||
|
@ -2773,22 +2786,44 @@ def _processPolicyDefinitions(policy_def_path='c:\\Windows\\PolicyDefinitions',
|
|||
temp_ns = policy_ns
|
||||
temp_ns = _updateNamespace(temp_ns, this_namespace)
|
||||
policydefs_policyns_xpath(t_policy_definitions)[0].append(temp_ns)
|
||||
adml_file = os.path.join(root, display_language, os.path.splitext(t_admfile)[0] + '.adml')
|
||||
|
||||
# We need to make sure the adml file exists. First we'll check
|
||||
# the passed display_language (eg: en-US). Then we'll try the
|
||||
# abbreviated version (en) to account for alternate locations.
|
||||
# We'll do the same for the display_language_fallback (en_US).
|
||||
adml_file = os.path.join(root, display_language,
|
||||
os.path.splitext(t_admfile)[0] + '.adml')
|
||||
if not __salt__['file.file_exists'](adml_file):
|
||||
msg = ('An ADML file in the specified ADML language "{0}" '
|
||||
'does not exist for the ADMX "{1}", the fallback '
|
||||
'language will be tried.')
|
||||
'does not exist for the ADMX "{1}", the abbreviated '
|
||||
'language code will be tried.')
|
||||
log.info(msg.format(display_language, t_admfile))
|
||||
adml_file = os.path.join(root,
|
||||
display_language_fallback,
|
||||
os.path.splitext(t_admfile)[0] + '.adml')
|
||||
|
||||
adml_file = os.path.join(root, display_language.split('-')[0],
|
||||
os.path.splitext(t_admfile)[0] + '.adml')
|
||||
if not __salt__['file.file_exists'](adml_file):
|
||||
msg = ('An ADML file in the specified ADML language '
|
||||
'"{0}" and the fallback language "{1}" do not '
|
||||
'exist for the ADMX "{2}".')
|
||||
raise SaltInvocationError(msg.format(display_language,
|
||||
display_language_fallback,
|
||||
t_admfile))
|
||||
msg = ('An ADML file in the specified ADML language code "{0}" '
|
||||
'does not exist for the ADMX "{1}", the fallback '
|
||||
'language will be tried.')
|
||||
log.info(msg.format(display_language[:2], t_admfile))
|
||||
|
||||
adml_file = os.path.join(root, display_language_fallback,
|
||||
os.path.splitext(t_admfile)[0] + '.adml')
|
||||
if not __salt__['file.file_exists'](adml_file):
|
||||
msg = ('An ADML file in the specified ADML fallback language "{0}" '
|
||||
'does not exist for the ADMX "{1}", the abbreviated'
|
||||
'fallback language code will be tried.')
|
||||
log.info(msg.format(display_language_fallback, t_admfile))
|
||||
|
||||
adml_file = os.path.join(root, display_language_fallback.split('-')[0],
|
||||
os.path.splitext(t_admfile)[0] + '.adml')
|
||||
if not __salt__['file.file_exists'](adml_file):
|
||||
msg = ('An ADML file in the specified ADML language '
|
||||
'"{0}" and the fallback language "{1}" do not '
|
||||
'exist for the ADMX "{2}".')
|
||||
raise SaltInvocationError(msg.format(display_language,
|
||||
display_language_fallback,
|
||||
t_admfile))
|
||||
try:
|
||||
xmltree = lxml.etree.parse(adml_file)
|
||||
except lxml.etree.XMLSyntaxError:
|
||||
|
@ -2796,8 +2831,8 @@ def _processPolicyDefinitions(policy_def_path='c:\\Windows\\PolicyDefinitions',
|
|||
try:
|
||||
xmltree = _remove_unicode_encoding(adml_file)
|
||||
except Exception:
|
||||
msg = ('An error was found while processing adml file {0}, all policy'
|
||||
' languange data from this file will be unavailable via this module')
|
||||
msg = ('An error was found while processing adml file {0}, all policy '
|
||||
'language data from this file will be unavailable via this module')
|
||||
log.error(msg.format(adml_file))
|
||||
continue
|
||||
if None in namespaces:
|
||||
|
@ -2828,15 +2863,23 @@ def _findOptionValueInSeceditFile(option):
|
|||
'''
|
||||
try:
|
||||
_d = uuid.uuid4().hex
|
||||
_tfile = '{0}\\{1}'.format(__salt__['config.get']('cachedir'),
|
||||
_tfile = '{0}\\{1}'.format(__opts__['cachedir'],
|
||||
'salt-secedit-dump-{0}.txt'.format(_d))
|
||||
_ret = __salt__['cmd.run']('secedit /export /cfg {0}'.format(_tfile))
|
||||
if _ret:
|
||||
_reader = codecs.open(_tfile, 'r', encoding='utf-16')
|
||||
_secdata = _reader.readlines()
|
||||
_reader.close()
|
||||
with io.open(_tfile, encoding='utf-16') as _reader:
|
||||
_secdata = _reader.readlines()
|
||||
if __salt__['file.file_exists'](_tfile):
|
||||
_ret = __salt__['file.remove'](_tfile)
|
||||
for _ in range(5):
|
||||
try:
|
||||
__salt__['file.remove'](_tfile)
|
||||
except CommandExecutionError:
|
||||
time.sleep(.1)
|
||||
continue
|
||||
else:
|
||||
break
|
||||
else:
|
||||
log.error('error occurred removing {0}'.format(_tfile))
|
||||
for _line in _secdata:
|
||||
if _line.startswith(option):
|
||||
return True, _line.split('=')[1].strip()
|
||||
|
@ -2852,9 +2895,9 @@ def _importSeceditConfig(infdata):
|
|||
'''
|
||||
try:
|
||||
_d = uuid.uuid4().hex
|
||||
_tSdbfile = '{0}\\{1}'.format(__salt__['config.get']('cachedir'),
|
||||
_tSdbfile = '{0}\\{1}'.format(__opts__['cachedir'],
|
||||
'salt-secedit-import-{0}.sdb'.format(_d))
|
||||
_tInfFile = '{0}\\{1}'.format(__salt__['config.get']('cachedir'),
|
||||
_tInfFile = '{0}\\{1}'.format(__opts__['cachedir'],
|
||||
'salt-secedit-config-{0}.inf'.format(_d))
|
||||
# make sure our temp files don't already exist
|
||||
if __salt__['file.file_exists'](_tSdbfile):
|
||||
|
|
Loading…
Add table
Reference in a new issue