From 12265f95ab58cf1e8235f6ad9b4fb49f6055f21f Mon Sep 17 00:00:00 2001 From: Alexandra Ellwood Date: Wed, 15 Oct 2008 21:41:00 +0000 Subject: [PATCH] Move GUI/CLI detection from KerberosIPC into KIM ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20874 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kim/lib/mac/kim_os_library.c | 47 ++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/kim/lib/mac/kim_os_library.c b/src/kim/lib/mac/kim_os_library.c index 4d44f792d..2c4eb90d8 100644 --- a/src/kim/lib/mac/kim_os_library.c +++ b/src/kim/lib/mac/kim_os_library.c @@ -25,8 +25,8 @@ */ #include +#include #include -#include #include "k5-int.h" #include "k5-thread.h" #include @@ -96,14 +96,45 @@ kim_error kim_os_library_unlock_for_bundle_lookup (void) kim_ui_environment kim_os_library_get_ui_environment (void) { -#ifndef LEAN_CLIENT - kipc_session_attributes_t attributes = kipc_session_get_attributes (); +#ifdef KIM_BUILTIN_UI + kim_boolean has_gui_access = 0; + SessionAttributeBits sattrs = 0L; - if (attributes & kkipc_session_caller_uses_gui) { - return KIM_UI_ENVIRONMENT_GUI; - } else if (attributes & kkipc_session_has_cli_access) { - return KIM_UI_ENVIRONMENT_CLI; - } else if (attributes & kkipc_session_has_gui_access) { + has_gui_access = ((SessionGetInfo (callerSecuritySession, + NULL, &sattrs) == noErr) && + (sattrs & sessionHasGraphicAccess)); + + if (has_gui_access) { + /* 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)) { + /* Using Carbon */ + return KIM_UI_ENVIRONMENT_GUI; + } + + if (appKitBundle && CFBundleIsExecutableLoaded (appKitBundle)) { + /* Using Cocoa */ + return KIM_UI_ENVIRONMENT_GUI; + } + } + + { + int fd_stdin = fileno (stdin); + int fd_stdout = fileno (stdout); + char *fd_stdin_name = ttyname (fd_stdin); + + /* Session info isn't reliable for remote sessions. + * Check manually for terminal access with file descriptors */ + if (isatty (fd_stdin) && isatty (fd_stdout) && fd_stdin_name) { + return KIM_UI_ENVIRONMENT_CLI; + } + } + + /* If we don't have a CLI but can talk to the GUI, use that */ + if (has_gui_access) { return KIM_UI_ENVIRONMENT_GUI; } -- 2.26.2