diff --git a/salt/modules/win_lgpo.py b/salt/modules/win_lgpo.py index 1892fa497f88..c34911b39d64 100644 --- a/salt/modules/win_lgpo.py +++ b/salt/modules/win_lgpo.py @@ -6777,13 +6777,16 @@ def _regexSearchKeyValueCombo(policy_data, policy_regpath, policy_regkey): for a policy_regpath and policy_regkey combo ''' if policy_data: - specialValueRegex = salt.utils.stringutils.to_bytes(r'(\*\*Del\.|\*\*DelVals\.){0,1}') + regex_str = [r'(\*', r'\*', 'D', 'e', 'l', r'\.', r'|\*', r'\*', 'D', + 'e', 'l', 'V', 'a', 'l', 's', r'\.', '){0,1}'] + specialValueRegex = '\x00'.join(regex_str) + specialValueRegex = salt.utils.stringutils.to_bytes(specialValueRegex) _thisSearch = b''.join([salt.utils.stringutils.to_bytes(r'\['), - re.escape(policy_regpath), - b'\00;', - specialValueRegex, - re.escape(policy_regkey), - b'\00;']) + re.escape(policy_regpath), + b'\x00;\x00', + specialValueRegex, + re.escape(policy_regkey.lstrip(b'\x00')), + b'\x00;']) match = re.search(_thisSearch, policy_data, re.IGNORECASE) if match: # add 2 so we get the ']' and the \00 diff --git a/tests/unit/modules/test_win_lgpo.py b/tests/unit/modules/test_win_lgpo.py index 3373e88aad79..aa30ec9e9094 100644 --- a/tests/unit/modules/test_win_lgpo.py +++ b/tests/unit/modules/test_win_lgpo.py @@ -60,6 +60,88 @@ def test__getAdmlDisplayName(self): expected = '300000 or 5 minutes (recommended)' self.assertEqual(result, expected) + def test__regexSearchKeyValueCombo_enabled(self): + ''' + Make sure + ''' + policy_data = b'[\x00s\x00o\x00f\x00t\x00w\x00a\x00r\x00e\x00\\\x00p' \ + b'\x00o\x00l\x00i\x00c\x00i\x00e\x00s\x00\\\x00m\x00i' \ + b'\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00\\\x00w\x00i' \ + b'\x00n\x00d\x00o\x00w\x00s\x00\\\x00w\x00i\x00n\x00d' \ + b'\x00o\x00w\x00s\x00 \x00e\x00r\x00r\x00o\x00r\x00 ' \ + b'\x00r\x00e\x00p\x00o\x00r\x00t\x00i\x00n\x00g\x00\\' \ + b'\x00c\x00o\x00n\x00s\x00e\x00n\x00t\x00\x00\x00;\x00D' \ + b'\x00e\x00f\x00a\x00u\x00l\x00t\x00C\x00o\x00n\x00s' \ + b'\x00e\x00n\x00t\x00\x00\x00;\x00\x01\x00\x00\x00;\x00' \ + b'\x04\x00\x00\x00;\x00\x02\x00\x00\x00]\x00' + policy_regpath = b'\x00s\x00o\x00f\x00t\x00w\x00a\x00r\x00e\x00\\\x00p' \ + b'\x00o\x00l\x00i\x00c\x00i\x00e\x00s\x00\\\x00m\x00i' \ + b'\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00\\\x00w\x00i' \ + b'\x00n\x00d\x00o\x00w\x00s\x00\\\x00w\x00i\x00n\x00d' \ + b'\x00o\x00w\x00s\x00 \x00e\x00r\x00r\x00o\x00r\x00 ' \ + b'\x00r\x00e\x00p\x00o\x00r\x00t\x00i\x00n\x00g\x00\\' \ + b'\x00c\x00o\x00n\x00s\x00e\x00n\x00t\x00\x00' + policy_regkey = b'\x00D\x00e\x00f\x00a\x00u\x00l\x00t\x00C\x00o\x00n' \ + b'\x00s\x00e\x00n\x00t\x00\x00' + test = win_lgpo._regexSearchKeyValueCombo( + policy_data=policy_data, + policy_regpath=policy_regpath, + policy_regkey=policy_regkey + ) + self.assertEqual(test, policy_data) + + def test__regexSearchKeyValueCombo_not_configured(self): + ''' + Make sure + ''' + policy_data = b'' + policy_regpath = b'\x00s\x00o\x00f\x00t\x00w\x00a\x00r\x00e\x00\\\x00p' \ + b'\x00o\x00l\x00i\x00c\x00i\x00e\x00s\x00\\\x00m\x00i' \ + b'\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00\\\x00w\x00i' \ + b'\x00n\x00d\x00o\x00w\x00s\x00\\\x00w\x00i\x00n\x00d' \ + b'\x00o\x00w\x00s\x00 \x00e\x00r\x00r\x00o\x00r\x00 ' \ + b'\x00r\x00e\x00p\x00o\x00r\x00t\x00i\x00n\x00g\x00\\' \ + b'\x00c\x00o\x00n\x00s\x00e\x00n\x00t\x00\x00' + policy_regkey = b'\x00D\x00e\x00f\x00a\x00u\x00l\x00t\x00C\x00o\x00n' \ + b'\x00s\x00e\x00n\x00t\x00\x00' + test = win_lgpo._regexSearchKeyValueCombo( + policy_data=policy_data, + policy_regpath=policy_regpath, + policy_regkey=policy_regkey + ) + self.assertIsNone(test) + + def test__regexSearchKeyValueCombo_disabled(self): + ''' + Make sure + ''' + policy_data = b'[\x00s\x00o\x00f\x00t\x00w\x00a\x00r\x00e\x00\\\x00p' \ + b'\x00o\x00l\x00i\x00c\x00i\x00e\x00s\x00\\\x00m\x00i' \ + b'\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00\\\x00w\x00i' \ + b'\x00n\x00d\x00o\x00w\x00s\x00\\\x00w\x00i\x00n\x00d' \ + b'\x00o\x00w\x00s\x00 \x00e\x00r\x00r\x00o\x00r\x00 ' \ + b'\x00r\x00e\x00p\x00o\x00r\x00t\x00i\x00n\x00g\x00\\' \ + b'\x00c\x00o\x00n\x00s\x00e\x00n\x00t\x00\x00\x00;\x00*' \ + b'\x00*\x00d\x00e\x00l\x00.\x00D\x00e\x00f\x00a\x00u' \ + b'\x00l\x00t\x00C\x00o\x00n\x00s\x00e\x00n\x00t\x00\x00' \ + b'\x00;\x00\x01\x00\x00\x00;\x00\x04\x00\x00\x00;\x00 ' \ + b'\x00\x00\x00]\x00' + policy_regpath = b'\x00s\x00o\x00f\x00t\x00w\x00a\x00r\x00e\x00\\\x00p' \ + b'\x00o\x00l\x00i\x00c\x00i\x00e\x00s\x00\\\x00m\x00i' \ + b'\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00\\\x00w\x00i' \ + b'\x00n\x00d\x00o\x00w\x00s\x00\\\x00w\x00i\x00n\x00d' \ + b'\x00o\x00w\x00s\x00 \x00e\x00r\x00r\x00o\x00r\x00 ' \ + b'\x00r\x00e\x00p\x00o\x00r\x00t\x00i\x00n\x00g\x00\\' \ + b'\x00c\x00o\x00n\x00s\x00e\x00n\x00t\x00\x00' + policy_regkey = b'\x00D\x00e\x00f\x00a\x00u\x00l\x00t\x00C\x00o\x00n' \ + b'\x00s\x00e\x00n\x00t\x00\x00' + test = win_lgpo._regexSearchKeyValueCombo( + policy_data=policy_data, + policy_regpath=policy_regpath, + policy_regkey=policy_regkey + ) + self.assertEqual(test, policy_data) + def test__encode_string(self): ''' ``_encode_string`` should return a null terminated ``utf-16-le`` encoded