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

Move agents whitelist to a configuration file

parent f585fe60
......@@ -185,6 +185,7 @@ AC_CONFIG_FILES([
src/geoip-server/Makefile
po/Makefile.in
data/org.freedesktop.GeoClue2.conf
data/geoclue.conf
data/Makefile
demo/Makefile
docs/Makefile
......
sysconf_DATA = geoclue.conf
servicedir = $(datadir)/dbus-1/system-services
service_in_files = org.freedesktop.GeoClue2.service.in
service_DATA = $(service_in_files:.service.in=.service)
......
# Configuration file for Geoclue
# Agent configuration options
[agent]
# Whitelist of all agents we recognise, as their commandlines. The commandlines
# do not need to be complete and geoclue only checks if the actual commandline
# has the specified prefix.
whitelist=@abs_top_srcdir@/demo/agent;/usr/bin/gnome-shell
......@@ -30,6 +30,8 @@ geoclue_SOURCES = \
gclue-main.c \
gclue-client-info.h \
gclue-client-info.c \
gclue-config.h \
gclue-config.c \
gclue-error.h \
gclue-error.c \
gclue-ipclient.h \
......@@ -50,7 +52,8 @@ geoclue_CFLAGS = $(GEOCLUE_CFLAGS) \
$(WARN_CFLAGS) \
-DLOCALEDIR="\"$(datadir)/locale\"" \
-DG_LOG_DOMAIN=\""Geoclue"\" \
-DABS_TOP_SRCDIR=\""$(abs_top_srcdir)"\"
-DABS_TOP_SRCDIR=\""$(abs_top_srcdir)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\"
geoclue_LDADD = $(GEOCLUE_LIBS) $(LIBS)
CLEANFILES = $(BUILT_SOURCES)
......
/* vim: set et ts=8 sw=8: */
/* gclue-config.c
*
* Copyright (C) 2013 Red Hat, Inc.
*
* Geoclue is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* Geoclue is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
*/
#include <glib/gi18n.h>
#include "gclue-config.h"
#define CONFIG_FILE_PATH SYSCONFDIR "/geoclue.conf"
/* This class will be responsible for fetching configuration. */
G_DEFINE_TYPE (GClueConfig, gclue_config, G_TYPE_OBJECT)
struct _GClueConfigPrivate
{
GKeyFile *key_file;
};
static void
gclue_config_finalize (GObject *object)
{
GClueConfigPrivate *priv;
priv = GCLUE_CONFIG (object)->priv;
g_clear_pointer (&priv->key_file, g_key_file_unref);
G_OBJECT_CLASS (gclue_config_parent_class)->finalize (object);
}
static void
gclue_config_class_init (GClueConfigClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gclue_config_finalize;
g_type_class_add_private (object_class, sizeof (GClueConfigPrivate));
}
static void
gclue_config_init (GClueConfig *config)
{
GError *error = NULL;
config->priv =
G_TYPE_INSTANCE_GET_PRIVATE (config,
GCLUE_TYPE_CONFIG,
GClueConfigPrivate);
config->priv->key_file = g_key_file_new ();
g_key_file_load_from_file (config->priv->key_file,
CONFIG_FILE_PATH,
0,
&error);
if (error != NULL) {
g_critical ("Failed to load configuration file '%s': %s", CONFIG_FILE_PATH, error->message);
g_error_free (error);
}
}
GClueConfig *
gclue_config_get_singleton (void)
{
static GClueConfig *config = NULL;
if (config == NULL)
config = g_object_new (GCLUE_TYPE_CONFIG, NULL);
return config;
}
gchar **
gclue_config_get_agents (GClueConfig *config,
gsize *num_agents)
{
GClueConfigPrivate *priv = config->priv;
gchar **ret;
GError *error = NULL;
ret = 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 ret;
}
/* vim: set et ts=8 sw=8: */
/* gclue-config.h
*
* Copyright (C) 2013 Red Hat, Inc.
*
* Geoclue is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* Geoclue is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
*/
#ifndef GCLUE_CONFIG_H
#define GCLUE_CONFIG_H
#include <gio/gio.h>
#include "geocode-location.h"
G_BEGIN_DECLS
#define GCLUE_TYPE_CONFIG (gclue_config_get_type())
#define GCLUE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCLUE_TYPE_CONFIG, GClueConfig))
#define GCLUE_CONFIG_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCLUE_TYPE_CONFIG, GClueConfig const))
#define GCLUE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCLUE_TYPE_CONFIG, GClueConfigClass))
#define GCLUE_IS_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCLUE_TYPE_CONFIG))
#define GCLUE_IS_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCLUE_TYPE_CONFIG))
#define GCLUE_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCLUE_TYPE_CONFIG, GClueConfigClass))
typedef struct _GClueConfig GClueConfig;
typedef struct _GClueConfigClass GClueConfigClass;
typedef struct _GClueConfigPrivate GClueConfigPrivate;
struct _GClueConfig
{
GObject parent;
/*< private >*/
GClueConfigPrivate *priv;
};
struct _GClueConfigClass
{
GObjectClass parent_class;
};
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);
G_END_DECLS
#endif /* GCLUE_CONFIG_H */
......@@ -26,13 +26,10 @@
#include "gclue-service-manager.h"
#include "gclue-service-client.h"
#include "gclue-client-info.h"
#include "gclue-config.h"
#define AGENT_WAIT_TIMEOUT 1 /* seconds */
/* A whitelist of agent commandlines */
static char *whitelisted_agents[] = { ABS_TOP_SRCDIR "/demo/agent",
"/usr/bin/gnome-shell" };
static void
gclue_service_manager_manager_iface_init (GClueManagerIface *iface);
static void
......@@ -294,8 +291,11 @@ on_agent_info_new_ready (GObject *source_object,
AddAgentData *data = (AddAgentData *) user_data;
GError *error = NULL;
char *path;
GClueConfig *config;
char **whitelisted_agents;
gsize num_agents;
gboolean allowed = FALSE;
guint8 i;
gsize i;
data->info = gclue_client_info_new_finish (res, &error);
if (data->info == NULL) {
......@@ -309,7 +309,9 @@ on_agent_info_new_ready (GObject *source_object,
return;
}
for (i = 0; i < G_N_ELEMENTS (whitelisted_agents); i++) {
config = gclue_config_get_singleton ();
whitelisted_agents = gclue_config_get_agents (config, &num_agents);
for (i = 0; i < num_agents; i++) {
const char *cmd = gclue_client_info_get_cmdline (data->info);
if (g_str_has_prefix (cmd, whitelisted_agents[i])) {
......@@ -318,6 +320,7 @@ on_agent_info_new_ready (GObject *source_object,
break;
}
}
g_strfreev (whitelisted_agents);
if (!allowed) {
g_dbus_method_invocation_return_error (data->invocation,
G_DBUS_ERROR,
......
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