/* * Function: copy_configured_interface_names * * Purpose: * Return the BSD interface name of all configured interfaces. If * 'entity' is non-NULL, also check that the interface has the specified * extended configuration. */ STATIC CFArrayRef /* of CFStringRef */ copy_configured_interface_names(SCPreferencesRef prefs, CFStringRef entity_name) { SCNetworkSetRef current_set = NULL; int count; int i; CFMutableArrayRef ret_names = NULL; CFRange ret_names_range = { 0 , 0 }; CFArrayRef services = NULL; if (prefs == NULL) { goto done; } current_set = SCNetworkSetCopyCurrent(prefs); if (current_set == NULL) { goto done; } services = SCNetworkSetCopyServices(current_set); if (services == NULL) { goto done; } count = CFArrayGetCount(services); for (i = 0; i < count; i++) { CFStringRef this_if_name; SCNetworkInterfaceRef this_if; SCNetworkServiceRef s; s = (SCNetworkServiceRef)CFArrayGetValueAtIndex(services, i); this_if = SCNetworkServiceGetInterface(s); if (this_if == NULL) { continue; } if (entity_name != NULL && (SCNetworkInterfaceGetExtendedConfiguration(this_if, entity_name) == NULL)) { /* interface doesn't have specified entity */ continue; } this_if_name = SCNetworkInterfaceGetBSDName(this_if); if (this_if_name == NULL) { continue; } if (ret_names == NULL || CFArrayContainsValue(ret_names, ret_names_range, this_if_name) == FALSE) { if (ret_names == NULL) { ret_names = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks); } CFArrayAppendValue(ret_names, this_if_name); ret_names_range.length++; } } done: my_CFRelease(¤t_set); my_CFRelease(&services); return (ret_names); }
__private_extern__ CFPropertyListRef cache_SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key) { CFPropertyListRef value; value = CFDictionaryGetValue(cached_set, key); if (value) { // if we have "set" a new value return (CFRetain(value)); } if (CFArrayContainsValue(cached_removals, CFRangeMake(0, CFArrayGetCount(cached_removals)), key)) { // if we have "removed" the key return NULL; } value = CFDictionaryGetValue(cached_keys, key); if (value) { // if we have a cached value return (CFRetain(value)); } value = SCDynamicStoreCopyValue(store, key); if (value) { CFDictionarySetValue(cached_keys, key, value); } return value; }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ static Boolean hasEntitlement(audit_token_t audit_token, CFStringRef entitlement, CFStringRef vpntype) { Boolean hasEntitlement = FALSE; SecTaskRef task; /* Create the security task from the audit token. */ task = SecTaskCreateWithAuditToken(NULL, audit_token); if (task != NULL) { CFErrorRef error = NULL; CFTypeRef value; /* Get the value for the entitlement. */ value = SecTaskCopyValueForEntitlement(task, entitlement, &error); if (value != NULL) { if (isA_CFBoolean(value)) { if (CFBooleanGetValue(value)) { /* if client DOES have entitlement */ hasEntitlement = TRUE; } } else if (isA_CFArray(value)){ if (vpntype == NULL){ /* we don't care about subtype */ hasEntitlement = TRUE; }else { if (CFArrayContainsValue(value, CFRangeMake(0, CFArrayGetCount(value)), vpntype)) { // if client DOES have entitlement hasEntitlement = TRUE; } } } else { SCLog(TRUE, LOG_ERR, CFSTR("SCNC Controller: entitlement not valid: %@"), entitlement); } CFRelease(value); } else if (error != NULL) { SCLog(TRUE, LOG_ERR, CFSTR("SCNC Controller: SecTaskCopyValueForEntitlement() failed, error=%@: %@"), error, entitlement); CFRelease(error); } CFRelease(task); } else { SCLog(TRUE, LOG_ERR, CFSTR("SCNC Controller: SecTaskCreateWithAuditToken() failed: %@"), entitlement); } return hasEntitlement; }
__private_extern__ void link_add(const char *if_name) { CFStringRef interface; CFStringRef cacheKey; CFDictionaryRef dict; CFMutableDictionaryRef newDict = NULL; CFArrayRef ifList; CFMutableArrayRef newIFList = NULL; interface = CFStringCreateWithCString(NULL, if_name, kCFStringEncodingMacRoman); cacheKey = SCDynamicStoreKeyCreateNetworkInterface(NULL, kSCDynamicStoreDomainState); dict = cache_SCDynamicStoreCopyValue(store, cacheKey); if (dict) { if (isA_CFDictionary(dict)) { newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict); ifList = CFDictionaryGetValue(newDict, kSCPropNetInterfaces); if (isA_CFArray(ifList)) { newIFList = CFArrayCreateMutableCopy(NULL, 0, ifList); } } CFRelease(dict); } if (!newDict) { newDict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } if (!newIFList) { newIFList = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } if (CFArrayContainsValue(newIFList, CFRangeMake(0, CFArrayGetCount(newIFList)), interface) == FALSE) { CFArrayAppendValue(newIFList, interface); CFDictionarySetValue(newDict, kSCPropNetInterfaces, newIFList); } cache_SCDynamicStoreSetValue(store, cacheKey, newDict); link_update_status(if_name, TRUE); #ifdef KEV_DL_LINK_QUALITY_METRIC_CHANGED link_update_quality_metric(if_name); #endif /* KEV_DL_LINK_QUALITY_METRIC_CHANGED */ CFRelease(cacheKey); CFRelease(interface); if (newDict) CFRelease(newDict); if (newIFList) CFRelease(newIFList); return; }
bool CACFArray::HasItem(const void* inItem) const { bool theAnswer = false; if(mCFArray != NULL) { CFRange theRange = { 0, CFArrayGetCount(mCFArray)}; theAnswer = CFArrayContainsValue(mCFArray, theRange, inItem); } return theAnswer; }
Boolean _CFApplicationPreferencesContainsDomain(_CFApplicationPreferences *self, CFPreferencesDomainRef domain) { Boolean result; if (!domain) { return false; } __CFSpinLock(&__CFApplicationPreferencesLock); result = CFArrayContainsValue(self->_search, CFRangeMake(0, CFArrayGetCount(self->_search)), domain); __CFSpinUnlock(&__CFApplicationPreferencesLock); return result; }
__private_extern__ void cache_SCDynamicStoreNotifyValue(SCDynamicStoreRef store, CFStringRef key) { if (!CFArrayContainsValue(cached_notifys, CFRangeMake(0, CFArrayGetCount(cached_notifys)), key)) { CFArrayAppendValue(cached_notifys, key); } return; }
void addArch( KcgenArgs * toolArgs, const NXArchInfo * arch) { if (CFArrayContainsValue(toolArgs->targetArchs, RANGE_ALL(toolArgs->targetArchs), arch)) { return; } CFArrayAppendValue(toolArgs->targetArchs, arch); }
static CFArrayRef copy_certificate_labels(CFArrayRef certs, CFStringRef cert_label, CFArrayRef * ret_identities) { CFMutableArrayRef cert_labels = NULL; CFMutableArrayRef certs_filtered = NULL; int count; int i; CFRange r; count = CFArrayGetCount(certs); cert_labels = CFArrayCreateMutable(NULL, count + 1, &kCFTypeArrayCallBacks); /* add the first element which is reserved to mean no cert is selected */ CFArrayAppendValue(cert_labels, cert_label); r.location = 0; r.length = 1; certs_filtered = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks); for (i = 0; i < count; i++) { SecCertificateRef cert = NULL; SecIdentityRef identity; CFStringRef str = NULL; identity = (SecIdentityRef)CFArrayGetValueAtIndex(certs, i); SecIdentityCopyCertificate(identity, &cert); if (cert != NULL) { str = SecCertificateCopyShortDescription(NULL, cert, NULL); CFRelease(cert); } if (str != NULL) { int instance; CFStringRef new_str; for (instance = 2, new_str = CFRetain(str); CFArrayContainsValue(cert_labels, r, new_str); instance++) { CFRelease(new_str); new_str = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%d)"), str, instance); } CFArrayAppendValue(cert_labels, new_str); r.length++; CFRelease(new_str); CFRelease(str); CFArrayAppendValue(certs_filtered, identity); } } *ret_identities = certs_filtered; return (cert_labels); }
static void sysEventConfigurationNotifier( SCDynamicStoreRef store, /* I - System data (unused) */ CFArrayRef changedKeys, /* I - Changed data */ void *context) /* I - Thread context data */ { cupsd_thread_data_t *threadData; /* Thread context data */ threadData = (cupsd_thread_data_t *)context; (void)store; /* anti-compiler-warning-code */ CFRange range = CFRangeMake(0, CFArrayGetCount(changedKeys)); if (CFArrayContainsValue(changedKeys, range, ComputerNameKey) || CFArrayContainsValue(changedKeys, range, BTMMKey)) threadData->sysevent.event |= SYSEVENT_NAMECHANGED; else { threadData->sysevent.event |= SYSEVENT_NETCHANGED; /* * Indicate the network interface list needs updating... */ NetIFUpdate = 1; } /* * Because we registered for several different kinds of change notifications * this callback usually gets called several times in a row. We use a timer to * de-bounce these so we only end up generating one event for the main thread. */ CFRunLoopTimerSetNextFireDate(threadData->timerRef, CFAbsoluteTimeGetCurrent() + 5); }
void _CFApplicationPreferencesSet(_CFApplicationPreferences *self, CFStringRef defaultName, CFTypeRef value) { CFPreferencesDomainRef applicationDomain; __CFSpinLock(&__CFApplicationPreferencesLock); applicationDomain = _CFPreferencesStandardDomain(self->_appName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); if(applicationDomain) { _CFPreferencesDomainSet(applicationDomain, defaultName, value); if (CFArrayContainsValue(self->_search, CFRangeMake(0, CFArrayGetCount(self->_search)), applicationDomain)) { // Expensive; can't we just check the relevant value throughout the appropriate sets of domains? -- REW, 7/19/99 updateDictRep(self); } } __CFSpinUnlock(&__CFApplicationPreferencesLock); }
void _CFApplicationPreferencesRemove(_CFApplicationPreferences *self, CFStringRef defaultName) { CFPreferencesDomainRef appDomain; __CFSpinLock(&__CFApplicationPreferencesLock); appDomain = _CFPreferencesStandardDomain(self->_appName, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); if(appDomain) { _CFPreferencesDomainSet(appDomain, defaultName, NULL); if (CFArrayContainsValue(self->_search, CFRangeMake(0, CFArrayGetCount(self->_search)), appDomain)) { // If key exists, it will be in the _dictRep (but possibly overridden) updateDictRep(self); } } __CFSpinUnlock(&__CFApplicationPreferencesLock); }
__private_extern__ void cache_SCDynamicStoreRemoveValue(SCDynamicStoreRef store, CFStringRef key) { CFDictionaryRemoveValue(cached_set, key); if (!CFArrayContainsValue(cached_removals, CFRangeMake(0, CFArrayGetCount(cached_removals)), key)) { CFArrayAppendValue(cached_removals, key); } return; }
static CFArrayRef copy_bssid_list_from_scan(CFArrayRef scan_result, CFStringRef ssid) { CFMutableArrayRef bssid_list = NULL; int count; int i; CFRange range; EAPLOG(LOG_ERR, "######## DEBUG ####### - FAIL - copy_bssid_list_from_scan"); count = CFArrayGetCount(scan_result); if (count == 0) { goto failed; } bssid_list = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); range.location = 0; range.length = 0; for (i = 0; i < count; i++) { CFStringRef bssid; CFDataRef bssid_data; CFDictionaryRef dict = CFArrayGetValueAtIndex(scan_result, i); CFStringRef this_ssid; this_ssid = CFDictionaryGetValue(dict, APPLE80211KEY_SSID_STR); if (this_ssid == NULL || !CFEqual(this_ssid, ssid)) { continue; } bssid = CFDictionaryGetValue(dict, APPLE80211KEY_BSSID); if (isA_CFString(bssid) == NULL) { continue; } bssid_data = bssid_string_to_data(bssid); if (bssid_data != NULL) { if (!CFArrayContainsValue(bssid_list, range, bssid_data)) { CFArrayAppendValue(bssid_list, bssid_data); range.length++; } CFRelease(bssid_data); } } if (CFArrayGetCount(bssid_list) == 0) { CFRelease(bssid_list); bssid_list = NULL; } failed: return (bssid_list); }
static void ToggleKeyAttribute( CFArrayRef keyAttrs, CFTypeRef attr, CSSM_KEYATTR_FLAGS mask, CSSM_KEYATTR_FLAGS &result) { // If the keyAttrs array contains the given attribute, // set the corresponding keyattr flags, otherwise clear them. // (Note: caller verifies that keyAttrs is not NULL.) CFIndex numItems = CFArrayGetCount(keyAttrs); result &= ~(mask); if (numItems > 0) { CFRange range = CFRangeMake(0, numItems); if (CFArrayContainsValue(keyAttrs, range, attr)) result |= mask; } }
static void kicker(SCDynamicStoreRef store, CFArrayRef changedKeys, void *arg) { CFIndex i; CFIndex n = CFArrayGetCount(changedKeys); kickeeRef target = (kickeeRef)arg; /* * Start a new kicker. If a kicker was already active then flag * the need for a second kick after the active one completes. */ /* create (or add to) the full list of keys that have changed */ if (!target->changedKeys) { target->changedKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } for (i = 0; i < n; i++) { CFStringRef key = CFArrayGetValueAtIndex(changedKeys, i); if (!CFArrayContainsValue(target->changedKeys, CFRangeMake(0, CFArrayGetCount(target->changedKeys)), key)) { CFArrayAppendValue(target->changedKeys, key); } } if (target->active) { CFStringRef name = CFDictionaryGetValue(target->dict, CFSTR("name")); /* we need another kick! */ target->needsKick = TRUE; SCLog(_verbose, LOG_DEBUG, CFSTR("Kicker callback, target=%@ request queued"), name); return; } /* start a new kicker */ target->active = TRUE; /* * let 'er rip. */ booter(target); return; }
Boolean SCNetworkSetSetSelectedVPNService(SCNetworkSetRef set, SCNetworkServiceRef service) { Boolean ok = TRUE; CFArrayRef services; if (!isA_SCNetworkSet(set)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } if (!isA_SCNetworkService(service) || !_SCNetworkServiceIsVPN(service)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } services = SCNetworkSetCopyServices(set); if (services != NULL) { CFIndex i; CFIndex n = CFArrayGetCount(services); if (!CFArrayContainsValue(services, CFRangeMake(0, n), service)) { // if selected service not a member of the current set _SCErrorSet(kSCStatusInvalidArgument); ok = FALSE; goto done; } for (i = 0; ok && (i < n); i++) { SCNetworkServiceRef vpn; vpn = CFArrayGetValueAtIndex(services, i); if (!_SCNetworkServiceIsVPN(vpn)) { // if not VPN service continue; } ok = SCNetworkServiceSetEnabled(vpn, CFEqual(service, vpn)); } } done : if (services != NULL) CFRelease(services); return ok; }
void filterKextID(const void * vValue, void * vContext) { CFStringRef kextID = (CFStringRef)vValue; FilterIDContext * context = (FilterIDContext *)vContext; OSKextRef theKext = OSKextGetKextWithIdentifier(kextID); if (!theKext) { char kextIDCString[KMOD_MAX_NAME]; CFStringGetCString(kextID, kextIDCString, sizeof(kextIDCString), kCFStringEncodingUTF8); if (context->optional) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Can't find kext with optional identifier %s; skipping.", kextIDCString); } else { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Error - can't find kext with identifier %s.", kextIDCString); context->error = TRUE; } goto finish; } if (checkKextForProblems(context->toolArgs, theKext, context->arch)) { if (!context->optional) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Error - a required kext was omitted"); context->error = true; } goto finish; } if (!CFArrayContainsValue(context->kextArray, RANGE_ALL(context->kextArray), theKext)) { CFArrayAppendValue(context->kextArray, theKext); } finish: return; }
void diskChangedCallback(DADiskRef disk, CFArrayRef keys, void *context) { if (CFArrayContainsValue(keys, CFRangeMake(0, CFArrayGetCount(keys)), kDADiskDescriptionVolumeNameKey)) { const char *BSDname = DADiskGetBSDName(disk); CFDictionaryRef details = DADiskCopyDescription(disk); char *volName = getVolName(details); LOG(VB_MEDIA, LOG_INFO, QString("Disk %1 - changed name to '%2'.") .arg(BSDname).arg(volName)); reinterpret_cast<MonitorThreadDarwin *>(context) ->diskRename(BSDname, volName); CFRelease(details); free(volName); } }
static CFArrayRef service_order_copy_all(CFDictionaryRef services, CFArrayRef service_order) { const void * keys_q[N_QUICK]; const void ** keys = keys_q; CFIndex i; CFIndex n_order; CFIndex n_services; CFMutableArrayRef order; // ensure that we process all services in order n_services = isA_CFDictionary(services) ? CFDictionaryGetCount(services) : 0; if (n_services == 0) { // if no services return NULL; } // ensure that we process all services in order n_order = isA_CFArray(service_order) ? CFArrayGetCount(service_order) : 0; if (n_order > 0) { order = CFArrayCreateMutableCopy(NULL, 0, service_order); } else { order = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } if (n_services > (CFIndex)(sizeof(keys_q) / sizeof(CFTypeRef))) { keys = CFAllocatorAllocate(NULL, n_services * sizeof(CFTypeRef), 0); } CFDictionaryGetKeysAndValues(services, keys, NULL); for (i = 0; i < n_services; i++) { CFStringRef serviceID = (CFStringRef)keys[i]; if (!CFArrayContainsValue(order, CFRangeMake(0, n_order), serviceID)) { CFArrayAppendValue(order, serviceID); n_order++; } } if (keys != keys_q) { CFAllocatorDeallocate(NULL, keys); } return order; }
static void writeXMLValue(CFTypeRef context, void *xmlDomain, CFStringRef key, CFTypeRef value) { _CFXMLPreferencesDomain *domain = (_CFXMLPreferencesDomain *)xmlDomain; const void *existing = NULL; __CFLock(&domain->_lock); if (domain->_domainDict == NULL) { _loadXMLDomainIfStale((CFURLRef )context, domain); } // check to see if the value is the same // if (1) the key is present AND value is !NULL and equal to existing, do nothing, or // if (2) the key is not present AND value is NULL, do nothing // these things are no-ops, and should not dirty the domain if (CFDictionaryGetValueIfPresent(domain->_domainDict, key, &existing)) { if (NULL != value && (existing == value || CFEqual(existing, value))) { __CFUnlock(&domain->_lock); return; } } else { if (NULL == value) { __CFUnlock(&domain->_lock); return; } } // We must append first so key gets another retain (in case we're // about to remove it from the dictionary, and that's the sole reference) // This should be a set not an array. if (!CFArrayContainsValue(domain->_dirtyKeys, CFRangeMake(0, CFArrayGetCount(domain->_dirtyKeys)), key)) { CFArrayAppendValue(domain->_dirtyKeys, key); } if (value) { // Must copy for two reasons - we don't want mutable objects in the cache, and we don't want objects allocated from a different allocator in the cache. CFTypeRef newValue = CFPropertyListCreateDeepCopy(__CFPreferencesAllocator(), value, kCFPropertyListImmutable); CFDictionarySetValue(domain->_domainDict, key, newValue); CFRelease(newValue); } else { CFDictionaryRemoveValue(domain->_domainDict, key); } __CFUnlock(&domain->_lock); }
static void convertWebResourceDataToString(CFMutableDictionaryRef resource) { CFMutableStringRef mimeType = (CFMutableStringRef)CFDictionaryGetValue(resource, CFSTR("WebResourceMIMEType")); CFStringLowercase(mimeType, CFLocaleGetSystem()); convertMIMEType(mimeType); CFArrayRef supportedMIMETypes = supportedNonImageMIMETypes(); if (CFStringHasPrefix(mimeType, CFSTR("text/")) || CFArrayContainsValue(supportedMIMETypes, CFRangeMake(0, CFArrayGetCount(supportedMIMETypes)), mimeType)) { CFStringRef textEncodingName = static_cast<CFStringRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceTextEncodingName"))); CFStringEncoding stringEncoding; if (textEncodingName && CFStringGetLength(textEncodingName)) stringEncoding = CFStringConvertIANACharSetNameToEncoding(textEncodingName); else stringEncoding = kCFStringEncodingUTF8; CFDataRef data = static_cast<CFDataRef>(CFDictionaryGetValue(resource, CFSTR("WebResourceData"))); RetainPtr<CFStringRef> dataAsString = adoptCF(CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data, stringEncoding)); if (dataAsString) CFDictionarySetValue(resource, CFSTR("WebResourceData"), dataAsString.get()); } }
/* * Function: setInterfaceEAPOLConfiguration * Purpose: * Set the EAPOL configuration for the particular interface in the * cfg->sc_prefs and add the SCNetworkInterfaceRef to cfg->sc_changed_if. * That allows saveInterfaceEAPOLConfiguration() to know which interfaces * were changed when it commits the changes to the writable prefs. */ STATIC Boolean setInterfaceEAPOLConfiguration(EAPOLClientConfigurationRef cfg, SCNetworkInterfaceRef net_if, CFDictionaryRef dict) { CFRange r; Boolean ret; ret = SCNetworkInterfaceSetExtendedConfiguration(net_if, kEAPOL, dict); if (ret == FALSE) { return (ret); } /* keep track of which SCNetworkInterfaceRef's were changed */ if (cfg->sc_changed_if == NULL) { cfg->sc_changed_if = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } r.location = 0; r.length = CFArrayGetCount(cfg->sc_changed_if); if (CFArrayContainsValue(cfg->sc_changed_if, r, net_if) == FALSE) { CFArrayAppendValue(cfg->sc_changed_if, net_if); } return (TRUE); }
Boolean _CFApplicationPreferencesContainsDomainNoLock(_CFApplicationPreferences *self, CFPreferencesDomainRef domain) { Boolean result; result = CFArrayContainsValue(self->_search, CFRangeMake(0, CFArrayGetCount(self->_search)), domain); return result; }
static void _serviceOrder_add(SCNetworkSetRef set, SCNetworkServiceRef service) { CFIndex i; CFIndex n; CFMutableArrayRef newOrder; CFArrayRef order; CFStringRef serviceID; CFIndex serviceOrder; SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set; CFIndex slot; order = SCNetworkSetGetServiceOrder(set); if (order != NULL) { newOrder = CFArrayCreateMutableCopy(NULL, 0, order); } else { newOrder = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } assert(newOrder != NULL); n = CFArrayGetCount(newOrder); serviceID = SCNetworkServiceGetServiceID(service); if (CFArrayContainsValue(newOrder, CFRangeMake(0, n), serviceID)) { // if serviceID already present goto done; } serviceOrder = _serviceOrder(service); slot = 0; for (i = 0; i < n; i++) { int slotOrder; SCNetworkServiceRef slotService; CFStringRef slotServiceID; slotServiceID = CFArrayGetValueAtIndex(newOrder, i); if (!isA_CFString(slotServiceID)) { // if bad prefs continue; } slotService = SCNetworkServiceCopy(setPrivate->prefs, slotServiceID); if (slotService == NULL) { // if serviceID not valid continue; } slotOrder = _serviceOrder(slotService); if (serviceOrder >= slotOrder) { // add the service *after* this one slot = i + 1; } CFRelease(slotService); } CFArrayInsertValueAtIndex(newOrder, slot, serviceID); (void) SCNetworkSetSetServiceOrder(set, newOrder); done : CFRelease(newOrder); return; }
__private_extern__ CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFStringRef hostName) { CFAllocatorRef prefAlloc = __CFPreferencesAllocator(); CFArrayRef domains; CFMutableArrayRef marray; CFStringRef *cachedDomainKeys; CFPreferencesDomainRef *cachedDomains; SInt32 idx, cnt; CFStringRef suffix; UInt32 suffixLen; CFURLRef prefDir = _preferencesDirectoryForUserHost(userName, hostName); if (!prefDir) { return NULL; } if (hostName == kCFPreferencesAnyHost) { suffix = CFStringCreateWithCString(prefAlloc, ".plist", kCFStringEncodingASCII); } else if (hostName == kCFPreferencesCurrentHost) { CFStringRef hostID = _CFPreferencesGetByHostIdentifierString(); suffix = CFStringCreateWithFormat(prefAlloc, NULL, CFSTR(".%@.plist"), hostID); } else { suffix = CFStringCreateWithFormat(prefAlloc, NULL, CFSTR(".%@.plist"), hostName); // sketchy - this allows someone to create a domain list for an arbitrary hostname. } suffixLen = CFStringGetLength(suffix); domains = (CFArrayRef)CFURLCreatePropertyFromResource(prefAlloc, prefDir, kCFURLFileDirectoryContents, NULL); CFRelease(prefDir); if (domains){ marray = CFArrayCreateMutableCopy(prefAlloc, 0, domains); CFRelease(domains); } else { marray = CFArrayCreateMutable(prefAlloc, 0, & kCFTypeArrayCallBacks); } for (idx = CFArrayGetCount(marray)-1; idx >= 0; idx --) { CFURLRef url = (CFURLRef)CFArrayGetValueAtIndex(marray, idx); CFStringRef string = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); if (!CFStringHasSuffix(string, suffix)) { CFArrayRemoveValueAtIndex(marray, idx); } else { CFStringRef dom = CFStringCreateWithSubstring(prefAlloc, string, CFRangeMake(0, CFStringGetLength(string) - suffixLen)); if (CFEqual(dom, CFSTR(".GlobalPreferences"))) { CFArraySetValueAtIndex(marray, idx, kCFPreferencesAnyApplication); } else { CFArraySetValueAtIndex(marray, idx, dom); } CFRelease(dom); } CFRelease(string); } CFRelease(suffix); // Now add any domains added in the cache; delete any that have been deleted in the cache __CFSpinLock(&domainCacheLock); if (!domainCache) { __CFSpinUnlock(&domainCacheLock); return marray; } cnt = CFDictionaryGetCount(domainCache); cachedDomainKeys = (CFStringRef *)CFAllocatorAllocate(prefAlloc, 2 * cnt * sizeof(CFStringRef), 0); cachedDomains = (CFPreferencesDomainRef *)(cachedDomainKeys + cnt); CFDictionaryGetKeysAndValues(domainCache, (const void **)cachedDomainKeys, (const void **)cachedDomains); __CFSpinUnlock(&domainCacheLock); suffix = _CFPreferencesCachePrefixForUserHost(userName, hostName); suffixLen = CFStringGetLength(suffix); for (idx = 0; idx < cnt; idx ++) { CFStringRef domainKey = cachedDomainKeys[idx]; CFPreferencesDomainRef domain = cachedDomains[idx]; CFStringRef domainName; CFIndex keyCount = 0; if (!CFStringHasPrefix(domainKey, suffix)) continue; domainName = CFStringCreateWithSubstring(prefAlloc, domainKey, CFRangeMake(suffixLen, CFStringGetLength(domainKey) - suffixLen)); if (CFEqual(domainName, CFSTR("*"))) { CFRelease(domainName); domainName = (CFStringRef)CFRetain(kCFPreferencesAnyApplication); } else if (CFEqual(domainName, kCFPreferencesCurrentApplication)) { CFRelease(domainName); domainName = (CFStringRef)CFRetain(_CFProcessNameString()); } CFDictionaryRef d = _CFPreferencesDomainDeepCopyDictionary(domain); keyCount = d ? CFDictionaryGetCount(d) : 0; if (keyCount) CFRelease(d); if (keyCount == 0) { // Domain was deleted SInt32 firstIndexOfValue = CFArrayGetFirstIndexOfValue(marray, CFRangeMake(0, CFArrayGetCount(marray)), domainName); if (0 <= firstIndexOfValue) { CFArrayRemoveValueAtIndex(marray, firstIndexOfValue); } } else if (!CFArrayContainsValue(marray, CFRangeMake(0, CFArrayGetCount(marray)), domainName)) { CFArrayAppendValue(marray, domainName); } CFRelease(domainName); } CFRelease(suffix); CFAllocatorDeallocate(prefAlloc, cachedDomainKeys); return marray; }
static void add_supplemental_proxies(CFMutableArrayRef proxies, CFDictionaryRef services, CFArrayRef service_order) { const void * keys_q[N_QUICK]; const void ** keys = keys_q; CFIndex i; CFIndex n_order; CFIndex n_services; const void * vals_q[N_QUICK]; const void ** vals = vals_q; n_services = isA_CFDictionary(services) ? CFDictionaryGetCount(services) : 0; if (n_services == 0) { return; // if no services } if (n_services > (CFIndex)(sizeof(keys_q) / sizeof(CFTypeRef))) { keys = CFAllocatorAllocate(NULL, n_services * sizeof(CFTypeRef), 0); vals = CFAllocatorAllocate(NULL, n_services * sizeof(CFTypeRef), 0); } n_order = isA_CFArray(service_order) ? CFArrayGetCount(service_order) : 0; CFDictionaryGetKeysAndValues(services, keys, vals); for (i = 0; i < n_services; i++) { uint32_t defaultOrder; CFDictionaryRef proxy; CFMutableDictionaryRef proxyWithDNS = NULL; CFDictionaryRef service = (CFDictionaryRef)vals[i]; if (!isA_CFDictionary(service)) { continue; } proxy = CFDictionaryGetValue(service, kSCEntNetProxies); if (!isA_CFDictionary(proxy)) { continue; } if ((G_supplemental_proxies_follow_dns != NULL) && CFBooleanGetValue(G_supplemental_proxies_follow_dns)) { CFDictionaryRef dns; CFArrayRef matchDomains; CFArrayRef matchOrders; if (!CFDictionaryContainsKey(proxy, kSCPropNetProxiesSupplementalMatchDomains) && CFDictionaryGetValueIfPresent(service, kSCEntNetDNS, (const void **)&dns) && isA_CFDictionary(dns) && CFDictionaryGetValueIfPresent(dns, kSCPropNetDNSSupplementalMatchDomains, (const void **)&matchDomains) && isA_CFArray(matchDomains)) { proxyWithDNS = CFDictionaryCreateMutableCopy(NULL, 0, proxy); CFDictionarySetValue(proxyWithDNS, kSCPropNetProxiesSupplementalMatchDomains, matchDomains); if (CFDictionaryGetValueIfPresent(dns, kSCPropNetDNSSupplementalMatchOrders, (const void **)&matchOrders) && isA_CFArray(matchOrders)) { CFDictionarySetValue(proxyWithDNS, kSCPropNetProxiesSupplementalMatchOrders, matchOrders); } else { CFDictionaryRemoveValue(proxyWithDNS, kSCPropNetProxiesSupplementalMatchOrders); } proxy = proxyWithDNS; } } defaultOrder = DEFAULT_MATCH_ORDER - (DEFAULT_MATCH_ORDER / 2) + ((DEFAULT_MATCH_ORDER / 1000) * i); if ((n_order > 0) && !CFArrayContainsValue(service_order, CFRangeMake(0, n_order), keys[i])) { // push out services not specified in service order defaultOrder += (DEFAULT_MATCH_ORDER / 1000) * n_services; } add_supplemental(proxies, proxy, defaultOrder); if (proxyWithDNS != NULL) CFRelease(proxyWithDNS); } if (keys != keys_q) { CFAllocatorDeallocate(NULL, keys); CFAllocatorDeallocate(NULL, vals); } return; }
Boolean SCNetworkSetAddService(SCNetworkSetRef set, SCNetworkServiceRef service) { SCNetworkInterfaceRef interface; CFArrayRef interface_config = NULL; CFStringRef link; Boolean ok; CFStringRef path; SCNetworkServicePrivateRef servicePrivate = (SCNetworkServicePrivateRef)service; SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set; if (!isA_SCNetworkSet(set)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } if (!isA_SCNetworkService(service) || (servicePrivate->prefs == NULL)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } // make sure that we do not add an orphaned network service if its // associated interface is a member of a bond or bridge. interface = SCNetworkServiceGetInterface(service); if ((interface != NULL) && __SCNetworkInterfaceIsMember(servicePrivate->prefs, interface)) { _SCErrorSet(kSCStatusKeyExists); return FALSE; } //#define PREVENT_DUPLICATE_SETS #ifdef PREVENT_DUPLICATE_SETS CFArrayRef sets; // ensure that each service is only a member of ONE set sets = SCNetworkSetCopyAll(setPrivate->prefs); if (sets != NULL) { CFIndex i; CFIndex n; n = CFArrayGetCount(sets); for (i = 0; i < n; i++) { Boolean found; CFArrayRef services; SCNetworkSetRef set; set = CFArrayGetValueAtIndex(sets, i); services = SCNetworkSetCopyServices(set); found = CFArrayContainsValue(services, CFRangeMake(0, CFArrayGetCount(services)), service); CFRelease(services); if (found) { CFRelease(sets); _SCErrorSet(kSCStatusKeyExists); return FALSE; } } CFRelease(sets); } #endif /* PREVENT_DUPLICATE_SETS */ // get the [deep] interface configuration settings interface = SCNetworkServiceGetInterface(service); if (interface != NULL) { interface_config = __SCNetworkInterfaceCopyDeepConfiguration(set, interface); } // create the link between "set" and the "service" path = SCPreferencesPathKeyCreateSetNetworkServiceEntity(NULL, // allocator setPrivate->setID, // set servicePrivate->serviceID, // service NULL); // entity link = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator servicePrivate->serviceID, // service NULL); // entity ok = SCPreferencesPathSetLink(setPrivate->prefs, path, link); #ifdef PREVENT_DUPLICATE_SERVICE_NAMES if (ok) { ok = ensure_unique_service_name(service); if (!ok) { // if we could not ensure a unique name, remove the (just added) // link between the "set" and the "service" (void) SCPreferencesPathRemoveValue(setPrivate->prefs, path); } } #endif // PREVENT_DUPLICATE_SERVICE_NAMES CFRelease(path); CFRelease(link); if (!ok) { goto done; } // push the [deep] interface configuration into all sets which contain this service. if (interface != NULL) { __SCNetworkInterfaceSetDeepConfiguration(set, interface, interface_config); } // add service to ServiceOrder _serviceOrder_add(set, service); // mark set as no longer "new" setPrivate->established = TRUE; done : if (interface_config != NULL) CFRelease(interface_config); return ok; }
CFDictionaryRef APCreateDictionaryForLicenseData(CFDataRef data) { if (!rsaKey->n || !rsaKey->e) return NULL; // Make the property list from the data CFStringRef errorString = NULL; CFPropertyListRef propertyList; propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, data, kCFPropertyListMutableContainers, &errorString); if (errorString || CFDictionaryGetTypeID() != CFGetTypeID(propertyList) || !CFPropertyListIsValid(propertyList, kCFPropertyListXMLFormat_v1_0)) { if (propertyList) CFRelease(propertyList); return NULL; } // Load the signature CFMutableDictionaryRef licenseDictionary = (CFMutableDictionaryRef)propertyList; if (!CFDictionaryContainsKey(licenseDictionary, CFSTR("Signature"))) { CFRelease(licenseDictionary); return NULL; } CFDataRef sigData = CFDictionaryGetValue(licenseDictionary, CFSTR("Signature")); CFIndex sigDataLength = CFDataGetLength(sigData); UInt8 sigBytes[sigDataLength]; CFDataGetBytes(sigData, CFRangeMake(0, sigDataLength), sigBytes); CFDictionaryRemoveValue(licenseDictionary, CFSTR("Signature")); // Decrypt the signature int checkDigestMaxSize = RSA_size(rsaKey)-11; unsigned char checkDigest[checkDigestMaxSize]; if (RSA_public_decrypt((int) sigDataLength, sigBytes, checkDigest, rsaKey, RSA_PKCS1_PADDING) != SHA_DIGEST_LENGTH) { CFRelease(licenseDictionary); return NULL; } // Get the license hash CFMutableStringRef hashCheck = CFStringCreateMutable(kCFAllocatorDefault,0); int hashIndex; for (hashIndex = 0; hashIndex < SHA_DIGEST_LENGTH; hashIndex++) CFStringAppendFormat(hashCheck, nil, CFSTR("%02x"), checkDigest[hashIndex]); APSetHash(hashCheck); CFRelease(hashCheck); if (blacklist && (CFArrayContainsValue(blacklist, CFRangeMake(0, CFArrayGetCount(blacklist)), hash) == true)) return NULL; // Get the number of elements CFIndex count = CFDictionaryGetCount(licenseDictionary); // Load the keys and build up the key array CFMutableArrayRef keyArray = CFArrayCreateMutable(kCFAllocatorDefault, count, NULL); CFStringRef keys[count]; CFDictionaryGetKeysAndValues(licenseDictionary, (const void**)&keys, NULL); int i; for (i = 0; i < count; i++) CFArrayAppendValue(keyArray, keys[i]); // Sort the array int context = kCFCompareCaseInsensitive; CFArraySortValues(keyArray, CFRangeMake(0, count), (CFComparatorFunction)CFStringCompare, &context); // Setup up the hash context SHA_CTX ctx; SHA1_Init(&ctx); // Convert into UTF8 strings for (i = 0; i < count; i++) { char *valueBytes; CFIndex valueLengthAsUTF8; CFStringRef key = CFArrayGetValueAtIndex(keyArray, i); CFStringRef value = CFDictionaryGetValue(licenseDictionary, key); // Account for the null terminator valueLengthAsUTF8 = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value), kCFStringEncodingUTF8) + 1; valueBytes = (char *)malloc(valueLengthAsUTF8); CFStringGetCString(value, valueBytes, valueLengthAsUTF8, kCFStringEncodingUTF8); SHA1_Update(&ctx, valueBytes, strlen(valueBytes)); free(valueBytes); } unsigned char digest[SHA_DIGEST_LENGTH]; SHA1_Final(digest, &ctx); if (keyArray != NULL) CFRelease(keyArray); // Check if the signature is a match for (i = 0; i < SHA_DIGEST_LENGTH; i++) { if (checkDigest[i] ^ digest[i]) { CFRelease(licenseDictionary); return NULL; } } // If it's a match, we return the dictionary; otherwise, we never reach this return licenseDictionary; }
static void initializeDb() { QFontDatabasePrivate *db = privateDb(); if(!db || db->count) return; #if defined(QT_MAC_USE_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { QCFType<CTFontCollectionRef> collection = CTFontCollectionCreateFromAvailableFonts(0); if(!collection) return; QCFType<CFArrayRef> fonts = CTFontCollectionCreateMatchingFontDescriptors(collection); if(!fonts) return; QString foundry_name = "CoreText"; const int numFonts = CFArrayGetCount(fonts); for(int i = 0; i < numFonts; ++i) { CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i); QCFString family_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL); QCFString style_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL); QtFontFamily *family = db->family(family_name, true); if (QCFType<CFArrayRef> languages = (CFArrayRef) CTFontDescriptorCopyAttribute(font, kCTFontLanguagesAttribute)) { CFIndex length = CFArrayGetCount(languages); for (int i = 1; i < LanguageCount; ++i) { if (!languageForWritingSystem[i]) continue; QCFString lang = CFStringCreateWithCString(NULL, languageForWritingSystem[i], kCFStringEncodingASCII); if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang)) family->writingSystems[i] = QtFontFamily::Supported; } } QtFontFoundry *foundry = family->foundry(foundry_name, true); QtFontStyle::Key styleKey; QString styleName = style_name; if(QCFType<CFDictionaryRef> styles = (CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute)) { if(CFNumberRef weight = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontWeightTrait)) { Q_ASSERT(CFNumberIsFloatType(weight)); double d; if(CFNumberGetValue(weight, kCFNumberDoubleType, &d)) { //qDebug() << "BOLD" << (QString)family_name << d; styleKey.weight = (d > 0.0) ? QFont::Bold : QFont::Normal; } } if(CFNumberRef italic = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontSlantTrait)) { Q_ASSERT(CFNumberIsFloatType(italic)); double d; if(CFNumberGetValue(italic, kCFNumberDoubleType, &d)) { //qDebug() << "ITALIC" << (QString)family_name << d; if (d > 0.0) styleKey.style = QFont::StyleItalic; } } } QtFontStyle *style = foundry->style(styleKey, styleName, true); style->smoothScalable = true; if(QCFType<CFNumberRef> size = (CFNumberRef)CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute)) { //qDebug() << "WHEE"; int pixel_size=0; if(CFNumberIsFloatType(size)) { double d; CFNumberGetValue(size, kCFNumberDoubleType, &d); pixel_size = d; } else { CFNumberGetValue(size, kCFNumberIntType, &pixel_size); } //qDebug() << "SIZE" << (QString)family_name << pixel_size; if(pixel_size) style->pixelSize(pixel_size, true); } else { //qDebug() << "WTF?"; } } } else #endif { #ifndef QT_MAC_USE_COCOA FMFontIterator it; if (!FMCreateFontIterator(0, 0, kFMUseGlobalScopeOption, &it)) { while (true) { FMFont fmFont; if (FMGetNextFont(&it, &fmFont) != noErr) break; FMFontFamily fmFamily; FMFontStyle fmStyle; QString familyName; QtFontStyle::Key styleKey; ATSFontRef atsFont = FMGetATSFontRefFromFont(fmFont); if (!FMGetFontFamilyInstanceFromFont(fmFont, &fmFamily, &fmStyle)) { { //sanity check the font, and see if we can use it at all! --Sam ATSUFontID fontID; if(ATSUFONDtoFontID(fmFamily, 0, &fontID) != noErr) continue; } if (fmStyle & ::italic) styleKey.style = QFont::StyleItalic; if (fmStyle & ::bold) styleKey.weight = QFont::Bold; ATSFontFamilyRef familyRef = FMGetATSFontFamilyRefFromFontFamily(fmFamily); QCFString cfFamilyName;; ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &cfFamilyName); familyName = cfFamilyName; } else { QCFString cfFontName; ATSFontGetName(atsFont, kATSOptionFlagsDefault, &cfFontName); familyName = cfFontName; quint16 macStyle = 0; { uchar data[4]; ByteCount len = 4; if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 44, 4, &data, &len) == noErr) macStyle = qFromBigEndian<quint16>(data); } if (macStyle & 1) styleKey.weight = QFont::Bold; if (macStyle & 2) styleKey.style = QFont::StyleItalic; } QtFontFamily *family = db->family(familyName, true); QtFontFoundry *foundry = family->foundry(QString(), true); QtFontStyle *style = foundry->style(styleKey, QString(), true); style->pixelSize(0, true); style->smoothScalable = true; initWritingSystems(family, atsFont); } FMDisposeFontIterator(&it); } #endif } }