static kim_error kim_os_selection_hints_get_dictionary_identity (CFDictionaryRef  in_dictionary,
                                                                 kim_identity    *out_identity)
{
    kim_error err = KIM_NO_ERROR;
    CFStringRef identity_cfstr = NULL;
    kim_string identity_string = NULL;

    identity_cfstr = CFDictionaryGetValue (in_dictionary, KIM_IDENTITY_HINT);
    if (!identity_cfstr || CFGetTypeID (identity_cfstr) != CFStringGetTypeID ()) {
        kim_debug_printf ("%s: Malformed hints dictionary (invalid identity).", __FUNCTION__);
        err = check_error (KIM_PREFERENCES_READ_ERR);
    }

    if (!err) {
        err = kim_os_string_create_from_cfstring (&identity_string, identity_cfstr);
    }

    if (!err) {
        err = kim_identity_create_from_string (out_identity, identity_string);
    }

    kim_string_free (&identity_string);

    return check_error (err);
}
kim_error kim_os_string_create_localized (kim_string *out_string,
                                          kim_string in_string)
{
    kim_error lock_err = kim_os_library_lock_for_bundle_lookup ();
    kim_error err = lock_err;
    kim_string string = NULL;
    CFStringRef cfkey = NULL;
    
    if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
   
    if (!err) {
        err = kim_os_string_get_cfstring (in_string, &cfkey);
    }
    
    if (!err && kim_library_allow_home_directory_access ()) {
        CFStringRef cfstring = NULL;
        CFBundleRef framework = CFBundleGetBundleWithIdentifier (CFSTR ("edu.mit.Kerberos"));
        CFBundleRef main_bundle = CFBundleGetMainBundle ();

        if (framework) {
            cfstring = CFCopyLocalizedStringFromTableInBundle (cfkey,
                                                               CFSTR ("InfoPlist"),
                                                               framework,
                                                               "");
        }
        
        if (main_bundle && !cfstring) {
            cfstring = CFCopyLocalizedStringFromTableInBundle (cfkey,
                                                                CFSTR ("InfoPlist"),
                                                               main_bundle,
                                                               "");
        }        
        
        if (!err && cfstring) {
            err = kim_os_string_create_from_cfstring (&string, cfstring);
        }
        
        if (cfstring) { CFRelease (cfstring); }
    }
    
    if (!err && !string) {
        err = kim_string_copy (&string, in_string);
    }
    
    if (!err) {
        *out_string = string;
        string = NULL;
    }
    
    if (cfkey) { CFRelease (cfkey); }
    kim_string_free (&string);
    
    if (!lock_err) { kim_os_library_unlock_for_bundle_lookup (); }
    
    return check_error (err);
}
Beispiel #3
0
kim_error kim_os_preferences_get_identity_for_key (kim_preference_key  in_key,
                                                   kim_identity        in_hardcoded_default,
                                                   kim_identity       *out_identity)
{
    kim_error err = KIM_NO_ERROR;
    kim_string string = NULL;
    CFStringRef value = NULL;

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

    if (!err) {
        err = kim_os_preferences_copy_value (in_key, CFStringGetTypeID (),
                                             (CFPropertyListRef *) &value);

    }

    if (!err && !value) {
        err = kim_os_preferences_copy_value_compat (in_key, CFStringGetTypeID (),
                                                    (CFPropertyListRef *) &value);
    }

    if (!err) {
        if (value) {
            err = kim_os_string_create_from_cfstring (&string, value);

            if (!err) {
                if (!strcmp (kim_os_preference_any_identity, string)) {
                    *out_identity = KIM_IDENTITY_ANY;

                } else {
                    err = kim_identity_create_from_string (out_identity, string);
                }
            }
        } else {
            err = kim_identity_copy (out_identity, in_hardcoded_default);
        }
    }

    kim_string_free (&string);
    if (value) { CFRelease (value); }

    return check_error (err);
}
Beispiel #4
0
kim_error kim_os_library_get_caller_name (kim_string *out_application_name)
{
    kim_error err = KIM_NO_ERROR;
    kim_string name = NULL;
    CFBundleRef bundle = CFBundleGetMainBundle ();
    CFStringRef cfname = NULL;

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

    if (!err && bundle) {
        cfname = CFBundleGetValueForInfoDictionaryKey (bundle,
                                                       kCFBundleNameKey);

        if (!cfname || CFGetTypeID (cfname) != CFStringGetTypeID ()) {
            cfname = CFBundleGetValueForInfoDictionaryKey (bundle,
                                                           kCFBundleExecutableKey);
        }

        if (cfname) {
            cfname = CFStringCreateCopy (kCFAllocatorDefault, cfname);
        }
    }

    if (!err && !cfname) {
        kim_string path = NULL;
        CFURLRef cfpath = NULL;
        CFURLRef cfpathnoext = NULL;

        err = kim_os_library_get_application_path (&path);

        if (!err) {
            cfpath = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault,
                                                              (const UInt8 *) path,
                                                              strlen (path),
                                                              0);

            if (cfpath) {
                cfpathnoext = CFURLCreateCopyDeletingPathExtension (kCFAllocatorDefault,
                                                                    cfpath);
            }

            if (cfpathnoext) {
                cfname = CFURLCopyLastPathComponent (cfpathnoext);
            } else {
                cfname = CFURLCopyLastPathComponent (cfpath);
            }
        }

        if (cfpathnoext) { CFRelease (cfpathnoext); }
        if (cfpath     ) { CFRelease (cfpath); }
        kim_string_free (&path);
    }

    if (!err && cfname) {
        err = kim_os_string_create_from_cfstring (&name, cfname);
    }

    if (!err) {
        *out_application_name = name;
        name = NULL;

    }

    if (cfname) { CFRelease (cfname); }
    kim_string_free (&name);

    return check_error (err);
}
Beispiel #5
0
kim_error kim_os_library_get_application_path (kim_string *out_path)
{
    kim_error err = KIM_NO_ERROR;
    kim_string path = NULL;
    CFBundleRef bundle = CFBundleGetMainBundle ();

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

    /* Check if the caller is a bundle */
    if (!err && bundle) {
        CFURLRef bundle_url = CFBundleCopyBundleURL (bundle);
        CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL (bundle);
        CFURLRef executable_url = CFBundleCopyExecutableURL (bundle);
        CFURLRef absolute_url = NULL;
        CFStringRef cfpath = NULL;

        if (bundle_url && resources_url && !CFEqual (bundle_url, resources_url)) {
            absolute_url = CFURLCopyAbsoluteURL (bundle_url);
        } else if (executable_url) {
            absolute_url = CFURLCopyAbsoluteURL (executable_url);
        }

        if (absolute_url) {
            cfpath = CFURLCopyFileSystemPath (absolute_url,
                                              kCFURLPOSIXPathStyle);
            if (!cfpath) { err = check_error (KIM_OUT_OF_MEMORY_ERR); }
        }

        if (!err && cfpath) {
            err = kim_os_string_create_from_cfstring (&path, cfpath);
        }

        if (cfpath        ) { CFRelease (cfpath); }
        if (absolute_url  ) { CFRelease (absolute_url); }
        if (bundle_url    ) { CFRelease (bundle_url); }
        if (resources_url ) { CFRelease (resources_url); }
        if (executable_url) { CFRelease (executable_url); }
    }

    /* Caller is not a bundle, try _NSGetExecutablePath */
    /* Note: this does not work on CFM applications */
    if (!err && !path) {
        char *buffer = NULL;
        uint32_t len = 0;

        /* Tiny stupid buffer to get the length of the path */
        if (!err) {
            buffer = malloc (1);
            if (!buffer) { err = check_error (KIM_OUT_OF_MEMORY_ERR); }
        }

        /* Get the length of the path */
        if (!err) {
            if (_NSGetExecutablePath (buffer, &len) != 0) {
                char *temp = realloc (buffer, len + 1);
                if (!temp) {
                    err = check_error (KIM_OUT_OF_MEMORY_ERR);
                } else {
                    buffer = temp;
                }
            }
        }

        /* Get the path */
        if (!err) {
            if (_NSGetExecutablePath (buffer, &len) != 0) {
                err = check_error (KIM_OUT_OF_MEMORY_ERR);
            } else {
                err = kim_string_copy (&path, buffer);
            }
        }

        if (buffer) { free (buffer); }
    }

    if (!err) {
        *out_path = path;
        path = NULL;
    }

    kim_string_free (&path);

    return check_error (err);
}
Beispiel #6
0
kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key,
                                                    kim_favorites      io_favorites)
{
    kim_error err = KIM_NO_ERROR;
    CFArrayRef value = NULL;

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

    if (!err) {
        err = kim_os_preferences_copy_value (in_key, CFArrayGetTypeID (),
                                             (CFPropertyListRef *) &value);
    }

    if (!err && value) {
        if (!value || CFArrayGetCount (value) < 1) {
            err =  kim_favorites_remove_all_identities (io_favorites);

        } else {
            CFIndex count = CFArrayGetCount (value);
            CFIndex i;

            for (i = 0; !err && i < count; i++) {
                CFDictionaryRef dictionary = NULL;
                CFStringRef cfstring = NULL;

                dictionary = (CFDictionaryRef) CFArrayGetValueAtIndex (value, i);
                if (!dictionary || CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) {
                    err = check_error (KIM_PREFERENCES_READ_ERR);
                }

                if (!err) {
                    err = kim_os_preferences_copy_value_for_dict_key (dictionary,
                                                                      kim_preference_key_client_identity,
                                                                      CFStringGetTypeID (),
                                                                      (CFPropertyListRef *) &cfstring);
                }

                if (!err && cfstring) {
                    kim_string string = NULL;
                    kim_identity identity = NULL;
                    kim_options options = KIM_OPTIONS_DEFAULT;

                    err = kim_os_string_create_from_cfstring (&string, cfstring);

                    if (!err) {
                        err = kim_identity_create_from_string (&identity, string);
                    }

                    if (!err && (CFDictionaryGetCount (dictionary) > 1)) {
                        err = kim_os_preferences_dictionary_to_options (dictionary,
                                                                        &options);
                    }

                    if (!err) {
                        err = kim_favorites_add_identity (io_favorites, identity,
                                                          options);
                    }

                    kim_string_free (&string);
                    kim_options_free (&options);
                    kim_identity_free (&identity);
                }
            }

            if (err) {
                kim_favorites_remove_all_identities (io_favorites);
            }
        }
    }

    if (value) { CFRelease (value); }

    return check_error (err);
}