예제 #1
0
def reset_original_catalogurl():
    """Resets SoftwareUpdate's CatalogURL to the original value"""
    software_update_key_list = CFPreferencesCopyKeyList(
        APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN, kCFPreferencesAnyUser,
        kCFPreferencesCurrentHost) or []
    if ORIGINAL_CATALOG_URL_KEY not in software_update_key_list:
        # do nothing
        return
    original_catalog_url = CFPreferencesCopyValue(
        ORIGINAL_CATALOG_URL_KEY, APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
        kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    if not original_catalog_url:
        original_catalog_url = None
    # reset CatalogURL to the one we stored
    os_version_tuple = osutils.getOsVersion(as_tuple=True)
    if os_version_tuple < (10, 11):
        CFPreferencesSetValue('CatalogURL', original_catalog_url,
                              APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
                              kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    else:
        if original_catalog_url:
            # use softwareupdate --set-catalog
            cmd = [
                '/usr/sbin/softwareupdate', '--set-catalog',
                original_catalog_url
            ]
        else:
            # use softwareupdate --clear-catalog
            cmd = ['/usr/sbin/softwareupdate', '--clear-catalog']
        proc = subprocess.Popen(cmd,
                                bufsize=-1,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        (output, err) = proc.communicate()
        if output:
            display.display_detail(output)
        if err:
            display.display_error(err)

    # remove ORIGINAL_CATALOG_URL_KEY
    CFPreferencesSetValue(ORIGINAL_CATALOG_URL_KEY, None,
                          APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
                          kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    # sync
    if not CFPreferencesSynchronize(APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
                                    kCFPreferencesAnyUser,
                                    kCFPreferencesCurrentHost):
        display.display_error(
            'Error resetting com.apple.SoftwareUpdate CatalogURL.')
예제 #2
0
def set_preference_anyuser(preference_key, preference_value, bundle_id):
    # Set the specified preference key from the specified preference
    # bundle ID for any user (current host) to the specified value using CoreFoundation
    CFPreferencesSetValue(preference_key, preference_value, bundle_id,
                          kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    CFPreferencesSynchronize(bundle_id, kCFPreferencesAnyUser,
                             kCFPreferencesCurrentHost)
예제 #3
0
def set_pref(pref_name, value):
    """Sets a value in /Library/Preferences/com.apple.SoftwareUpdate.
    Uses CoreFoundation.
    Args:
       pref_name: str preference name to set.
       valueL value to set it to.
    """
    CFPreferencesSetValue(pref_name, value, APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
                          kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
예제 #4
0
def set_custom_catalogurl(catalog_url):
    """Sets Software Update's CatalogURL to custom value, storing the
    original"""
    software_update_key_list = CFPreferencesCopyKeyList(
        APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
        kCFPreferencesAnyUser, kCFPreferencesCurrentHost) or []
    if ORIGINAL_CATALOG_URL_KEY not in software_update_key_list:
        # store the original CatalogURL
        original_catalog_url = get_catalogurl()
        if not original_catalog_url:
            # can't store None as a CFPreference
            original_catalog_url = ""
        CFPreferencesSetValue(
            ORIGINAL_CATALOG_URL_KEY,
            original_catalog_url,
            APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
            kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    # now set our custom CatalogURL
    os_version_tuple = osutils.getOsVersion(as_tuple=True)
    if os_version_tuple < (10, 11):
        CFPreferencesSetValue(
            'CatalogURL', catalog_url,
            APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
            kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
        # finally, sync things up
        if not CFPreferencesSynchronize(
                APPLE_SOFTWARE_UPDATE_PREFS_DOMAIN,
                kCFPreferencesAnyUser, kCFPreferencesCurrentHost):
            display.display_error(
                'Error setting com.apple.SoftwareUpdate CatalogURL.')
    else:
        # use softwareupdate --set-catalog
        proc = subprocess.Popen(
            ['/usr/sbin/softwareupdate', '--set-catalog', catalog_url],
            bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (output, err) = proc.communicate()
        if output:
            display.display_detail(output)
        if err:
            display.display_error(err)
예제 #5
0
def write(appid, key, value):
    '''
    Write a simple preference value.

    appid
        Bundle identifier such as com.apple.Finder

    key
        Preference key to read

    .. code-block:: bash

        salt '*' cfpreferences.write com.example.test example a

    '''
    # didSync = CFPreferencesSynchronize(appid, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    CFPreferencesSetValue(key, value, appid, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    didSync = CFPreferencesSynchronize(appid, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
    return didSync
예제 #6
0
def set_screensaver_password_pref(state):
    '''Set boolean value for askForPassword for com.apple.screensaver'''
    CFPreferencesSetValue(
        'askForPassword', int(bool(state)), 'com.apple.screensaver',
        kCFPreferencesCurrentUser, kCFPreferencesCurrentHost)
    CFPreferencesAppSynchronize('com.apple.screensaver')