static void handleConfigFile(const char *file) { bool on_demand = true, is_kunc = false; uid_t u = getuid(); struct passwd *pwe; char usr[4096]; char serv_name[4096]; char serv_cmd[4096]; CFPropertyListRef plist = CreateMyPropertyListFromFile(file); if (u == 0) u = geteuid(); if (plist) { if (CFDictionaryContainsKey(plist, CFSTR("Username"))) { const void *v = CFDictionaryGetValue(plist, CFSTR("Username")); if (v) CFStringGetCString(v, usr, sizeof(usr), kCFStringEncodingUTF8); else goto out; if ((pwe = getpwnam(usr))) { u = pwe->pw_uid; } else { fprintf(stderr, "%s: user not found\n", argv0); goto out; } } if (CFDictionaryContainsKey(plist, CFSTR("OnDemand"))) { const void *v = CFDictionaryGetValue(plist, CFSTR("OnDemand")); if (v) on_demand = CFBooleanGetValue(v); else goto out; } if (CFDictionaryContainsKey(plist, CFSTR("ServiceName"))) { const void *v = CFDictionaryGetValue(plist, CFSTR("ServiceName")); if (v) CFStringGetCString(v, serv_name, sizeof(serv_name), kCFStringEncodingUTF8); else goto out; } if (CFDictionaryContainsKey(plist, CFSTR("Command"))) { const void *v = CFDictionaryGetValue(plist, CFSTR("Command")); if (v) CFStringGetCString(v, serv_cmd, sizeof(serv_cmd), kCFStringEncodingUTF8); else goto out; } if (CFDictionaryContainsKey(plist, CFSTR("isKUNCServer"))) { const void *v = CFDictionaryGetValue(plist, CFSTR("isKUNCServer")); if (v && CFBooleanGetValue(v)) is_kunc = true; else goto out; } regServ(u, on_demand, is_kunc, serv_name, serv_cmd); goto out_good; out: fprintf(stdout, "%s: failed to register: %s\n", argv0, file); out_good: CFRelease(plist); } else { fprintf(stderr, "%s: no plist was returned for: %s\n", argv0, file); } }
// Asssumes caller already knows the directory doesn't exist. static Boolean _createDirectory(CFURLRef dirURL, Boolean worldReadable) { CFAllocatorRef alloc = __CFPreferencesAllocator(); CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(alloc, dirURL); CFBooleanRef val = (CFBooleanRef) CFURLCreatePropertyFromResource(alloc, parentURL, kCFURLFileExists, NULL); Boolean parentExists = (val && CFBooleanGetValue(val)); SInt32 mode; Boolean result; if (val) CFRelease(val); if (!parentExists) { CFStringRef path = CFURLCopyPath(parentURL); if (!CFEqual(path, CFSTR("/"))) { _createDirectory(parentURL, worldReadable); val = (CFBooleanRef) CFURLCreatePropertyFromResource(alloc, parentURL, kCFURLFileExists, NULL); parentExists = (val && CFBooleanGetValue(val)); if (val) CFRelease(val); } CFRelease(path); } if (parentURL) CFRelease(parentURL); if (!parentExists) return false; #if TARGET_OS_OSX || TARGET_OS_LINUX mode = worldReadable ? S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH : S_IRWXU; #else mode = 0666; #endif result = CFURLWriteDataAndPropertiesToResource(dirURL, (CFDataRef)dirURL, URLPropertyDictForPOSIXMode(mode), NULL); URLPropertyDictRelease(); return result; }
kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, kim_boolean in_hardcoded_default, kim_boolean *out_boolean) { kim_error err = KIM_NO_ERROR; CFBooleanRef value = NULL; if (!err && !out_boolean) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_copy_value (in_key, CFBooleanGetTypeID (), (CFPropertyListRef *) &value); } if (!err && !value) { err = kim_os_preferences_copy_value_compat (in_key, CFBooleanGetTypeID (), (CFPropertyListRef *) &value); } if (!err) { if (value) { *out_boolean = CFBooleanGetValue (value); } else { *out_boolean = in_hardcoded_default; } } if (value) { CFRelease (value); } return check_error (err); }
Boolean GetDictionaryBoolean(CFDictionaryRef theDict, const void *key){ Boolean value = false; CFBooleanRef boolRef = (CFBooleanRef) CFDictionaryGetValue(theDict, key); if (boolRef != NULL) value = CFBooleanGetValue(boolRef); return value; }
TStringIRep* TSICTStringCreateWithObjectAndFormat(CFTypeRef object, TSITStringFormat format) { if (object == NULL) { return TSICTStringCreateNullWithFormat(format); } CFRetain(object); CFTypeID cfType = CFGetTypeID(object); TStringIRep* rep = NULL; if (cfType == kCFDataTypeID) { rep = TSICTStringCreateWithDataOfTypeAndFormat(object, kTSITStringTagString, format); } else if (cfType == kCFStringTypeID) { rep = TSICTStringCreateWithStringAndFormat(object, format); } else if (cfType == kCFNumberTypeID) { rep = TSICTStringCreateWithNumberAndFormat(object, format); } else if (cfType == kCFBooleanTypeID) { if (CFBooleanGetValue(object)) { rep = TSICTStringCreateTrueWithFormat(format); } else { rep = TSICTStringCreateFalseWithFormat(format); } } else if (cfType == kCFNullTypeID) { rep = TSICTStringCreateNullWithFormat(format); } else if (cfType == kCFArrayTypeID) { rep = TSICTStringCreateWithArrayAndFormat(object, format); } else if (cfType == kCFDictionaryTypeID) { rep = TSICTStringCreateWithDictionaryAndFormat(object, format); } else { rep = TSICTStringCreateInvalidWithFormat(format); } CFRelease(object); return rep; }
void EnableExtendedLogging(SDMMD_AMDeviceRef device) { sdmmd_return_t result = SDMMD_AMDeviceConnect(device); if (SDM_MD_CallSuccessful(result)) { result = SDMMD_AMDeviceStartSession(device); if (SDM_MD_CallSuccessful(result)) { CFTypeRef value = SDMMD_AMDeviceCopyValue(device, CFSTR(AMSVC_MOBILE_DEBUG), CFSTR(kEnableLockdownExtendedLogging)); if (CFGetTypeID(value) == CFBooleanGetTypeID()) { if (!CFBooleanGetValue(value)) { result = SDMMD_AMDeviceSetValue(device, CFSTR(AMSVC_MOBILE_DEBUG), CFSTR(kEnableLockdownExtendedLogging), kCFBooleanTrue); if (SDM_MD_CallSuccessful(result)) { printf("Enabling extended logging...\n"); } } else { printf("Extended logging already enabled.\n"); } } else { PrintCFType(value); } CFSafeRelease(value); } SDMMD_AMDeviceStopSession(device); SDMMD_AMDeviceDisconnect(device); } }
CryptoX_Result CryptoMac_VerifySignature(CryptoX_SignatureHandle* aInputData, CryptoX_PublicKey* aPublicKey, const unsigned char* aSignature, unsigned int aSignatureLen) { if (!OnLionOrLater()) { return NSS_VerifySignature((VFYContext* const*)aInputData, aSignature, aSignatureLen); } if (!aInputData || !*aInputData || !aPublicKey || !*aPublicKey || !aSignature || aSignatureLen == 0) { return CryptoX_Error; } CFDataRef signatureData = CFDataCreate(kCFAllocatorDefault, aSignature, aSignatureLen); if (!signatureData) { return CryptoX_Error; } CFErrorRef error; SecTransformRef verifier = SecVerifyTransformCreatePtr((SecKeyRef)*aPublicKey, signatureData, &error); if (!verifier || error) { CFRelease(signatureData); return CryptoX_Error; } SecTransformSetAttributePtr(verifier, kSecTransformInputAttributeName, (CFDataRef)*aInputData, &error); if (error) { CFRelease(signatureData); CFRelease(verifier); return CryptoX_Error; } CryptoX_Result result = CryptoX_Error; CFTypeRef rv = SecTransformExecutePtr(verifier, &error); if (error) { CFRelease(signatureData); CFRelease(verifier); return CryptoX_Error; } if (CFGetTypeID(rv) == CFBooleanGetTypeID() && CFBooleanGetValue((CFBooleanRef)rv) == true) { result = CryptoX_Success; } CFRelease(signatureData); CFRelease(verifier); return result; }
std::string DiskArbitrationEventPublisher::getProperty( const CFStringRef& property, const CFDictionaryRef& dict) { CFTypeRef value = (CFTypeRef)CFDictionaryGetValue(dict, property); if (value == nullptr) { return ""; } if (CFStringCompare(property, CFSTR(kDAAppearanceTime_), kNilOptions) == kCFCompareEqualTo) { return stringFromCFAbsoluteTime((CFDataRef)value); } if (CFGetTypeID(value) == CFNumberGetTypeID()) { return stringFromCFNumber((CFDataRef)value, CFNumberGetType((CFNumberRef)value)); } else if (CFGetTypeID(value) == CFStringGetTypeID()) { return stringFromCFString((CFStringRef)value); } else if (CFGetTypeID(value) == CFBooleanGetTypeID()) { return (CFBooleanGetValue((CFBooleanRef)value)) ? "1" : "0"; } else if (CFGetTypeID(value) == CFUUIDGetTypeID()) { return stringFromCFString( CFUUIDCreateString(kCFAllocatorDefault, (CFUUIDRef)value)); } return ""; }
static void GetImportPrefs() { #if TARGET_API_MAC_CARBON CFStringRef prefs_id = CFStringCreateWithCString(NULL, SUPERPNG_PREFS_ID, kCFStringEncodingASCII); CFStringRef alpha_id = CFStringCreateWithCString(NULL, SUPERPNG_PREFS_ALPHA, kCFStringEncodingASCII); CFStringRef mult_id = CFStringCreateWithCString(NULL, SUPERPNG_PREFS_MULT, kCFStringEncodingASCII); CFPropertyListRef alphaMode_val = CFPreferencesCopyAppValue(alpha_id, prefs_id); CFPropertyListRef mult_val = CFPreferencesCopyAppValue(mult_id, prefs_id); if(alphaMode_val) { char alphaMode_char; if( CFNumberGetValue((CFNumberRef)alphaMode_val, kCFNumberCharType, &alphaMode_char) ) g_alpha = (DialogAlpha)alphaMode_char; CFRelease(alphaMode_val); } if(mult_val) { g_mult = CFBooleanGetValue((CFBooleanRef)mult_val); CFRelease(mult_val); } CFRelease(alpha_id); CFRelease(mult_id); CFRelease(prefs_id); #endif }
void CASettingsStorage::CopyBoolValue(CFStringRef inKey, bool& outValue, bool inDefaultValue) const { // initialize the return value outValue = inDefaultValue; // get the raw value CFTypeRef theValue = NULL; CopyCFTypeValue(inKey, theValue, NULL); // for this type, NULL is an invalid value if(theValue != NULL) { // bools can be made from either CFBooleans or CFNumbers if(CFGetTypeID(theValue) == CFBooleanGetTypeID()) { // get the return value from the CF object outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue)); } else if(CFGetTypeID(theValue) == CFNumberGetTypeID()) { // get the numeric value SInt32 theNumericValue = 0; CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue); // non-zero indicates true outValue = theNumericValue != 0; } // release the value since we aren't returning it CFRelease(theValue); } }
std::string getIOKitProperty(const CFMutableDictionaryRef& details, const std::string& key) { std::string value; // Get a property from the device. auto cfkey = CFStringCreateWithCString( kCFAllocatorDefault, key.c_str(), kCFStringEncodingUTF8); auto property = CFDictionaryGetValue(details, cfkey); CFRelease(cfkey); // Several supported ways of parsing IOKit-encoded data. if (property) { if (CFGetTypeID(property) == CFNumberGetTypeID()) { value = stringFromCFNumber((CFDataRef)property); } else if (CFGetTypeID(property) == CFStringGetTypeID()) { value = stringFromCFString((CFStringRef)property); } else if (CFGetTypeID(property) == CFDataGetTypeID()) { value = stringFromCFData((CFDataRef)property); } else if (CFGetTypeID(property) == CFBooleanGetTypeID()) { value = (CFBooleanGetValue((CFBooleanRef)property)) ? "1" : "0"; } } return value; }
static bool GetDictionaryBoolean(CFDictionaryRef d, const void *key) { CFBooleanRef ref = (CFBooleanRef) CFDictionaryGetValue(d, key); if(ref) return CFBooleanGetValue(ref); return false; }
////////////////////////////////////////////////////////////////////////// //Boolean ////////////////////////////////////////////////////////////////////////// Boolean getBool(CFTypeRef preference, Boolean* boolean) { Boolean ret = FALSE; if (!preference) return FALSE; if (CFGetTypeID(preference) == CFBooleanGetTypeID()) { ret = TRUE; *boolean = CFBooleanGetValue((CFBooleanRef) preference); } else if (CFGetTypeID(preference) == CFStringGetTypeID()) { if (!CFStringCompare((CFStringRef)preference, Yes, kCFCompareCaseInsensitive)) { ret = TRUE; *boolean = TRUE; } else if (!CFStringCompare((CFStringRef)preference, No, kCFCompareCaseInsensitive)) { ret = TRUE; *boolean = FALSE; } else if (!CFStringCompare((CFStringRef)preference, True, kCFCompareCaseInsensitive)) { ret = TRUE; *boolean = TRUE; } else if (!CFStringCompare((CFStringRef)preference, False, kCFCompareCaseInsensitive)) { ret = TRUE; *boolean = FALSE; } } return ret; }
static OSStatus ScanDictionaryForParameters(CFDictionaryRef parameters, void* attributePointers[]) { int i; for (i = 0; i < kNumberOfAttributes; ++i) { // see if the corresponding tag exists in the dictionary CFTypeRef value = CFDictionaryGetValue(parameters, *(gAttributes[i].name)); if (value != NULL) { switch (gAttributes[i].type) { case kStringType: // just return the value *(CFTypeRef*) attributePointers[i] = value; break; case kBooleanType: { CFBooleanRef bRef = (CFBooleanRef) value; *(bool*) attributePointers[i] = CFBooleanGetValue(bRef); } break; case kIntegerType: { CFNumberRef nRef = (CFNumberRef) value; CFNumberGetValue(nRef, kCFNumberSInt32Type, attributePointers[i]); } break; } } } return noErr; }
static void disk_appeared_cb(DADiskRef disk, void *ctx) { CFDictionaryRef description = NULL; CFBooleanRef mountable; CFStringRef content = NULL; if (!ctx || !disk) return; description = DADiskCopyDescription(disk); if (!description) return; mountable = CFDictionaryGetValue(description, kDADiskDescriptionVolumeMountableKey); if (!mountable) goto out; content = CFDictionaryGetValue(description, kDADiskDescriptionMediaContentKey); if (!content) goto out; if (CFBooleanGetValue(mountable) && CFStringCompare(content, CFSTR("53746F72-6167-11AA-AA11-00306543ECAC"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && CFStringCompare(content, CFSTR("426F6F74-0000-11AA-AA11-00306543ECAC"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) { /* The disk is marked mountable and isn't CoreStorage or Apple_Boot, * which means that it actually is mountable (since we lie and mark * CoreStorage disks as mountable). */ *((bool *)ctx) = true; } out: if (description) CFRelease(description); }
static void printObj(CFPropertyListRef obj, struct printContext* c) { CFTypeID typeID = CFGetTypeID(obj); if (typeID == _CFKeyedArchiverUIDGetTypeID()) { unsigned uid = _CFKeyedArchiverUIDGetValue(obj); CFPropertyListRef refObj = CFArrayGetValueAtIndex(c->objs, uid); if (CFEqual(refObj, CFSTR("$null"))) printf("nil"); else if (c->refCount[uid] > 1 && isComplexObj(refObj)) printf("{CF$UID = %u;}", uid); else printObj(refObj, c); } else if (typeID == CFArrayGetTypeID()) { printf("(\n"); ++ c->tabs; CFArrayApplyFunction(obj, CFRangeMake(0, CFArrayGetCount(obj)), (CFArrayApplierFunction)&printObjAsArrayEntry, c); -- c->tabs; for (unsigned i = 0; i < c->tabs; ++ i) printf("\t"); printf(")"); } else if (typeID == CFDictionaryGetTypeID()) { CFStringRef className = CFDictionaryGetValue(obj, CFSTR("$classname")); if (className != NULL) printObjAsClassName(className); else { printf("{\n"); ++ c->tabs; CFIndex dictCount = CFDictionaryGetCount(obj); struct dictionarySorterContext sc; sc.keys = malloc(sizeof(CFStringRef)*dictCount); sc.values = malloc(sizeof(CFPropertyListRef)*dictCount); unsigned* mapping = malloc(sizeof(unsigned)*dictCount); for (unsigned i = 0; i < dictCount; ++ i) mapping[i] = i; CFDictionaryGetKeysAndValues(obj, (const void**)sc.keys, sc.values); qsort_r(mapping, dictCount, sizeof(unsigned), &sc, (int(*)(void*,const void*,const void*))&dictionaryComparer); for (unsigned i = 0; i < dictCount; ++ i) printObjAsDictionaryEntry(sc.keys[mapping[i]], sc.values[mapping[i]], c); free(mapping); free(sc.keys); free(sc.values); -- c->tabs; for (unsigned i = 0; i < c->tabs; ++ i) printf("\t"); printf("}"); } } else if (typeID == CFDataGetTypeID()) printObjAsData(obj); else if (typeID == CFNumberGetTypeID()) printObjAsNumber(obj); else if (typeID == CFStringGetTypeID()) printObjAsString(obj); else if (typeID == CFBooleanGetTypeID()) printf(CFBooleanGetValue(obj) ? "true" : "false"); else if (typeID == CFDateGetTypeID()) printf("/*date*/ %0.09g", CFDateGetAbsoluteTime(obj)); }
/* * Given disk2s1, look up "disk2" is IOKit and attempt to determine if * it is an optical device. */ int is_optical_media(const char *bsdname) { CFMutableDictionaryRef matchingDict; int ret = 0; io_service_t service, start; kern_return_t kernResult; io_iterator_t iter; if ((matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, bsdname)) == NULL) return(0); start = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict); if (IO_OBJECT_NULL == start) return (0); service = start; // Create an iterator across all parents of the service object passed in. // since only disk2 would match with ConfirmsTo, and not disk2s1, so // we search the parents until we find "Whole", ie, disk2. kernResult = IORegistryEntryCreateIterator(service, kIOServicePlane, kIORegistryIterateRecursively | kIORegistryIterateParents, &iter); if (KERN_SUCCESS == kernResult) { Boolean isWholeMedia = false; IOObjectRetain(service); do { // Lookup "Whole" if we can if (IOObjectConformsTo(service, kIOMediaClass)) { CFTypeRef wholeMedia; wholeMedia = IORegistryEntryCreateCFProperty(service, CFSTR(kIOMediaWholeKey), kCFAllocatorDefault, 0); if (wholeMedia) { isWholeMedia = CFBooleanGetValue(wholeMedia); CFRelease(wholeMedia); } } // If we found "Whole", check the service type. if (isWholeMedia && ( (IOObjectConformsTo(service, kIOCDMediaClass)) || (IOObjectConformsTo(service, kIODVDMediaClass)) )) { ret = 1; // Is optical, skip } IOObjectRelease(service); } while ((service = IOIteratorNext(iter)) && !isWholeMedia); IOObjectRelease(iter); } IOObjectRelease(start); return ret; }
void extmgr_mntopts (const char *device, int *mopts, int *eopts, int *nomount) { CFPropertyListRef mediaRoot; CFDictionaryRef media; CFStringRef uuid; CFBooleanRef boolVal; *nomount = 0; mediaRoot = CFPreferencesCopyAppValue(EXT_PREF_KEY_MEDIA, EXT_PREF_ID); if (mediaRoot && CFDictionaryGetTypeID() == CFGetTypeID(mediaRoot)) { uuid = extsuper_uuid(device); if (uuid) { media = CFDictionaryGetValue(mediaRoot, uuid); if (media && CFDictionaryGetTypeID() == CFGetTypeID(media)) { boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_NOAUTO); if (boolVal && CFBooleanGetValue(boolVal)) { *nomount = 1; goto out; } boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_RDONLY); if (boolVal && CFBooleanGetValue(boolVal)) { *mopts |= MNT_RDONLY; } boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_NOPERMS); if (boolVal && CFBooleanGetValue(boolVal)) { *mopts |= MNT_IGNORE_OWNERSHIP; } /* Ext2/3 specific */ boolVal = CFDictionaryGetValue(media, EXT_PREF_KEY_DIRINDEX); if (boolVal && CFBooleanGetValue(boolVal)) { *eopts |= EXT2_MNT_INDEX; } } out: CFRelease(uuid); } } if (mediaRoot) CFRelease(mediaRoot); }
static Boolean volumeIsRemovable(const char *path) { CFBooleanRef removableRef; if (getVolumeProperty(fs->f_mntonname, kCFURLVolumeIsRemovableKey, &removableRef) && removableRef != NULL) return CFBooleanGetValue(removableRef); else return false; }
bool KeyedDecoder::decodeBool(const String& key, bool& result) { auto boolean = dynamic_cf_cast<CFBooleanRef>(CFDictionaryGetValue(m_dictionaryStack.last(), key.createCFString().get())); if (!boolean) return false; result = CFBooleanGetValue(boolean); return true; }
static void InternSettings(CFDictionaryRef srcDict, MySettings* settings) { CFTypeRef dictValue; if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHaveSelection)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mHaveSelection = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHaveFrames)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mHaveFrames = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHaveFrameSelected)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mHaveFrameSelected = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintFrameType)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) { if (CFEqual(dictValue, kPDEValueFramesAsIs)) settings->mPrintFrameAsIs = true; else if (CFEqual(dictValue, kPDEValueSelectedFrame)) settings->mPrintSelectedFrame = true; else if (CFEqual(dictValue, kPDEValueEachFrameSep)) settings->mPrintFramesSeparately = true; } if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintSelection)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mPrintSelection = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyShrinkToFit)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mShrinkToFit = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintBGColors)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mPrintBGColors = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintBGImages)) && (CFGetTypeID(dictValue) == CFBooleanGetTypeID())) settings->mPrintBGImages = CFBooleanGetValue((CFBooleanRef)dictValue); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHeaderLeft)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) settings->mHeaderLeft = MyCFAssign(dictValue, settings->mHeaderLeft); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHeaderCenter)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) settings->mHeaderCenter = MyCFAssign(dictValue, settings->mHeaderCenter); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHeaderRight)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) settings->mHeaderRight = MyCFAssign(dictValue, settings->mHeaderRight); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyFooterLeft)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) settings->mFooterLeft = MyCFAssign(dictValue, settings->mFooterLeft); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyFooterCenter)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) settings->mFooterCenter = MyCFAssign(dictValue, settings->mFooterCenter); if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyFooterRight)) && (CFGetTypeID(dictValue) == CFStringGetTypeID())) settings->mFooterRight = MyCFAssign(dictValue, settings->mFooterRight); }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ 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; }
static uint32_t utilGetMaskValFromCFDict(CFDictionaryRef parameters, CFTypeRef key, uint32_t maskValue) { CFTypeRef value = CFDictionaryGetValue(parameters, key); if (value != NULL) { CFBooleanRef bRef = (CFBooleanRef) value; if(CFBooleanGetValue(bRef)) return maskValue; } return 0; }
void DiskArbitrationEventPublisher::DiskAppearedCallback(DADiskRef disk, void* context) { auto ec = createEventContext(); CFDictionaryRef disk_properties = DADiskCopyDescription(disk); CFTypeRef devicePathKey; if (!CFDictionaryGetValueIfPresent( disk_properties, kDADiskDescriptionDevicePathKey, &devicePathKey)) { CFRelease(disk_properties); return; } auto device_path = stringFromCFString((CFStringRef)devicePathKey); ec->device_path = device_path; auto entry = IORegistryEntryFromPath(kIOMasterPortDefault, device_path.c_str()); if (entry == MACH_PORT_NULL) { CFRelease(disk_properties); return; } auto protocol_properties = (CFDictionaryRef)IORegistryEntryCreateCFProperty( entry, CFSTR(kIOPropertyProtocolCharacteristicsKey_), kCFAllocatorDefault, kNilOptions); if (protocol_properties != nullptr) { CFDataRef path = (CFDataRef)CFDictionaryGetValue( protocol_properties, CFSTR(kVirtualInterfaceLocation_)); if (path != nullptr) { ec->path = stringFromCFData(path); // extract checksum once on the whole disk and not for every partition if (CFBooleanGetValue((CFBooleanRef)CFDictionaryGetValue( disk_properties, kDADiskDescriptionMediaWholeKey))) { ec->checksum = extractUdifChecksum(ec->path); } } else { // There was no interface location. ec->path = getProperty(kDADiskDescriptionDevicePathKey, disk_properties); } CFRelease(protocol_properties); } else { ec->path = ""; } if (ec->path.find("/SSD0@0") == std::string::npos) { // This is not an internal SSD. fire("add", ec, disk_properties); } CFRelease(disk_properties); IOObjectRelease(entry); }
static netfsError OpenSession9P(CFURLRef url, void *v, CFDictionaryRef opts, CFDictionaryRef * info) { CFMutableDictionaryRef dict; Context9P *ctx; int useGuest, e; TRACE(); ctx = v; if (ctx == NULL || url == NULL || info == NULL || !CFURLCanBeDecomposed(url)) return EINVAL; DEBUG("url=%s opts=%s", NetFSCFStringtoCString(CFURLGetString(url)), NetFSCFStringtoCString(CFCopyDescription(opts))); *info = dict = CreateDict9P(); if (dict == NULL) return ENOMEM; useGuest = FALSE; if (opts != NULL) { CFBooleanRef boolean = CFDictionaryGetValue(opts, kNetFSUseGuestKey); if (boolean != NULL) useGuest = CFBooleanGetValue(boolean); } if (useGuest) CFDictionarySetValue(dict, kNetFSMountedByGuestKey, kCFBooleanTrue); else { ctx->user = CFURLCopyUserName(url); ctx->pass = CFURLCopyPassword(url); if (ctx->user == NULL || ctx->pass == NULL) { if (ctx->user) CFRelease(ctx->user); if (ctx->pass) CFRelease(ctx->pass); ctx->user = ctx->pass = NULL; goto error; } DEBUG("user=%s pass=%s", NetFSCFStringtoCString(ctx->user), NetFSCFStringtoCString(ctx->pass)); CFDictionarySetValue(dict, kNetFSMountedByUserKey, ctx->user); } return 0; error: e = errno; *info = NULL; CFRelease(dict); return e; }
static void init_log(void) { static dispatch_once_t once = 0; dispatch_once(&once, ^{ CFBooleanRef b; b = CFPreferencesCopyAppValue(CFSTR("EnableDebugging"), CFSTR("com.apple.MITKerberosShim")); if (b && CFGetTypeID(b) == CFBooleanGetTypeID()) do_log = CFBooleanGetValue(b); });
SFB::Audio::Metadata::unique_ptr SFB::Audio::Metadata::CreateMetadataForURL(CFURLRef url, CFErrorRef *error) { if(nullptr == url) return nullptr; // If this is a file URL, use the extension-based resolvers SFB::CFString scheme = CFURLCopyScheme(url); // If there is no scheme the URL is invalid if(!scheme) { if(error) *error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, EINVAL, nullptr); return nullptr; } if(kCFCompareEqualTo == CFStringCompare(CFSTR("file"), scheme, kCFCompareCaseInsensitive)) { // Verify the file exists SInt32 errorCode = noErr; SFB::CFBoolean fileExists = (CFBooleanRef)CFURLCreatePropertyFromResource(kCFAllocatorDefault, url, kCFURLFileExists, &errorCode); if(fileExists) { if(CFBooleanGetValue(fileExists)) { SFB::CFString pathExtension = CFURLCopyPathExtension(url); if(pathExtension) { // Some extensions (.oga for example) support multiple audio codecs (Vorbis, FLAC, Speex) for(auto subclassInfo : sRegisteredSubclasses) { if(subclassInfo.mHandlesFilesWithExtension(pathExtension)) { unique_ptr metadata(subclassInfo.mCreateMetadata(url)); if(metadata->ReadMetadata(error)) return metadata; } } } } else { LOGGER_WARNING("org.sbooth.AudioEngine.Metadata", "The requested URL doesn't exist"); if(error) { SFB::CFString description = CFCopyLocalizedString(CFSTR("The file “%@” does not exist."), ""); SFB::CFString failureReason = CFCopyLocalizedString(CFSTR("File not found"), ""); SFB::CFString recoverySuggestion = CFCopyLocalizedString(CFSTR("The file may exist on removable media or may have been deleted."), ""); *error = CreateErrorForURL(Metadata::ErrorDomain, Metadata::InputOutputError, description, url, failureReason, recoverySuggestion); } } } else LOGGER_WARNING("org.sbooth.AudioEngine.Metadata", "CFURLCreatePropertyFromResource failed: " << errorCode); } return nullptr; }
static bool getBoolForKey(CFDictionaryRef dict, CFStringRef key, bool default_value) { CFTypeRef value = CFDictionaryGetValue(dict, key); if (value) { if (CFGetTypeID(value) == CFBooleanGetTypeID()) { return CFBooleanGetValue(value); } else { secwarning("Value %@ for key %@ is not bool", value, key); } } return default_value; }
IntSize ImageSource::frameSizeAtIndex(size_t index, ImageOrientationDescription description) const { RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions(SkipMetadata))); if (!properties) return IntSize(); int w = 0, h = 0; CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelWidth); if (num) CFNumberGetValue(num, kCFNumberIntType, &w); num = (CFNumberRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelHeight); if (num) CFNumberGetValue(num, kCFNumberIntType, &h); #if PLATFORM(IOS) if (!m_isProgressive) { CFDictionaryRef jfifProperties = static_cast<CFDictionaryRef>(CFDictionaryGetValue(properties.get(), kCGImagePropertyJFIFDictionary)); if (jfifProperties) { CFBooleanRef isProgCFBool = static_cast<CFBooleanRef>(CFDictionaryGetValue(jfifProperties, kCGImagePropertyJFIFIsProgressive)); if (isProgCFBool) m_isProgressive = CFBooleanGetValue(isProgCFBool); // Workaround for <rdar://problem/5184655> - Hang rendering very large progressive JPEG. Decoding progressive // images hangs for a very long time right now. Until this is fixed, don't sub-sample progressive images. This // will cause them to fail our large image check and they won't be decoded. // FIXME: Remove once underlying issue is fixed (<rdar://problem/5191418>) } } if ((m_baseSubsampling == 0) && !m_isProgressive) { IntSize subsampledSize(w, h); const int cMaximumImageSizeBeforeSubsampling = 5 * 1024 * 1024; while ((m_baseSubsampling < 3) && subsampledSize.width() * subsampledSize.height() > cMaximumImageSizeBeforeSubsampling) { // We know the size, but the actual image is very large and should be sub-sampled. // Increase the base subsampling and ask for the size again. If the image can be subsampled, the size will be // greatly reduced. 4x sub-sampling will make us support up to 320MP (5MP * 4^3) images, which should be plenty. // There's no callback from ImageIO when the size is available, so we do the check when we happen // to check the size and its non - zero. // Note: Some clients of this class don't call isSizeAvailable() so we can't rely on that. ++m_baseSubsampling; subsampledSize = frameSizeAtIndex(index, description.respectImageOrientation()); } w = subsampledSize.width(); h = subsampledSize.height(); } #endif if ((description.respectImageOrientation() == RespectImageOrientation) && orientationFromProperties(properties.get()).usesWidthAsHeight()) return IntSize(h, w); return IntSize(w, h); }
static bool SetXiphCommentBoolean(TagLib::Ogg::XiphComment *tag, const char *key, CFBooleanRef value) { assert(NULL != tag); assert(NULL != key); if(NULL == value) return SetXiphComment(tag, key, NULL); else if(CFBooleanGetValue(value)) return SetXiphComment(tag, key, CFSTR("1")); else return SetXiphComment(tag, key, CFSTR("0")); }