diff options
author | Alexandra Ellwood <lxs@mit.edu> | 2008-10-15 21:41:00 +0000 |
---|---|---|
committer | Alexandra Ellwood <lxs@mit.edu> | 2008-10-15 21:41:00 +0000 |
commit | 12265f95ab58cf1e8235f6ad9b4fb49f6055f21f (patch) | |
tree | 4938d2e418eb32ad661d84fa5108eb4a05bfcdc1 /src/kim | |
parent | f393a36a63846b24219d510d41011e0d2a91d2bb (diff) | |
download | krb5-12265f95ab58cf1e8235f6ad9b4fb49f6055f21f.zip krb5-12265f95ab58cf1e8235f6ad9b4fb49f6055f21f.tar.gz krb5-12265f95ab58cf1e8235f6ad9b4fb49f6055f21f.tar.bz2 |
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
Diffstat (limited to 'src/kim')
-rw-r--r-- | src/kim/lib/mac/kim_os_library.c | 47 |
1 files 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 4d44f79..2c4eb90 100644 --- a/src/kim/lib/mac/kim_os_library.c +++ b/src/kim/lib/mac/kim_os_library.c @@ -25,8 +25,8 @@ */ #include <CoreFoundation/CoreFoundation.h> +#include <Security/AuthSession.h> #include <mach-o/dyld.h> -#include <Kerberos/kipc_session.h> #include "k5-int.h" #include "k5-thread.h" #include <krb5/krb5.h> @@ -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; } |