OSStatus PosixPathToParentFSRefAndName(const char *path, FSRef &outParentDir, CFStringRef &outFileName) { // convert C string to CFString #if !TARGET_OS_WIN32 CFStringRef cfFullPath = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8); #else CFStringRef cfFullPath = CFStringCreateWithCString(NULL, path, kCFStringEncodingWindowsLatin1); #endif // convert CF string to URL CFURLRef fullurl = CFURLCreateWithFileSystemPath(NULL, cfFullPath, TARGET_OS_WIN32 ? kCFURLWindowsPathStyle : kCFURLPOSIXPathStyle, false); CFRelease(cfFullPath); // get the directory portion of the URL CFURLRef dirurl = CFURLCreateCopyDeletingLastPathComponent(NULL, fullurl); // get the directory's FSRef OSStatus err = CFURLGetFSRef(dirurl, &outParentDir) ? OSStatus(noErr) : OSStatus(kAudio_FileNotFoundError); CFRelease(dirurl); CFStringRef lastPathComponent = CFURLCopyLastPathComponent(fullurl); CFRelease(fullurl); CFMutableStringRef filename = CFStringCreateMutableCopy(NULL, 0, lastPathComponent); CFRelease(lastPathComponent); // convert colons (legal in POSIX paths, illegal in File Manager) to slashes CFStringFindAndReplace(filename, CFSTR(":"), CFSTR("/"), CFRangeMake(0, CFStringGetLength(filename)), 0); outFileName = filename; return err; }
void AUOutputBL::Prepare (UInt32 inNumFrames, bool inWantNullBufferIfAllocated) { UInt32 channelsPerBuffer = mFormat.IsInterleaved() ? mFormat.NumberChannels() : 1; if (mBufferMemory == NULL || inWantNullBufferIfAllocated) { mBufferList->mNumberBuffers = mNumberBuffers; AudioBuffer *buf = &mBufferList->mBuffers[0]; for (UInt32 i = 0; i < mNumberBuffers; ++i, ++buf) { buf->mNumberChannels = channelsPerBuffer; buf->mDataByteSize = mFormat.FramesToBytes (inNumFrames); buf->mData = NULL; } } else { UInt32 nBytes = mFormat.FramesToBytes (inNumFrames); if ((nBytes * mNumberBuffers) > AllocatedBytes()) throw OSStatus(kAudioUnitErr_TooManyFramesToProcess); mBufferList->mNumberBuffers = mNumberBuffers; AudioBuffer *buf = &mBufferList->mBuffers[0]; Byte* p = mBufferMemory; for (UInt32 i = 0; i < mNumberBuffers; ++i, ++buf) { buf->mNumberChannels = channelsPerBuffer; buf->mDataByteSize = nBytes; buf->mData = p; p += mBufferSize; } } }
// Make a new ScreenRef that corresponds to the rectangle indicated by the where parameter ScreenRef NewScreenRef( const Rect *where, OSStatus *error ) { RLDisplay *display = NULL; // MakeNewRLDisplay may throw exceptions so we have to catch them here so // that we dont inflict them on our C loving public! try { display = MakeNewRLDisplay( where ); // In the particular case of operator new failing, we just get a NULL // pointer back, so generate the exception ourselves. if( ! display ) { DEBUGMESSAGE( "Screen Ref allocation failed -- not enough memory!" ); throw OSStatus( rlOutOfMemory ); } if( error ) *error = noErr; } catch( OSStatus err ) { if( error ) *error = err; } return ScreenRef( display ); }
// // Executable code. // Read from disk, evaluate properly, cache as indicated. // void PolicyEngine::evaluateCode(CFURLRef path, AuthorityType type, SecAssessmentFlags flags, CFDictionaryRef context, CFMutableDictionaryRef result, bool handleUnsigned) { // not really a Gatekeeper function... but reject all "hard quarantined" files because they were made from sandboxed sources without download privilege FileQuarantine qtn(cfString(path).c_str()); if (qtn.flag(QTN_FLAG_HARD)) MacOSError::throwMe(errSecCSFileHardQuarantined); CFCopyRef<SecStaticCodeRef> code; MacOSError::check(SecStaticCodeCreateWithPath(path, kSecCSDefaultFlags, &code.aref())); SecCSFlags validationFlags = kSecCSEnforceRevocationChecks | kSecCSCheckAllArchitectures; if (!(flags & kSecAssessmentFlagAllowWeak)) validationFlags |= kSecCSStrictValidate; adjustValidation(code); // deal with a very special case (broken 10.6/10.7 Applet bundles) OSStatus rc = SecStaticCodeCheckValidity(code, validationFlags | kSecCSBasicValidateOnly, NULL); if (rc == errSecCSSignatureFailed) { if (!codeInvalidityExceptions(code, result)) { // invalidly signed, no exceptions -> error if (SYSPOLICY_ASSESS_OUTCOME_BROKEN_ENABLED()) SYSPOLICY_ASSESS_OUTCOME_BROKEN(cfString(path).c_str(), type, false); MacOSError::throwMe(rc); } // recognized exception - treat as unsigned if (SYSPOLICY_ASSESS_OUTCOME_BROKEN_ENABLED()) SYSPOLICY_ASSESS_OUTCOME_BROKEN(cfString(path).c_str(), type, true); rc = errSecCSUnsigned; } // ad-hoc sign unsigned code if (rc == errSecCSUnsigned && handleUnsigned && (!overrideAssessment(flags) || SYSPOLICY_RECORDER_MODE_ENABLED())) { if (temporarySigning(code, type, path, 0)) { rc = errSecSuccess; // clear unsigned; we are now well-signed validationFlags |= kSecCSBasicValidateOnly; // no need to re-validate deep contents } } // prepare for deep traversal of (hopefully) good signatures SecAssessmentFeedback feedback = SecAssessmentFeedback(CFDictionaryGetValue(context, kSecAssessmentContextKeyFeedback)); MacOSError::check(SecStaticCodeSetCallback(code, kSecCSDefaultFlags, NULL, ^CFTypeRef (SecStaticCodeRef item, CFStringRef cfStage, CFDictionaryRef info) { string stage = cfString(cfStage); if (stage == "prepared") { if (!CFEqual(item, code)) // genuine nested (not top) code adjustValidation(item); } else if (stage == "progress") { if (feedback && CFEqual(item, code)) { // top level progress bool proceed = feedback(kSecAssessmentFeedbackProgress, info); if (!proceed) SecStaticCodeCancelValidation(code, kSecCSDefaultFlags); } } else if (stage == "validated") { SecStaticCodeSetCallback(item, kSecCSDefaultFlags, NULL, NULL); // clear callback to avoid unwanted recursion evaluateCodeItem(item, path, type, flags, item != code, result); if (CFTypeRef verdict = CFDictionaryGetValue(result, kSecAssessmentAssessmentVerdict)) if (CFEqual(verdict, kCFBooleanFalse)) return makeCFNumber(OSStatus(errSecCSVetoed)); // (signal nested-code policy failure, picked up below) } return NULL; }));
void TTFoundationLoadExternalClassesFromFolder(const TTString& fullpath) { #ifdef TT_PLATFORM_MAC FSRef ref; Boolean isDirectory; OSStatus status = noErr; ItemCount count = 0; FSIterator iterator; HFSUniStr255* names = NULL; CFStringRef name; char cname[4096]; TTString path; TTCString cpath = (char*)fullpath.c_str(); void* handle; TTExtensionInitializationMethod initializer; TTErr err; status = FSPathMakeRef((UInt8*)cpath, &ref, &isDirectory); if (status != noErr) { #ifdef TT_DEBUG TTLogMessage("TTFoundation - no extensions location found @ %s\n", cpath); #endif return; } status = FSOpenIterator(&ref, kFSIterateFlat, &iterator); if (!status) { names = (HFSUniStr255 *)malloc(sizeof(HFSUniStr255) * 4096); if (names) { // Request information about files in the given directory, // until we get a status code back from the File Manager do{ status = FSGetCatalogInfoBulk(iterator, 4096, &count, NULL, kFSCatInfoNone, NULL, NULL, NULL, names); // Process all items received if (status == OSStatus(noErr) || status == OSStatus(errFSNoMoreItems)) { for (UInt32 i=0; i < count; i += 1) { name = CFStringCreateWithCharacters(kCFAllocatorDefault, names[i].unicode, names[i].length); // TODO: filter on name. We only want to try and load .ttdylib files CFStringGetCString(name, cname, 4096, kCFStringEncodingUTF8); path = fullpath; path += "/"; path += cname; handle = dlopen(path.c_str(), RTLD_LAZY); // TODO: assert -- or at least do a log post -- if handle is NULL initializer = (TTExtensionInitializationMethod)dlsym(handle, "loadTTExtension"); if (initializer) err = initializer(); CFRelease(name); } } } while (status == OSStatus(noErr)); // errFSNoMoreItems tells us we have successfully processed all // items in the directory -- not really an error if (status == OSStatus(errFSNoMoreItems)) status = noErr; // Free the array memory free( (void *) names ); } FSCloseIterator(iterator); } #elif TT_PLATFORM_WIN HANDLE fdHandle; WIN32_FIND_DATA findFileData; TTString path; HANDLE hLib = NULL; TTExtensionInitializationMethod initializer; TTErr err; path = fullpath; path += "*.ttdll"; fdHandle = FindFirstFile(path.c_str(), &findFileData); if (fdHandle && (fdHandle != INVALID_HANDLE_VALUE)) { while (fdHandle) { path = fullpath; path += findFileData.cFileName; hLib = LoadLibrary(path.c_str()); if (hLib) { initializer = (TTExtensionInitializationMethod)GetProcAddress((HMODULE)hLib, "loadTTExtension"); if (initializer) err = initializer(); } if (!FindNextFile(fdHandle, &findFileData)) break; } } #else ; #endif }