예제 #1
0
UIOHOOK_API long int hook_get_pointer_acceleration_multiplier() {
	#if defined USE_IOKIT || defined USE_COREFOUNDATION
	bool successful = false;
	double multiplier;
	#endif

	long int value = -1;

	#ifdef USE_IOKIT
	if (!successful) {
		io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));

		if (service) {
			kern_return_t kren_ret = kIOReturnError;
			io_connect_t connection;

			kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection);
			if (kren_ret == kIOReturnSuccess) {
				// IOByteCount size = sizeof(multiplier);

				kren_ret = IOHIDGetAccelerationWithKey(connection, CFSTR(kIOHIDMouseAccelerationType), &multiplier);
				if (kren_ret == kIOReturnSuccess) {
					// Calculate the greatest common factor.

					unsigned long denominator = 1000000, d = denominator;
					unsigned long numerator = multiplier * denominator, gcf = numerator;

					while (d != 0) {
						unsigned long i = gcf % d;
						gcf = d;
						d = i;
					}

					value = denominator / gcf;
					successful = true;

					logger(LOG_LEVEL_INFO,	"%s [%u]: IOHIDGetAccelerationWithKey: %li.\n",
							__FUNCTION__, __LINE__, value);
				}
			}
		}
	}
	#endif

	#ifdef USE_COREFOUNDATION
	if (!successful) {
		CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("com.apple.mouse.scaling"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
		if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
			if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &multiplier)) {
				value = (long) multiplier;

				logger(LOG_LEVEL_INFO,	"%s [%u]: CFPreferencesCopyValue: %li.\n",
						__FUNCTION__, __LINE__, value);
			}
		}
	}
	#endif

	return value;
}
예제 #2
0
static char* copyDefaultLocale()
{
#if !PLATFORM(IOS_FAMILY)
    return copyShortASCIIString(static_cast<CFStringRef>(CFLocaleGetValue(adoptCF(CFLocaleCopyCurrent()).get(), kCFLocaleCollatorIdentifier)));
#else
    // FIXME: Documentation claims the code above would work on iOS 4.0 and later. After test that works, we should remove this and use that instead.
    return copyShortASCIIString(adoptCF(static_cast<CFStringRef>(CFPreferencesCopyValue(CFSTR("AppleCollationOrder"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost))).get());
#endif
}
예제 #3
0
CFTypeRef
copyDefaultValue(const char* propName)
{
	char* p;
	CFStringRef str;
	CFPropertyListRef pref;

	pthread_once(&allow_debug_once, loadAllowDebuggingDefaults);

	if (allowDebuggingDefaults == FALSE)
		return 0;

	p  = getenv(propName);
	if (p) {
		str = CGCFStringCreate((const char*)p);
		return ((CFTypeRef)str);
	}
	else {
		str = CGCFStringCreate(propName);
		if (str) {
			pref = CFPreferencesCopyValue(str,
				kCFPreferencesCurrentApplication, 
				kCFPreferencesCurrentUser,
				kCFPreferencesAnyHost);
			
			if (pref == NULL) {
				pref = CFPreferencesCopyValue(str,
					Com_apple_core,
					kCFPreferencesCurrentUser,
					kCFPreferencesAnyHost);
			}

			CFRelease((CFTypeRef)str);
		}
		else {
			pref = NULL;
		}
		
	}

	return pref;
}
CFPropertyListRef	CACFPreferences::CopyValue(CFStringRef inKey, bool inCurrentUser, bool inCurrentHost)
{
	//	synchronize to make sure that what's in memory matches what's on disk
	Synchronize(inCurrentUser, inCurrentHost, false);
	
	CFPropertyListRef theAnswer = NULL;
	CFStringRef theUser = inCurrentUser ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
	CFStringRef theHost = inCurrentHost ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
	
	theAnswer = CFPreferencesCopyValue(inKey, kCFPreferencesAnyApplication, theUser, theHost);
	
	return theAnswer;
}
예제 #5
0
파일: CollatorICU.cpp 프로젝트: Fale/qtmoko
std::auto_ptr<Collator> Collator::userDefault()
{
#if PLATFORM(DARWIN) && PLATFORM(CF)
    // Mac OS X doesn't set UNIX locale to match user-selected one, so ICU default doesn't work.
    CFStringRef collationOrder = (CFStringRef)CFPreferencesCopyValue(CFSTR("AppleCollationOrder"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
    char buf[256];
    if (collationOrder) {
        CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII);
        CFRelease(collationOrder);
        return std::auto_ptr<Collator>(new Collator(buf));
    } else
        return std::auto_ptr<Collator>(new Collator(""));
#else
    return std::auto_ptr<Collator>(new Collator(0));
#endif
}
예제 #6
0
void
loadAllowDebuggingDefaults(void)
{
	CFPropertyListRef debugPref;

	debugPref = CFPreferencesCopyValue(CGAllowDebuggingDefaults, 
		kCFPreferencesAnyApplication, 
		kCFPreferencesCurrentUser,
		kCFPreferencesAnyHost);

	if (getBool(debugPref, &allowDebuggingDefaults) == FALSE) {
		allowDebuggingDefaults = FALSE;
	}

	if (debugPref)
		CFRelease((CFTypeRef)debugPref);
}
예제 #7
0
/*
 * Obtain the CFDictionary representing this user's PKINIT client cert prefs, if it
 * exists. Returns noErr or errSecItemNotFound as appropriate.
 */
static OSStatus pkinit_get_pref_dict(
    CFDictionaryRef *dict)
{
    CFDictionaryRef theDict;
    theDict = (CFDictionaryRef)CFPreferencesCopyValue(CFSTR(kPkinitClientCertKey),
                                                      CFSTR(kPkinitClientCertApp), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
    if(theDict == NULL) {
        pkiDebug("pkinit_get_pref_dict: no kPkinitClientCertKey\n");
        return errSecItemNotFound;
    }
    if(CFGetTypeID(theDict) != CFDictionaryGetTypeID()) {
        pkiDebug("pkinit_get_pref_dict: bad kPkinitClientCertKey pref\n");
        CFRelease(theDict);
        return errSecItemNotFound;
    }
    *dict = theDict;
    return noErr;
}
static bool
security_auth_verbose(void)
{
    static dispatch_once_t onceToken;
    static bool verbose_enabled = false;
    
    //sudo defaults write /Library/Preferences/com.apple.authd verbose -bool true
    dispatch_once(&onceToken, ^{
		CFTypeRef verbose = (CFNumberRef)CFPreferencesCopyValue(CFSTR("verbose"), CFSTR(SECURITY_AUTH_NAME), kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
        
        if (verbose && CFGetTypeID(verbose) == CFBooleanGetTypeID()) {
            verbose_enabled = CFBooleanGetValue((CFBooleanRef)verbose);
        }
#if DEBUG
        syslog(LOG_NOTICE, "verbose: %s", verbose_enabled ? "enabled" : "disabled");
#endif
        CFReleaseSafe(verbose);
    });
예제 #9
0
static kim_error kim_os_preferences_copy_value_for_file (CFStringRef         in_key,
                                                         CFTypeID            in_type,
                                                         CFStringRef         in_file,
                                                         CFPropertyListRef  *out_value)
{

    kim_error err = KIM_NO_ERROR;
    CFPropertyListRef value = NULL;
    CFStringRef users[] = { kCFPreferencesCurrentUser, kCFPreferencesAnyUser, NULL };
    CFStringRef hosts[] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost, NULL };

    if (!err && !in_key   ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !in_file  ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !out_value) { err = check_error (KIM_NULL_PARAMETER_ERR); }

    if (!err) {
        kim_count u, h;

        if (!kim_library_allow_home_directory_access()) {
            users[0] = kCFPreferencesAnyUser;
            users[1] = NULL;
        }

        for (u = 0; !value && users[u]; u++) {
            for (h = 0; !value && hosts[h]; h++) {
                value = CFPreferencesCopyValue (in_key, in_file, users[u], hosts[h]);
            }
        }

        if (value && CFGetTypeID (value) != in_type) {
            err = check_error (KIM_PREFERENCES_READ_ERR);
        }
    }


    if (!err) {
        *out_value = value;
        value = NULL;
    }

    if (value) { CFRelease (value); }

    return check_error (err);
}
예제 #10
0
QLocale::Language
UnicornUtils::osxLanguageCode()
{
    CFArrayRef languages;
    languages = (CFArrayRef)CFPreferencesCopyValue( CFSTR( "AppleLanguages" ),
                                                    kCFPreferencesAnyApplication,
                                                    kCFPreferencesCurrentUser,
                                                    kCFPreferencesAnyHost );

    QString langCode;

    if ( languages != NULL )
    {
        CFStringRef uxstylelangs = CFStringCreateByCombiningStrings( kCFAllocatorDefault, languages, CFSTR( ":" ) );
        langCode = UnicornUtils::CFStringToQString( uxstylelangs ).split( ':' ).value( 0 );
    }

    return QLocale( langCode ).language();
}
PassOwnPtr<Collator> Collator::userDefault()
{
#if OS(DARWIN) && USE(CF)
    // Mac OS X doesn't set UNIX locale to match user-selected one, so ICU default doesn't work.
#if !OS(IOS)
    RetainPtr<CFLocaleRef> currentLocale = adoptCF(CFLocaleCopyCurrent());
    CFStringRef collationOrder = (CFStringRef)CFLocaleGetValue(currentLocale.get(), kCFLocaleCollatorIdentifier);
#else
    RetainPtr<CFStringRef> collationOrderRetainer = adoptCF((CFStringRef)CFPreferencesCopyValue(CFSTR("AppleCollationOrder"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
    CFStringRef collationOrder = collationOrderRetainer.get();
#endif
    char buf[256];
    if (!collationOrder)
        return adoptPtr(new Collator(""));
    CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII);
    return adoptPtr(new Collator(buf));
#else
    return adoptPtr(new Collator(0));
#endif
}
예제 #12
0
bool QMacSettingsPrivate::get(const QString &key, QVariant *value) const
{
    QCFString k = macKey(key);
    for (int i = 0; i < numDomains; ++i) {
        for (int j = 0; j < numHostNames; ++j) {
            QCFType<CFPropertyListRef> ret =
                CFPreferencesCopyValue(k, domains[i].applicationOrSuiteId, domains[i].userName,
                                       hostNames[j]);
            if (ret) {
                if (value)
                    *value = qtValue(ret);
                return true;
            }
        }

        if (!fallbacks)
            break;
    }
    return false;
}
예제 #13
0
CFStringRef NDASPreferencesGetRAIDNameByUUIDString(CFStringRef cfsUUIDString)
{
	CFDictionaryRef			dictRef = NULL;
	CFStringRef				strNameValue = NULL;
	bool					present;
		
	if (NULL == cfsUUIDString) {
		return NULL;
	}
	
	dictRef = CFPreferencesCopyValue (
									  cfsUUIDString,
									  NDAS_PREFERENCES_FILE_RAID_INFORMATION,
									  kCFPreferencesAnyUser,
									  kCFPreferencesCurrentHost
									  );
	
	if(dictRef == NULL) {
		return NULL;
	} 
		
	present = CFDictionaryGetValueIfPresent(
											dictRef,
											CFSTR(KEY_NAME_STRING),
											(const void**)&strNameValue
											);
	
	CFRelease(dictRef);
	
	if(!present || !strNameValue) {
		// Write Key is Optional.
		return NULL;
	} else {
		
		CFRetain(strNameValue);
		
		if(CFStringGetTypeID() == CFGetTypeID(strNameValue)) {
			return strNameValue;
		}
	}
}
std::auto_ptr<Collator> Collator::userDefault()
{
#if OS(DARWIN) && PLATFORM(CF)
    // Mac OS X doesn't set UNIX locale to match user-selected one, so ICU default doesn't work.
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !OS(IPHONE_OS)
    RetainPtr<CFLocaleRef> currentLocale(AdoptCF, CFLocaleCopyCurrent());
    CFStringRef collationOrder = (CFStringRef)CFLocaleGetValue(currentLocale.get(), kCFLocaleCollatorIdentifier);
#else
    RetainPtr<CFStringRef> collationOrderRetainer(AdoptCF, (CFStringRef)CFPreferencesCopyValue(CFSTR("AppleCollationOrder"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
    CFStringRef collationOrder = collationOrderRetainer.get();
#endif
    char buf[256];
    if (collationOrder) {
        CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII);
        return std::auto_ptr<Collator>(new Collator(buf));
    } else
        return std::auto_ptr<Collator>(new Collator(""));
#else
    return std::auto_ptr<Collator>(new Collator(0));
#endif
}
예제 #15
0
long int GetPointerAccelerationThreshold() {
	#if defined COREFOUNDATION
	bool successful = false;
	SInt32 threshold;
	#endif

	long int value = -1;

	#ifdef COREFOUNDATION
	if (!successful) {
		CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("mouseDriverMaxSpeed"), CFSTR("com.apple.universalaccess"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
		if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
			if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &threshold)) {
				value = (long) threshold;
			}
		}
	}
	#endif

	return value;
}
static kim_error kim_os_selection_hints_get_selection_hints_array (CFArrayRef *out_selection_hints_array)
{
    kim_error err = KIM_NO_ERROR;
    CFPropertyListRef value = NULL;
    CFStringRef users[] = { kCFPreferencesCurrentUser, kCFPreferencesAnyUser, NULL };
    CFStringRef hosts[] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost, NULL };

    if (!err && !out_selection_hints_array) { err = check_error (KIM_NULL_PARAMETER_ERR); }

    if (!err) {
        kim_count u, h;

        if (!kim_library_allow_home_directory_access()) {
            users[0] = kCFPreferencesAnyUser;
            users[1] = NULL;
        }

        for (u = 0; !value && users[u]; u++) {
            for (h = 0; !value && hosts[h]; h++) {
                value = CFPreferencesCopyValue (KIM_SELECTION_HINTS_ARRAY,
                                                KIM_SELECTION_HINTS_FILE,
                                                users[u], hosts[h]);
            }
        }

        if (value && CFGetTypeID (value) != CFArrayGetTypeID ()) {
            err = check_error (KIM_PREFERENCES_READ_ERR);
        }
    }

    if (!err) {
        *out_selection_hints_array = value;
        value = NULL;
    }

    if (value) { CFRelease (value); }

    return check_error (err);
}
예제 #17
0
uint32 CommonBlob::getCurrentVersion() {
    uint32 ret = version_MacOS_10_0;
    // If the integrity protections are turned on, use version_partition.
    // else, use version_MacOS_10_0.
    CFTypeRef integrity = (CFNumberRef)CFPreferencesCopyValue(CFSTR("KeychainIntegrity"), CFSTR("com.apple.security"), kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
    if (integrity && CFGetTypeID(integrity) == CFBooleanGetTypeID()) {
        bool integrityProtections = CFBooleanGetValue((CFBooleanRef)integrity);

        if(integrityProtections) {
            secnotice("integrity", "creating a partition keychain; global is on");
            ret = version_partition;
        } else {
            secnotice("integrity", "creating a old-style keychain; global is off");
            ret = version_MacOS_10_0;
        }
    } else {
        secnotice("integrity", "global integrity not set, defaulting to on");
        ret = version_partition;
    }
    CFReleaseSafe(integrity);

    return ret;
}
예제 #18
0
UIOHOOK_API long int hook_get_pointer_acceleration_threshold() {
	#if defined USE_COREFOUNDATION
	bool successful = false;
	SInt32 threshold;
	#endif

	long int value = -1;

	#ifdef USE_COREFOUNDATION
	if (!successful) {
		CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("mouseDriverMaxSpeed"), CFSTR("com.apple.universalaccess"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
		if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
			if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &threshold)) {
				value = (long) threshold;

				logger(LOG_LEVEL_INFO,	"%s [%u]: CFPreferencesCopyValue: %li.\n",
						__FUNCTION__, __LINE__, value);
			}
		}
	}
	#endif

	return value;
}
예제 #19
0
UInt32 NDASPreferencesGetConfiguration(CFStringRef key)
{
	CFNumberRef				cfnConfigurationValue = NULL;
	UInt32					configuration;
	
	if(key == NULL) {
		return false;
	}
		
	cfnConfigurationValue = CFPreferencesCopyValue (
													key,
													NDAS_PREFERENCES_FILE_CONFIGURATION,
													kCFPreferencesAnyUser,
													kCFPreferencesCurrentHost
													);
	
	if(cfnConfigurationValue == NULL) {
		return false;
	} 

	CFNumberGetValue(cfnConfigurationValue, kCFNumberSInt32Type, &configuration);
	
	return configuration;
}
예제 #20
0
static Boolean LoadSettingsForUser(CFStringRef username) {
	io_iterator_t		iter = 0;
	io_registry_entry_t	regEntry = 0;
	CFDictionaryRef		newSettings = NULL;
	const char			* name;
	Boolean				success = TRUE;

	if(username != NULL) {
		name = CFStringGetCStringPtr(username, kCFStringEncodingMacRoman);
		write_log(LOG_NOTICE, "Loading settings for user '%s'.", name);
	
		CFPreferencesSynchronize(CFSTR(kDriverAppID), username, 
									kCFPreferencesAnyHost);
		newSettings = CFPreferencesCopyValue(CFSTR(kCurrentParametersKey), 
											CFSTR(kDriverAppID), username, 
											kCFPreferencesAnyHost);
		if(newSettings == NULL)
			write_log(LOG_NOTICE, "No custom settings found.");
	}
	
	if(newSettings == NULL) {
		write_log(LOG_NOTICE, "Loading default settings.");
	
		CFPreferencesSynchronize(CFSTR(kDriverAppID), 
								kCFPreferencesAnyUser, 
								kCFPreferencesCurrentHost);
		newSettings = CFPreferencesCopyValue(CFSTR(kDefaultParametersKey), 
											 CFSTR(kDriverAppID), 
											 kCFPreferencesAnyUser, 
											 kCFPreferencesCurrentHost);
		if(newSettings == NULL) {
			write_log(LOG_ERR, "No default settings found.");
			success = FALSE;
			goto EXIT;
		}
	}
	
	if(IOServiceGetMatchingServices(kIOMasterPortDefault, 
									IOServiceMatching(kIOHIDSystemClass),
									&iter) != KERN_SUCCESS) {
		iter = 0;
		write_log(LOG_ERR, "Error locating HIDSystem service!");
		success = FALSE;
		goto EXIT;
	}
	
	regEntry = IOIteratorNext(iter);
	if(regEntry == 0) {
		write_log(LOG_ERR, "No HIDSystem service found!");
		success = FALSE;
		goto EXIT;
	}
	
	if(IORegistryEntrySetCFProperty(regEntry, CFSTR(kiScroll2SettingsKey), 
									newSettings) != KERN_SUCCESS) {
		write_log(LOG_ERR, "Error setting HIDSystem properties!");
		success = FALSE;
		goto EXIT;
	}
	
EXIT:
	if(newSettings != NULL) {
		CFRelease(newSettings);
		newSettings = NULL;
	}
	if(regEntry != 0) {
		IOObjectRelease(regEntry);
		regEntry = 0;
	}
	if(iter != 0) {
		IOObjectRelease(iter);
		iter = 0;
	}
	return success;
}
예제 #21
0
파일: sshversion.c 프로젝트: csm/fugu
    int
sshversion()
{
    const CFStringRef   user = kCFPreferencesCurrentUser;
    const CFStringRef   host = kCFPreferencesAnyHost;
    CFStringRef         appID = CFSTR( "edu.umich.fugu" );
    CFStringRef         key = CFSTR( "ExecutableSearchPath" );
    CFStringRef         sshbinary = NULL;
    CFRange             range = { 0, 0 };
    struct stat         st;
    int                 efd[ 2 ];
    char                *sshexec[] = { NULL, NULL, NULL }, *p;
    char                line[ MAXPATHLEN ], sshpath[ MAXPATHLEN ] = { 0 };
    int                 estatus, rr;
    
    if (( sshbinary = CFPreferencesCopyValue( key, appID, user, host )) == NULL ) {
        strcpy( sshpath, "/usr/bin/ssh" );
    } else {
        range.length = CFStringGetLength( sshbinary );
        if ( CFStringGetBytes( sshbinary, range, kCFStringEncodingUTF8, '?',
                                FALSE, sshpath, MAXPATHLEN, NULL ) == 0 ) {
            syslog( LOG_ERR, "CFStringGetBytes failed" );
            strcpy( sshpath, "/usr/bin/ssh" );
        } else {
            if ( strlen( sshpath ) + strlen( "/ssh" ) >= MAXPATHLEN ) {
                syslog( LOG_ERR, "%sssh: too long", sshpath );
                return( -1 );
            }
            strcat( sshpath, "/ssh" );
        }
        CFRelease( sshbinary );
    }
    
    if ( stat( sshpath, &st ) < 0 ) {
        syslog( LOG_ERR, "stat %s: %m", sshpath );
        return( -1 );
    }
    if ( ! S_ISREG( st.st_mode ) ||
            ! ( st.st_mode & ( S_IRUSR | S_IXUSR ))) {
        syslog( LOG_ERR, "%s cannot be executed", sshpath );
        return( -1 );
    }
    
    if ( pipe( efd ) < 0 ) {
        syslog( LOG_ERR, "pipe: %s", strerror( errno ));
        return( -1 );
    }
    
    sshexec[ 0 ] = sshpath;
    sshexec[ 1 ] = "-V";
    sshexec[ 2 ] = NULL;
    
    switch ( fork()) {
    case 0:
        if ( dup2( efd[ 1 ], 2 ) < 0 ) {
            syslog( LOG_ERR, "dup2: %s", strerror( errno ));
            break;
        }
        ( void )close( efd[ 0 ] );
        ( void )close( efd[ 1 ] );
        
        execve( sshpath, ( char ** )sshexec, NULL );
        syslog( LOG_ERR, "execve ssh -V: %s", strerror( errno ));
        break;
        
    case -1:
        ( void )close( efd[ 0 ] );
        ( void )close( efd[ 1 ] );
        syslog( LOG_ERR, "fork failed: %s", strerror( errno ));
        exit( 2 );
        
    default:
        break;
    }
    
    ( void )close( efd[ 1 ] );
    rr = read( efd[ 0 ], line, MAXPATHLEN );
    if ( rr < 0 ) {
        syslog( LOG_ERR, "read returned < 0: %s", strerror( errno ));
        return( -1 );
    }
    
    line[ rr ] = '\0';
    syslog( LOG_INFO, line );
    
    wait( &estatus );

    if (( p = strstr( line, "OpenSSH" )) == NULL ) {
        /* maybe we're dealing with an SSH.com version */
        if (( p = strstr( line, "SSH Secure Shell" )) != NULL ) {
            return( SFTP_VERSION_UNSUPPORTED );
        }
        return( -1 );
    }
    
    if (( p = strchr( line, '_' )) == NULL ) {
        return( -1 );
    }
    
    p++;
    if ( p != NULL ) {
        double	ver;
        int		i;
        char	tmp[ 4 ];
        
        for ( i = 0; i < 3; i++ ) {
            if ( *p == NULL ) break;
            tmp[ i ] = *p;
            p++;
        }
	
        ver = strtod( tmp, NULL );
        
        if ( ver < 3.5 ) {
            return( SFTP_LS_SHORT_FORM );
        } else if ( ver >= 3.9 ) {
            return( SFTP_LS_EXTENDED_LONG_FORM );
        }
        
        return( SFTP_LS_LONG_FORM );
    }
    
    return( -1 );
}
예제 #22
0
UIOHOOK_API long int hook_get_auto_repeat_rate() {
	#if defined USE_IOKIT || defined USE_COREFOUNDATION || defined USE_CARBON_LEGACY
	bool successful = false;
	SInt64 rate;
	#endif

	long int value = -1;

	#ifdef USE_IOKIT
	if (!successful) {
		io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
		if (service) {
			kern_return_t kren_ret = kIOReturnError;
			io_connect_t connection;

			kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection);
			if (kren_ret == kIOReturnSuccess) {
				IOByteCount size = sizeof(rate);

				kren_ret = IOHIDGetParameter(connection, CFSTR(kIOHIDKeyRepeatKey), (IOByteCount) sizeof(rate), &rate, &size);
				if (kren_ret == kIOReturnSuccess) {
					/* This is in some undefined unit of time that if we happen
					 * to multiply by 900 gives us the time in milliseconds. We
					 * add 0.5 to the result so that when we cast to long we
					 * actually get a rounded result.  Saves the math.h depend.
					 *
					 *    33,333,333.0 / 1000.0 / 1000.0 / 1000.0 == 0.033333333	* Fast *
					 *   100,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.1
  					 *   200,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.2
  					 *   500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.5
					 * 1,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1
					 * 1,500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1.5
					 * 2,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 2				* Slow *
					 */
					value = (long) (900.0 * ((double) rate) / 1000.0 / 1000.0 / 1000.0 + 0.5);
					successful = true;

					logger(LOG_LEVEL_INFO,	"%s [%u]: IOHIDGetParameter: %li.\n",
							__FUNCTION__, __LINE__, value);
				}
			}
		}
	}
	#endif

	#ifdef USE_COREFOUNDATION
	if (!successful) {
		CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("KeyRepeat"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
		if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
			if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &rate)) {
				// This is the slider value, we must multiply by 15 to convert to milliseconds.
				value = (long) rate * 15;
				successful = true;

				logger(LOG_LEVEL_INFO,	"%s [%u]: CFPreferencesCopyValue: %li.\n",
						__FUNCTION__, __LINE__, value);
			}
		}
	}
	#endif

	#ifdef USE_CARBON_LEGACY
	if (!successful) {
		// Apple documentation states that value is in 'ticks'. I am not sure
		// what that means, but it looks a lot like the arbitrary slider value.
		rate = LMGetKeyRepThresh();
		if (rate > -1) {
			/* This is the slider value, we must multiply by 15 to convert to
			 * milliseconds.
			 */
			value = (long) rate * 15;
			successful = true;

			logger(LOG_LEVEL_INFO,	"%s [%u]: LMGetKeyRepThresh: %li.\n",
					__FUNCTION__, __LINE__, value);
		}
	}
	#endif

	return value;
}
예제 #23
0
UIOHOOK_API long int hook_get_multi_click_time() {
	#if defined USE_IOKIT || defined USE_COREFOUNDATION || defined USE_CARBON_LEGACY
	bool successful = false;
	#if defined USE_IOKIT || defined USE_CARBON_LEGACY
	// This needs to be defined only if we have USE_IOKIT or USE_CARBON_LEGACY.
	SInt64 time;
	#endif
	#endif

	long int value = -1;

	#ifdef USE_IOKIT
	if (!successful) {
		io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
		if (service) {
			kern_return_t kren_ret = kIOReturnError;
			io_connect_t connection;

			kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection);
			if (kren_ret == kIOReturnSuccess) {
				IOByteCount size = sizeof(time);

				kren_ret = IOHIDGetParameter(connection, CFSTR(kIOHIDClickTimeKey), (IOByteCount) sizeof(time), &time, &size);
				if (kren_ret == kIOReturnSuccess) {
					/* This is in some undefined unit of time that if we happen
					 * to multiply by 900 gives us the time in milliseconds. We
					 * add 0.5 to the result so that when we cast to long we
					 * actually get a rounded result.  Saves the math.h depend.
					 */
					value = (long) (900.0 * ((double) time) / 1000.0 / 1000.0 / 1000.0 + 0.5);
					successful = true;

					logger(LOG_LEVEL_INFO,	"%s [%u]: IOHIDGetParameter: %li.\n",
							__FUNCTION__, __LINE__, value);
				}
			}
		}
	}
	#endif

	#ifdef USE_COREFOUNDATION
	if (!successful) {
		Float32 clicktime;
		CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("com.apple.mouse.doubleClickThreshold"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
		if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
			if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberFloat32Type, &clicktime)) {
				/* This is in some undefined unit of time that if we happen
				 * to multiply by 900 gives us the time in milliseconds.  It is
				 * completely possible that this value is in seconds and should be
				 * multiplied by 1000 but because IOKit values are undocumented and
				 * I have no idea what a Carbon 'tick' is so there really is no way
				 * to confirm this.
				 */
				value = (long) (clicktime * 900);

				logger(LOG_LEVEL_INFO,	"%s [%u]: CFPreferencesCopyValue: %li.\n",
						__FUNCTION__, __LINE__, value);
			}
		}
	}
	#endif

	#ifdef USE_CARBON_LEGACY
	if (!successful) {
		// Apple documentation states that value is in 'ticks'. I am not sure
		// what that means, but it looks a lot like the arbitrary slider value.
		time = GetDblTime();
		if (time > -1) {
			// This is the slider value, we must multiply by 15 to convert to
			// milliseconds.
			value = (long) time * 15;
			successful = true;

			logger(LOG_LEVEL_INFO,	"%s [%u]: GetDblTime: %li.\n",
					__FUNCTION__, __LINE__, value);
		}
	}
	#endif

	return value;
}
예제 #24
0
long int GetAutoRepeatDelay() {
	#if defined IOKIT || defined COREFOUNDATION || defined CARBON_LEGACY
	bool successful = false;
	SInt64 delay;
	#endif

	long int value = -1;

	#ifdef IOKIT
	if (!successful) {
		io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
		if (service) {
			kern_return_t kren_ret = kIOReturnError;
			io_connect_t connection;

			kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection);
			if (kren_ret == kIOReturnSuccess) {
				IOByteCount size = sizeof(delay);

				kren_ret = IOHIDGetParameter(connection, CFSTR(kIOHIDInitialKeyRepeatKey), (IOByteCount) sizeof(delay), &delay, &size);
				if (kren_ret == kIOReturnSuccess) {
					/* This is in some undefined unit of time that if we happen
					 * to multiply by 900 gives us the time in milliseconds. We
					 * add 0.5 to the result so that when we cast to long we
					 * actually get a rounded result.  Saves the math.h depend.
					 *
					 *    33,333,333.0 / 1000.0 / 1000.0 / 1000.0 == 0.033333333	* Fast *
					 *   100,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.1
  					 *   200,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.2
  					 *   500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.5
					 * 1,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1
					 * 1,500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1.5
					 * 2,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 2				* Slow *
					 */
					value = (long) (900.0 * ((double) delay) / 1000.0 / 1000.0 / 1000.0 + 0.5);
					successful = true;
				}
			}
		}
	}
	#endif

	#ifdef COREFOUNDATION
	if (!successful) {
		CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("InitialKeyRepeat"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
		if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
			if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &delay)) {
				// This is the slider value, we must multiply by 15 to convert to
				// milliseconds.
				printf("Test: %i\n\n", (int) delay);
				value = (long) delay * 15;
				successful = true;
			}
		}
	}
	#endif

	#ifdef CARBON_LEGACY
	if (!successful) {
		// Apple documentation states that value is in 'ticks'. I am not sure
		// what that means, but it looks a lot like the arbitrary slider value.
		delay = LMGetKeyThresh();
		if (delay > -1) {
			// This is the slider value, we must multiply by 15 to convert to
			// milliseconds.
			value = (long) delay * 15;
			successful = true;
		}
	}
	#endif

	return value;
}
예제 #25
0
//
// Query NDAS info by Slot number.
//
// Return :	-1 if Bad parameters, No memory or bad Infos.
//			0 if Not exist
//			1 if success.
//
SInt32 NDASPreferencesQueryBySlotNumber(PNDASPreferencesParameter parameter)
{
	CFStringRef				strEntryKey = NULL;	
	CFStringRef				strIDKey[4] = { NULL };
	CFStringRef				strWriteKeyKey = NULL;
	CFStringRef				strConfigurationKey = NULL;
	CFStringRef				strNameKey = NULL;
	
	CFStringRef				strIDValue[4] = { NULL };
	CFStringRef				strWriteKeyValue = NULL;
	CFNumberRef				numberConfigurationValue = NULL;
	CFStringRef				strNameValue = NULL;
	
	CFDictionaryRef			dictEntry = NULL;
	
	int						count;
	bool					present;
	SInt32					result = -1;
	CFArrayRef				cfaKeys = NULL;
	
	if(parameter == NULL || parameter->slotNumber == 0) {
		return -1;
	}

	// Read Last Value.
	CFPreferencesSynchronize( 
							 NDAS_PREFERENCES_FILE_REGISTER,
							 kCFPreferencesAnyUser, 
							 kCFPreferencesCurrentHost
							 );
	
	// Slot Number is the Key.
	strEntryKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_SLOT_NUMBER_STRING), parameter->slotNumber);
	if(NULL == strEntryKey) {
		return -1;
	}
	
	dictEntry = CFPreferencesCopyValue (
										strEntryKey,
										NDAS_PREFERENCES_FILE_REGISTER,
										kCFPreferencesAnyUser,
										kCFPreferencesCurrentHost
										);
	
	if(dictEntry == NULL) {
		result = 0;
		goto cleanup;
	}
	
	//
	// Check and Copy Values.
	//
	
	// Create Keys.
	for(count = 0; count < 4; count++) {		
		strIDKey[count] = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_ID_STRING), count);
		if(NULL == strIDKey[count]) {
			goto cleanup;
		}
	}
	strWriteKeyKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_WRITEKEY_STRING));
	strConfigurationKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_CONFIGURATION_STRING));
	if(NULL == strWriteKeyKey || NULL == strConfigurationKey) {
		goto cleanup;
	}
	
	// ID
	for(count = 0; count < 4; count++) {
		
		strIDValue[count] = NDASPreferencesGetIDorWriteKey(dictEntry, strIDKey[count]);
		if (NULL == strIDValue[count]) {
			result = -1;
			goto cleanup;			
		}
		
		if(!CFStringGetCString(strIDValue[count], parameter->chID[count], 6, CFStringGetSystemEncoding())) {
			goto cleanup;
		}
	}
	
	// Write Key.
	strWriteKeyValue = NDASPreferencesGetIDorWriteKey(dictEntry, strWriteKeyKey);
	if (NULL == strWriteKeyValue) {
		// Write Key is Optional.
		memset(parameter->chWriteKey, 0, 6);
	}
	CFStringGetCString(strWriteKeyValue, parameter->chWriteKey, 6, CFStringGetSystemEncoding());
	
	// Copy Name.
	strNameKey = CFStringCreateWithFormat(NULL, NULL, CFSTR(KEY_NAME_STRING), KEY_NAME_STRING);
	if(NULL == strNameKey) {
		goto cleanup;
	}
	
	present = CFDictionaryGetValueIfPresent(
											dictEntry,
											strNameKey,
											(const void**)&strNameValue
											);
	if(!present || !strNameValue) {
		// Name is Optional.
		parameter->cfsName = NULL;
	} else {
		
		CFRetain(strNameValue);
		
		if(CFStringGetTypeID() == CFGetTypeID(strNameValue)) {
			parameter->cfsName = CFStringCreateCopy(kCFAllocatorDefault, strNameValue);
		}
	}
	
	// Configuration.
	present = CFDictionaryGetValueIfPresent(
											dictEntry,
											strConfigurationKey,
											(const void**)&numberConfigurationValue
											);
	if(!present || !numberConfigurationValue) {
		// configuraton is Optional.
		parameter->configuration = kNDASUnitConfigurationUnmount;
	} else {
		
		CFRetain(numberConfigurationValue);
		
		// Convert CF Number to int
		CFNumberGetValue (numberConfigurationValue, kCFNumberSInt32Type, &parameter->configuration);
		
		if(parameter->configuration > kNDASNumberOfUnitConfiguration) {
			parameter->configuration = kNDASUnitConfigurationUnmount;
		}
	}
	
	result = 1;
	
