kim_error kim_library_set_ui_environment (kim_ui_environment in_ui_environment);
-kim_ui_environment kim_library_ui_environment (void);
-
-
kim_error kim_library_set_allow_home_directory_access (kim_boolean in_allow_access);
-kim_boolean kim_library_allow_home_directory_access (void);
-
-
kim_error kim_library_set_allow_automatic_prompting (kim_boolean in_allow_automatic_prompting);
-kim_boolean kim_library_allow_automatic_prompting (void);
+kim_error kim_library_set_application_name (kim_string in_application_name);
+
#endif /* KIM_LIBRARY_H */
kim_selection_hints_copy
kim_selection_hints_set_hint
kim_selection_hints_get_hint
-kim_selection_hints_set_application_name
-kim_selection_hints_get_application_name
kim_selection_hints_set_explanation
kim_selection_hints_get_explanation
kim_selection_hints_set_options
kim_selection_hints_copy
kim_selection_hints_set_hint
kim_selection_hints_get_hint
-kim_selection_hints_set_application_name
-kim_selection_hints_get_application_name
kim_selection_hints_set_explanation
kim_selection_hints_get_explanation
kim_selection_hints_set_options
kim_ccache_validate
kim_ccache_destroy
kim_ccache_free
+
+kim_library_set_ui_environment
+kim_library_set_allow_home_directory_access
+kim_library_set_allow_automatic_prompting
+kim_library_set_application_name
static k5_mutex_t g_allow_home_directory_access_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
static k5_mutex_t g_allow_automatic_prompting_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
static k5_mutex_t g_ui_environment_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
+static k5_mutex_t g_application_name_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
kim_boolean g_allow_home_directory_access = TRUE;
kim_boolean g_allow_automatic_prompting = TRUE;
kim_ui_environment g_ui_environment = KIM_UI_ENVIRONMENT_AUTO;
+kim_string g_application_name = NULL;
MAKE_INIT_FUNCTION(kim_thread_init);
MAKE_FINI_FUNCTION(kim_thread_fini);
err = k5_mutex_finish_init (&g_ui_environment_mutex);
}
+ if (!err) {
+ err = k5_mutex_finish_init (&g_application_name_mutex);
+ }
+
return err;
}
k5_mutex_destroy (&g_allow_home_directory_access_mutex);
k5_mutex_destroy (&g_allow_automatic_prompting_mutex);
k5_mutex_destroy (&g_ui_environment_mutex);
+ k5_mutex_destroy (&g_application_name_mutex);
}
#pragma mark -- Allow Home Directory Access --
return !err ? ui_environment : KIM_UI_ENVIRONMENT_NONE;
}
+
+#pragma mark -- Application Name --
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_library_set_application_name (kim_string in_application_name)
+{
+ kim_error err = CALL_INIT_FUNCTION (kim_thread_init);
+ kim_error mutex_err = KIM_NO_ERROR;
+
+ if (!err) {
+ mutex_err = k5_mutex_lock (&g_application_name_mutex);
+ if (mutex_err) { err = mutex_err; }
+ }
+
+ if (!err) {
+ kim_string old_application_name = g_application_name;
+
+ if (in_application_name) {
+ err = kim_string_copy (&g_application_name, in_application_name);
+ } else {
+ g_application_name = NULL;
+ }
+
+ if (!err) { kim_string_free (&old_application_name); }
+ }
+
+ if (!mutex_err) { k5_mutex_unlock (&g_application_name_mutex); }
+ return check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_library_get_application_name (kim_string *out_application_name)
+{
+ kim_error err = CALL_INIT_FUNCTION (kim_thread_init);
+ kim_error mutex_err = KIM_NO_ERROR;
+ kim_string application_name = NULL;
+
+ if (!err && !out_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+
+ if (!err) {
+ mutex_err = k5_mutex_lock (&g_application_name_mutex);
+ if (mutex_err) { err = mutex_err; }
+ }
+
+ if (!err && g_application_name) {
+ err = kim_string_copy (&application_name, g_application_name);
+ }
+
+ if (!mutex_err) { k5_mutex_unlock (&g_application_name_mutex); }
+
+ if (!err && !application_name) {
+ err = kim_os_library_get_caller_name (&application_name);
+ }
+
+ if (!err) {
+ *out_application_name = application_name;
+ application_name = NULL;
+
+ }
+
+ kim_string_free (&application_name);
+
+ return check_error (err);
+}
kim_ui_environment kim_os_library_get_ui_environment (void);
+kim_ui_environment kim_library_ui_environment (void);
+
+kim_boolean kim_library_allow_home_directory_access (void);
+
+kim_boolean kim_library_allow_automatic_prompting (void);
+
+kim_error kim_library_get_application_name (kim_string *out_application_name);
+
+/* OS-specific. Call kim_library_get_application_name */
+kim_error kim_os_library_get_caller_name (kim_string *out_application_name);
+
kim_boolean kim_os_library_caller_is_server (void);
#endif /* KIM_LIBRARY_PRIVATE_H */
struct kim_selection_hints_opaque {
kim_string application_identifier;
- kim_string application_name;
kim_string explanation;
kim_options options;
kim_boolean allow_user_interaction;
};
struct kim_selection_hints_opaque kim_selection_hints_initializer = {
- NULL,
NULL,
NULL,
KIM_OPTIONS_DEFAULT,
in_selection_hints->application_identifier);
}
- if (!err && in_selection_hints->application_name) {
- err = kim_string_copy (&selection_hints->application_name,
- in_selection_hints->application_name);
- }
-
if (!err && in_selection_hints->explanation) {
err = kim_string_copy (&selection_hints->explanation,
in_selection_hints->explanation);
/* ------------------------------------------------------------------------ */
-kim_error kim_selection_hints_set_application_name (kim_selection_hints io_selection_hints,
- kim_string in_application_name)
-{
- kim_error err = KIM_NO_ERROR;
-
- if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
- if (!err && !in_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); }
-
- if (!err) {
- err = kim_string_copy (&io_selection_hints->application_name, in_application_name);
- }
-
- return check_error (err);
-}
-
-/* ------------------------------------------------------------------------ */
-
-kim_error kim_selection_hints_get_application_name (kim_selection_hints in_selection_hints,
- kim_string *out_application_name)
-{
- kim_error err = KIM_NO_ERROR;
-
- if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
- if (!err && !out_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); }
-
- if (!err) {
- if (in_selection_hints->application_name) {
- err = kim_string_copy (out_application_name, in_selection_hints->application_name);
- } else {
- *out_application_name = NULL;
- }
- }
-
- return check_error (err);
-}
-
-/* ------------------------------------------------------------------------ */
-
kim_error kim_selection_hints_set_explanation (kim_selection_hints io_selection_hints,
kim_string in_explanation)
{
{
if (io_selection_hints && *io_selection_hints) {
kim_string_free (&(*io_selection_hints)->application_identifier);
- kim_string_free (&(*io_selection_hints)->application_name);
kim_string_free (&(*io_selection_hints)->explanation);
kim_options_free (&(*io_selection_hints)->options);
kim_string_free (&(*io_selection_hints)->service_identity);
kim_string unknown_response = NULL;
kim_boolean done = 0;
kim_comparison no_comparison, yes_comparison;
-
+
if (!err) {
err = kim_os_string_create_localized (&ask_change_password,
"KLStringPasswordExpired");
if (!err && !out_old_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
if (!err && !out_new_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
if (!err && !out_verify_password) { err = check_error (KIM_NULL_PARAMETER_ERR); }
-
+
if (!err) {
err = kim_identity_get_display_string (in_identity, &identity_string);
}
*/
#include <CoreFoundation/CoreFoundation.h>
+#include <ApplicationServices/ApplicationServices.h>
+#include <mach-o/dyld.h>
#include <Kerberos/kipc_session.h>
#include "k5-int.h"
#include "k5-thread.h"
CFStringRef mainBundleID = CFBundleGetIdentifier (mainBundle);
if (mainBundleID) {
CFComparisonResult result;
- result = CFStringCompare (mainBundleID, CFSTR("edu.mit.Kerberos.KerberosAgent"), 0);
+ result = CFStringCompare (mainBundleID, CFSTR(kim_os_agent_bundle_id), 0);
if (result == kCFCompareEqualTo) {
return TRUE;
}
return FALSE;
}
+
+#pragma mark -
+
+/* ------------------------------------------------------------------------ */
+
+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 (bundle_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);
+}
+
+/* ------------------------------------------------------------------------ */
+
+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) {
+ CFURLRef bundle_url = CFBundleCopyBundleURL (bundle);
+
+ if (bundle_url) {
+ err = LSCopyDisplayNameForURL (bundle_url, &cfname);
+ }
+
+ if (bundle_url) { CFRelease (bundle_url); }
+ }
+
+ if (!err && !name) {
+ kim_string path = NULL;
+ CFURLRef cfpath = NULL;
+
+ err = kim_os_library_get_application_path (&path);
+
+ if (!err) {
+ cfpath = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault,
+ (const UInt8 *) path,
+ strlen (path),
+ 0);
+ if (cfpath) {
+ cfname = CFURLCopyLastPathComponent (cfpath);
+ }
+ }
+
+ if (cfpath) { CFRelease (cfpath); }
+ }
+
+ 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);
+}
#include <CoreFoundation/CoreFoundation.h>
#include "kim_private.h"
+#define kim_os_agent_bundle_id "edu.mit.Kerberos.KerberosAgent"
+
kim_error kim_os_library_lock_for_bundle_lookup (void);
kim_error kim_os_library_unlock_for_bundle_lookup (void);
+kim_error kim_os_library_get_application_path (kim_string *out_path);
+
kim_error kim_os_string_create_for_key (kim_string *out_string,
kim_string in_key_string);
CFStringRef in_compare_to_cfstring,
kim_comparison *out_comparison);
+kim_error kim_os_library_get_application_path (kim_string *out_path);
+
#endif /* KIM_PRIVATE_H */
kCFStringEncodingUTF8) + 1;
string = (char *) calloc (length, sizeof (char));
- if (!string) { err = KIM_OUT_OF_MEMORY_ERR; }
+ if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); }
}
if (!err) {
#ifndef LEAN_CLIENT
-#include "kim_private.h"
+#include "kim_os_private.h"
+#include "kim_mig_types.h"
+#include "kim_mig.h"
+#define kKerberosAgentBundleID "edu.mit.Kerberos.KerberosAgent"
+#define kKerberosAgentPath "/System/Library/CoreServices/KerberosAgent.app/Contents/MacOS/KerberosAgent"
+
+#include <Kerberos/kipc_client.h>
+#include <mach/mach.h>
+#include <mach/mach_error.h>
struct kim_ui_gui_context {
+ mach_port_t port;
};
}
if (!err) {
+ context->port = MACH_PORT_NULL;
+
*out_context = context;
context = NULL;
}
{
kim_error err = KIM_NO_ERROR;
kim_ui_gui_context context = NULL;
+ kim_string path = NULL;
if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); }
}
if (!err) {
+ err = kipc_client_lookup_server (kim_os_agent_bundle_id,
+ 1 /* launch */,
+ 0 /* don't use cached port */,
+ &context->port);
+ }
+
+ if (!err) {
+ err = kim_os_library_get_application_path (&path);
+ }
+
+ if (!err) {
+ kim_mipc_in_string application_name = NULL;
+ mach_msg_type_number_t application_name_len = 0;
+ kim_mipc_in_string application_path = path;
+ mach_msg_type_number_t application_path_len = strlen (path) + 1;
+ kim_mipc_error result = 0;
+
+ err = kim_mipc_cli_init (context->port,
+ mach_task_self (),
+ application_name,
+ application_name_len,
+ application_path,
+ application_path_len,
+ &result);
+ if (!err) { err = check_error (result); }
}
if (!err) {
context = NULL;
}
+ kim_string_free (&path);
kim_os_ui_gui_context_free (&context);
return check_error (err);
if (!err) {
kim_ui_gui_context context = (kim_ui_gui_context) in_context->tcontext;
+
}
return check_error (err);
/* ------------------------------------------------------------------------ */
kim_error kim_os_ui_gui_auth_prompt (kim_ui_context *in_context,
- kim_identity in_identity,
+ kim_identity in_identity,
kim_prompt_type in_type,
kim_boolean in_hide_reply,
kim_string in_title,
--- /dev/null
+/*
+ * $Header$
+ *
+ * Copyright 2006-2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <mach/std_types.defs>
+#include <mach/mach_types.defs>
+
+import "kim_mig_types.h";
+
+subsystem kim 100;
+
+serverprefix kim_mipc_srv_;
+userprefix kim_mipc_cli_;
+
+type kim_mipc_in_string = array [] of char;
+type kim_mipc_out_string = array [] of char;
+type kim_mipc_error = int32_t;
+type kim_mipc_boolean = boolean_t;
+type kim_mipc_time = uint32_t;
+type kim_mipc_lifetime = uint32_t;
+type kim_mipc_prompt_type = uint32_t;
+
+routine init (in_server_port : mach_port_t;
+ in_application_task : task_t;
+ in_application_name : kim_mipc_in_string;
+ in_application_path : kim_mipc_in_string;
+ out out_error : kim_mipc_error);
+
+routine fini (in_server_port : mach_port_t;
+ out out_error : kim_mipc_error);
+
+
+routine enter_identity (in_server_port : mach_port_t;
+ out out_identity : kim_mipc_out_string;
+ out out_error : kim_mipc_error);
+
+routine select_identity (in_server_port : mach_port_t;
+ in_explanation : kim_mipc_in_string;
+
+ in_start_time : kim_mipc_time;
+ in_lifetime : kim_mipc_lifetime;
+ in_renewable : kim_mipc_boolean;
+ in_renewal_lifetime : kim_mipc_lifetime;
+ in_forwardable : kim_mipc_boolean;
+ in_proxiable : kim_mipc_boolean;
+ in_addressless : kim_mipc_boolean;
+ in_service_name : kim_mipc_in_string;
+
+ in_service_identity_hint : kim_mipc_in_string;
+ in_client_realm_hint : kim_mipc_in_string;
+ in_user_hint : kim_mipc_in_string;
+ in_service_realm_hint : kim_mipc_in_string;
+ in_service_hint : kim_mipc_in_string;
+ in_server_hint : kim_mipc_in_string;
+
+ out out_identity : kim_mipc_out_string;
+ out out_error : kim_mipc_error);
+
+routine auth_prompt (in_server_port : mach_port_t;
+ in_identity : kim_mipc_in_string;
+ in_prompt_type : kim_mipc_prompt_type;
+ in_hidden : kim_mipc_boolean;
+ in_title : kim_mipc_in_string;
+ in_message : kim_mipc_in_string;
+ in_description : kim_mipc_in_string;
+ out out_response : kim_mipc_out_string;
+ out out_error : kim_mipc_error);
+
+routine change_password (in_server_port : mach_port_t;
+ in_identity : kim_mipc_in_string;
+ in_old_password_expired : kim_mipc_boolean;
+ out out_old_password : kim_mipc_out_string;
+ out out_new_password : kim_mipc_out_string;
+ out out_verify_password : kim_mipc_out_string;
+ out out_error : kim_mipc_error);
+
+ routine handle_error (in_server_port : mach_port_t;
+ in_identity : kim_mipc_in_string;
+ in_error : kim_mipc_error;
+ in_message : kim_mipc_in_string;
+ in_description : kim_mipc_in_string;
+ out out_error : kim_mipc_error);
+
+
--- /dev/null
+/*
+ * $Header$
+ *
+ * Copyright 2006-2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef KIM_MIG_H
+#define KIM_MIG_H
+
+#include <kim/kim.h>
+
+typedef const char *kim_mipc_in_string;
+typedef char *kim_mipc_out_string;
+typedef int32_t kim_mipc_error;
+typedef boolean_t kim_mipc_boolean;
+typedef uint32_t kim_mipc_lifetime;
+typedef uint32_t kim_mipc_time;
+typedef uint32_t kim_mipc_prompt_type;
+
+#endif /* KIM_MIG_H */
fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err,
"while getting favorite identity %d", (int) j);
- if (!err)
- {
+ if (!err) {
kim_identity_get_display_string(compare_identity, &string);
err = kim_preferences_remove_favorite_identity(prefs, compare_identity);
fail_if_error (state, "kim_preferences_remove_favorite_identity", err,