diff options
author | Bastien Nocera <hadess@hadess.net> | 2018-05-02 11:43:54 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2018-05-02 15:34:11 +0200 |
commit | c26ecf714c4711ca92bec892b305c7de842ffade (patch) | |
tree | fb953177c2109ab9a080d8bd1546a19cc3b7c23f | |
parent | 9d42708cc71da9799c24379b8a3533b35edde0a3 (diff) |
service-client: Split off post agent auth check
Separate the authorization checks that happen after the agent
availability is checked, to make it possible to delay that portion.
https://bugs.freedesktop.org/show_bug.cgi?id=106236
-rw-r--r-- | src/gclue-service-client.c | 80 |
1 files changed, 48 insertions, 32 deletions
diff --git a/src/gclue-service-client.c b/src/gclue-service-client.c index 695bc32..13dd19d 100644 --- a/src/gclue-service-client.c +++ b/src/gclue-service-client.c @@ -401,6 +401,53 @@ error_out: start_data_free (data); } +static void +handle_post_agent_check_auth (StartData *data) +{ + GClueServiceClientPrivate *priv = GCLUE_SERVICE_CLIENT (data->client)->priv; + GClueAccuracyLevel max_accuracy; + GClueConfig *config; + GClueAppPerm app_perm; + guint32 uid; + + uid = gclue_client_info_get_user_id (priv->client_info); + max_accuracy = gclue_agent_get_max_accuracy_level (priv->agent_proxy); + + if (max_accuracy == 0) { + // Agent disabled geolocation for the user + g_dbus_method_invocation_return_error (data->invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_ACCESS_DENIED, + "Geolocation disabled for" + " UID %u", + uid); + start_data_free (data); + return; + } + g_debug ("requested accuracy level: %u. " + "Max accuracy level allowed by agent: %u", + data->accuracy_level, max_accuracy); + data->accuracy_level = CLAMP (data->accuracy_level, 0, max_accuracy); + + config = gclue_config_get_singleton (); + app_perm = gclue_config_get_app_perm (config, + data->desktop_id, + priv->client_info); + + if (gclue_config_is_system_component (config, data->desktop_id) || + app_perm == GCLUE_APP_PERM_ALLOWED) { + complete_start (data); + return; + } + + gclue_agent_call_authorize_app (priv->agent_proxy, + data->desktop_id, + data->accuracy_level, + NULL, + on_authorize_app_ready, + data); +} + static gboolean gclue_service_client_handle_start (GClueDBusClient *client, GDBusMethodInvocation *invocation) @@ -409,7 +456,6 @@ gclue_service_client_handle_start (GClueDBusClient *client, GClueConfig *config; StartData *data; const char *desktop_id; - GClueAccuracyLevel max_accuracy; GClueAppPerm app_perm; guint32 uid; @@ -471,37 +517,7 @@ gclue_service_client_handle_start (GClueDBusClient *client, return TRUE; } - max_accuracy = gclue_agent_get_max_accuracy_level (priv->agent_proxy); - - if (max_accuracy == 0) { - // Agent disabled geolocation for the user - g_dbus_method_invocation_return_error (invocation, - G_DBUS_ERROR, - G_DBUS_ERROR_ACCESS_DENIED, - "Geolocation disabled for" - " UID %u", - uid); - start_data_free (data); - return TRUE; - } - g_debug ("requested accuracy level: %u. " - "Max accuracy level allowed by agent: %u", - data->accuracy_level, max_accuracy); - data->accuracy_level = CLAMP (data->accuracy_level, 0, max_accuracy); - - if (gclue_config_is_system_component (config, desktop_id) || - app_perm == GCLUE_APP_PERM_ALLOWED) { - complete_start (data); - - return TRUE; - } - - gclue_agent_call_authorize_app (priv->agent_proxy, - desktop_id, - data->accuracy_level, - NULL, - on_authorize_app_ready, - data); + handle_post_agent_check_auth (data); return TRUE; } |