Пример #1
0
static kim_error kim_os_preferences_set_value (kim_preference_key in_key,
                                               CFPropertyListRef  in_value)
{
    kim_error err = KIM_NO_ERROR;
    CFStringRef key = NULL;

    /* in_value may be NULL if removing the key */

    if (!err) {
        key = kim_os_preferences_cfstring_for_key (in_key);
    }

    if (!err && key) {
        kim_boolean homedir_ok = kim_library_allow_home_directory_access();
        CFStringRef user = homedir_ok ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
        CFStringRef host = homedir_ok ? kCFPreferencesAnyHost : kCFPreferencesCurrentHost;

        CFPreferencesSetValue (key, in_value, KIM_PREFERENCES_FILE, user, host);
        if (!CFPreferencesSynchronize (KIM_PREFERENCES_FILE, user, host)) {
            err = check_error (KIM_PREFERENCES_WRITE_ERR);
        }
    }

    return check_error (err);
}
Пример #2
0
//
// Delete a NDAS device info.
//
// Return :	false if No memory.
//			true if success.
//
bool NDASPreferencesDelete(UInt32 slotNumber)
{
	CFStringRef				strEntryKey = NULL;	
	
	// Slot Number is the Key.
	strEntryKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_SLOT_NUMBER_STRING), slotNumber);
	if(NULL == strEntryKey) {
		return false;
	}
	
	// Set Values.
	CFPreferencesSetValue(
						  strEntryKey, 
						  NULL, 
						  NDAS_PREFERENCES_FILE_REGISTER,
						  kCFPreferencesAnyUser, 
						  kCFPreferencesCurrentHost
						  );
	
	// Write out the preference data.
	CFPreferencesSynchronize( 
							 NDAS_PREFERENCES_FILE_REGISTER,
							 kCFPreferencesAnyUser, 
							 kCFPreferencesCurrentHost
							 );
	// Clean up.
	if(strEntryKey)					CFRelease(strEntryKey);
	
	return true;
}
void	CACFPreferences::DeleteValue(CFStringRef inKey, bool inCurrentUser, bool inCurrentHost, bool inSynchronize)
{
	CFStringRef theUser = inCurrentUser ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
	CFStringRef theHost = inCurrentHost ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
	CFPreferencesSetValue(inKey, NULL, kCFPreferencesAnyApplication, theUser, theHost);
	
	if(inSynchronize)
	{
		Synchronize(theUser, inCurrentHost, true);
	}
}
Пример #4
0
void QMacSettingsPrivate::remove(const QString &key)
{
    QStringList keys = children(key + QLatin1Char('/'), AllKeys);

    // If i == -1, then delete "key" itself.
    for (int i = -1; i < keys.size(); ++i) {
        QString subKey = key;
        if (i >= 0) {
            subKey += QLatin1Char('/');
            subKey += keys.at(i);
        }
        CFPreferencesSetValue(macKey(subKey), 0, domains[0].applicationOrSuiteId,
                              domains[0].userName, hostName);
    }
}
static kim_error kim_os_selection_hints_set_selection_hints_array (CFArrayRef in_selection_hints_array)
{
    kim_error err = KIM_NO_ERROR;

    if (!err && !in_selection_hints_array) { err = check_error (KIM_NULL_PARAMETER_ERR); }

    if (!err) {
        kim_boolean homedir_ok = kim_library_allow_home_directory_access();
        CFStringRef user = homedir_ok ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
        CFStringRef host = homedir_ok ? kCFPreferencesAnyHost : kCFPreferencesCurrentHost;

        CFPreferencesSetValue (KIM_SELECTION_HINTS_ARRAY, in_selection_hints_array,
                               KIM_SELECTION_HINTS_FILE, user, host);
        if (!CFPreferencesSynchronize (KIM_SELECTION_HINTS_FILE, user, host)) {
            err = check_error (KIM_PREFERENCES_WRITE_ERR);
        }
    }

    return check_error (err);
}
Пример #6
0
bool NDASPreferencesChangeNameOfRAIDDevice(PGUID raidID, CFStringRef name)
{		
	CFStringRef				cfsKey = NULL;
	CFMutableDictionaryRef	dictEntry = NULL;
	CFUUIDRef				cfuGuid= NULL;
	
	if (name) {
		
		// Create Dict
		dictEntry = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
		
		if (NULL == dictEntry) {
			return false;
		}
		
		CFDictionaryAddValue(dictEntry, 
							 CFSTR(KEY_NAME_STRING),  
							 name	
							 );
	}
	
	// GUID is key.
	cfuGuid = CFUUIDCreateWithBytes(kCFAllocatorDefault, 
						  raidID->guid[0], raidID->guid[1], raidID->guid[2], raidID->guid[3],
						  raidID->guid[4], raidID->guid[5], raidID->guid[6], raidID->guid[7],
						  raidID->guid[8], raidID->guid[9], raidID->guid[10], raidID->guid[11],
						  raidID->guid[12], raidID->guid[13], raidID->guid[14], raidID->guid[15]);
	if (NULL == cfuGuid) {
		return false;
	}
	
	
	cfsKey = CFUUIDCreateString (
								 kCFAllocatorDefault,
								 cfuGuid
								 );
	if (NULL == cfsKey) {
		return false;
	}
	
	// Set Values.
	CFPreferencesSetValue(
						  cfsKey, 
						  dictEntry, 
						  NDAS_PREFERENCES_FILE_RAID_INFORMATION,
						  kCFPreferencesAnyUser, 
						  kCFPreferencesCurrentHost
						  );
	
	// Write out the preference data.
	CFPreferencesSynchronize( 
							  NDAS_PREFERENCES_FILE_RAID_INFORMATION,
							  kCFPreferencesAnyUser, 
							  kCFPreferencesCurrentHost
							  );
	
	if (cfsKey)			CFRelease(cfsKey);
	if (dictEntry)		CFRelease(dictEntry);
	if (cfuGuid)		CFRelease(cfuGuid);
	
	return true;
}
Пример #7
0
bool NDASPreferencesChangeConfigurationOfLogicalDevice(UInt32 index, UInt32 configuration)
{
	// Get Logical Device.
	NDASLogicalDeviceInformation	NDASInfo = { 0 };
	
	NDASInfo.index = index;
	
	if(NDASGetLogicalDeviceInformationByIndex(&NDASInfo)) {
	
		CFStringRef	cfsKey = NULL;
		CFNumberRef	cfnConfiguration = NULL;
		CFUUIDRef	cfuGuid = NULL;
		
		switch(configuration) {
			case kNDASUnitConfigurationMountRW:
			case kNDASUnitConfigurationMountRO:
			{
				cfnConfiguration = CFNumberCreate (NULL, kCFNumberSInt32Type, &configuration);
			}
				break;
			case kNDASUnitConfigurationUnmount:
			{
			}
				break;
		}
		
		// GUID is key.
		cfuGuid = CFUUIDCreateWithBytes(kCFAllocatorDefault, 
										NDASInfo.LowerUnitDeviceID.guid[0], NDASInfo.LowerUnitDeviceID.guid[1], NDASInfo.LowerUnitDeviceID.guid[2], NDASInfo.LowerUnitDeviceID.guid[3],
										NDASInfo.LowerUnitDeviceID.guid[4], NDASInfo.LowerUnitDeviceID.guid[5], NDASInfo.LowerUnitDeviceID.guid[6], NDASInfo.LowerUnitDeviceID.guid[7],
										NDASInfo.LowerUnitDeviceID.guid[8], NDASInfo.LowerUnitDeviceID.guid[9], NDASInfo.LowerUnitDeviceID.guid[10], NDASInfo.LowerUnitDeviceID.guid[11],
										NDASInfo.LowerUnitDeviceID.guid[12], NDASInfo.LowerUnitDeviceID.guid[13], NDASInfo.LowerUnitDeviceID.guid[14], NDASInfo.LowerUnitDeviceID.guid		[15]);
		
		cfsKey = CFUUIDCreateString(kCFAllocatorDefault, cfuGuid);
		
		CFRelease(cfuGuid);
		
		// Set Values.
		CFPreferencesSetValue(
							  cfsKey, 
							  cfnConfiguration, 
							  NDAS_PREFERENCES_FILE_CONFIGURATION,
							  kCFPreferencesAnyUser, 
							  kCFPreferencesCurrentHost
							  );
		
		// Write out the preference data.
		CFPreferencesSynchronize( 
								  NDAS_PREFERENCES_FILE_CONFIGURATION,
								  kCFPreferencesAnyUser, 
								  kCFPreferencesCurrentHost
								  );
		
		if (cfsKey)				CFRelease(cfsKey);
		if (cfnConfiguration)	CFRelease(cfnConfiguration);
		
	} else {
		return false;
	}
			
	return true;
}
Пример #8
0
//
// Insert New NDAS device info.
//
// Return :	false if Bad parameters or No memory.
//			true if success.
//
bool NDASPreferencesInsert(PNDASPreferencesParameter parameter)
{
	CFStringRef				strEntryKey = NULL;
	CFStringRef				strIDKey[4] = { NULL };
	CFStringRef				strWriteKeyKey = NULL;
	CFStringRef				strConfigurationKey = NULL;
	
	CFStringRef				strIDValue[4] = { NULL };
	CFStringRef				strWriteKeyValue = NULL;
	CFNumberRef				numberConfigurationValue = NULL;
	CFStringRef				strNameKey = NULL;
	
	CFMutableDictionaryRef	dictEntry = NULL;
	int						count;
	bool					result = false;
	
	if(parameter->slotNumber == 0) {
		return false;
	}
		
	// Create Dict
	dictEntry = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	if (NULL == dictEntry) {
		return false;
	}
	
	// Copy ID
	for(count = 0; count < 4; count++) {
		
		// Create Key.
		strIDKey[count] = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_ID_STRING), count);		
		// Create Value.
		strIDValue[count] = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s"), parameter->chID[count]);
		if (NULL == strIDKey[count] || NULL == strIDValue[count]) {
			goto cleanup;
		}
				
		if (!NDASPreferencesSetIDorWriteKey(dictEntry, strIDKey[count], strIDValue[count])) {
			goto cleanup;
		}
	}
	
	// Copy WriteKey.
	strWriteKeyKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_WRITEKEY_STRING));
	strWriteKeyValue = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s"), parameter->chWriteKey);
	if (NULL == strWriteKeyKey || NULL == strWriteKeyValue) {
		goto cleanup;
	}
	
	if(!NDASPreferencesSetIDorWriteKey(dictEntry, strWriteKeyKey, strWriteKeyValue)) {
		goto cleanup;
	}
	
	// Copy Name
	strNameKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_NAME_STRING));
	if (NULL == strNameKey) {
		goto cleanup;
	}
	
	//strNameValue = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s"), parameter->Name);
	//strNameValue = CFStringCreateWithCharacters(kCFAllocatorDefault, (UniChar *)parameter->Name, MAX_NDAS_NAME_SIZE / 2);
	
	CFDictionaryAddValue(dictEntry, 
						 strNameKey, 
						 parameter->cfsName
						 );
	
	// Copy Configuration.
	strConfigurationKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_CONFIGURATION_STRING));
	numberConfigurationValue = CFNumberCreate (NULL, kCFNumberSInt32Type, &parameter->configuration);
	if (NULL == strConfigurationKey || NULL == numberConfigurationValue) {
		goto cleanup;
	}
	
	CFDictionaryAddValue(dictEntry, strConfigurationKey, numberConfigurationValue);
	
	// Slot Number is the Key.
	strEntryKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_SLOT_NUMBER_STRING), parameter->slotNumber);
	
	// Set Values.
	CFPreferencesSetValue(
						  strEntryKey, 
						  dictEntry, 
						  NDAS_PREFERENCES_FILE_REGISTER,
						  kCFPreferencesAnyUser, 
						  kCFPreferencesCurrentHost
						  );
	
	// Write out the preference data.
	CFPreferencesSynchronize( 
							 NDAS_PREFERENCES_FILE_REGISTER,
							 kCFPreferencesAnyUser, 
							 kCFPreferencesCurrentHost
							 );
	
	
	result = true;
	
