コード例 #1
0
ファイル: kim_os_preferences.c プロジェクト: Brainiarc7/pbis
kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key,
                                                   kim_identity       in_identity)
{
    kim_error err = KIM_NO_ERROR;
    CFStringRef value = NULL;
    kim_string string = NULL;

    /* in_identity can be KIM_IDENTITY_ANY */

    if (!err) {
        if (in_identity) {
            err = kim_identity_get_string (in_identity, &string);

        } else {
            err = kim_string_copy (&string, kim_os_preference_any_identity);
        }
    }

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

    if (!err) {
        err = kim_os_preferences_set_value (in_key, value);
    }

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

    return check_error (err);
}
コード例 #2
0
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);
}
コード例 #3
0
kim_error kim_os_string_compare (kim_string      in_string,
                                 kim_string      in_compare_to_string,
                                 kim_boolean     in_case_insensitive,
                                 kim_comparison *out_comparison)
{
    kim_error err = KIM_NO_ERROR;
    CFStringRef cfstring = NULL;
    CFStringRef compare_to_cfstring = NULL;
    
    if (!err && !in_string           ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !in_compare_to_string) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !out_comparison      ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    
    if (!err) {
        err = kim_os_string_get_cfstring (in_string, 
                                          &cfstring);
    }
    
    if (!err) {
        err = kim_os_string_get_cfstring (in_compare_to_string, 
                                          &compare_to_cfstring);
    }
    
    if (!err) {
        CFOptionFlags options = (in_case_insensitive ? 
                                 1 : kCFCompareCaseInsensitive);
        
        /* Returned CFComparisonResult is compatible with kim_comparison_t */
        *out_comparison = CFStringCompare (cfstring, 
                                           compare_to_cfstring, 
                                           options);            
    }
    
    if (cfstring           ) { CFRelease (cfstring); }
    if (compare_to_cfstring) { CFRelease (compare_to_cfstring); }
    
    return check_error (err);
}
コード例 #4
0
kim_error kim_os_string_compare_to_cfstring (kim_string      in_string,
                                             CFStringRef     in_compare_to_cfstring,
                                             kim_comparison *out_comparison)
{
    kim_error err = KIM_NO_ERROR;
    CFStringRef cfstring = NULL;
    
    if (!err && !in_string             ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !in_compare_to_cfstring) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !out_comparison        ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    
    if (!err) {
        err = kim_os_string_get_cfstring (in_string, &cfstring);
    }
    
    if (!err) {
        /* Returned CFComparisonResult is compatible with kim_comparison_t */
        *out_comparison = CFStringCompare (cfstring, in_compare_to_cfstring, 0);            
    }
    
    if (cfstring) { CFRelease (cfstring); }
    
    return check_error (err);
}
コード例 #5
0
static kim_error kim_os_selection_hints_create_dictionary (kim_selection_hints  in_selection_hints,
                                                           kim_identity         in_identity,
                                                           CFDictionaryRef     *out_hints_dictionary)
{
    kim_error err = KIM_NO_ERROR;
    kim_selection_hints_preference_strings preference_strings = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    kim_string identity_string = NULL;
    CFStringRef keys[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    CFStringRef values[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    CFIndex i = 0;

    if (!err && !in_selection_hints  ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !in_identity         ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
    if (!err && !out_hints_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); }

    if (!err) {
        err = kim_selection_hints_get_preference_strings (in_selection_hints, &preference_strings);
    }

    if (!err) {
        err = kim_identity_get_string (in_identity, &identity_string);
    }

    if (!err) {
        keys[i] = KIM_APPLICATION_ID_HINT;
        err = kim_os_string_get_cfstring (preference_strings.application_identifier, &values[i]);
    }

    if (!err) {
        keys[++i] = KIM_IDENTITY_HINT;
        err = kim_os_string_get_cfstring (identity_string, &values[i]);
    }

    if (!err && preference_strings.service_identity) {
        keys[++i] = KIM_SERVICE_IDENTITY_HINT;
        err = kim_os_string_get_cfstring (preference_strings.service_identity, &values[i]);
    }

    if (!err && preference_strings.user) {
        keys[++i] = KIM_USER_HINT;
        err = kim_os_string_get_cfstring (preference_strings.user, &values[i]);
    }

    if (!err && preference_strings.client_realm) {
        keys[++i] = KIM_CLIENT_REALM_HINT;
        err = kim_os_string_get_cfstring (preference_strings.client_realm, &values[i]);
    }

    if (!err && preference_strings.service) {
        keys[++i] = KIM_SERVICE_HINT;
        err = kim_os_string_get_cfstring (preference_strings.service, &values[i]);
    }

    if (!err && preference_strings.service_realm) {
        keys[++i] = KIM_SERVICE_REALM_HINT;
        err = kim_os_string_get_cfstring (preference_strings.service_realm, &values[i]);
    }

    if (!err && preference_strings.server) {
        keys[++i] = KIM_SERVER_HINT;
        err = kim_os_string_get_cfstring (preference_strings.server, &values[i]);
    }

    if (!err) {
        *out_hints_dictionary = CFDictionaryCreate (kCFAllocatorDefault,
                                                    (const void **) keys,
                                                    (const void **) values,
                                                    i+1, /* number of hints */
                                                    &kCFTypeDictionaryKeyCallBacks,
                                                    &kCFTypeDictionaryValueCallBacks);
    }

    for (i = 0; i < KIM_MAX_HINTS; i++) { if (values[i]) { CFRelease (values[i]); } }
    kim_string_free (&identity_string);

    return check_error (err);
}
コード例 #6
0
ファイル: kim_os_preferences.c プロジェクト: Brainiarc7/pbis
/* ------------------------------------------------------------------------ */
kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key,
                                                    kim_favorites      in_favorites)
{
    kim_error err = KIM_NO_ERROR;
    kim_count count = 0;
    CFMutableArrayRef array = NULL;

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

    if (!err) {
        err = kim_favorites_get_number_of_identities (in_favorites, &count);
    }

    if (!err) {
        array = CFArrayCreateMutable (kCFAllocatorDefault, count,
                                      &kCFTypeArrayCallBacks);
        if (!array) { err = KIM_OUT_OF_MEMORY_ERR; }
    }

    if (!err) {
        kim_count i;

        for (i = 0; !err && i < count; i++) {
            kim_identity identity = NULL;
            kim_options options = NULL;
            kim_string string = NULL;
            CFStringRef cfstring = NULL;
            CFMutableDictionaryRef dictionary = NULL;

            err = kim_favorites_get_identity_at_index (in_favorites, i,
                                                       &identity,
                                                       &options);

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

            if (!err) {
                err = kim_os_string_get_cfstring (string, &cfstring);
            }

            if (!err) {
                dictionary = CFDictionaryCreateMutable (kCFAllocatorDefault, 0,
                                                        &kCFTypeDictionaryKeyCallBacks,
                                                        &kCFTypeDictionaryValueCallBacks);
                if (!dictionary) { err = check_error (KIM_OUT_OF_MEMORY_ERR); }
            }

            if (!err) {
                err = kim_os_preferences_set_value_for_dict_key (dictionary,
                                                                 kim_preference_key_client_identity,
                                                                 cfstring);
            }

            if (!err && options) {
                err = kim_os_preferences_options_to_dictionary (options,
                                                                dictionary);
            }

            if (!err) {
                CFArrayAppendValue (array, dictionary);
            }

            if (dictionary) { CFRelease (dictionary); }
            if (cfstring  ) { CFRelease (cfstring); }
            kim_string_free (&string);
            kim_options_free (&options);
            kim_identity_free (&identity);
        }
    }

    if (!err) {
        err = kim_os_preferences_set_value (in_key, array);
    }

    if (array) { CFRelease (array); }

    return check_error (err);
}