Commit 9a04f588 authored by Zeeshan Ali's avatar Zeeshan Ali

config: Minor clean-up

GClueConfig should handle the checking of agent against the whitelist.
parent f6b78f3f
......@@ -88,23 +88,38 @@ gclue_config_get_singleton (void)
return config;
}
gchar **
gclue_config_get_agents (GClueConfig *config,
gsize *num_agents)
gboolean
gclue_config_is_agent_allowed (GClueConfig *config,
GClueClientInfo *agent_info)
{
GClueConfigPrivate *priv = config->priv;
gchar **ret;
const char *agent_path;
char **agents;
gsize num_agents, i;
gboolean allowed = FALSE;
GError *error = NULL;
ret = g_key_file_get_string_list (priv->key_file,
"agent",
"whitelist",
num_agents,
&error);
agents = g_key_file_get_string_list (priv->key_file,
"agent",
"whitelist",
&num_agents,
&error);
if (error != NULL) {
g_critical ("Failed to read 'agent/whitelist' key: %s", error->message);
g_error_free (error);
return FALSE;
}
agent_path = gclue_client_info_get_bin_path (agent_info);
for (i = 0; i < num_agents; i++) {
if (g_strcmp0 (agent_path, agents[i]) == 0) {
allowed = TRUE;
break;
}
}
g_strfreev (agents);
return ret;
return allowed;
}
......@@ -25,6 +25,7 @@
#include <gio/gio.h>
#include "geocode-location.h"
#include "gclue-client-info.h"
G_BEGIN_DECLS
......@@ -55,9 +56,9 @@ struct _GClueConfigClass
GType gclue_config_get_type (void) G_GNUC_CONST;
GClueConfig * gclue_config_get_singleton (void);
gchar ** gclue_config_get_agents (GClueConfig *config,
gsize *num_agents);
GClueConfig * gclue_config_get_singleton (void);
gboolean gclue_config_is_agent_allowed (GClueConfig *config,
GClueClientInfo *agent_info);
G_END_DECLS
......
......@@ -292,10 +292,6 @@ on_agent_info_new_ready (GObject *source_object,
GError *error = NULL;
char *path;
GClueConfig *config;
char **whitelisted_agents;
gsize num_agents;
gboolean allowed = FALSE;
gsize i;
data->info = gclue_client_info_new_finish (res, &error);
if (data->info == NULL) {
......@@ -310,18 +306,7 @@ on_agent_info_new_ready (GObject *source_object,
}
config = gclue_config_get_singleton ();
whitelisted_agents = gclue_config_get_agents (config, &num_agents);
for (i = 0; i < num_agents; i++) {
const char *path = gclue_client_info_get_bin_path (data->info);
if (g_strcmp0 (path, whitelisted_agents[i]) == 0) {
allowed = TRUE;
break;
}
}
g_strfreev (whitelisted_agents);
if (!allowed) {
if (!gclue_config_is_agent_allowed (config, data->info)) {
g_dbus_method_invocation_return_error (data->invocation,
G_DBUS_ERROR,
G_DBUS_ERROR_ACCESS_DENIED,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment