/* Turns a service ID or name into a vendor type, or preserves type */ static CFStringRef nc_copy_vendor_type (CFStringRef input) { SCNetworkInterfaceRef child; SCNetworkInterfaceRef interface; CFStringRef output_name = input; SCNetworkServiceRef service = NULL; CFStringRef type; if (input == NULL) { goto done; } service = nc_copy_service(NULL, input); if (service != NULL) { interface = SCNetworkServiceGetInterface(service); child = SCNetworkInterfaceGetInterface(interface); type = SCNetworkInterfaceGetInterfaceType(interface); /* Must be of type VPN */ if (!CFEqual(type, kSCNetworkInterfaceTypeVPN)) { output_name = NULL; goto done; } output_name = SCNetworkInterfaceGetInterfaceType(child); goto done; } done : if (output_name != NULL) CFRetain(output_name); my_CFRelease(&service); return output_name; }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ static void nc_get_service_type_and_subtype(SCNetworkServiceRef service, CFStringRef *iftype, CFStringRef *ifsubtype) { SCNetworkInterfaceRef interface = SCNetworkServiceGetInterface(service); SCNetworkInterfaceRef child = SCNetworkInterfaceGetInterface(interface); *iftype = SCNetworkInterfaceGetInterfaceType(interface); *ifsubtype = NULL; if (CFEqual(*iftype, kSCNetworkInterfaceTypePPP) || CFEqual(*iftype, kSCNetworkInterfaceTypeVPN)) { *ifsubtype = (child != NULL) ? SCNetworkInterfaceGetInterfaceType(child) : NULL; } }
vector<InterfaceInfo> OSXPlatform::interfaces() { vector<InterfaceInfo> result; CFStringRef name = CFSTR("com.codebutler.firesheep.backend"); SCPreferencesRef prefs = SCPreferencesCreate(NULL, name, NULL); SCNetworkSetRef set = SCNetworkSetCopyCurrent(prefs); CFArrayRef services = SCNetworkSetCopyServices(set); int arraySize = CFArrayGetCount(services); for (int i = 0; i < arraySize; i++) { SCNetworkServiceRef service = (SCNetworkServiceRef) CFArrayGetValueAtIndex(services, i); if (SCNetworkServiceGetEnabled(service)) { SCNetworkInterfaceRef iface = SCNetworkServiceGetInterface(service); CFStringRef serviceName = SCNetworkServiceGetName(service); char cServiceName[(CFStringGetLength(serviceName) * 4) + 1]; CFStringGetCString(serviceName, cServiceName, sizeof(cServiceName), kCFStringEncodingUTF8); CFStringRef type = SCNetworkInterfaceGetInterfaceType(iface); if (CFStringCompare(type, CFSTR("Ethernet"), 0) == kCFCompareEqualTo || CFStringCompare(type, CFSTR("IEEE80211"), 0) == kCFCompareEqualTo) { char cType[(CFStringGetLength(type) * 4) + 1]; CFStringGetCString(type, cType, sizeof(cType), kCFStringEncodingUTF8); CFStringRef bsdName = SCNetworkInterfaceGetBSDName(iface); char cBsdName[(CFStringGetLength(bsdName) * 4) + 1]; CFStringGetCString(bsdName, cBsdName, sizeof(cBsdName), kCFStringEncodingUTF8); InterfaceInfo info((string(cBsdName)), (string(cServiceName)), (string(cType))); result.push_back(info); } } } CFRelease(services); CFRelease(set); CFRelease(prefs); return result; }
/* * 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); }
/* * Function: EAPOLClientConfigurationSetSystemProfile * * Purpose: * Set the profile configured for System mode on the specified * BSD network interface (e.g. "en0", "en1"). * * If you pass NULL for the "profile" argument, the System profile * list is cleared. */ Boolean EAPOLClientConfigurationSetSystemProfile(EAPOLClientConfigurationRef cfg, CFStringRef if_name, EAPOLClientProfileRef profile) { CFDictionaryRef dict; CFStringRef existing_profileID = NULL; CFMutableDictionaryRef new_dict = NULL; SCNetworkInterfaceRef net_if = NULL; CFStringRef profileID = NULL; Boolean ret = FALSE; if (profile != NULL) { profileID = EAPOLClientProfileGetID(profile); } dict = get_eapol_configuration(get_sc_prefs(cfg), if_name, &net_if); if (net_if == NULL) { goto done; } if (CFEqual(SCNetworkInterfaceGetInterfaceType(net_if), kSCNetworkInterfaceTypeIEEE80211)) { /* disallow setting static System Mode on AirPort interfaces */ goto done; } if (dict != NULL) { existing_profileID = CFDictionaryGetValue(dict, kSystemProfileID); } if (my_CFEqual(existing_profileID, profileID)) { /* nothing to do */ ret = TRUE; goto done; } if (dict != NULL) { /* * remove the AcceptEAPTypes array to give EAPOLController a way to * know whether we're using new configuration or the old */ new_dict = CFDictionaryCreateMutableCopy(NULL, 0, dict); CFDictionaryRemoveValue(new_dict, kEAPClientPropAcceptEAPTypes); CFDictionaryRemoveValue(new_dict, kSCResvInactive); } else { new_dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } if (profileID == NULL) { CFDictionaryRemoveValue(new_dict, kSystemProfileID); if (CFDictionaryGetCount(new_dict) == 0) { my_CFRelease(&new_dict); } } else { CFDictionarySetValue(new_dict, kSystemProfileID, profileID); } if (setInterfaceEAPOLConfiguration(cfg, net_if, new_dict) == FALSE) { goto done; } ret = TRUE; done: my_CFRelease(&new_dict); my_CFRelease(&net_if); return (ret); }
__private_extern__ void select_service(int argc, char **argv) { SCNetworkInterfaceRef interface; SCNetworkServiceRef service; CFStringRef serviceName; service = _find_service(argv[0]); if (service == NULL) { return; } if (net_service != NULL) CFRelease(net_service); net_service = CFRetain(service); serviceName = SCNetworkServiceGetName(service); if (serviceName != NULL) { SCPrint(TRUE, stdout, CFSTR("service \"%@\" selected\n"), serviceName); } else { SCPrint(TRUE, stdout, CFSTR("service ID \"%@\" selected\n"), SCNetworkServiceGetServiceID(service)); } interface = SCNetworkServiceGetInterface(service); if (interface != NULL) { CFStringRef interfaceName; if (net_interface != NULL) CFRelease(net_interface); net_interface = CFRetain(interface); interfaceName = SCNetworkInterfaceGetLocalizedDisplayName(interface); if (interfaceName == NULL) { interfaceName = SCNetworkInterfaceGetBSDName(interface); } if (interfaceName == NULL) { interfaceName = SCNetworkInterfaceGetInterfaceType(interface); } SCPrint(TRUE, stdout, CFSTR("& interface \"%@\" selected\n"), interfaceName); } else { if (net_interface != NULL) { CFRelease(net_interface); net_interface = NULL; SCPrint(TRUE, stdout, CFSTR("& no interface selected\n")); } } if (protocols != NULL) { CFRelease(protocols); protocols = NULL; } if (net_protocol != NULL) { CFRelease(net_protocol); net_protocol = NULL; SCPrint(TRUE, stdout, CFSTR("& no protocol selected\n")); } return; }
__private_extern__ void create_service(int argc, char **argv) { SCNetworkInterfaceRef interface; CFStringRef interfaceName; Boolean ok; SCNetworkServiceRef service = NULL; CFStringRef serviceName; CFStringRef setName; CFArrayRef supported; if (prefs == NULL) { SCPrint(TRUE, stdout, CFSTR("network configuration not open\n")); return; } if (net_set == NULL) { SCPrint(TRUE, stdout, CFSTR("set not selected\n")); return; } if (argc < 1) { if (net_interface == NULL) { SCPrint(TRUE, stdout, CFSTR("no network interface selected\n")); return; } interface = net_interface; } else { int nArgs; interface = _find_interface(argc, argv, &nArgs); argv += nArgs; argc -= nArgs; } if (interface == NULL) { return; } supported = SCNetworkInterfaceGetSupportedProtocolTypes(interface); if (supported == NULL) { SCPrint(TRUE, stdout, CFSTR("no network protocols are supported over this interface\n")); return; } service = SCNetworkServiceCreate(prefs, interface); if (service == NULL) { SCPrint(TRUE, stdout, CFSTR("%s\n"), SCErrorString(SCError())); goto done; } if ((argc > 0) && (strlen(argv[0]) > 0)) { Boolean ok; serviceName = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8); // argv++; // argc--; ok = SCNetworkServiceSetName(service, serviceName); CFRelease(serviceName); if (!ok) { SCPrint(TRUE, stdout, CFSTR("%s\n"), SCErrorString(SCError())); (void)SCNetworkServiceRemove(service); goto done; } } ok = SCNetworkServiceEstablishDefaultConfiguration(service); if (!ok) { SCPrint(TRUE, stdout, CFSTR("%s\n"), SCErrorString(SCError())); (void)SCNetworkServiceRemove(service); goto done; } ok = SCNetworkSetAddService(net_set, service); if (!ok) { SCPrint(TRUE, stdout, CFSTR("service not created: %s\n"), SCErrorString(SCError())); (void)SCNetworkServiceRemove(service); goto done; } _prefs_changed = TRUE; if (net_service != NULL) CFRelease(net_service); net_service = CFRetain(service); serviceName = SCNetworkServiceGetName(service); if (serviceName != NULL) { SCPrint(TRUE, stdout, CFSTR("service \"%@\" (%@) created and selected\n"), serviceName, SCNetworkServiceGetServiceID(service)); } else { SCPrint(TRUE, stdout, CFSTR("service ID \"%@\" created and selected\n"), SCNetworkServiceGetServiceID(service)); } setName = SCNetworkSetGetName(net_set); if (setName != NULL) { SCPrint(TRUE, stdout, CFSTR("& added to set \"%@\"\n"), setName); } else { SCPrint(TRUE, stdout, CFSTR("& added to set ID \"%@\"\n"), SCNetworkSetGetSetID(net_set)); } if (net_interface != NULL) CFRelease(net_interface); net_interface = SCNetworkServiceGetInterface(net_service); if (net_interface != NULL) { CFRetain(net_interface); } interfaceName = SCNetworkInterfaceGetLocalizedDisplayName(interface); if (interfaceName == NULL) { interfaceName = SCNetworkInterfaceGetBSDName(interface); } if (interfaceName == NULL) { interfaceName = SCNetworkInterfaceGetInterfaceType(interface); } SCPrint(TRUE, stdout, CFSTR("& interface \"%@\" selected\n"), interfaceName); if (protocols != NULL) { CFRelease(protocols); protocols = NULL; } if (net_protocol != NULL) { CFRelease(net_protocol); net_protocol = NULL; SCPrint(TRUE, stdout, CFSTR("& no protocol selected\n")); } if (services != NULL) { CFRelease(services); services = NULL; } done : if (service != NULL) CFRelease(service); return; }