예제 #1
0
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);
}
예제 #2
0
/*
 * Function: EAPOLClientProfileSetWLANDomain
 *
 * Purpose:
 *   Bind the profile to a Hotspot 2.0 domain name.
 *
 *   Only a single profile can be associated with a particular domain name.
 *
 *   To un-bind the profile from the domain name, set the domain
 *   argument to NULL.
 *
 * Returns:
 *    FALSE if there's an existing profile with the same domain name,
 *    TRUE otherwise.
 *
 * Note:
 *    EAPOLClientProfileSetWLANSSIDAndSecurityType() and
 *    EAPOLClientProfileSetWLANDomain() are mutally exclusive.
 *    A given profile can only be associated with a WLAN SSID *or* a
 *    WLAN domain and not both.
 */
Boolean
EAPOLClientProfileSetWLANDomain(EAPOLClientProfileRef profile,
				CFStringRef domain)
{
    EAPOLClientProfileRef	existing_profile;

    if (domain != NULL) {
	if (profile->WLAN.ssid != NULL) {
	    /* can't specify a domain when ssid is already specified */
	    return (FALSE);
	}
	if (profile->cfg != NULL) {
	    existing_profile
		= EAPOLClientConfigurationGetProfileWithWLANDomain(profile->cfg,
								   domain);
	    if (existing_profile != NULL && existing_profile != profile) {
		/* some other profile has this domain already */
		return (FALSE);
	    }
	}
    }

    /* give up the existing domain */
    if (profile->WLAN.domain != NULL && profile->cfg != NULL) {
	/* clear the old binding */
	EAPOLClientConfigurationSetProfileForWLANDomain(profile->cfg,
							profile->WLAN.domain,
							NULL);
    }

    /* claim the domain */
    if (domain != NULL) {
	CFRetain(domain);
	if (profile->cfg != NULL) {
	    EAPOLClientConfigurationSetProfileForWLANDomain(profile->cfg,
							    domain,
							    profile);
	}
    }
    if (profile->WLAN.domain != NULL) {
	CFRelease(profile->WLAN.domain);
    }
    profile->WLAN.domain = domain;
    return (TRUE);
}
예제 #3
0
/*
 * 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);
}
예제 #4
0
/*
 * 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));
}