From b4ffa8094837bc6033930f407777f43ab2f2a02c Mon Sep 17 00:00:00 2001 From: Alexandra Ellwood Date: Sun, 28 Sep 2008 23:39:25 +0000 Subject: [PATCH] Place structure in thread specific data to store client connection port so that multiple services can be supported simultaneously. ticket: 6055 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20773 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kim/lib/mac/kim_os_ui_gui.c | 54 +++++++++++++++++++------------ src/util/mac/k5_mig_client.c | 57 +++++++++++++++++++++++++++------ src/util/mac/k5_mig_client.h | 3 +- 3 files changed, 82 insertions(+), 32 deletions(-) diff --git a/src/kim/lib/mac/kim_os_ui_gui.c b/src/kim/lib/mac/kim_os_ui_gui.c index a011ec251..832724f32 100644 --- a/src/kim/lib/mac/kim_os_ui_gui.c +++ b/src/kim/lib/mac/kim_os_ui_gui.c @@ -35,6 +35,18 @@ #include #include +/* ------------------------------------------------------------------------ */ + +static inline int32_t kim_os_ui_gui_send_request (int32_t in_launch_server, + k5_ipc_stream in_request_stream, + k5_ipc_stream *out_reply_stream) +{ + return k5_ipc_send_request (kim_os_agent_bundle_id, + in_launch_server, + in_request_stream, + out_reply_stream); +} + /* ------------------------------------------------------------------------ */ @@ -75,9 +87,9 @@ kim_error kim_os_ui_gui_init (kim_ui_context *io_context) } if (!err) { - err = k5_ipc_send_request (1 /* launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (1 /* launch server */, + request, + &reply); } if (!err) { @@ -121,9 +133,9 @@ kim_error kim_os_ui_gui_enter_identity (kim_ui_context *in_context, if (!err) { - err = k5_ipc_send_request (0 /* don't launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (0 /* don't launch server */, + request, + &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } @@ -176,9 +188,9 @@ kim_error kim_os_ui_gui_select_identity (kim_ui_context *in_context, } if (!err) { - err = k5_ipc_send_request (0 /* don't launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (0 /* don't launch server */, + request, + &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } @@ -264,9 +276,9 @@ kim_error kim_os_ui_gui_auth_prompt (kim_ui_context *in_context, } if (!err) { - err = k5_ipc_send_request (0 /* don't launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (0 /* don't launch server */, + request, + &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } @@ -333,9 +345,9 @@ kim_error kim_os_ui_gui_change_password (kim_ui_context *in_context, } if (!err) { - err = k5_ipc_send_request (0 /* don't launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (0 /* don't launch server */, + request, + &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } @@ -423,9 +435,9 @@ kim_error kim_os_ui_gui_handle_error (kim_ui_context *in_context, } if (!err) { - err = k5_ipc_send_request (0 /* don't launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (0 /* don't launch server */, + request, + &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } @@ -469,9 +481,9 @@ kim_error kim_os_ui_gui_fini (kim_ui_context *io_context) } if (!err) { - err = k5_ipc_send_request (0 /* don't launch server */, - request, - &reply); + err = kim_os_ui_gui_send_request (0 /* don't launch server */, + request, + &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } diff --git a/src/util/mac/k5_mig_client.c b/src/util/mac/k5_mig_client.c index 5ffe7deb8..d0556fa84 100644 --- a/src/util/mac/k5_mig_client.c +++ b/src/util/mac/k5_mig_client.c @@ -31,6 +31,18 @@ #include "k5_mig_replyServer.h" #include "k5-thread.h" +#define KIPC_SERVICE_COUNT 3 + +typedef struct k5_ipc_request_port { + char *service_id; + mach_port_t port; +} k5_ipc_request_port; + +static k5_ipc_request_port k5_ipc_known_ports[KIPC_SERVICE_COUNT] = { +{ "edu.mit.Kerberos.CCacheServer", MACH_PORT_NULL }, +{ "edu.mit.Kerberos.KerberosAgent", MACH_PORT_NULL }, +{ "edu.mit.Kerberos.OldKerberosAgent", MACH_PORT_NULL } }; + MAKE_INIT_FUNCTION(k5_cli_ipc_thread_init); MAKE_FINI_FUNCTION(k5_cli_ipc_thread_fini); @@ -132,7 +144,8 @@ kern_return_t k5_ipc_client_reply (mach_port_t in_reply_port, /* ------------------------------------------------------------------------ */ -int32_t k5_ipc_send_request (int32_t in_launch_server, +int32_t k5_ipc_send_request (const char *in_service_id, + int32_t in_launch_server, k5_ipc_stream in_request_stream, k5_ipc_stream *out_reply_stream) { @@ -178,17 +191,40 @@ int32_t k5_ipc_send_request (int32_t in_launch_server, } if (!err) { - request_port = k5_getspecific (K5_KEY_IPC_REQUEST_PORT); + k5_ipc_request_port *request_ports = NULL; - if (!request_port) { - request_port = malloc (sizeof (mach_port_t)); + request_ports = k5_getspecific (K5_KEY_IPC_REQUEST_PORT); + + if (!request_ports) { + int size = sizeof (*request_ports) * KIPC_SERVICE_COUNT; + + request_ports = malloc (size); if (!request_port) { err = ENOMEM; } if (!err) { - *request_port = MACH_PORT_NULL; - err = k5_setspecific (K5_KEY_IPC_REQUEST_PORT, request_port); + int i; + + for (i = 0; i < KIPC_SERVICE_COUNT; i++) { + request_ports[i].service_id = k5_ipc_known_ports [i].service_id; + request_ports[i].port = k5_ipc_known_ports [i].port; + } + + err = k5_setspecific (K5_KEY_IPC_REQUEST_PORT, request_ports); } } + + if (!err) { + int i, found = 0; + + for (i = 0; i < KIPC_SERVICE_COUNT; i++) { + if (!strcmp (in_service_id, request_ports[i].service_id)) { + found = 1; + request_port = &request_ports[i].port; + } + } + + if (!found) { err = EINVAL; } + } } if (!err) { @@ -196,8 +232,8 @@ int32_t k5_ipc_send_request (int32_t in_launch_server, } if (!err) { - err = kipc_client_lookup_server (K5_IPC_SERVER_ID, - in_launch_server, TRUE, &server_port); + err = kipc_client_lookup_server (in_service_id, in_launch_server, + TRUE, &server_port); } while (!err && !done) { @@ -224,8 +260,9 @@ int32_t k5_ipc_send_request (int32_t in_launch_server, } /* Look up server name again without using the cached copy */ - err = kipc_client_lookup_server (K5_IPC_SERVER_ID, - in_launch_server, FALSE, &server_port); + err = kipc_client_lookup_server (in_service_id, + in_launch_server, + FALSE, &server_port); } else { /* Talked to server, though we may have gotten an error */ diff --git a/src/util/mac/k5_mig_client.h b/src/util/mac/k5_mig_client.h index b5eefdc3a..10cc43f88 100644 --- a/src/util/mac/k5_mig_client.h +++ b/src/util/mac/k5_mig_client.h @@ -29,7 +29,8 @@ #include "k5-ipc_stream.h" -int32_t k5_ipc_send_request (int32_t in_launch_server, +int32_t k5_ipc_send_request (const char *in_service_id, + int32_t in_launch_server, k5_ipc_stream in_request_stream, k5_ipc_stream *out_reply_stream); -- 2.26.2