static void cockpit_auth_session_login_async (CockpitAuth *self, const gchar *path, GHashTable *headers, const gchar *remote_peer, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *result; SessionLoginData *sl; GBytes *input; gchar *application; gchar *type = NULL; result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, cockpit_auth_session_login_async); application = cockpit_auth_parse_application (path); input = cockpit_auth_parse_authorization (headers, &type); if (input && application) { sl = g_new0 (SessionLoginData, 1); sl->remote_peer = g_strdup (remote_peer); sl->auth_type = type; sl->authorization = g_bytes_ref (input); sl->application = application; application = NULL; g_simple_async_result_set_op_res_gpointer (result, sl, session_login_data_free); sl->session_pipe = spawn_session_process (type, input, remote_peer, &sl->auth_pipe); if (sl->session_pipe) { g_signal_connect (sl->auth_pipe, "close", G_CALLBACK (on_session_login_done), g_object_ref (result)); } else { g_simple_async_result_set_error (result, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "Internal error starting session process"); g_simple_async_result_complete_in_idle (result); } } else { g_free (type); g_simple_async_result_set_error (result, COCKPIT_ERROR, COCKPIT_ERROR_AUTHENTICATION_FAILED, "Authentication required"); g_simple_async_result_complete_in_idle (result); } g_bytes_unref (input); g_free (application); g_object_unref (result); }
static void cockpit_auth_choose_login_async (CockpitAuth *self, const gchar *path, GHashTable *headers, const gchar *remote_peer, GAsyncReadyCallback callback, gpointer user_data) { const gchar *action; gchar *application = NULL; gchar *type = NULL; application = cockpit_auth_parse_application (path); type = cockpit_auth_parse_authorization_type (headers); if (!type) type = g_strdup ("negotiate"); action = action_for_type (type, application, self->login_loopback); if (g_strcmp0 (action, ACTION_SPAWN_HEADER) == 0) { cockpit_auth_spawn_login_async (self, application, type, FALSE, headers, remote_peer, callback, user_data); } else if (g_strcmp0 (action, ACTION_SPAWN_DECODE) == 0) { cockpit_auth_spawn_login_async (self, application, type, TRUE, headers, remote_peer, callback, user_data); } else if (g_strcmp0 (action, ACTION_SSH) == 0) { cockpit_auth_remote_login_async (self, application, type, headers, remote_peer, callback, user_data); } else if (g_strcmp0 (action, ACTION_CONVERSATION) == 0) { cockpit_auth_resume_async (self, application, type, headers, remote_peer, callback, user_data); } else if (g_strcmp0 (action, ACTION_NONE) == 0) { cockpit_auth_none_login_async (self, callback, user_data); } else { g_message ("got unknown login action: %s", action); cockpit_auth_none_login_async (self, callback, user_data); } g_free (type); g_free (application); }
static void handle_noauth_socket (GIOStream *io_stream, const gchar *path, GHashTable *headers, GByteArray *input_buffer) { WebSocketConnection *connection; gchar *application; application = cockpit_auth_parse_application (path); connection = cockpit_web_service_create_socket (NULL, application, io_stream, headers, input_buffer); g_free (application); g_signal_connect (connection, "open", G_CALLBACK (on_web_socket_noauth), NULL); /* Unreferences connection when it closes */ g_signal_connect (connection, "close", G_CALLBACK (g_object_unref), NULL); }
static CockpitAuthenticated * authenticated_for_headers (CockpitAuth *self, const gchar *path, GHashTable *in_headers) { gchar *cookie = NULL; gchar *raw = NULL; const char *prefix = "v=2;k="; CockpitAuthenticated *ret = NULL; gchar *application; gchar *cookie_name = NULL; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (in_headers != NULL, FALSE); application = cockpit_auth_parse_application (path); if (!application) return NULL; cookie_name = application_cookie_name (application); raw = cockpit_web_server_parse_cookie (in_headers, cookie_name); if (raw) { cookie = base64_decode_string (raw); if (cookie != NULL) { if (g_str_has_prefix (cookie, prefix)) ret = g_hash_table_lookup (self->authenticated, cookie); else g_debug ("invalid or unsupported cookie: %s", cookie); g_free (cookie); } g_free (raw); } g_free (application); g_free (cookie_name); return ret; }