cleanup:
	
	CFDictionaryRemoveAllValues(dictEntry);
	
	// Clean up.
	if(strEntryKey)					CFRelease(strEntryKey);
	if(dictEntry)					CFRelease(dictEntry);
	
	if(strWriteKeyKey)				CFRelease(strWriteKeyKey);
	if(strWriteKeyValue)			CFRelease(strWriteKeyValue);
	
	if(strConfigurationKey)			CFRelease(strConfigurationKey);
	if(numberConfigurationValue)	CFRelease(numberConfigurationValue);
	if(strNameKey)					CFRelease(strNameKey);
	
	for(count = 0; count < 4; count++) {
		if(strIDKey[count])			CFRelease(strIDKey[count]);
		if(strIDValue[count])		CFRelease(strIDValue[count]);
	}
	
	return result;
}
Пример #9
0
/*
 * Store the specified certificate (or, more likely, some platform-dependent
 * reference to it) as the specified principal's certificate. Passing
 * in NULL for the client_cert has the effect of deleting the relevant entry
 * in the cert storage.
 */
krb5_error_code krb5_pkinit_set_client_cert(
    const char                  *principal,     /* full principal string */
    krb5_pkinit_cert_t          client_cert)
{
    SecCertificateRef certRef = (SecCertificateRef)client_cert;
    OSStatus ortn;
    CSSM_DATA issuerSerial = {0, NULL};
    CFDataRef cfIssuerSerial = NULL;
    CFDictionaryRef existDict = NULL;
    CFMutableDictionaryRef newDict = NULL;
    CFStringRef keyStr = NULL;
    krb5_error_code ourRtn = 0;

    if(certRef != NULL) {
        if(CFGetTypeID(certRef) != SecCertificateGetTypeID()) {
            return KRB5KRB_ERR_GENERIC;
        }

        /* Cook up DER-encoded issuer/serial number */
        ortn = pkinit_get_cert_issuer_sn(certRef, &issuerSerial);
        if(ortn) {
            ourRtn = KRB5KRB_ERR_GENERIC;
            goto errOut;
        }
    }

    /*
     * Obtain the existing pref for kPkinitClientCertKey as a CFDictionary, or
     * cook up a new one.
     */
    ortn = pkinit_get_pref_dict(&existDict);
    if(ortn == noErr) {
        /* dup to a mutable dictionary */
        newDict = CFDictionaryCreateMutableCopy(NULL, 0, existDict);
    }
    else {
        if(certRef == NULL) {
            /* no existing entry, nothing to delete, we're done */
            return 0;
        }
        newDict = CFDictionaryCreateMutable(NULL, 0,
                                            &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    }
    if(newDict == NULL) {
        ourRtn = ENOMEM;
        goto errOut;
    }

    /* issuer / serial number ==> that dictionary */
    keyStr = CFStringCreateWithCString(NULL, principal, kCFStringEncodingASCII);
    if(certRef == NULL) {
        CFDictionaryRemoveValue(newDict, keyStr);
    }
    else {
        cfIssuerSerial = CFDataCreate(NULL, issuerSerial.Data, issuerSerial.Length);
        CFDictionarySetValue(newDict, keyStr, cfIssuerSerial);
    }

    /* dictionary ==> prefs */
    CFPreferencesSetValue(CFSTR(kPkinitClientCertKey), newDict,
                          CFSTR(kPkinitClientCertApp), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
    if(CFPreferencesSynchronize(CFSTR(kPkinitClientCertApp), kCFPreferencesCurrentUser,
                                kCFPreferencesAnyHost)) {
        ourRtn = 0;
    }
    else {
        ourRtn = EACCES;   /* any better ideas? */
    }
errOut:
    if(cfIssuerSerial) {
        CFRelease(cfIssuerSerial);
    }
    if(issuerSerial.Data) {
        free(issuerSerial.Data);
    }
    if(existDict) {
        CFRelease(existDict);
    }
    if(newDict) {
        CFRelease(newDict);
    }
    if(keyStr) {
        CFRelease(keyStr);
    }
    return ourRtn;
}
Пример #10
0
void QMacSettingsPrivate::set(const QString &key, const QVariant &value)
{
    CFPreferencesSetValue(macKey(key), macValue(value), domains[0].applicationOrSuiteId,
                          domains[0].userName, hostName);
}
Пример #11
0
OSErr SetScreenSaverSelection(passwd *pw, char *moduleName, char *modulePath, int type) {
    OSErr err = noErr;
    CFStringRef preferenceName = CFSTR("com.apple.screensaver");
    CFStringRef mainKeyName = CFSTR("moduleDict");
    CFDictionaryRef emptyData;
    CFMutableDictionaryRef newData;
    Boolean success;

    CFStringRef nameKey = CFStringCreateWithCString(NULL, "moduleName", kCFStringEncodingASCII);
    CFStringRef nameValue = CFStringCreateWithCString(NULL, moduleName, kCFStringEncodingASCII);
        
    CFStringRef pathKey = CFStringCreateWithCString(NULL, "path", kCFStringEncodingASCII);
    CFStringRef pathValue = CFStringCreateWithCString(NULL, modulePath, kCFStringEncodingASCII);
    
    CFStringRef typeKey = CFStringCreateWithCString(NULL, "type", kCFStringEncodingASCII);
    CFNumberRef typeValue = CFNumberCreate(NULL, kCFNumberIntType, &type);
    
    emptyData = CFDictionaryCreate(NULL, NULL, NULL, 0, NULL, NULL);
    if (emptyData == NULL) {
        fprintf(stderr, "Could not set screensaver for user %s\n", pw->pw_name);
        fflush(stderr);
        CFRelease(nameKey);
        CFRelease(nameValue);
        CFRelease(pathKey);
        CFRelease(pathValue);
        CFRelease(typeKey);
        CFRelease(typeValue);
        return(-1);
    }

    newData = CFDictionaryCreateMutableCopy(NULL,0, emptyData);

    if (newData == NULL)
    {
        fprintf(stderr, "Could not set screensaver for user %s\n", pw->pw_name);
        fflush(stderr);
        CFRelease(nameKey);
        CFRelease(nameValue);
        CFRelease(pathKey);
        CFRelease(pathValue);
        CFRelease(typeKey);
        CFRelease(typeValue);
        CFRelease(emptyData);
        return(-1);
    }

    CFDictionaryAddValue(newData, nameKey, nameValue);     
    CFDictionaryAddValue(newData, pathKey, pathValue);     
    CFDictionaryAddValue(newData, typeKey, typeValue);     

    CFPreferencesSetValue(mainKeyName, newData, preferenceName, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
    success = CFPreferencesSynchronize(preferenceName, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);

    if (!success) {
        fprintf(stderr, "Could not set screensaver for user %s\n", pw->pw_name);
        fflush(stderr);
        err = -1;
    }
    
    CFRelease(nameKey);
    CFRelease(nameValue);
    CFRelease(pathKey);
    CFRelease(pathValue);
    CFRelease(typeKey);
    CFRelease(typeValue);
    CFRelease(emptyData);
    CFRelease(newData);

    return err;
}