Place structure in thread specific data to store client connection
authorAlexandra Ellwood <lxs@mit.edu>
Sun, 28 Sep 2008 23:39:25 +0000 (23:39 +0000)
committerAlexandra Ellwood <lxs@mit.edu>
Sun, 28 Sep 2008 23:39:25 +0000 (23:39 +0000)
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
src/util/mac/k5_mig_client.c
src/util/mac/k5_mig_client.h

index a011ec25139156e7c8272e7f38aa19c8477bd5bc..832724f32a17fcbc6d68301209a28a203abeee71 100644 (file)
 #include <mach/mach_error.h>
 #include <unistd.h>
 
+/* ------------------------------------------------------------------------ */
+
+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); }
     }
     
index 5ffe7deb8d4338de5decec9f7891225e026a0db4..d0556fa842e31345e833255f452356dd4367b9f9 100644 (file)
 #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 */
index b5eefdc3af781b369dece1bb6659a1779e0c38bb..10cc43f8858e17fd5dca80b59b5bbfcfc9389871 100644 (file)
@@ -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);