コード例 #1
0
ファイル: kim_os_library.c プロジェクト: Losteven/krb5-test
kim_boolean kim_os_library_caller_uses_gui (void)
{
    kim_boolean caller_uses_gui = 0;

    /* Check for the HIToolbox (Carbon) or AppKit (Cocoa).
     * If either is loaded, we are a GUI app! */
    CFBundleRef appKitBundle = CFBundleGetBundleWithIdentifier (CFSTR ("com.apple.AppKit"));
    CFBundleRef hiToolBoxBundle = CFBundleGetBundleWithIdentifier (CFSTR ("com.apple.HIToolbox"));

    if (hiToolBoxBundle && CFBundleIsExecutableLoaded (hiToolBoxBundle)) {
        caller_uses_gui = 1; /* Using Carbon */
    }

    if (appKitBundle && CFBundleIsExecutableLoaded (appKitBundle)) {
        caller_uses_gui = 1; /* Using Cocoa */
    }

    return caller_uses_gui;
}
コード例 #2
0
int DYN_CloseLibrary(void **pvLHandle)
{

	CFBundleRef bundle = (CFBundleRef) * pvLHandle;

	if (CFBundleIsExecutableLoaded(bundle) == TRUE)
	{
		CFBundleUnloadExecutable(bundle);
		CFRelease(bundle);
	}
	else
		Log1(PCSC_LOG_ERROR, "Cannot unload library.");

	*pvLHandle = 0;
	return SCARD_S_SUCCESS;
}
コード例 #3
0
__private_extern__ void _CFBundleInitPlugIn(CFBundleRef bundle) {
    CFArrayCallBacks _pluginFactoryArrayCallbacks = {0, NULL, NULL, NULL, NULL};
    Boolean doDynamicReg = false;
    CFDictionaryRef infoDict;
    CFDictionaryRef factoryDict;
    CFDictionaryRef typeDict;
    CFStringRef tempStr;

    infoDict = CFBundleGetInfoDictionary(bundle);
    if (!infoDict) return;
    
    factoryDict = (CFDictionaryRef)CFDictionaryGetValue(infoDict, kCFPlugInFactoriesKey);
    if (factoryDict && CFGetTypeID(factoryDict) != CFDictionaryGetTypeID()) factoryDict = NULL;
    tempStr = (CFStringRef)CFDictionaryGetValue(infoDict, kCFPlugInDynamicRegistrationKey);
    if (tempStr && CFGetTypeID(tempStr) == CFStringGetTypeID() && CFStringCompare(tempStr, CFSTR("YES"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) doDynamicReg = true;
    if (!factoryDict && !doDynamicReg) return;  // This is not a plug-in.

    /* loadOnDemand is true by default if the plugIn does not do dynamic registration.  It is false, by default if it does do dynamic registration.  The dynamic register function can set this. */
    __CFBundleGetPlugInData(bundle)->_isPlugIn = true;
    __CFBundleGetPlugInData(bundle)->_loadOnDemand = true;
    __CFBundleGetPlugInData(bundle)->_isDoingDynamicRegistration = false;
    __CFBundleGetPlugInData(bundle)->_instanceCount = 0;

    __CFBundleGetPlugInData(bundle)->_factories = CFArrayCreateMutable(CFGetAllocator(bundle), 0, &_pluginFactoryArrayCallbacks);

    /* Now do the registration */

    /* First do static registrations, if any. */
    if (factoryDict) CFDictionaryApplyFunction(factoryDict, _registerFactory, bundle);
    typeDict = (CFDictionaryRef)CFDictionaryGetValue(infoDict, kCFPlugInTypesKey);
    if (typeDict && CFGetTypeID(typeDict) != CFDictionaryGetTypeID()) typeDict = NULL;
    if (typeDict) CFDictionaryApplyFunction(typeDict, _registerType, bundle);

    /* Now set key for dynamic registration if necessary */
    if (doDynamicReg) {
        CFDictionarySetValue((CFMutableDictionaryRef)infoDict, CFSTR("CFPlugInNeedsDynamicRegistration"), CFSTR("YES"));
        if (CFBundleIsExecutableLoaded(bundle)) _CFBundlePlugInLoaded(bundle);
    }
}
コード例 #4
0
ファイル: osxcode.cpp プロジェクト: Proteas/codesign
bool LoadableBundle::isLoaded() const
{
	return CFBundleIsExecutableLoaded(cfBundle());
}
コード例 #5
0
// ---------------------------------------------------------------------------
// Constructeur
// ------------
bStdExtLib::bStdExtLib(CFBundleRef bndl,
                       bGenericMacMapApp* gapp){
_bTrace_("bStdExtLib::bStdExtLib",false);
char	path[PATH_MAX];
UInt32	lsign=_kNULLSign_;

	_status=_bStdExtLibNoErr_;
	_bndl=bndl;
	_family=_kNULLSign_;
	_creator=_kNULLSign_;
	_version=NULL;
	_name=NULL;
	_sign=_kNULLSign_;
	_mmvers=NULL;
	_init=NULL;
	_destroy=NULL;
	_inst=NULL;
	
	for(;;){
		CFBundleGetPackageInfo(_bndl,&_family,&_creator);
		_version=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("CFBundleVersion"));
		_name=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("CFBundleName"));
				
CFStringRef	cfs;
		
		cfs=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("MacMapLibSign"));
		_sign=(cfs)?(*((int*)CFStringGetCStringPtr(cfs,0))):_kNULLSign_;
		_mmvers=(CFStringRef)CFBundleGetValueForInfoDictionaryKey(_bndl,CFSTR("MacMapMinVers"));

CFURLRef	url=CFBundleCopyBundleURL(_bndl);

		cfs=CFURLCopyFileSystemPath(url,kCFURLPOSIXPathStyle);
		CFStringGetCString(cfs,path,PATH_MAX,kCFStringEncodingUTF8);
		CFRelease(cfs);
		
		if(_family==_kNULLSign_){
			_status=_bStdExtLibNoFamilyErr_;
			break;
		}
		if(_creator==_kNULLSign_){
			_status=_bStdExtLibNoCreatorErr_;
			break;
		}
		if(_version==NULL){
			_status=_bStdExtLibNoVersErr_;
			break;
		}
		if(_name==NULL){
			break;
		}
		if(_sign==_kNULLSign_){
			_status=_bStdExtLibNoSignatureErr_;
			break;
		}
		if(_mmvers==NULL){
			_status=_bStdExtLibNoMacMapVersErr_;
			break;
		}
		if(CFBundleIsExecutableLoaded(_bndl)){
			_status=_bStdExtLibBundleAlreadyLoadedErr_;
			break;
		}
		if(!CFBundleLoadExecutable(_bndl)){
			_status=_bStdExtLibBundleLoadErr_;
			break;
		}
		
		_init=(initPtr)CFBundleGetFunctionPointerForName(bndl,CFSTR("init"));
		if(!_init){
			_status=_bStdExtLibNoInitProcErr_;
			break;
		}
		_destroy=(destroyPtr)CFBundleGetFunctionPointerForName(bndl,CFSTR("destroy"));
		if(!_destroy){
			_status=_bStdExtLibNoDestroyProcErr_;
			break;
		}
		_init(&_inst,gapp,_bndl);
		if(!_inst){
			_status=_bStdExtLibNoInstanceErr_;
			break;
		}
		break;
	}
	
	if(_status){
		_status+=_bStdExtLibRootErr_;
_te_("bStdExtLib::bStdExtLib returns "+_status);
	}
	else{
char	c[256];
		name(c);
        (void)bSplashWd::instance(false,gapp)->set_progress(c);
// DEBUG<
        MacRoman2UTF8(c,256);
		lsign=_sign;
#ifdef __LITTLE_ENDIAN__
        LBSwapWord(&lsign,sizeof(int));
#endif
_tm_(c+" "+(unsigned int*)(&_family)+"\t"+(unsigned int*)(&lsign)+" loaded");
// DEBUG>
	}
	
}
コード例 #6
0
ファイル: plugins.c プロジェクト: NanXiao/illumos-joyent
/*ARGSUSED2*/
long KRB5_CALLCONV
krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct errinfo *ep)
{
    long err = 0;
    struct stat statbuf;
    struct plugin_file_handle *htmp = NULL;
    int got_plugin = 0;

    if (!err) {
        if (stat (filepath, &statbuf) < 0) {
            Tprintf ("stat(%s): %s\n", filepath, strerror (errno));
            err = errno;
        }
    }

    if (!err) {
        htmp = calloc (1, sizeof (*htmp)); /* calloc initializes ptrs to NULL */
        if (htmp == NULL) { err = errno; }
    }

#if USE_DLOPEN
    if (!err && (statbuf.st_mode & S_IFMT) == S_IFREG) {
        void *handle = NULL;
#ifdef RTLD_GROUP
#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL | RTLD_GROUP)
#else
#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL)
#endif

        if (!err) {
            handle = dlopen(filepath, PLUGIN_DLOPEN_FLAGS);
            if (handle == NULL) {
                const char *e = dlerror();
                Tprintf ("dlopen(%s): %s\n", filepath, e);
                err = ENOENT; /* XXX */
		krb5int_set_error (ep, err, "%s", e);
            }
        }

        if (!err) {
            got_plugin = 1;
            htmp->dlhandle = handle;
            handle = NULL;
        }

        if (handle != NULL) { dlclose (handle); }
    }
#endif

#if USE_CFBUNDLE
    if (!err && (statbuf.st_mode & S_IFMT) == S_IFDIR) {
        CFStringRef pluginPath = NULL;
        CFURLRef pluginURL = NULL;
        CFBundleRef pluginBundle = NULL;

        if (!err) {
            pluginPath = CFStringCreateWithCString (kCFAllocatorDefault, filepath, 
                                                    kCFStringEncodingASCII);
            if (pluginPath == NULL) { err = ENOMEM; }
        }
        
        if (!err) {
            pluginURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, pluginPath, 
                                                       kCFURLPOSIXPathStyle, true);
            if (pluginURL == NULL) { err = ENOMEM; }
        }
        
        if (!err) {
            pluginBundle = CFBundleCreate (kCFAllocatorDefault, pluginURL);
            if (pluginBundle == NULL) { err = ENOENT; } /* XXX need better error */
        }
        
        if (!err) {
            if (!CFBundleIsExecutableLoaded (pluginBundle)) {
                int loaded = CFBundleLoadExecutable (pluginBundle);
                if (!loaded) { err = ENOENT; }  /* XXX need better error */
            }
        }
        
        if (!err) {
            got_plugin = 1;
            htmp->bundle = pluginBundle;
            pluginBundle = NULL;  /* htmp->bundle takes ownership */
        }

        if (pluginBundle != NULL) { CFRelease (pluginBundle); }
        if (pluginURL    != NULL) { CFRelease (pluginURL); }
        if (pluginPath   != NULL) { CFRelease (pluginPath); }
    }
