EAPOLClientItemIDRef EAPOLClientItemIDCreateWithDictionary(EAPOLClientConfigurationRef cfg, CFDictionaryRef dict) { CFStringRef domain; EAPOLClientProfileRef profile; CFStringRef profileID; CFDataRef ssid; if (isA_CFDictionary(dict) == NULL) { return (NULL); } profileID = CFDictionaryGetValue(dict, kItemProfileID); if (isA_CFString(profileID) != NULL) { if (cfg != NULL) { profile = EAPOLClientConfigurationGetProfileWithID(cfg, profileID); if (profile != NULL) { return (EAPOLClientItemIDCreateWithProfile(profile)); } } return (EAPOLClientItemIDCreateWithProfileID(profileID)); } ssid = CFDictionaryGetValue(dict, kItemSSID); if (isA_CFData(ssid) != NULL) { if (cfg != NULL) { profile = EAPOLClientConfigurationGetProfileWithWLANSSID(cfg, ssid); if (profile != NULL) { return (EAPOLClientItemIDCreateWithProfile(profile)); } } return (EAPOLClientItemIDCreateWithWLANSSID(ssid)); } domain = CFDictionaryGetValue(dict, kItemDomain); if (isA_CFString(domain) != NULL) { if (cfg != NULL) { profile = EAPOLClientConfigurationGetProfileWithWLANDomain(cfg, domain); if (profile != NULL) { return (EAPOLClientItemIDCreateWithProfile(profile)); } } return (EAPOLClientItemIDCreateWithWLANDomain(domain)); } if (CFDictionaryGetValue(dict, kItemDefault) != NULL) { return (EAPOLClientItemIDCreateDefault()); } return (NULL); }
/* * Function: EAPOLClientConfigurationRemoveProfile * * Purpose: * Remove the specified profile from the configuration. * * Returns: * FALSE if the profile is invalid or not in the configuration, * TRUE otherwise. */ Boolean EAPOLClientConfigurationRemoveProfile(EAPOLClientConfigurationRef cfg, EAPOLClientProfileRef profile) { CFStringRef profileID = EAPOLClientProfileGetID(profile); CFDataRef ssid; if (EAPOLClientConfigurationGetProfileWithID(cfg, profileID) != profile) { /* trying to remove profile that isn't part of the configuration */ return (FALSE); } ssid = EAPOLClientProfileGetWLANSSIDAndSecurityType(profile, NULL); if (ssid != NULL) { CFDictionaryRemoveValue(cfg->ssids, ssid); } CFDictionaryRemoveValue(cfg->profiles, profileID); return (TRUE); }
/* * Function: EAPOLClientConfigurationCopyLoginWindowProfiles * * Purpose: * Return the list of profiles configured for LoginWindow mode on the * specified BSD network interface (e.g. "en0", "en1"). * * Returns: * NULL if no profiles are defined, non-NULL non-empty array of profiles * otherwise. */ CFArrayRef /* of EAPOLClientProfileRef */ EAPOLClientConfigurationCopyLoginWindowProfiles(EAPOLClientConfigurationRef cfg, CFStringRef if_name) { int count; int i; CFDictionaryRef dict; CFArrayRef profile_ids; CFMutableArrayRef ret_profiles = NULL; dict = get_eapol_configuration(get_sc_prefs(cfg), if_name, NULL); if (dict == NULL) { goto done; } profile_ids = CFDictionaryGetValue(dict, kLoginWindowProfileIDs); if (isA_CFArray(profile_ids) == NULL) { goto done; } count = CFArrayGetCount(profile_ids); if (count == 0) { goto done; } ret_profiles = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks); for (i = 0; i < count; i++) { CFStringRef profileID; EAPOLClientProfileRef profile; profileID = (CFStringRef)CFArrayGetValueAtIndex(profile_ids, i); if (isA_CFString(profileID) == NULL) { continue; } profile = EAPOLClientConfigurationGetProfileWithID(cfg, profileID); if (profile != NULL) { CFArrayAppendValue(ret_profiles, profile); } } if (CFArrayGetCount(ret_profiles) == 0) { my_CFRelease(&ret_profiles); } done: return (ret_profiles); }
/* * Function: EAPOLClientConfigurationAddProfile * * Purpose: * Add the specified profile to the configuration. * * Returns: * FALSE if the profile could not be added, either because: * - the profile is already in the configuration, or * - the profile conflicts with an existing profile (profileID or WLAN SSID) * TRUE if the profile was added successfully. */ Boolean EAPOLClientConfigurationAddProfile(EAPOLClientConfigurationRef cfg, EAPOLClientProfileRef profile) { CFStringRef domain = NULL; CFStringRef profileID = EAPOLClientProfileGetID(profile); CFDataRef ssid; if (profile->cfg != NULL) { /* profile is already part of the configuration */ return (FALSE); } if (EAPOLClientConfigurationGetProfileWithID(cfg, profileID) != NULL) { /* profile already present with that profileID */ return (FALSE); } ssid = EAPOLClientProfileGetWLANSSIDAndSecurityType(profile, NULL); if (ssid != NULL) { if (EAPOLClientConfigurationGetProfileWithWLANSSID(cfg, ssid) != NULL) { /* profile already present with that SSID */ return (FALSE); } } else { domain = EAPOLClientProfileGetWLANDomain(profile); if (domain != NULL) { if (EAPOLClientConfigurationGetProfileWithWLANDomain(cfg, domain) != NULL) { /* profile already exists with that domain */ return (FALSE); } } } CFDictionarySetValue(cfg->profiles, profileID, profile); if (ssid != NULL) { CFDictionarySetValue(cfg->ssids, ssid, profileID); } else if (domain != NULL) { CFDictionarySetValue(cfg->domains, domain, profileID); } EAPOLClientProfileSetConfiguration(profile, cfg); return (TRUE); }
/* * Function: EAPOLClientConfigurationCopyMatchingProfiles * * Purpose: * Find the profile(s) matching the specified profile. * A profile is matched based on the profileID, the WLAN SSID, and * the WLAN domain, all of which must be unique in the configuration. * * Usually invoked after calling * EAPOLClientProfileCreateWithPropertyList() to instantiate a profile * from an external format. * * Returns: * NULL if no matching profile is part of the configuration, * non-NULL CFArrayRef of EAPOLClientProfileRef if found. */ CFArrayRef /* of EAPOLClientProfileRef */ EAPOLClientConfigurationCopyMatchingProfiles(EAPOLClientConfigurationRef cfg, EAPOLClientProfileRef profile) { int count; EAPOLClientProfileRef matching_profile; CFStringRef profileID = EAPOLClientProfileGetID(profile); CFDataRef ssid; const void * values[2] = { NULL, NULL }; count = 0; matching_profile = EAPOLClientConfigurationGetProfileWithID(cfg, profileID); if (matching_profile != NULL) { values[count] = matching_profile; count++; } matching_profile = NULL; ssid = EAPOLClientProfileGetWLANSSIDAndSecurityType(profile, NULL); if (ssid != NULL) { matching_profile = EAPOLClientConfigurationGetProfileWithWLANSSID(cfg, ssid); } else { CFStringRef domain; domain = EAPOLClientProfileGetWLANDomain(profile); if (domain != NULL) { matching_profile = EAPOLClientConfigurationGetProfileWithWLANDomain(cfg, domain); } } if (matching_profile != NULL && values[0] != matching_profile) { values[count] = matching_profile; count++; } if (count == 0) { return (NULL); } return (CFArrayCreate(CFGetAllocator(cfg), values, count, &kCFTypeArrayCallBacks)); }
/* * Function: EAPOLClientConfigurationGetSystemProfile * * Purpose: * Return the profile configured for System mode on the * specified BSD network interface (e.g. "en0", "en1"). * * Returns: * NULL if no such profile is defined, non-NULL profile * otherwise. */ EAPOLClientProfileRef EAPOLClientConfigurationGetSystemProfile(EAPOLClientConfigurationRef cfg, CFStringRef if_name) { CFDictionaryRef dict; SCNetworkInterfaceRef net_if = NULL; EAPOLClientProfileRef profile = NULL; CFStringRef profileID; dict = get_eapol_configuration(get_sc_prefs(cfg), if_name, &net_if); if (dict != NULL && !CFEqual(SCNetworkInterfaceGetInterfaceType(net_if), kSCNetworkInterfaceTypeIEEE80211)) { profileID = CFDictionaryGetValue(dict, kSystemProfileID); if (isA_CFString(profileID) != NULL) { profile = EAPOLClientConfigurationGetProfileWithID(cfg, profileID); } } my_CFRelease(&net_if); return (profile); }