+
+
+Boolean
+_SCNetworkServiceIsVPN(SCNetworkServiceRef service)
+{
+ SCNetworkInterfaceRef interface;
+ CFStringRef interfaceType;
+
+ interface = SCNetworkServiceGetInterface(service);
+ if (interface == NULL) {
+ return FALSE;
+ }
+
+ interfaceType = SCNetworkInterfaceGetInterfaceType(interface);
+ if (CFEqual(interfaceType, kSCNetworkInterfaceTypePPP)) {
+ interface = SCNetworkInterfaceGetInterface(interface);
+ if (interface == NULL) {
+ return FALSE;
+ }
+
+ interfaceType = SCNetworkInterfaceGetInterfaceType(interface);
+ if (CFEqual(interfaceType, kSCNetworkInterfaceTypeL2TP)) {
+ return TRUE;
+ }
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated"
+ if (CFEqual(interfaceType, kSCNetworkInterfaceTypePPTP)) {
+ return TRUE;
+ }
+#pragma GCC diagnostic pop
+ } else if (CFEqual(interfaceType, kSCNetworkInterfaceTypeVPN)) {
+ return TRUE;
+ } else if (CFEqual(interfaceType, kSCNetworkInterfaceTypeIPSec)) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+Boolean
+SCNetworkServiceSetExternalID(SCNetworkServiceRef service, CFStringRef identifierDomain, CFStringRef identifier)
+{
+ CFStringRef prefs_path;
+ CFDictionaryRef service_dictionary;
+ SCNetworkServicePrivateRef servicePrivate = (SCNetworkServicePrivateRef)service;
+ Boolean success = FALSE;
+ CFStringRef prefixed_domain;
+
+ if (!isA_SCNetworkService(service) || (servicePrivate->prefs == NULL) || !isA_CFString(identifierDomain)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ if (!__SCNetworkServiceExists(service)) {
+ SC_log(LOG_ERR, "SCNetworkServiceSetExternalID() w/removed\n service = %@\n id = %@",
+ service,
+ identifier);
+ _SC_crash_once("SCNetworkServiceSetExternalID() w/removed service", NULL, NULL);
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ if (identifier != NULL && !isA_CFString(identifier)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ prefixed_domain = CFStringCreateWithFormat(NULL, 0, CFSTR("%s%@"), EXTERNAL_ID_DOMAIN_PREFIX, identifierDomain);
+
+ prefs_path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL,
+ servicePrivate->serviceID,
+ NULL);
+
+ service_dictionary = SCPreferencesPathGetValue(servicePrivate->prefs, prefs_path);
+ if (isA_CFDictionary(service_dictionary) || ((service_dictionary == NULL) && (identifier != NULL))) {
+ CFMutableDictionaryRef new_service_dictionary;
+
+ if (service_dictionary != NULL) {
+ new_service_dictionary = CFDictionaryCreateMutableCopy(NULL, 0, service_dictionary);
+ } else {
+ new_service_dictionary = CFDictionaryCreateMutable(NULL,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ }
+
+ if (identifier != NULL) {
+ CFDictionarySetValue(new_service_dictionary, prefixed_domain, identifier);
+ } else {
+ CFDictionaryRemoveValue(new_service_dictionary, prefixed_domain);
+ }
+ success = SCPreferencesPathSetValue(servicePrivate->prefs, prefs_path, new_service_dictionary);
+ CFRelease(new_service_dictionary);
+ }
+ CFRelease(prefs_path);
+
+ if (identifier != NULL) {
+ if (servicePrivate->externalIDs == NULL) {
+ servicePrivate->externalIDs = CFDictionaryCreateMutable(NULL,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ }
+ CFDictionarySetValue(servicePrivate->externalIDs, prefixed_domain, identifier);
+ } else {
+ if (servicePrivate->externalIDs != NULL) {
+ CFDictionaryRemoveValue(servicePrivate->externalIDs, prefixed_domain);
+ }
+ }
+
+ CFRelease(prefixed_domain);
+
+ if (!success) {
+ _SCErrorSet(kSCStatusFailed);
+ }
+
+ return success;
+}
+
+
+CFStringRef
+SCNetworkServiceCopyExternalID(SCNetworkServiceRef service, CFStringRef identifierDomain)
+{
+ CFStringRef identifier = NULL;
+ CFStringRef prefixed_domain;
+ SCNetworkServicePrivateRef service_private = (SCNetworkServicePrivateRef)service;
+
+ if (!isA_SCNetworkService(service) || (service_private->prefs == NULL) || !isA_CFString(identifierDomain)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+
+ prefixed_domain = CFStringCreateWithFormat(NULL, 0, CFSTR("%s%@"), EXTERNAL_ID_DOMAIN_PREFIX, identifierDomain);
+
+ if (service_private->externalIDs != NULL) {
+ identifier = CFDictionaryGetValue(service_private->externalIDs, prefixed_domain);
+ if (identifier != NULL) {
+ CFRetain(identifier);
+ }
+ }
+
+ if (identifier == NULL) {
+ CFStringRef prefs_path;
+ CFDictionaryRef service_dictionary;
+
+ prefs_path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL,
+ service_private->serviceID,
+ NULL);
+
+ service_dictionary = SCPreferencesPathGetValue(service_private->prefs, prefs_path);
+ if (isA_CFDictionary(service_dictionary)) {
+ identifier = CFDictionaryGetValue(service_dictionary, prefixed_domain);
+ if (identifier != NULL) {
+ CFRetain(identifier);
+ if (service_private->externalIDs == NULL) {
+ service_private->externalIDs = CFDictionaryCreateMutable(NULL,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ }
+ CFDictionarySetValue(service_private->externalIDs, prefixed_domain, identifier);
+ }
+ }
+ CFRelease(prefs_path);
+ }
+
+ CFRelease(prefixed_domain);
+
+ if (identifier == NULL) {
+ _SCErrorSet(kSCStatusNoKey);
+ }
+
+ return identifier;
+}
+
+
+typedef struct {
+ CFStringRef oldServiceID;
+ CFStringRef newServiceID;
+} serviceContext, *serviceContextRef;
+
+
+static void
+replaceServiceID(const void *value, void *context)
+{
+ CFStringRef link = NULL;
+ CFStringRef oldLink;
+ CFMutableArrayRef newServiceOrder;
+ CFStringRef path;
+ serviceContextRef service_context = (serviceContextRef)context;
+ CFArrayRef serviceOrder = NULL;
+ SCNetworkSetRef set = (SCNetworkSetRef)value;
+ SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set;
+
+ // update service order
+ serviceOrder = SCNetworkSetGetServiceOrder(set);
+ if ((isA_CFArray(serviceOrder) != NULL) &&
+ CFArrayContainsValue(serviceOrder,
+ CFRangeMake(0, CFArrayGetCount(serviceOrder)),
+ service_context->oldServiceID)) {
+ CFIndex count;
+ CFIndex serviceOrderIndex;
+
+ // replacing all instances of old service ID with new one
+ newServiceOrder = CFArrayCreateMutableCopy(NULL, 0, serviceOrder);
+ count = CFArrayGetCount(newServiceOrder);
+ for (serviceOrderIndex = 0; serviceOrderIndex < count; serviceOrderIndex++) {
+ CFStringRef serviceID;
+
+ serviceID = CFArrayGetValueAtIndex(newServiceOrder, serviceOrderIndex);
+ if (CFEqual(serviceID, service_context->oldServiceID)) {
+ CFArraySetValueAtIndex(newServiceOrder, serviceOrderIndex, service_context->newServiceID);
+ }
+ }
+ SCNetworkSetSetServiceOrder(set, newServiceOrder);
+ CFRelease(newServiceOrder);
+ }
+
+ // check if service with old serviceID is part of the set
+ path = SCPreferencesPathKeyCreateSetNetworkServiceEntity(NULL, // allocator
+ setPrivate->setID, // set
+ service_context->oldServiceID, // service
+ NULL); // entity
+ oldLink = SCPreferencesPathGetLink(setPrivate->prefs, path);
+ if (oldLink == NULL) {
+ // don't make any changes if service with old serviceID is not found
+ goto done;
+ }
+
+ // remove link between "set" and old "service"
+ (void) SCPreferencesPathRemoveValue(setPrivate->prefs, path);
+ CFRelease(path);
+
+ // create the link between "set" and the "service"
+ path = SCPreferencesPathKeyCreateSetNetworkServiceEntity(NULL, // allocator
+ setPrivate->setID, // set
+ service_context->newServiceID, // service
+ NULL); // entity
+ link = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator
+ service_context->newServiceID, // service
+ NULL); // entity
+ (void) SCPreferencesPathSetLink(setPrivate->prefs, path, link);
+
+ done:
+
+ if (path != NULL) {
+ CFRelease(path);
+ }
+ if (link != NULL) {
+ CFRelease(link);
+ }
+
+ return;
+}
+
+
+Boolean
+_SCNetworkServiceSetServiceID(SCNetworkServiceRef service, CFStringRef newServiceID)
+{
+ CFArrayRef allSets = NULL;
+ CFDictionaryRef entity;
+ CFStringRef newPath;
+ Boolean ok = FALSE;
+ CFStringRef oldPath = NULL;
+ serviceContext service_context;
+ SCNetworkServicePrivateRef servicePrivate = (SCNetworkServicePrivateRef)service;
+
+ if (!isA_SCNetworkService(service) || (servicePrivate->prefs == NULL)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ if (!isA_CFString(newServiceID)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ if (CFEqual(newServiceID, servicePrivate->serviceID)) {
+ // no work needs to be done if new service ID is equal to current service ID
+ return TRUE;
+ }
+
+ if (!__SCNetworkServiceExists(service)) {
+ SC_log(LOG_ERR, "_SCNetworkServiceSetServiceID() w/removed service\n service = %@\n serviceID = %@",
+ service,
+ newServiceID);
+ _SC_crash_once("_SCNetworkServiceSetServiceID() w/removed service", NULL, NULL);
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ newPath = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator
+ newServiceID, // service
+ NULL); // entity
+ entity = SCPreferencesPathGetValue(servicePrivate->prefs, newPath);
+ if (isA_CFDictionary(entity)) {
+ // if the new service already exists
+ _SCErrorSet(kSCStatusKeyExists);
+ goto done;
+ }
+
+ oldPath = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator
+ servicePrivate->serviceID, // service
+ NULL); // entity
+ entity = SCPreferencesPathGetValue(servicePrivate->prefs, oldPath);
+ if (!isA_CFDictionary(entity)) {
+ // if the service has already been removed
+ _SCErrorSet(kSCStatusNoKey);
+ goto done;
+ }
+
+ ok = SCPreferencesPathSetValue(servicePrivate->prefs, newPath, entity);
+ if (!ok) goto done;
+
+ ok = SCPreferencesPathRemoveValue(servicePrivate->prefs, oldPath);
+ if (!ok) goto done;
+
+ allSets = SCNetworkSetCopyAll(servicePrivate->prefs);
+
+ service_context.newServiceID = newServiceID;
+ service_context.oldServiceID = servicePrivate->serviceID;
+
+ // find all sets w/oldServiceID and update
+ // ... and update the serviceOrder
+ CFArrayApplyFunction(allSets,
+ CFRangeMake(0, CFArrayGetCount(allSets)),
+ replaceServiceID,
+ &service_context);
+
+ if (servicePrivate->interface != NULL) {
+ SCNetworkInterfaceRef newInterface;
+
+ // duplicate the interface and associate the copy with the new service ID
+ newInterface = (SCNetworkInterfaceRef)__SCNetworkInterfaceCreateCopy(NULL,
+ servicePrivate->interface,
+ servicePrivate->prefs,
+ newServiceID);
+ CFRelease(servicePrivate->interface);
+ servicePrivate->interface = newInterface;
+ }
+
+ SC_log(LOG_DEBUG, "_SCNetworkServiceSetServiceID(): %@ --> %@", service, newServiceID);
+
+ // replace serviceID with new one
+ CFRetain(newServiceID);
+ CFRelease(servicePrivate->serviceID);
+ servicePrivate->serviceID = newServiceID;
+
+ done:
+
+ if (oldPath != NULL) {
+ CFRelease(oldPath);
+ }
+ if (newPath != NULL) {
+ CFRelease(newPath);
+ }
+ if (allSets != NULL) {
+ CFRelease(allSets);
+ }
+
+ return ok;
+}
+
+#define kVPNProtocolPayloadInfo CFSTR("com.apple.payload")
+#define kSCEntNetLoginWindowEAPOL CFSTR("EAPOL.LoginWindow")
+
+static void
+copyInterfaceConfiguration(SCNetworkServiceRef oldService, SCNetworkServiceRef newService)
+{
+ SCNetworkInterfaceRef oldInterface;
+ SCNetworkInterfaceRef newInterface;
+
+ oldInterface = SCNetworkServiceGetInterface(oldService);
+ newInterface = SCNetworkServiceGetInterface(newService);
+
+ while (oldInterface != NULL) {
+ CFDictionaryRef configuration;
+ CFStringRef interfaceType;
+
+ if (newInterface == NULL) {
+ // oops ... interface layering does not match
+ return;
+ }
+
+ // copy interface configuration
+ configuration = SCNetworkInterfaceGetConfiguration(oldInterface);
+
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ if (!SCNetworkInterfaceSetConfiguration(newInterface, configuration)) {
+ SC_log(LOG_INFO, "problem setting interface configuration");
+ }
+
+ }
+
+ // special case: PPP/L2TP + IPSec
+ interfaceType = SCNetworkInterfaceGetInterfaceType(oldInterface);
+ if (CFEqual(interfaceType, kSCNetworkInterfaceTypePPP)) {
+ SCNetworkInterfaceRef childInterface;
+
+ childInterface = SCNetworkInterfaceGetInterface(oldInterface);
+ if (childInterface != NULL) {
+ CFStringRef childInterfaceType;
+
+ childInterfaceType = SCNetworkInterfaceGetInterfaceType(childInterface);
+
+ if (CFEqual(childInterfaceType, kSCNetworkInterfaceTypeL2TP)) {
+ configuration = SCNetworkInterfaceGetExtendedConfiguration(oldInterface, kSCEntNetIPSec);
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ if (!SCNetworkInterfaceSetExtendedConfiguration(newInterface, kSCEntNetIPSec, configuration)) {
+ SC_log(LOG_INFO, "problem setting child interface configuration");
+ }
+ }
+ }
+ }
+ }
+
+ // special case: 802.1x
+ configuration = SCNetworkInterfaceGetExtendedConfiguration(oldInterface, kSCEntNetEAPOL);
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ (void) SCNetworkInterfaceSetExtendedConfiguration(newInterface, kSCEntNetEAPOL, configuration);
+ }
+
+ // special case: Managed Client
+ configuration = SCNetworkInterfaceGetExtendedConfiguration(oldInterface, kVPNProtocolPayloadInfo);
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ (void) SCNetworkInterfaceSetExtendedConfiguration(newInterface, kVPNProtocolPayloadInfo, configuration);
+ }
+
+ // special case: Network Pref
+ configuration = SCNetworkInterfaceGetExtendedConfiguration(oldInterface, kSCValNetPPPAuthProtocolEAP);
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ (void) SCNetworkInterfaceSetExtendedConfiguration(newInterface, kSCValNetPPPAuthProtocolEAP, configuration);
+ }
+
+ // special case: Remote Pref
+ configuration = SCNetworkInterfaceGetExtendedConfiguration(oldInterface, kSCEntNetLoginWindowEAPOL);
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ (void) SCNetworkInterfaceSetExtendedConfiguration(newInterface, kSCEntNetLoginWindowEAPOL, configuration);
+ }
+
+ // special case: Network Extension
+ configuration = SCNetworkInterfaceGetExtendedConfiguration(oldInterface, kSCNetworkInterfaceTypeIPSec);
+ if ((configuration != NULL) ||
+ (SCError() == kSCStatusOK)) {
+ (void) SCNetworkInterfaceSetExtendedConfiguration(newInterface, kSCNetworkInterfaceTypeIPSec, configuration);
+ }
+
+ oldInterface = SCNetworkInterfaceGetInterface(oldInterface);
+ newInterface = SCNetworkInterfaceGetInterface(newInterface);
+ }
+
+ return;
+}
+
+__private_extern__
+void
+__SCNetworkServiceAddProtocolToService(SCNetworkServiceRef service, CFStringRef protocolType, CFDictionaryRef configuration, Boolean enabled)
+{
+ Boolean ok;
+ SCNetworkProtocolRef protocol;
+
+ protocol = SCNetworkServiceCopyProtocol(service, protocolType);
+
+ if ((protocol == NULL) &&
+ (SCError() == kSCStatusNoKey)) {
+ ok = SCNetworkServiceAddProtocolType(service, protocolType);
+ if (ok) {
+ protocol = SCNetworkServiceCopyProtocol(service, protocolType);
+ }
+ }
+ if (protocol != NULL) {
+ SCNetworkProtocolSetConfiguration(protocol, configuration);
+ SCNetworkProtocolSetEnabled(protocol, enabled);
+ CFRelease(protocol);
+ }
+ return;
+}
+
+
+
+__private_extern__
+Boolean
+__SCNetworkServiceMigrateNew(SCPreferencesRef prefs,
+ SCNetworkServiceRef service,
+ CFDictionaryRef bsdMapping,
+ CFDictionaryRef setMapping,
+ CFDictionaryRef serviceSetMapping)
+{
+ CFStringRef deviceName = NULL;
+ Boolean enabled;
+ SCNetworkInterfaceRef interface = NULL;
+ CFDictionaryRef interfaceEntity = NULL;
+ CFMutableDictionaryRef interfaceEntityMutable = NULL;
+ SCNetworkSetRef newSet = NULL;
+ SCPreferencesRef ni_prefs = NULL;
+ SCNetworkInterfaceRef ni_interface = NULL;
+ SCNetworkInterfaceRef oldInterface = NULL;
+ SCNetworkSetRef oldSet = NULL;
+ SCNetworkServiceRef newService = NULL;
+ CFStringRef serviceID = NULL;
+ SCNetworkServicePrivateRef servicePrivate = (SCNetworkServicePrivateRef) service;
+ CFArrayRef setList = NULL;
+ Boolean success = FALSE;
+ CFStringRef targetDeviceName = NULL;
+ CFStringRef userDefinedName = NULL;
+ CFStringRef userDefinedNameInterface = NULL;
+ CFArrayRef protocols = NULL;
+ CFStringRef subType;
+
+ if ((isA_SCNetworkService(service) == NULL) ||
+ (isA_SCNetworkInterface(servicePrivate->interface) == NULL) ||
+ (servicePrivate->prefs == NULL)) {
+ goto done;
+ }
+ serviceID = servicePrivate->serviceID;
+
+ newService = SCNetworkServiceCopy(prefs, serviceID);
+ if (newService != NULL) {
+ // Cannot add service if it already exists
+ SC_log(LOG_INFO, "Service already exists");
+ goto done;
+ }
+
+ oldInterface = SCNetworkServiceGetInterface(service);
+ interfaceEntity = __SCNetworkInterfaceCopyInterfaceEntity(oldInterface);
+ if (interfaceEntity == NULL) {
+ SC_log(LOG_INFO, "No interface entity");
+ goto done;
+ }
+ interfaceEntityMutable = CFDictionaryCreateMutableCopy(NULL, 0, interfaceEntity);
+
+ if (isA_CFDictionary(bsdMapping) != NULL) {
+ deviceName = CFDictionaryGetValue(interfaceEntityMutable, kSCPropNetInterfaceDeviceName);
+ if (isA_CFString(deviceName) != NULL) {
+ targetDeviceName = CFDictionaryGetValue(bsdMapping, deviceName);
+ if (targetDeviceName != NULL) {
+ // update mapping
+ CFDictionarySetValue(interfaceEntityMutable, kSCPropNetInterfaceDeviceName, targetDeviceName);
+ ni_prefs = __SCPreferencesCreateNIPrefsFromPrefs(prefs);
+ ni_interface = __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(NULL, ni_prefs, targetDeviceName);
+ if (ni_interface != NULL) {
+ userDefinedNameInterface = __SCNetworkInterfaceGetUserDefinedName(ni_interface);
+ }
+ }
+ }
+ if (userDefinedNameInterface == NULL) {
+ userDefinedNameInterface = CFDictionaryGetValue(interfaceEntityMutable, kSCPropUserDefinedName);
+ }
+ }
+ subType = CFDictionaryGetValue(interfaceEntityMutable, kSCPropNetInterfaceSubType);
+ interface = _SCNetworkInterfaceCreateWithEntity(NULL, interfaceEntityMutable, NULL);
+ if (userDefinedNameInterface != NULL) {
+ __SCNetworkInterfaceSetUserDefinedName(interface, userDefinedNameInterface);
+ }
+ // Supporting PPPoE subtype
+ if (subType != NULL &&
+ CFEqual(subType, kSCValNetInterfaceSubTypePPPoE)) {
+ SCNetworkInterfaceRef childInterface = SCNetworkInterfaceGetInterface(interface);
+ if (childInterface != NULL) {
+ __SCNetworkInterfaceSetUserDefinedName(childInterface, userDefinedNameInterface);
+ }
+ }
+ newService = SCNetworkServiceCreate(prefs, interface);
+ if (newService == NULL) {
+ SC_log(LOG_INFO, "SCNetworkServiceCreate() failed");
+ goto done;
+ }
+
+ enabled = SCNetworkServiceGetEnabled(service);
+ if (!SCNetworkServiceSetEnabled(newService, enabled)) {
+ SCNetworkServiceRemove(newService);
+ SC_log(LOG_INFO, "SCNetworkServiceSetEnabled() failed");
+ goto done;
+ }
+
+ if (!SCNetworkServiceEstablishDefaultConfiguration(newService)) {
+ SCNetworkServiceRemove(newService);
+ SC_log(LOG_INFO, "SCNetworkServiceEstablishDefaultConfiguration() failed");
+ goto done;
+ }
+
+ // Set service ID
+ _SCNetworkServiceSetServiceID(newService, serviceID);
+
+ userDefinedName = SCNetworkServiceGetName(service);
+ if ((userDefinedName != NULL) &&
+ !SCNetworkServiceSetName(newService, userDefinedName)) {
+ SC_log(LOG_INFO, "SCNetworkServiceSetName(, %@) failed", userDefinedName);
+ }
+
+ // Determine which sets to add service
+ if (setMapping != NULL &&
+ serviceSetMapping != NULL) {
+ setList = CFDictionaryGetValue(serviceSetMapping, service);
+ if (setList != NULL) {
+ for (CFIndex idx = 0; idx < CFArrayGetCount(setList); idx++) {
+ oldSet = CFArrayGetValueAtIndex(setList, idx);
+ newSet = CFDictionaryGetValue(setMapping, oldSet);
+ if (newSet == NULL) {
+ continue;
+ }
+
+ if (!SCNetworkSetAddService(newSet, newService)) {
+ SC_log(LOG_INFO, "SCNetworkSetAddService() failed");
+ }
+ }
+ }
+ }
+
+ protocols = SCNetworkServiceCopyProtocols(service);
+ if (protocols != NULL) {
+
+ for (CFIndex idx = 0; idx < CFArrayGetCount(protocols); idx++) {
+ SCNetworkProtocolRef protocol = CFArrayGetValueAtIndex(protocols, idx);
+ CFDictionaryRef configuration = SCNetworkProtocolGetConfiguration(protocol);
+ CFStringRef protocolType = SCNetworkProtocolGetProtocolType(protocol);
+ enabled = SCNetworkProtocolGetEnabled(protocol);
+ __SCNetworkServiceAddProtocolToService(newService, protocolType, configuration, enabled);
+ }
+ CFRelease(protocols);
+ }
+
+ copyInterfaceConfiguration(service, newService);
+
+ success = TRUE;
+done:
+ if (interface != NULL) {
+ CFRelease(interface);
+ }
+ if (interfaceEntity != NULL) {
+ CFRelease(interfaceEntity);
+ }
+ if (interfaceEntityMutable != NULL) {
+ CFRelease(interfaceEntityMutable);
+ }
+ if (newService != NULL) {
+ CFRelease(newService);
+ }
+ if (ni_prefs != NULL) {
+ CFRelease(ni_prefs);
+ }
+ if (ni_interface != NULL) {
+ CFRelease(ni_interface);
+ }
+ return success;
+}
+
+
+__private_extern__
+Boolean
+__SCNetworkServiceCreate(SCPreferencesRef prefs,
+ SCNetworkInterfaceRef interface,
+ CFStringRef userDefinedName)
+{
+ SCNetworkSetRef currentSet = NULL;
+ Boolean ok = FALSE;
+ SCNetworkServiceRef service = NULL;
+
+ if (interface == NULL) {
+ goto done;
+ }
+
+ if (userDefinedName == NULL) {
+ userDefinedName = __SCNetworkInterfaceGetUserDefinedName(interface);
+ if (userDefinedName == NULL) {
+ SC_log(LOG_INFO, "No userDefinedName");
+ goto done;
+ }
+ }
+ service = SCNetworkServiceCreate(prefs, interface);
+ if (service == NULL) {
+ SC_log(LOG_INFO, "SCNetworkServiceCreate() failed: %s", SCErrorString(SCError()));
+ } else {
+ ok = SCNetworkServiceSetName(service, userDefinedName);
+ if (!ok) {
+ SC_log(LOG_INFO, "SCNetworkServiceSetName() failed: %s", SCErrorString(SCError()));
+ SCNetworkServiceRemove(service);
+ goto done;
+ }
+
+ ok = SCNetworkServiceEstablishDefaultConfiguration(service);
+ if (!ok) {
+ SC_log(LOG_INFO, "SCNetworkServiceEstablishDefaultConfiguration() failed: %s", SCErrorString(SCError()));
+ SCNetworkServiceRemove(service);
+ goto done;
+ }
+ }
+ currentSet = SCNetworkSetCopyCurrent(prefs);
+ if (currentSet == NULL) {
+ SC_log(LOG_INFO, "No current set");
+ if (service != NULL) {
+ SCNetworkServiceRemove(service);
+ }
+ goto done;
+ }
+ if (service != NULL) {
+ ok = SCNetworkSetAddService(currentSet, service);
+ if (!ok) {
+ SC_log(LOG_INFO, "Could not add service to the current set");
+ SCNetworkServiceRemove(service);
+ goto done;
+ }
+ }
+
+ done:
+ if (service != NULL) {
+ CFRelease(service);
+ }
+ if (currentSet != NULL) {
+ CFRelease(currentSet);
+ }
+ return ok;
+}
+
+__private_extern__ Boolean
+__SCNetworkServiceIsPPTP(SCNetworkServiceRef service)
+{
+ CFStringRef intfSubtype;
+ SCNetworkServicePrivateRef servicePrivate = (SCNetworkServicePrivateRef)service;
+
+ if (servicePrivate == NULL || servicePrivate->interface == NULL) {
+ return FALSE;
+ }
+
+ intfSubtype = __SCNetworkInterfaceGetEntitySubType(servicePrivate->interface);
+ if (intfSubtype == NULL) {
+ return FALSE;
+ }
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated"
+ if (CFEqual(intfSubtype, kSCValNetInterfaceSubTypePPTP)) {
+ return TRUE;
+ }
+#pragma GCC diagnostic pop
+
+ return FALSE;
+}