#endif
        
    if (!err && !got_plugin) {
        err = ENOENT;  /* no plugin or no way to load plugins */
    }
    
    if (!err) {
        *h = htmp;
        htmp = NULL;  /* h takes ownership */
    }
    
    if (htmp != NULL) { free (htmp); }
    
    return err;
}
コード例 #7
0
static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
{
	OSStatus 	err;
	FSRef 		frameworksFolderRef;
	CFURLRef	baseURL;
	CFURLRef	bundleURL;
	
	*bundlePtr = nil;
	
	baseURL = nil;
	bundleURL = nil;

	// Find the frameworks folder and create a URL for it.
	
	err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
	if (err == noErr) {
		baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
		if (baseURL == nil) {
			err = coreFoundationUnknownErr;
		}
	}
	
	// Append the name of the framework to the URL.
	
	if (err == noErr) {
		bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
		if (bundleURL == nil) {
			err = coreFoundationUnknownErr;
		}
	}
	
	// Create a bundle based on that URL and load the bundle into memory.
	// We never unload the bundle, which is reasonable in this case because 
	// the sample assumes that you'll be calling functions from this 
	// framework throughout the life of your application.
	if (err == noErr) {
		*bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
		if (*bundlePtr == nil) {
			err = coreFoundationUnknownErr;
		}
	}

	// first check if bundle is already loaded - if it is, there's no need
	// to load it
	if (!CFBundleIsExecutableLoaded(*bundlePtr))
	{
		if (err == noErr) {
		    if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
				err = coreFoundationUnknownErr;
		    }
		}
	}

	// Clean up.
	
	if (err != noErr && *bundlePtr != nil) {
		CFRelease(*bundlePtr);
		*bundlePtr = nil;
	}
	if (bundleURL != nil) {
		CFRelease(bundleURL);
	}	
	if (baseURL != nil) {
		CFRelease(baseURL);
	}	
	
	return err;
}
コード例 #8
0
__private_extern__ void _CFBundlePlugInLoaded(CFBundleRef bundle) {
    CFDictionaryRef infoDict = CFBundleGetInfoDictionary(bundle);
    CFStringRef tempStr;
    CFPlugInDynamicRegisterFunction func = NULL;

    if (!__CFBundleGetPlugInData(bundle)->_isPlugIn || __CFBundleGetPlugInData(bundle)->_isDoingDynamicRegistration || !infoDict || !CFBundleIsExecutableLoaded(bundle)) return;

    tempStr = (CFStringRef)CFDictionaryGetValue(infoDict, CFSTR("CFPlugInNeedsDynamicRegistration"));
    if (tempStr && CFGetTypeID(tempStr) == CFStringGetTypeID() && CFStringCompare(tempStr, CFSTR("YES"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
        CFDictionaryRemoveValue((CFMutableDictionaryRef)infoDict, CFSTR("CFPlugInNeedsDynamicRegistration"));
        tempStr = (CFStringRef)CFDictionaryGetValue(infoDict, kCFPlugInDynamicRegisterFunctionKey);
        if (!tempStr || CFGetTypeID(tempStr) != CFStringGetTypeID() || CFStringGetLength(tempStr) <= 0) tempStr = CFSTR("CFPlugInDynamicRegister");
        __CFBundleGetPlugInData(bundle)->_loadOnDemand = false;
        __CFBundleGetPlugInData(bundle)->_isDoingDynamicRegistration = true;

        /* Find the symbol and call it. */
        func = (CFPlugInDynamicRegisterFunction)CFBundleGetFunctionPointerForName(bundle, tempStr);
        if (func) {
            func(bundle);
            // MF:!!! Unload function is never called.  Need to deal with this!
        }

        __CFBundleGetPlugInData(bundle)->_isDoingDynamicRegistration = false;
        if (__CFBundleGetPlugInData(bundle)->_loadOnDemand && __CFBundleGetPlugInData(bundle)->_instanceCount == 0) CFBundleUnloadExecutable(bundle);   // Unload now if we can/should.
    } else {
        CFDictionaryRemoveValue((CFMutableDictionaryRef)infoDict, CFSTR("CFPlugInNeedsDynamicRegistration"));
    }
}