/* * Function: EAPOLClientProfileCreateWithPropertyList * * Purpose: * Create a profile using the supplied "external_format". The profile * is not tied to the configuration until the function * EAPOLClientConfigurationAddProfile() is invoked successfully. * Use EAPOLClientConfigurationGetMatchingProfiles() to check for conflicts * if calling that function fails. * * Returns: * NULL if the "external_format" property list was not a valid format, * non-NULL EAPOLClientProfileRef otherwise. */ EAPOLClientProfileRef EAPOLClientProfileCreateWithPropertyList(CFPropertyListRef external_format) { CFDictionaryRef dict = (CFDictionaryRef)external_format; CFStringRef profileID; if (isA_CFDictionary(dict) == NULL) { return (NULL); } profileID = CFDictionaryGetValue(dict, kProfileKeyProfileID); if (isA_CFString(profileID) == NULL) { return (NULL); } return (EAPOLClientProfileCreateWithDictAndProfileID(dict, profileID)); }
STATIC void import_profiles(EAPOLClientConfigurationRef cfg) { int count = 0; CFMutableDictionaryRef domains_dict; int i; const void * * keys; CFDictionaryRef prefs_dict; CFMutableDictionaryRef profiles_dict; CFMutableDictionaryRef ssids_dict; const void * * values; profiles_dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); ssids_dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); domains_dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); prefs_dict = SCPreferencesGetValue(cfg->eap_prefs, kConfigurationKeyProfiles); if (isA_CFDictionary(prefs_dict) != NULL) { count = CFDictionaryGetCount(prefs_dict); } if (count == 0) { goto done; } /* allocate a single array, half for keys, half for values */ keys = (const void * *)malloc(sizeof(*keys) * count * 2); values = keys + count; CFDictionaryGetKeysAndValues(prefs_dict, keys, values); for (i = 0; i < count; i++) { EAPOLClientProfileRef profile; CFDictionaryRef profile_dict = values[i]; CFStringRef profileID = keys[i]; CFDataRef ssid; if (isA_CFDictionary(profile_dict) == NULL) { SCLog(TRUE, LOG_NOTICE, CFSTR("EAPOLClientConfiguration: invalid profile with id %@"), profileID); continue; } profile = EAPOLClientProfileCreateWithDictAndProfileID(profile_dict, profileID); if (profile == NULL) { continue; } ssid = EAPOLClientProfileGetWLANSSIDAndSecurityType(profile, NULL); if (ssid != NULL) { CFStringRef conflicting_profileID; conflicting_profileID = CFDictionaryGetValue(ssids_dict, ssid); if (conflicting_profileID != NULL) { CFStringRef ssid_str = my_CFStringCreateWithData(ssid); SCLog(TRUE, LOG_NOTICE, CFSTR("EAPOLClientConfiguration: ignoring profile %@:" " SSID '%@' already used by %@"), profileID, ssid_str, conflicting_profileID); CFRelease(ssid_str); CFRelease(profile); continue; } CFDictionarySetValue(ssids_dict, ssid, profileID); } else { CFStringRef domain; domain = EAPOLClientProfileGetWLANDomain(profile); if (domain != NULL) { CFStringRef conflicting_profileID; conflicting_profileID = CFDictionaryGetValue(profiles_dict, domain); if (conflicting_profileID != NULL) { SCLog(TRUE, LOG_NOTICE, CFSTR("EAPOLClientConfiguration: ignoring profile %@:" " WLAN domain '%@' already used by %@"), profileID, domain, conflicting_profileID); CFRelease(profile); continue; } CFDictionarySetValue(domains_dict, domain, profileID); } } CFDictionarySetValue(profiles_dict, profileID, profile); EAPOLClientProfileSetConfiguration(profile, cfg); CFRelease(profile); } free(keys); done: cfg->ssids = ssids_dict; cfg->profiles = profiles_dict; cfg->domains = domains_dict; return; }