X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=libmoonshot%2Flibmoonshot-msrpc.c;h=6a2010d89241ff4917167c4e3df7e300aed7500f;hb=cc8495fdeae73745d095525e843c750e7c277dce;hp=c87775f7196ab2a866a9002257ad3d699905e3e5;hpb=0b311f4c0c74df1b2da100b7d143e3fa472c41f8;p=moonshot-ui.git diff --git a/libmoonshot/libmoonshot-msrpc.c b/libmoonshot/libmoonshot-msrpc.c index c87775f..6a2010d 100644 --- a/libmoonshot/libmoonshot-msrpc.c +++ b/libmoonshot/libmoonshot-msrpc.c @@ -47,6 +47,21 @@ #define MOONSHOT_ENDPOINT_NAME "/org/janet/Moonshot" #define MOONSHOT_INSTALL_PATH_KEY "Software\\Moonshot" +void *__RPC_USER MIDL_user_allocate (size_t size) { + return malloc (size); +} + +void __RPC_USER MIDL_user_free (void *data) { + if (data == NULL) + return; + + free (data); +} + +void moonshot_free (void *data) +{ + free (data); +} static MoonshotError *moonshot_error_new_from_status (MoonshotErrorCode code, DWORD status) @@ -127,7 +142,7 @@ static void launch_server (MoonshotError **error) { } length = 1023; - status = RegQueryValueEx (key, NULL, NULL, &value_type, exe_path, &length); + status = RegQueryValueEx (key, NULL, NULL, &value_type, (LPBYTE )exe_path, &length); if (value_type != REG_SZ) { *error = moonshot_error_new_with_status @@ -150,7 +165,6 @@ static void launch_server (MoonshotError **error) { } startup_info.cb = sizeof (startup_info); - success = CreateProcess (exe_path, NULL, NULL, @@ -194,8 +208,8 @@ static void bind_rpc (MoonshotError **error) if (*error != NULL) return; - /* Allow 10 seconds for the server to launch before we time out */ - for (i=0; i<100; i++) { + /* Allow 1 minute for the server to launch before we time out */ + for (i=0; i<600; i++) { Sleep (100); /* ms */ status = RpcMgmtIsServerListening (moonshot_binding_handle); @@ -216,7 +230,6 @@ static void bind_rpc (MoonshotError **error) static void init_rpc (MoonshotError **error) { static volatile LONG binding_init_flag = 2; - int status; /* Hack to avoid requiring a moonshot_init() function. Windows does not * provide any synchronisation primitives that can be statically init'ed, @@ -259,7 +272,7 @@ int moonshot_get_identity (const char *nai, char **subject_alt_name_constraint_out, MoonshotError **error) { - int success; + int success = FALSE; RpcAsyncCall call; init_rpc (error); @@ -269,12 +282,16 @@ int moonshot_get_identity (const char *nai, rpc_async_call_init (&call); - nai_out = NULL; - password_out = NULL; - server_certificate_hash_out = NULL; - ca_certificate_out = NULL; - subject_name_constraint_out = NULL; - subject_alt_name_constraint_out = NULL; + if (nai == NULL) nai = ""; + if (password == NULL) password = ""; + if (service == NULL) service = ""; + + *nai_out = NULL; + *password_out = NULL; + *server_certificate_hash_out = NULL; + *ca_certificate_out = NULL; + *subject_name_constraint_out = NULL; + *subject_alt_name_constraint_out = NULL; RPC_TRY_EXCEPT { moonshot_get_identity_rpc (&call, @@ -318,7 +335,7 @@ int moonshot_get_default_identity (char **nai_out, char **subject_alt_name_constraint_out, MoonshotError **error) { - int success; + int success = FALSE; RpcAsyncCall call; init_rpc (error); @@ -328,12 +345,12 @@ int moonshot_get_default_identity (char **nai_out, rpc_async_call_init (&call); - nai_out = NULL; - password_out = NULL; - server_certificate_hash_out = NULL; - ca_certificate_out = NULL; - subject_name_constraint_out = NULL; - subject_alt_name_constraint_out = NULL; + *nai_out = NULL; + *password_out = NULL; + *server_certificate_hash_out = NULL; + *ca_certificate_out = NULL; + *subject_name_constraint_out = NULL; + *subject_alt_name_constraint_out = NULL; RPC_TRY_EXCEPT { moonshot_get_default_identity_rpc (&call, @@ -364,3 +381,77 @@ int moonshot_get_default_identity (char **nai_out, return TRUE; }; + +int moonshot_install_id_card (const char *display_name, + const char *user_name, + const char *password, + const char *realm, + char *rules_patterns[], + int rules_patterns_length, + char *rules_always_confirm[], + int rules_always_confirm_length, + char *services[], + int services_length, + const char *ca_cert, + const char *subject, + const char *subject_alt, + const char *server_cert, + int force_flat_file_store, + MoonshotError **error) +{ + int success = FALSE; + + init_rpc (error); + if (*error != NULL) + return FALSE; + + if (user_name == NULL) user_name = ""; + if (password == NULL) password = ""; + if (realm == NULL) realm = ""; + if (ca_cert == NULL) ca_cert = ""; + if (subject == NULL) subject = ""; + if (subject_alt == NULL) subject_alt = ""; + if (server_cert == NULL) server_cert = ""; + + RPC_TRY_EXCEPT { + success = moonshot_install_id_card_rpc (display_name, + user_name, + password, + realm, + rules_patterns, + rules_patterns_length, + rules_always_confirm, + rules_always_confirm_length, + services, + services_length, + ca_cert, + subject, + subject_alt, + server_cert, + force_flat_file_store); + } + RPC_EXCEPT { + *error = moonshot_error_new_from_status (MOONSHOT_ERROR_IPC_ERROR, + RPC_GET_EXCEPTION_CODE ()); + } + RPC_END_EXCEPT + return success; +} + +BOOL WINAPI DllMain (HINSTANCE hinst, + DWORD reason, + void *reserved) +{ + if (reason == DLL_PROCESS_DETACH) { + /* Process exiting/DLL being unloaded. This is a good + * opportunity to free the RPC binding. + * + * FIXME: we can't use the msrpc-mingw routine for this in case + * it was already unloaded. I'd love to work out how to link + * that library statically into libmoonshot-0.dll. + */ + RpcBindingFree (&moonshot_binding_handle); + } + + return TRUE; +}