cleanup:
	
	// clean up.	
	if(strEntryKey)					CFRelease(strEntryKey);
	if(dictEntry)					CFRelease(dictEntry);
	
	if(strWriteKeyKey)				CFRelease(strWriteKeyKey);
	if(strWriteKeyValue)			CFRelease(strWriteKeyValue);
	if(strNameKey)					CFRelease(strNameKey);
	if(strNameValue)				CFRelease(strNameValue);
	
	if(strConfigurationKey)			CFRelease(strConfigurationKey);
	if(numberConfigurationValue)	CFRelease(numberConfigurationValue);
	
	for(count = 0; count < 4; count++) {
		if(strIDKey[count])			CFRelease(strIDKey[count]);
		if(strIDValue[count])		CFRelease(strIDValue[count]);
	}
	
	return result;
}
OSStatus SecIdentityAddPreferenceItem(
	SecKeychainRef keychainRef,
	SecIdentityRef identityRef,
	CFStringRef idString,
	SecKeychainItemRef *itemRef)
{
    // The original implementation of SecIdentityAddPreferenceItem adds the exact string only.
    // That implementation has been moved to _SecIdentityAddPreferenceItemWithName (above),
    // and this function is a wrapper which calls it, so that existing clients will get the
    // extended behavior of server domain matching for items that specify URLs.
    // (Note that behavior is unchanged if the specified idString is not a URL.)

    BEGIN_SECAPI

    OSStatus status = errSecInternalComponent;
    CFArrayRef names = _SecIdentityCopyPossiblePaths(idString);
    if (!names) {
        return status;
    }

    CFIndex total = CFArrayGetCount(names);
    if (total > 0) {
        // add item for name (first element in array)
        CFStringRef aName = (CFStringRef)CFArrayGetValueAtIndex(names, 0);
        try {
            status = _SecIdentityAddPreferenceItemWithName(keychainRef, identityRef, aName, itemRef);
        }
        catch (const MacOSError &err)   { status=err.osStatus(); }
        catch (const CommonError &err)  { status=SecKeychainErrFromOSStatus(err.osStatus()); }
        catch (const std::bad_alloc &)  { status=errSecAllocate; }
        catch (...)                     { status=errSecInternalComponent; }
    }
    if (total > 2) {
		Boolean setDomainDefaultIdentity = FALSE;
		CFTypeRef val = (CFTypeRef)CFPreferencesCopyValue(CFSTR("SetDomainDefaultIdentity"),
														  CFSTR("com.apple.security.identities"),
														  kCFPreferencesCurrentUser,
														  kCFPreferencesAnyHost);
		if (val) {
			if (CFGetTypeID(val) == CFBooleanGetTypeID())
				setDomainDefaultIdentity = CFBooleanGetValue((CFBooleanRef)val) ? TRUE : FALSE;
			CFRelease(val);
		}
		if (setDomainDefaultIdentity) {
			// add item for domain (second-to-last element in array, e.g. "*.apple.com")
			OSStatus tmpStatus = errSecSuccess;
			CFStringRef aName = (CFStringRef)CFArrayGetValueAtIndex(names, total-2);
			try {
				tmpStatus = _SecIdentityAddPreferenceItemWithName(keychainRef, identityRef, aName, itemRef);
			}
			catch (const MacOSError &err)   { tmpStatus=err.osStatus(); }
			catch (const CommonError &err)  { tmpStatus=SecKeychainErrFromOSStatus(err.osStatus()); }
			catch (const std::bad_alloc &)  { tmpStatus=errSecAllocate; }
			catch (...)                     { tmpStatus=errSecInternalComponent; }
		}
    }

    CFRelease(names);
    return status;

    END_SECAPI
}
OSStatus SecIdentityCopyPreference(
    CFStringRef name,
    CSSM_KEYUSE keyUsage,
    CFArrayRef validIssuers,
    SecIdentityRef *identity)
{
    // The original implementation of SecIdentityCopyPreference matches the exact string only.
    // That implementation has been moved to _SecIdentityCopyPreferenceMatchingName (above),
    // and this function is a wrapper which calls it, so that existing clients will get the
    // extended behavior of server domain matching for items that specify URLs.
    // (Note that behavior is unchanged if the specified name is not a URL.)

    BEGIN_SECAPI

    CFTypeRef val = (CFTypeRef)CFPreferencesCopyValue(CFSTR("LogIdentityPreferenceLookup"),
                    CFSTR("com.apple.security"),
                    kCFPreferencesCurrentUser,
                    kCFPreferencesAnyHost);
    Boolean logging = false;
    if (val && CFGetTypeID(val) == CFBooleanGetTypeID()) {
        logging = CFBooleanGetValue((CFBooleanRef)val);
        CFRelease(val);
    }

    OSStatus status = errSecItemNotFound;
    CFArrayRef names = _SecIdentityCopyPossiblePaths(name);
    if (!names) {
        return status;
    }

    CFIndex idx, total = CFArrayGetCount(names);
    for (idx = 0; idx < total; idx++) {
        CFStringRef aName = (CFStringRef)CFArrayGetValueAtIndex(names, idx);
        try {
            status = _SecIdentityCopyPreferenceMatchingName(aName, keyUsage, validIssuers, identity);
        }
        catch (...) { status = errSecItemNotFound; }

        if (logging) {
            // get identity label
            CFStringRef labelString = NULL;
            if (!status && identity && *identity) {
                try {
                    SecPointer<Certificate> cert(Identity::required(*identity)->certificate());
                    cert->inferLabel(false, &labelString);
                }
                catch (...) { labelString = NULL; };
            }
            char *labelBuf = NULL;
            CFIndex labelBufSize = (labelString) ? CFStringGetLength(labelString) * 4 : 4;
            labelBuf = (char *)malloc(labelBufSize);
            if (!labelString || !CFStringGetCString(labelString, labelBuf, labelBufSize, kCFStringEncodingUTF8)) {
                labelBuf[0] = 0;
            }
            if (labelString) {
                CFRelease(labelString);
            }

            // get service name
            char *serviceBuf = NULL;
            CFIndex serviceBufSize = CFStringGetLength(aName) * 4;
            serviceBuf = (char *)malloc(serviceBufSize);
            if (!CFStringGetCString(aName, serviceBuf, serviceBufSize, kCFStringEncodingUTF8)) {
                serviceBuf[0] = 0;
            }

            syslog(LOG_NOTICE, "preferred identity: \"%s\" found for \"%s\"\n", labelBuf, serviceBuf);
            if (!status && name) {
                char *nameBuf = NULL;
                CFIndex nameBufSize = CFStringGetLength(name) * 4;
                nameBuf = (char *)malloc(nameBufSize);
                if (!CFStringGetCString(name, nameBuf, nameBufSize, kCFStringEncodingUTF8)) {
                    nameBuf[0] = 0;
                }
                syslog(LOG_NOTICE, "lookup complete; will use: \"%s\" for \"%s\"\n", labelBuf, nameBuf);
                free(nameBuf);
            }

            free(labelBuf);
            free(serviceBuf);
        }

        if (status == errSecSuccess) {
            break; // match found
        }
    }

    CFRelease(names);
    return status;

    END_SECAPI
}