defs['class'] = policy_class
defs['type'] = str_regtype(entry.type)
defs['data'] = entry.data
+ # Bytes aren't JSON serializable
+ if type(defs['data']) == bytes:
+ defs['data'] = list(defs['data'])
policy_defs.append(defs)
self.outf.write("Policies :\n")
json.dump(policy_defs, self.outf, indent=4)
"type": "REG_SZ",
"data": "google.com"
},
+ {
+ "keyname": "Software\\Microsoft\\Internet Explorer\\Toolbar",
+ "valuename": "IEToolbar",
+ "class": "USER",
+ "type": "REG_BINARY",
+ "data": [0]
+ },
+ {
+ "keyname": "Software\\Policies\\Microsoft\\InputPersonalization",
+ "valuename": "RestrictImplicitTextCollection",
+ "class": "USER",
+ "type": "REG_DWORD",
+ "data": 1
+ }
]
+
+ Valid class attributes: MACHINE|USER|BOTH
+ Data arrays are interpreted as bytes.
"""
synopsis = "%prog <gpo> [options]"
"valuename": "URL",
"class": "USER",
},
+ {
+ "keyname": "Software\\Microsoft\\Internet Explorer\\Toolbar",
+ "valuename": "IEToolbar",
+ "class": "USER"
+ },
+ {
+ "keyname": "Software\\Policies\\Microsoft\\InputPersonalization",
+ "valuename": "RestrictImplicitTextCollection",
+ "class": "USER"
+ }
]
+
+ Valid class attributes: MACHINE|USER|BOTH
"""
synopsis = "%prog <gpo> [options]"
for i in range(12):
if str_regtype(i) == entry['type'].upper():
return i
- return 0 # REG_NONE
+ raise TypeError('Unknown type %s' % entry['type'])
+
+ def __set_data(self, rtype, data):
+ # JSON can't store bytes, and have to be set via an int array
+ if rtype == 3 and type(data) == list: # REG_BINARY
+ return bytes(data)
+ return data
def __pol_replace(self, pol_data, entry):
for e in pol_data.entries:
if e.keyname == entry['keyname'] and \
e.valuename == entry['valuename']:
- e.data = entry['data']
+ e.data = self.__set_data(e.type, entry['data'])
break
else:
e = preg.entry()
e.keyname = entry['keyname']
e.valuename = entry['valuename']
e.type = self.__determine_data_type(entry)
- e.data = entry['data']
+ e.data = self.__set_data(e.type, entry['data'])
entries = list(pol_data.entries)
entries.append(e)
pol_data.entries = entries
"class": "USER",
"type": 1,
"data": "samba.org"
+ },
+ {
+ "keyname": "Software\\\\Microsoft\\\\Internet Explorer\\\\Toolbar",
+ "valuename": "IEToolbar",
+ "class": "USER",
+ "type": "REG_BINARY",
+ "data": [0]
+ },
+ {
+ "keyname": "Software\\\\Policies\\\\Microsoft\\\\InputPersonalization",
+ "valuename": "RestrictImplicitTextCollection",
+ "class": "USER",
+ "type": "REG_DWORD",
+ "data": 1
}
]
"""
"keyname": "Software\\\\Policies\\\\Mozilla\\\\Firefox\\\\Homepage",
"valuename": "URL",
"class": "USER"
+ },
+ {
+ "keyname": "Software\\\\Microsoft\\\\Internet Explorer\\\\Toolbar",
+ "valuename": "IEToolbar",
+ "class": "USER"
+ },
+ {
+ "keyname": "Software\\\\Policies\\\\Microsoft\\\\InputPersonalization",
+ "valuename": "RestrictImplicitTextCollection",
+ "class": "USER"
}
]
"""
(result, out, err) = self.runsubcmd("gpo", "show", self.gpo_guid, "-H",
"ldap://%s" % os.environ["SERVER"])
self.assertCmdSuccess(result, out, err, 'Failed to fetch gpos')
+ self.assertIn('homepage', out, 'Homepage policy not loaded')
self.assertIn('samba.org', out, 'Homepage policy not loaded')
+ toolbar_data = '"valuename": "IEToolbar",\n "class": "USER",' + \
+ '\n "type": "REG_BINARY",' + \
+ '\n "data": [\n 0\n ]'
+ self.assertIn(toolbar_data, out, 'Toolbar policy not loaded')
+ restrict_data = '"valuename": "RestrictImplicitTextCollection",' + \
+ '\n "class": "USER",' + \
+ '\n "type": "REG_DWORD",\n "data": 1\n'
+ self.assertIn(restrict_data, out, 'Restrict policy not loaded')
with NamedTemporaryFile() as f:
f.write(gpo_remove_json)