static SCBondStatusRef __SCBondStatusCreatePrivate(CFAllocatorRef allocator, SCBondInterfaceRef bond, CFDictionaryRef status_bond, CFDictionaryRef status_interfaces) { SCBondStatusPrivateRef statusPrivate; uint32_t size; /* initialize runtime */ pthread_once(&bondStatus_init, __SCBondStatusInitialize); /* allocate bond */ size = sizeof(SCBondStatusPrivate) - sizeof(CFRuntimeBase); statusPrivate = (SCBondStatusPrivateRef)_CFRuntimeCreateInstance(allocator, __kSCBondStatusTypeID, size, NULL); if (statusPrivate == NULL) { return NULL; } /* establish the bond status */ statusPrivate->bond = CFRetain(bond); statusPrivate->status_bond = CFDictionaryCreateCopy(NULL, status_bond); statusPrivate->interfaces = NULL; statusPrivate->status_interfaces = CFDictionaryCreateCopy(NULL, status_interfaces); return (SCBondStatusRef)statusPrivate; }
void SecKeyGeneratePairAsync(CFDictionaryRef parametersWhichMightBeMutiable, dispatch_queue_t deliveryQueue, SecKeyGeneratePairBlock result) { CFDictionaryRef parameters = CFDictionaryCreateCopy(NULL, parametersWhichMightBeMutiable); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ SecKeyRef publicKey = NULL; SecKeyRef privateKey = NULL; OSStatus status = SecKeyGeneratePair(parameters, &publicKey, &privateKey); dispatch_async(deliveryQueue, ^{ CFErrorRef error = NULL; if (noErr != status) { error = CFErrorCreate(NULL, kCFErrorDomainOSStatus, status, NULL); } result(publicKey, privateKey, error); if (error) { CFRelease(error); } if (publicKey) { CFRelease(publicKey); } if (privateKey) { CFRelease(privateKey); } CFRelease(parameters); }); });
/* Note that there are two entry points for creating CFErrors. * This one does it with a presupplied userInfo dictionary. */ CFErrorRef CFErrorCreate(CFAllocatorRef allocator, CFStringRef domain, CFIndex code, CFDictionaryRef userInfo) { CF_VALIDATE_OBJECT_ARG(CF, domain, CFStringGetTypeID()); if (userInfo) { CF_VALIDATE_OBJECT_ARG(CF, userInfo, CFDictionaryGetTypeID()); } CFErrorRef err = (CFErrorRef)_CFRuntimeCreateInstance( allocator, __kCFErrorTypeID, sizeof(struct __CFError) - sizeof(CFRuntimeBase), NULL); if (!err) { return NULL; } err->domain = CFStringCreateCopy(allocator, domain); err->code = code; err->userInfo = userInfo ? CFDictionaryCreateCopy(allocator, userInfo) : _CFErrorCreateEmptyDictionary(allocator); return err; }
int getPstateTable(PSTATE_CTL_INFO* info){ int count = 0; io_service_t IOService = IOServiceGetMatchingService(0, IOServiceMatching(SERVICE_NAME)); if (! IOService ) return 0; CFDictionaryRef CDictionary = (CFDictionaryRef) IORegistryEntryCreateCFProperty(IOService, CFSTR("Characteristics"),kCFAllocatorDefault,0); CFArrayRef PSArray = CFArrayCreateCopy(kCFAllocatorDefault, (CFArrayRef) CFDictionaryGetValue(CDictionary, CFSTR("PStates"))); if (PSArray) { count = CFArrayGetCount(PSArray); for( int k = 0; k < count; k++ ){ CFDictionaryRef PSDictionary = CFDictionaryCreateCopy(kCFAllocatorDefault, (CFDictionaryRef) CFArrayGetValueAtIndex(PSArray, k)); info->frequency = GetNumber(CFSTR("Frequency"), PSDictionary); info->voltage = GetNumber(CFSTR("Voltage"), PSDictionary); info->fid = GetNumber(CFSTR("FID"), PSDictionary); info->did = GetNumber(CFSTR("DID"), PSDictionary); info->vid = GetNumber(CFSTR("VID"), PSDictionary); info->pstate = k; info++; CFRelease(PSDictionary); } CFRelease(PSArray); } CFRelease(CDictionary); return count; }
CFMutableArrayRef AppendApp(struct SpringboardDeviceInfo *info, CFPropertyListRef homescreen, CFMutableArrayRef screen, CFDictionaryRef item) { CFDictionaryRef appInfo = NULL; CFStringRef appID = CFDictionaryGetValue(item, CFSTR("Contents")); bool appInstalled = HomescreenHasApp(homescreen, appID, &appInfo); if (appInstalled && appInfo) { CFDictionaryRef appInfoCopy = CFDictionaryCreateCopy(kCFAllocatorDefault, appInfo); CFArrayAppendValue(screen, appInfoCopy); } return screen; }
bool AppHasBundleID(CFDictionaryRef app, CFStringRef bundleID, CFDictionaryRef *appInfo) { bool foundBundleID = false; Boolean isApp = CFDictionaryContainsKey(app, CFSTR("bundleIdentifier")); if (isApp) { CFStringRef appID = CFDictionaryGetValue(app, CFSTR("bundleIdentifier")); if (CFStringCompare(appID, bundleID, 0x0) == 0x0) { foundBundleID = true; *appInfo = CFDictionaryCreateCopy(kCFAllocatorDefault, app); } } return foundBundleID; }
/* Note that there are two entry points for creating CFErrors. This one does it with a presupplied userInfo dictionary. */ CFErrorRef CFErrorCreate(CFAllocatorRef allocator, CFStringRef domain, CFIndex code, CFDictionaryRef userInfo) { __CFGenericValidateType(domain, CFStringGetTypeID()); if (userInfo) __CFGenericValidateType(userInfo, CFDictionaryGetTypeID()); CFErrorRef err = (CFErrorRef)_CFRuntimeCreateInstance(allocator, __kCFErrorTypeID, sizeof(struct __CFError) - sizeof(CFRuntimeBase), NULL); if (NULL == err) return NULL; err->domain = CFStringCreateCopy(allocator, domain); err->code = code; err->userInfo = userInfo ? CFDictionaryCreateCopy(allocator, userInfo) : _CFErrorCreateEmptyDictionary(allocator); return err; }
static __inline__ void my_CFDictionaryApplyFunction(CFDictionaryRef theDict, CFDictionaryApplierFunction applier, void *context) { CFAllocatorRef myAllocator; CFDictionaryRef myDict; myAllocator = CFGetAllocator(theDict); myDict = CFDictionaryCreateCopy(myAllocator, theDict); CFDictionaryApplyFunction(myDict, applier, context); CFRelease(myDict); return; }
/* Given window CFDictionaryRef and Ruby array, push MW_Window to array */ void StoreWindows(CFDictionaryRef cgWindow, void *rb_ary_ptr) { AXUIElementRef axWindow; MW_Window *mwWindow; VALUE wrappedMwWindow; VALUE mwWindows = (VALUE)rb_ary_ptr; axWindow = AXWindowFromCGWindow(cgWindow); mwWindow = (MW_Window *)malloc(sizeof(MW_Window)); mwWindow->cgWindow = CFDictionaryCreateCopy(kCFAllocatorDefault, cgWindow); mwWindow->axWindow = axWindow; wrappedMwWindow = Data_Wrap_Struct( MW_WindowClass, NULL, MW_Window_destroy, (void *)mwWindow ); rb_ary_push(mwWindows, wrappedMwWindow); }
__private_extern__ CFDictionaryRef PMSettings_CopyActivePMSettings(void) { CFDictionaryRef copy_all_settings; CFDictionaryRef energySettings; CFDictionaryRef return_val; copy_all_settings = _copyPMSettings(kIOPMRemoveUnsupportedSettings); if(!copy_all_settings) return NULL; energySettings = isA_CFDictionary(CFDictionaryGetValue(copy_all_settings,currentPowerSource)); if(energySettings) return_val = CFDictionaryCreateCopy(kCFAllocatorDefault, energySettings); else return_val = NULL; CFRelease(copy_all_settings); return return_val; }
static CFDictionaryRef CreateStringToNumDictionary() { int numItems = (sizeof(gValues) / sizeof(sint32)); CFMutableDictionaryRef tempDict = CFDictionaryCreateMutable(kCFAllocatorDefault, numItems, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); for (int iCnt = 0; iCnt < numItems; iCnt++) { sint32 aNumber = gValues[iCnt]; CFNumberRef aNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &aNumber); CFStringRef aString = gKeys[iCnt]; CFDictionaryAddValue(tempDict, aString, aNum); CFRelease(aNum); } CFDictionaryRef result = CFDictionaryCreateCopy(kCFAllocatorDefault, tempDict); CFRelease(tempDict); return result; }
static SCPreferencesPrivateRef __SCPreferencesCreate(CFAllocatorRef allocator, CFStringRef name, CFStringRef prefsID, CFDataRef authorizationData, CFDictionaryRef options) { SCPreferencesPrivateRef prefsPrivate; int sc_status = kSCStatusOK; /* * allocate and initialize a new prefs session */ prefsPrivate = __SCPreferencesCreatePrivate(allocator); if (prefsPrivate == NULL) { return NULL; } prefsPrivate->name = CFStringCreateCopy(allocator, name); if (prefsID != NULL) { prefsPrivate->prefsID = CFStringCreateCopy(allocator, prefsID); } if (authorizationData != NULL) { prefsPrivate->authorizationData = CFRetain(authorizationData); } if (options != NULL) { prefsPrivate->options = CFDictionaryCreateCopy(allocator, options); } retry : /* * convert prefsID to path */ prefsPrivate->path = __SCPreferencesPath(allocator, prefsID, (prefsPrivate->newPath == NULL)); if (prefsPrivate->path == NULL) { sc_status = kSCStatusFailed; goto error; } if (access(prefsPrivate->path, R_OK) == 0) { goto done; } switch (errno) { case ENOENT : /* no prefs file */ if ((prefsID == NULL) || !CFStringHasPrefix(prefsID, CFSTR("/"))) { /* if default preference ID or relative path */ if (prefsPrivate->newPath == NULL) { /* * we've looked in the "new" prefs directory * without success. Save the "new" path and * look in the "old" prefs directory. */ prefsPrivate->newPath = prefsPrivate->path; goto retry; } else { /* * we've looked in both the "new" and "old" * prefs directories without success. Use * the "new" path. */ CFAllocatorDeallocate(NULL, prefsPrivate->path); prefsPrivate->path = prefsPrivate->newPath; prefsPrivate->newPath = NULL; } } /* no preference data, start fresh */ sc_status = kSCStatusNoConfigFile; goto done; case EPERM : case EACCES : if (prefsPrivate->authorizationData != NULL) { /* no problem, we'll be using the helper */ goto done; } SCLog(_sc_verbose, LOG_DEBUG, CFSTR("__SCPreferencesCreate open() failed: %s"), strerror(errno)); sc_status = kSCStatusAccessError; break; default : SCLog(TRUE, LOG_ERR, CFSTR("__SCPreferencesCreate open() failed: %s"), strerror(errno)); sc_status = kSCStatusFailed; break; } error: CFRelease(prefsPrivate); _SCErrorSet(sc_status); return NULL; done : /* all OK */ _SCErrorSet(sc_status); return prefsPrivate; }
CFDictionaryRef APCreateDictionaryForLicenseData(CFDataRef data) { __block CFPropertyListRef propertyList = NULL; __block CFDataRef hashData = NULL; __block CFErrorRef error = NULL; __block SecTransformRef verifyFunction = NULL; __block CFBooleanRef valid = NULL; void(^cleanup)(void) = ^(void) { if (propertyList != NULL) { CFRelease(propertyList); propertyList = NULL; } if (hashData != NULL) { CFRelease(hashData); hashData = NULL; } if (error != NULL) { CFShow(error); CFRelease(error); error = NULL; } if (verifyFunction != NULL) { CFRelease(verifyFunction); verifyFunction = NULL; } if (valid != NULL) { CFRelease(valid); valid = NULL; } }; if (!publicKeyRef) { CFShow(CFSTR("Public key is invalid")); return NULL; } // Make the property list from the data CFStringRef errorString = NULL; propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, data, kCFPropertyListMutableContainers, &errorString); if (errorString || CFDictionaryGetTypeID() != CFGetTypeID(propertyList) || !CFPropertyListIsValid(propertyList, kCFPropertyListXMLFormat_v1_0)) { if (propertyList) CFRelease(propertyList); return NULL; } CFMutableDictionaryRef licenseDictionary = (CFMutableDictionaryRef)propertyList; CFDataRef signature = CFDictionaryGetValue(licenseDictionary, CFSTR("Signature")); if (!signature) { CFShow(CFSTR("No signature")); cleanup(); return NULL; } hashData = APCreateHashFromDictionary(licenseDictionary); CFStringRef hashCheck = APCopyHexStringFromData(hashData); APSetHash(hashCheck); CFRelease(hashCheck); // Check the hash against license blacklist if (blacklist && CFArrayContainsValue(blacklist, CFRangeMake(0, CFArrayGetCount(blacklist)), hash)) { cleanup(); return NULL; } // Verify the signed hash using the public key, passing the raw hash data as the input verifyFunction = SecVerifyTransformCreate(publicKeyRef, signature, &error); if (error) { cleanup(); return NULL; } SecTransformSetAttribute(verifyFunction, kSecTransformInputAttributeName, hashData, &error); if (error) { cleanup(); return NULL; } SecTransformSetAttribute(verifyFunction, kSecInputIsAttributeName, kSecInputIsRaw, &error); if (error) { cleanup(); return NULL; } valid = SecTransformExecute(verifyFunction, &error); if (error) { cleanup(); return NULL; } if (valid != kCFBooleanTrue) { cleanup(); return NULL; } CFDictionaryRef resultDict = CFDictionaryCreateCopy(kCFAllocatorDefault, licenseDictionary); cleanup(); return resultDict; }
/*! Copies a target object to a dictionary representation. */ CFDictionaryRef iSCSIPortalCreateDictionary(iSCSIPortalRef portal) { return CFDictionaryCreateCopy(kCFAllocatorDefault,portal); }
Boolean SCVLANInterfaceSetOptions(SCVLANInterfaceRef vlan, CFDictionaryRef newOptions) { SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)vlan; Boolean ok = TRUE; if (!isA_SCVLANInterface(vlan)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } if ((newOptions != NULL) && !isA_CFDictionary(newOptions)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } // set options in the stored preferences if (interfacePrivate->prefs != NULL) { CFDictionaryRef dict; CFMutableDictionaryRef newDict; CFStringRef path; path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/%@/%@/%@"), kSCPrefVirtualNetworkInterfaces, kSCNetworkInterfaceTypeVLAN, interfacePrivate->entity_device); dict = SCPreferencesPathGetValue(interfacePrivate->prefs, path); if (!isA_CFDictionary(dict)) { // if the prefs are confused CFRelease(path); _SCErrorSet(kSCStatusFailed); return FALSE; } newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict); if (newOptions != NULL) { CFDictionarySetValue(newDict, kSCPropVirtualNetworkInterfacesVLANOptions, newOptions); } else { CFDictionaryRemoveValue(newDict, kSCPropVirtualNetworkInterfacesVLANOptions); } if (!CFEqual(dict, newDict)) { ok = SCPreferencesPathSetValue(interfacePrivate->prefs, path, newDict); } CFRelease(newDict); CFRelease(path); } // set options in the SCVLANInterfaceRef if (ok) { if (interfacePrivate->vlan.options != NULL) { CFRelease(interfacePrivate->vlan.options); interfacePrivate->vlan.options = NULL; } if (newOptions != NULL) { interfacePrivate->vlan.options = CFDictionaryCreateCopy(NULL, newOptions); } } return ok; }
/*! Creates a new target object from a dictionary representation. */ iSCSITargetRef iSCSITargetCreateWithDictionary(CFDictionaryRef dict) { return CFDictionaryCreateCopy(kCFAllocatorDefault,dict); }
/*! Copies a target object to a dictionary representation. */ CFDictionaryRef iSCSITargetCreateDictionary(iSCSITargetRef target) { return CFDictionaryCreateCopy(kCFAllocatorDefault,target); }
/*! Copies an authentication object to a dictionary representation. */ CFDictionaryRef iSCSIAuthCreateDictionary(iSCSIAuthRef auth) { return CFDictionaryCreateCopy(kCFAllocatorDefault,auth); }
OSStatus performAuthenticatedXMLRPC( CFURLRef theURL, CFStringRef theMethod, CFDictionaryRef argDict, CFArrayRef argOrder, CFStringRef userName, CFStringRef password, CFDictionaryRef *resultDict, // RETURNED on success uint32_t *httpErrStatus) // possibly RETURNED on error (403, 500, etc.) { CFDictionaryRef result = NULL; bool done = false; OSStatus ortn = -1; // must set before return *httpErrStatus = 0; /* * Create a WebServices Invocation */ WSMethodInvocationRef wsRef = WSMethodInvocationCreate(theURL, theMethod, kWSXMLRPCProtocol); WSMethodInvocationSetParameters(wsRef, argDict, argOrder); for(unsigned attempt=0; attempt<2; attempt++) { xmlDebug("***************************************************************************\n"); xmlDebug("performAuthenticatedXMLRPC: WSMethodInvocationInvoke (attempt %u)\n", attempt); xmlDebug("***************************************************************************\n"); CFDictionaryRef response = WSMethodInvocationInvoke(wsRef); /* * Since we can't reuse the Invocation dump it as we have our response */ if (wsRef) { CFRelease(wsRef); wsRef = NULL; } #if XML_DEBUG logCFstr("performAuthenticatedXMLRPC: userName:"******"performAuthenticatedXMLRPC: errorMsg", errorMsg); #endif UInt32 HTTPResponseCode = getHTTPStatusCodeFromWSInvokationResponse(response); /* only try authentication once */ xmlDebug("performAuthenticatedXMLRPC: HTTP status %lu\n", HTTPResponseCode); if ((HTTPResponseCode == 401) && (attempt == 0)) { wsRef = WSMethodInvocationCreate(theURL, theMethod, kWSXMLRPCProtocol); WSMethodInvocationSetParameters(wsRef, argDict, argOrder); Boolean successful = addAuthenticationToWSInvokation(wsRef, userName, password, response); if (!successful) { xmlDebug("performAuthenticatedXMLRPC: unable to add authentication\n"); ortn = ioErr; done = TRUE; } xmlDebug("performAuthenticatedXMLRPC: retrying with auth\n"); /* else go one more time with authenticated invocation */ } else { /* other fatal HTTP error */ /* * From Scott Ryder: * * All other HTTP errs (eg 403 or 500) could / should be handled here * this could include adding proxy support * * FIXME does this mean that this code won't work through proxies? */ xmlDebug("performAuthenticatedXMLRPC: fatal RPC error\n"); *httpErrStatus = HTTPResponseCode; ortn = dotMacHttpStatToOs(HTTPResponseCode); done = TRUE; } } else { xmlDebug("performAuthenticatedXMLRPC: fault with no fault string!\n"); ortn = ioErr; done = TRUE; } } /* fault */ else { /* success */ xmlDebug("performAuthenticatedXMLRPC: success\n"); result = CFDictionaryCreateCopy(NULL, (CFDictionaryRef)CFDictionaryGetValue( response, kWSMethodInvocationResult)); ortn = noErr; done = true; } if((response != NULL) /*&& done*/) { #if RESPONSE_DICTIONARY_DEBUG dumpDictionary("XMLRPC response", response); #endif CFRelease(response); } if(done) { break; } } if(result != NULL) { *resultDict = result; } return ortn; }
/*! Creates a new portal object from a dictionary representation. */ iSCSIPortalRef iSCSIPortalCreateWithDictionary(CFDictionaryRef dict) { return CFDictionaryCreateCopy(kCFAllocatorDefault,dict); }
/*! Copies an configuration object to a dictionary representation. * @param config an iSCSI configuration object. * @return a dictionary representation of the configuration object or * NULL if configuration object is invalid. */ CFDictionaryRef iSCSIConnectionConfigCreateDictionary(iSCSIConnectionConfigRef config) { return CFDictionaryCreateCopy(kCFAllocatorDefault,config); }
/*! Creates a new configuration object object from a dictionary representation. * @return an iSCSI connection configuration object or * NULL if object creation failed. */ iSCSIConnectionConfigRef iSCSIConnectionConfigCreateWithDictionary(CFDictionaryRef dict) { return CFDictionaryCreateCopy(kCFAllocatorDefault,dict); }