From 8c239270b00dc373beda365249d6bf0e3e8a28e9 Mon Sep 17 00:00:00 2001 From: eholtam <(none)> Date: Fri, 10 Nov 2017 09:18:58 -0600 Subject: [PATCH 1/2] Taking a stab at adding option for custom PayloadType --- mcxToProfile.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/mcxToProfile.py b/mcxToProfile.py index 6a789e3..a7152a4 100755 --- a/mcxToProfile.py +++ b/mcxToProfile.py @@ -62,7 +62,7 @@ def __init__(self, identifier, uuid=False, removal_allowed=False, organization=' # An empty list for 'sub payloads' that we'll fill later self.data['PayloadContent'] = [] - def _addPayload(self, payload_content_dict): + def _addPayload(self, payload_content_dict, payload_type=None): """Add a Custom Settings payload to the profile. Takes a dict which will be the PayloadContent dict within the payload. Handles the boilerplate, naming and descriptive elements. @@ -80,10 +80,15 @@ def _addPayload(self, payload_content_dict): payload_dict['PayloadVersion'] = 1 payload_dict['PayloadUUID'] = makeNewUUID() payload_dict['PayloadEnabled'] = True - payload_dict['PayloadType'] = 'com.apple.ManagedClient.preferences' payload_dict['PayloadIdentifier'] = "%s.%s.alacarte.customsettings.%s" % ( 'MCXToProfile', self.data['PayloadUUID'], payload_dict['PayloadUUID']) + # Allow for custom PayloadTypes. With macOS 10.13 UAMDM introduced new PayloadType of 'com.apple.syspolicy.kernel-extension-policy'. More surely to follow. + if payload_type is None: + payload_dict['PayloadType'] = 'com.apple.ManagedClient.preferences' + else: + payload_dict['PayloadType'] = payload_type + # Update the top-level descriptive info if self.data['PayloadDisplayName'] == '': self.data['PayloadDisplayName'] = 'MCXToProfile: %s' % domain @@ -94,7 +99,7 @@ def _addPayload(self, payload_content_dict): # Add to the profile's PayloadContent array self.data['PayloadContent'].append(payload_dict) - def addPayloadFromPlistContents(self, plist_dict, domain, manage, is_byhost=False): + def addPayloadFromPlistContents(self, plist_dict, domain, manage, payload_type, is_byhost=False): """Add one plist dict contents to the profile's payloads. domain is the preferences domain (ie. com.apple.finder), manage is one of 'Once', 'Often' or 'Always', and is_byhost is a boolean representing whether the preference is to be used as a ByHost. @@ -122,13 +127,13 @@ def addPayloadFromPlistContents(self, plist_dict, domain, manage, is_byhost=Fals now = NSDate.new() payload_dict[domain][state][0]['mcx_data_timestamp'] = now - self._addPayload(payload_dict) + self._addPayload(payload_dict, payload_type) def addPayloadFromMCX(self, mcxdata): """Add MCX data to the profile's payloads. """ # MCX is already 'configured', we just need to add the dict to the payload - self._addPayload(mcxdata) + self._addPayload(mcxdata, payload_type) def finalizeAndSave(self, output_path): """Perform last modifications and save to an output plist. @@ -358,7 +363,7 @@ def main(): parser = optparse.OptionParser() parser.set_usage( """usage: %prog [--dsobject DSOBJECT | --plist PLIST | --defaults DOMAIN] - [--identifier IDENTIFIER | --identifier-from-profile PATH] [options] + [--identifier IDENTIFIER | --identifier-from-profile PATH] [--payloadtype PAYLOADTYPE] [options] One of '--dsobject', '--plist', or '--defaults' must be specified, and only one identifier option. Run '%prog --help' for more information.""") @@ -400,6 +405,10 @@ def main(): action="store", default="", help="Display name for profile. Defaults to 'MCXToProfile: '.") + parser.add_option('--payloadtype', + action="store", + default="com.apple.ManagedClient.preferences", + help="Specifies a specific PayloadType. com.apple.ManagedClient.preferences is default.") # Plist-specific plist_options = optparse.OptionGroup(parser, @@ -496,6 +505,9 @@ def main(): else: output_file = os.path.join(os.getcwd(), identifier + '.mobileconfig') + if options.payloadtype: + payload_type = options.payloadtype + newPayload = PayloadDict(identifier=identifier, uuid=uuid, removal_allowed=options.removal_allowed, @@ -515,6 +527,7 @@ def main(): newPayload.addPayloadFromPlistContents(source_data, source_domain['name'], manage, + payload_type, is_byhost=source_domain['is_byhost']) if options.dsobject: mcx_data = getMCXData(options.dsobject) @@ -529,6 +542,7 @@ def main(): newPayload.addPayloadFromPlistContents(defaults_data, defaults_domain, manage, + payload_type, isByHost) newPayload.finalizeAndSave(output_file) From b634fe5bfba6cb9e06a9a337be404b3432228ab2 Mon Sep 17 00:00:00 2001 From: eholtam <(none)> Date: Fri, 19 Aug 2022 10:16:13 -0500 Subject: [PATCH 2/2] Updated shebang due to Monterey no longer having a built-in Python framework --- mcxToProfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcxToProfile.py b/mcxToProfile.py index 6a789e3..49f4bf9 100755 --- a/mcxToProfile.py +++ b/mcxToProfile.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/local/munkireport/munkireport-python2 # mcxToProfile.py # Simple utility to assist with creating Custom Settings Configuration Profiles