From d36870d17e25071c8ef037b2676dcf5afba345b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 18 Jun 2015 21:56:32 +0200 Subject: [PATCH 2/2] Use the GLib 2.38 private instance data system i.e. drop g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() in favor of G_DEFINE_TYPE_WITH_PRIVATE() and *_get_instance_private(). Also removes unused polkitbackendconfigsource.? instead of converting it. Increases minimum required GLib version to 2.38. https://bugs.freedesktop.org/show_bug.cgi?id=91198 --- configure.ac | 2 +- src/polkitbackend/Makefile.am | 1 - src/polkitbackend/polkitbackendactionpool.c | 26 +- src/polkitbackend/polkitbackendconfigsource.c | 565 --------------------- src/polkitbackend/polkitbackendconfigsource.h | 98 ---- .../polkitbackendinteractiveauthority.c | 57 +-- src/polkitbackend/polkitbackendjsauthority.c | 373 +++++++------- src/polkitbackend/polkitbackendjsauthority.h | 1 - 8 files changed, 239 insertions(+), 884 deletions(-) delete mode 100644 src/polkitbackend/polkitbackendconfigsource.c delete mode 100644 src/polkitbackend/polkitbackendconfigsource.h diff --git a/configure.ac b/configure.ac index 9bdb975..061f74d 100644 --- a/configure.ac +++ b/configure.ac @@ -121,7 +121,7 @@ if test "x$GCC" = "xyes"; then changequote([,])dnl fi -PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0]) +PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.38.0]) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am index 547ca82..a80ca36 100644 --- a/src/polkitbackend/Makefile.am +++ b/src/polkitbackend/Makefile.am @@ -34,7 +34,6 @@ libpolkit_backend_1_la_SOURCES = \ polkitbackendinteractiveauthority.h polkitbackendinteractiveauthority.c \ polkitbackendjsauthority.h polkitbackendjsauthority.c \ polkitbackendactionpool.h polkitbackendactionpool.c \ - polkitbackendconfigsource.h polkitbackendconfigsource.c \ polkitbackendactionlookup.h polkitbackendactionlookup.c \ $(NULL) diff --git a/src/polkitbackend/polkitbackendactionpool.c b/src/polkitbackend/polkitbackendactionpool.c index 3894fe9..20db87a 100644 --- a/src/polkitbackend/polkitbackendactionpool.c +++ b/src/polkitbackend/polkitbackendactionpool.c @@ -111,8 +111,6 @@ enum PROP_DIRECTORY, }; -#define POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_ACTION_POOL, PolkitBackendActionPoolPrivate)) - enum { CHANGED_SIGNAL, @@ -121,14 +119,14 @@ enum static guint signals[LAST_SIGNAL] = {0}; -G_DEFINE_TYPE (PolkitBackendActionPool, polkit_backend_action_pool, G_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_PRIVATE (PolkitBackendActionPool, polkit_backend_action_pool, G_TYPE_OBJECT); static void polkit_backend_action_pool_init (PolkitBackendActionPool *pool) { PolkitBackendActionPoolPrivate *priv; - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); priv->parsed_actions = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -148,7 +146,7 @@ polkit_backend_action_pool_finalize (GObject *object) PolkitBackendActionPoolPrivate *priv; pool = POLKIT_BACKEND_ACTION_POOL (object); - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); if (priv->directory != NULL) g_object_unref (priv->directory); @@ -175,7 +173,7 @@ polkit_backend_action_pool_get_property (GObject *object, PolkitBackendActionPoolPrivate *priv; pool = POLKIT_BACKEND_ACTION_POOL (object); - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); switch (prop_id) { @@ -200,7 +198,7 @@ dir_monitor_changed (GFileMonitor *monitor, PolkitBackendActionPoolPrivate *priv; pool = POLKIT_BACKEND_ACTION_POOL (user_data); - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); /* TODO: maybe rate-limit so storms of events are collapsed into one with a 500ms resolution? * Because when editing a file with emacs we get 4-8 events.. @@ -248,7 +246,7 @@ polkit_backend_action_pool_set_property (GObject *object, GError *error; pool = POLKIT_BACKEND_ACTION_POOL (object); - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); switch (prop_id) { @@ -289,8 +287,6 @@ polkit_backend_action_pool_class_init (PolkitBackendActionPoolClass *klass) gobject_class->set_property = polkit_backend_action_pool_set_property; gobject_class->finalize = polkit_backend_action_pool_finalize; - g_type_class_add_private (klass, sizeof (PolkitBackendActionPoolPrivate)); - /** * PolkitBackendActionPool:directory: * @@ -369,7 +365,7 @@ polkit_backend_action_pool_get_action (PolkitBackendActionPool *pool, g_return_val_if_fail (POLKIT_BACKEND_IS_ACTION_POOL (pool), NULL); - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); /* TODO: just compute the name of the expected file and ensure it's parsed */ ensure_all_files (pool); @@ -427,7 +423,7 @@ polkit_backend_action_pool_get_all_actions (PolkitBackendActionPool *pool, g_return_val_if_fail (POLKIT_BACKEND_IS_ACTION_POOL (pool), NULL); - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); ensure_all_files (pool); @@ -462,7 +458,7 @@ ensure_file (PolkitBackendActionPool *pool, GError *error; gchar *uri; - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); uri = g_file_get_uri (file); @@ -508,7 +504,7 @@ ensure_all_files (PolkitBackendActionPool *pool) GFileInfo *file_info; GError *error; - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool); + priv = polkit_backend_action_pool_get_instance_private (pool); e = NULL; @@ -971,7 +967,7 @@ _end (void *data, const char *el) ParsedAction *action; PolkitBackendActionPoolPrivate *priv; - priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pd->pool); + priv = polkit_backend_action_pool_get_instance_private (pd->pool); vendor = pd->vendor; if (vendor == NULL) diff --git a/src/polkitbackend/polkitbackendconfigsource.c b/src/polkitbackend/polkitbackendconfigsource.c deleted file mode 100644 index 838bc6a..0000000 --- a/src/polkitbackend/polkitbackendconfigsource.c +++ /dev/null @@ -1,565 +0,0 @@ -/* - * Copyright (C) 2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include "config.h" - -#include -#include "polkitbackendconfigsource.h" - -/* - * SECTION:polkitbackendconfigsource - * @title: PolkitBackendConfigSource - * @short_description: Access configuration files - * - * The #PolkitBackendConfigSource class is a utility class to read - * configuration data from a set of prioritized key-value files in a - * given directory. - */ - -struct _PolkitBackendConfigSourcePrivate -{ - GFile *directory; - - GFileMonitor *directory_monitor; - - /* sorted according to priority, higher priority is first */ - GList *key_files; - - gboolean has_data; -}; - -enum -{ - PROP_0, - PROP_DIRECTORY, -}; - -enum -{ - CHANGED_SIGNAL, - LAST_SIGNAL, -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void polkit_backend_config_source_purge (PolkitBackendConfigSource *source); - -static void polkit_backend_config_source_ensure (PolkitBackendConfigSource *source); - -G_DEFINE_TYPE (PolkitBackendConfigSource, polkit_backend_config_source, G_TYPE_OBJECT); - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -polkit_backend_config_source_init (PolkitBackendConfigSource *source) -{ - source->priv = G_TYPE_INSTANCE_GET_PRIVATE (source, - POLKIT_BACKEND_TYPE_CONFIG_SOURCE, - PolkitBackendConfigSourcePrivate); -} - -static void -polkit_backend_config_source_finalize (GObject *object) -{ - PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object); - - if (source->priv->directory != NULL) - g_object_unref (source->priv->directory); - - if (source->priv->directory_monitor != NULL) - g_object_unref (source->priv->directory_monitor); - - g_list_foreach (source->priv->key_files, (GFunc) g_key_file_free, NULL); - g_list_free (source->priv->key_files); - - if (G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->finalize != NULL) - G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->finalize (object); -} - - -static void -polkit_backend_config_source_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object); - - switch (prop_id) - { - case PROP_DIRECTORY: - g_value_set_object (value, source->priv->directory); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -polkit_backend_config_source_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object); - - switch (prop_id) - { - case PROP_DIRECTORY: - source->priv->directory = g_value_dup_object (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -directory_monitor_changed (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event_type, - gpointer user_data) -{ - PolkitBackendConfigSource *source; - - source = POLKIT_BACKEND_CONFIG_SOURCE (user_data); - - if (file != NULL) - { - gchar *name; - - name = g_file_get_basename (file); - - //g_debug ("event_type=%d file=%p name=%s", event_type, file, name); - - if (!g_str_has_prefix (name, ".") && - !g_str_has_prefix (name, "#") && - g_str_has_suffix (name, ".conf") && - (event_type == G_FILE_MONITOR_EVENT_CREATED || - event_type == G_FILE_MONITOR_EVENT_DELETED || - event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)) - { - - //g_debug ("match"); - - /* now throw away all caches */ - polkit_backend_config_source_purge (source); - g_signal_emit_by_name (source, "changed"); - } - - g_free (name); - } -} - -static void -polkit_backend_config_source_constructed (GObject *object) -{ - PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object); - GError *error; - - error = NULL; - source->priv->directory_monitor = g_file_monitor_directory (source->priv->directory, - G_FILE_MONITOR_NONE, - NULL, - &error); - if (source->priv->directory_monitor == NULL) - { - gchar *dir_name; - dir_name = g_file_get_uri (source->priv->directory); - g_warning ("Error monitoring directory %s: %s", dir_name, error->message); - g_free (dir_name); - g_error_free (error); - } - else - { - g_signal_connect (source->priv->directory_monitor, - "changed", - (GCallback) directory_monitor_changed, - source); - } - - if (G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->constructed != NULL) - G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->constructed (object); -} - -static void -polkit_backend_config_source_class_init (PolkitBackendConfigSourceClass *klass) -{ - GObjectClass *gobject_class; - - gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->get_property = polkit_backend_config_source_get_property; - gobject_class->set_property = polkit_backend_config_source_set_property; - gobject_class->constructed = polkit_backend_config_source_constructed; - gobject_class->finalize = polkit_backend_config_source_finalize; - - g_type_class_add_private (klass, sizeof (PolkitBackendConfigSourcePrivate)); - - /** - * PolkitBackendConfigSource:directory: - * - * The directory to watch for configuration files. - */ - g_object_class_install_property (gobject_class, - PROP_DIRECTORY, - g_param_spec_object ("directory", - "Directory", - "The directory to watch for configuration files", - G_TYPE_FILE, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_BLURB | - G_PARAM_STATIC_NICK)); - - /** - * PolkitBackendConfiguSource::changed: - * @source: A #PolkitBackendConfigSource. - * - * Emitted when configuration files in #PolkitBackendConfiguSource:directory changes. - */ - signals[CHANGED_SIGNAL] = g_signal_new ("changed", - POLKIT_BACKEND_TYPE_CONFIG_SOURCE, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (PolkitBackendConfigSourceClass, changed), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); -} - -/** - * polkit_backend_config_source_new: - * @directory: The directory to watch. - * - * Creates a new #PolkitBackendConfigSource object that reads - * configuration from @directory. To watch for configuration changes, - * connect to the #PolkitBackendConfigSource::changed signal. - * - * Returns: A #PolkitBackendConfigSource for @directory. Free with - * g_object_unref(). - **/ -PolkitBackendConfigSource * -polkit_backend_config_source_new (GFile *directory) -{ - PolkitBackendConfigSource *source; - - source = POLKIT_BACKEND_CONFIG_SOURCE (g_object_new (POLKIT_BACKEND_TYPE_CONFIG_SOURCE, - "directory", directory, - NULL)); - - return source; -} - -static void -polkit_backend_config_source_purge (PolkitBackendConfigSource *source) -{ - g_list_foreach (source->priv->key_files, (GFunc) g_key_file_free, NULL); - g_list_free (source->priv->key_files); - source->priv->key_files = NULL; - - source->priv->has_data = FALSE; -} - -static gint -compare_filename (GFile *a, GFile *b) -{ - gchar *a_uri; - gchar *b_uri; - gint ret; - - a_uri = g_file_get_uri (a); - b_uri = g_file_get_uri (b); - - /* TODO: use ASCII sort function? */ - ret = -g_strcmp0 (a_uri, b_uri); - - return ret; -} - -static void -polkit_backend_config_source_ensure (PolkitBackendConfigSource *source) -{ - GFileEnumerator *enumerator; - GFileInfo *file_info; - GError *error; - GList *files; - GList *l; - - files = NULL; - - if (source->priv->has_data) - goto out; - - polkit_backend_config_source_purge (source); - - error = NULL; - enumerator = g_file_enumerate_children (source->priv->directory, - "standard::name", - G_FILE_QUERY_INFO_NONE, - NULL, - &error); - if (enumerator == NULL) - { - gchar *dir_name; - dir_name = g_file_get_uri (source->priv->directory); - g_warning ("Error enumerating files in %s: %s", dir_name, error->message); - g_free (dir_name); - g_error_free (error); - goto out; - } - - while ((file_info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL) - { - const gchar *name; - - name = g_file_info_get_name (file_info); - - /* only consider files ending in .conf */ - if (g_str_has_suffix (name, ".conf")) - files = g_list_prepend (files, g_file_get_child (source->priv->directory, name)); - - g_object_unref (file_info); - } - g_object_unref (enumerator); - if (error != NULL) - { - g_warning ("Error enumerating files: %s", error->message); - g_error_free (error); - goto out; - } - - files = g_list_sort (files, (GCompareFunc) compare_filename); - - /* process files; highest priority comes first */ - for (l = files; l != NULL; l = l->next) - { - GFile *file = G_FILE (l->data); - gchar *filename; - GKeyFile *key_file; - - filename = g_file_get_path (file); - - key_file = g_key_file_new (); - - error = NULL; - if (!g_key_file_load_from_file (key_file, - filename, - G_KEY_FILE_NONE, - NULL)) - { - g_warning ("Error loading key-file %s: %s", filename, error->message); - g_error_free (error); - error = NULL; - g_key_file_free (key_file); - } - else - { - source->priv->key_files = g_list_prepend (source->priv->key_files, key_file); - } - - g_free (filename); - } - - source->priv->key_files = g_list_reverse (source->priv->key_files); - source->priv->has_data = TRUE; - - out: - g_list_foreach (files, (GFunc) g_object_unref, NULL); - g_list_free (files); -} - -static GKeyFile * -find_key_file (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error) -{ - GList *l; - GKeyFile *ret; - - ret = NULL; - - for (l = source->priv->key_files; l != NULL; l = l->next) - { - GKeyFile *key_file = l->data; - - if (g_key_file_has_key (key_file, group, key, NULL)) - { - ret = key_file; - goto out; - } - } - - out: - if (ret == NULL) - g_set_error_literal (error, - G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_NOT_FOUND, - "Group/Key combo not found in any config file"); - return ret; -} - -/** - * polkit_backend_config_source_get_integer: - * @source: A PolkitBackendConfigSource. - * @group: A group name. - * @key: A key name. - * @error: Return location for error or %NULL. - * - * Gets the value associated with @key under @group_name. - * - * Returns: The value or 0 if @error is set. - **/ -gint -polkit_backend_config_source_get_integer (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error) -{ - GKeyFile *key_file; - - polkit_backend_config_source_ensure (source); - - key_file = find_key_file (source, group, key, error); - if (key_file == NULL) - return 0; - - return g_key_file_get_integer (key_file, group, key, error); -} - -/** - * polkit_backend_config_source_get_boolean: - * @source: A PolkitBackendConfigSource. - * @group: A group name. - * @key: A key name. - * @error: Return location for error or %NULL. - * - * Gets the value associated with @key under @group_name. - * - * Returns: The value or %FALSE if @error is set. - **/ -gboolean -polkit_backend_config_source_get_boolean (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error) -{ - GKeyFile *key_file; - - polkit_backend_config_source_ensure (source); - - key_file = find_key_file (source, group, key, error); - if (key_file == NULL) - return FALSE; - - return g_key_file_get_boolean (key_file, group, key, error); -} - -/** - * polkit_backend_config_source_get_double: - * @source: A PolkitBackendConfigSource. - * @group: A group name. - * @key: A key name. - * @error: Return location for error or %NULL. - * - * Gets the value associated with @key under @group_name. - * - * Returns: The value or 0.0 if @error is set. - **/ -gdouble -polkit_backend_config_source_get_double (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error) -{ - GKeyFile *key_file; - - polkit_backend_config_source_ensure (source); - - key_file = find_key_file (source, group, key, error); - if (key_file == NULL) - return 0.0; - - return g_key_file_get_double (key_file, group, key, error); -} - -/** - * polkit_backend_config_source_get_string: - * @source: A PolkitBackendConfigSource. - * @group: A group name. - * @key: A key name. - * @error: Return location for error or %NULL. - * - * Gets the value associated with @key under @group_name. - * - * Returns: The value or %NULL if @error is set. - **/ -gchar * -polkit_backend_config_source_get_string (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error) -{ - GKeyFile *key_file; - - polkit_backend_config_source_ensure (source); - - key_file = find_key_file (source, group, key, error); - if (key_file == NULL) - return NULL; - - return g_key_file_get_string (key_file, group, key, error); -} - -/** - * polkit_backend_config_source_get_string_list: - * @source: A PolkitBackendConfigSource. - * @group: A group name. - * @key: A key name. - * @error: Return location for error or %NULL. - * - * Gets the values associated with @key under @group_name. - * - * Returns: The value or %NULL if @error is set. - **/ -gchar ** -polkit_backend_config_source_get_string_list (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error) -{ - GKeyFile *key_file; - - polkit_backend_config_source_ensure (source); - - key_file = find_key_file (source, group, key, error); - if (key_file == NULL) - return NULL; - - return g_key_file_get_string_list (key_file, group, key, NULL, error); -} diff --git a/src/polkitbackend/polkitbackendconfigsource.h b/src/polkitbackend/polkitbackendconfigsource.h deleted file mode 100644 index f9a48c8..0000000 --- a/src/polkitbackend/polkitbackendconfigsource.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#if !defined (_POLKIT_BACKEND_COMPILATION) || defined(_POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H) -#error "This is a private header file." -#endif - -#ifndef __POLKIT_BACKEND_CONFIG_SOURCE_H -#define __POLKIT_BACKEND_CONFIG_SOURCE_H - -#include -#include -#include - -G_BEGIN_DECLS - -#define POLKIT_BACKEND_TYPE_CONFIG_SOURCE (polkit_backend_config_source_get_type ()) -#define POLKIT_BACKEND_CONFIG_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_CONFIG_SOURCE, PolkitBackendConfigSource)) -#define POLKIT_BACKEND_CONFIG_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_CONFIG_SOURCE, PolkitBackendConfigSourceClass)) -#define POLKIT_BACKEND_CONFIG_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_CONFIG_SOURCE,PolkitBackendConfigSourceClass)) -#define POLKIT_BACKEND_IS_CONFIG_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_CONFIG_SOURCE)) -#define POLKIT_BACKEND_IS_CONFIG_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_CONFIG_SOURCE)) - -typedef struct _PolkitBackendConfigSource PolkitBackendConfigSource; -typedef struct _PolkitBackendConfigSourceClass PolkitBackendConfigSourceClass; -typedef struct _PolkitBackendConfigSourcePrivate PolkitBackendConfigSourcePrivate; - -struct _PolkitBackendConfigSource -{ - GObject parent_instance; - PolkitBackendConfigSourcePrivate *priv; -}; - -struct _PolkitBackendConfigSourceClass -{ - /*< public >*/ - GObjectClass parent_class; - - /* Signals */ - void (*changed) (PolkitBackendConfigSource *config_source); - - /*< private >*/ - /* Padding for future expansion */ - void (*_polkit_reserved1) (void); - void (*_polkit_reserved2) (void); - void (*_polkit_reserved3) (void); - void (*_polkit_reserved4) (void); - void (*_polkit_reserved5) (void); - void (*_polkit_reserved6) (void); - void (*_polkit_reserved7) (void); - void (*_polkit_reserved8) (void); -}; - -GType polkit_backend_config_source_get_type (void) G_GNUC_CONST; -PolkitBackendConfigSource *polkit_backend_config_source_new (GFile *directory); -gint polkit_backend_config_source_get_integer (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error); -gboolean polkit_backend_config_source_get_boolean (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error); -gdouble polkit_backend_config_source_get_double (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error); -gchar *polkit_backend_config_source_get_string (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error); -gchar **polkit_backend_config_source_get_string_list (PolkitBackendConfigSource *source, - const gchar *group, - const gchar *key, - GError **error); - -G_END_DECLS - -#endif /* __POLKIT_BACKEND_CONFIG_SOURCE_H */ - diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c index 7019356..06ba785 100644 --- a/src/polkitbackend/polkitbackendinteractiveauthority.c +++ b/src/polkitbackend/polkitbackendinteractiveauthority.c @@ -32,7 +32,6 @@ #include "polkitbackendinteractiveauthority.h" #include "polkitbackendactionpool.h" #include "polkitbackendsessionmonitor.h" -#include "polkitbackendconfigsource.h" #include @@ -222,11 +221,9 @@ typedef struct /* ---------------------------------------------------------------------------------------------------- */ -G_DEFINE_TYPE (PolkitBackendInteractiveAuthority, - polkit_backend_interactive_authority, - POLKIT_BACKEND_TYPE_AUTHORITY); - -#define POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_INTERACTIVE_AUTHORITY, PolkitBackendInteractiveAuthorityPrivate)) +G_DEFINE_TYPE_WITH_PRIVATE (PolkitBackendInteractiveAuthority, + polkit_backend_interactive_authority, + POLKIT_BACKEND_TYPE_AUTHORITY); static gboolean identity_is_root_user (PolkitIdentity *user) @@ -294,7 +291,7 @@ polkit_backend_interactive_authority_init (PolkitBackendInteractiveAuthority *au /* Force registering error domain */ (void)POLKIT_ERROR; - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); directory = g_file_new_for_path (PACKAGE_DATA_DIR "/polkit-1/actions"); priv->action_pool = polkit_backend_action_pool_new (directory); @@ -348,7 +345,7 @@ polkit_backend_interactive_authority_finalize (GObject *object) PolkitBackendInteractiveAuthorityPrivate *priv; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (object); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); if (priv->name_owner_changed_signal_id > 0) g_dbus_connection_signal_unsubscribe (priv->system_bus_connection, priv->name_owner_changed_signal_id); @@ -410,10 +407,6 @@ polkit_backend_interactive_authority_class_init (PolkitBackendInteractiveAuthori authority_class->enumerate_temporary_authorizations = polkit_backend_interactive_authority_enumerate_temporary_authorizations; authority_class->revoke_temporary_authorizations = polkit_backend_interactive_authority_revoke_temporary_authorizations; authority_class->revoke_temporary_authorization_by_id = polkit_backend_interactive_authority_revoke_temporary_authorization_by_id; - - - - g_type_class_add_private (klass, sizeof (PolkitBackendInteractiveAuthorityPrivate)); } /* ---------------------------------------------------------------------------------------------------- */ @@ -429,7 +422,7 @@ polkit_backend_interactive_authority_enumerate_actions (PolkitBackendAuthority GList *actions; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); actions = polkit_backend_action_pool_get_all_actions (priv->action_pool, interactivee); @@ -566,7 +559,7 @@ log_result (PolkitBackendInteractiveAuthority *authority, gchar *subject_cmdline; gchar *caller_cmdline; - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); log_result_str = "DENYING"; if (polkit_authorization_result_get_is_authorized (result)) @@ -633,7 +626,7 @@ check_authorization_challenge_cb (AuthenticationAgent *agent, gchar *subject_cmdline; gboolean is_temp; - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); result = NULL; @@ -776,7 +769,7 @@ may_identity_check_authorization (PolkitBackendInteractiveAuthority *interacti const gchar *action_id, PolkitIdentity *identity) { - PolkitBackendInteractiveAuthorityPrivate *priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + PolkitBackendInteractiveAuthorityPrivate *priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); gboolean ret = FALSE; PolkitActionDescription *action_desc = NULL; const gchar *owners = NULL; @@ -854,7 +847,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority gchar **detail_keys; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); error = NULL; caller_str = NULL; @@ -1073,7 +1066,7 @@ check_authorization_sync (PolkitBackendAuthority *authority, GList *l; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); result = NULL; @@ -1688,7 +1681,7 @@ get_authentication_agent_for_subject (PolkitBackendInteractiveAuthority *authori AuthenticationAgent *agent_fallback = NULL; gboolean fallback = FALSE; - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); agent = g_hash_table_lookup (priv->hash_scope_to_authentication_agent, subject); @@ -1761,7 +1754,7 @@ get_authentication_session_for_uid_and_cookie (PolkitBackendInteractiveAuthority /* TODO: perhaps use a hash on the cookie to speed this up */ - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); g_hash_table_iter_init (&hash_iter, priv->hash_scope_to_authentication_agent); while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &agent)) @@ -1814,7 +1807,7 @@ get_authentication_sessions_initiated_by_system_bus_unique_name (PolkitBackendIn /* TODO: perhaps use a hash on the cookie to speed this up */ - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); g_hash_table_iter_init (&hash_iter, priv->hash_scope_to_authentication_agent); while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &agent)) @@ -1848,7 +1841,7 @@ get_authentication_sessions_for_system_bus_unique_name_subject (PolkitBackendInt /* TODO: perhaps use a hash on the cookie to speed this up */ - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); g_hash_table_iter_init (&hash_iter, priv->hash_scope_to_authentication_agent); while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &agent)) @@ -1880,7 +1873,7 @@ get_authentication_agent_by_unique_system_bus_name (PolkitBackendInteractiveAuth GHashTableIter hash_iter; AuthenticationAgent *agent; - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); g_hash_table_iter_init (&hash_iter, priv->hash_scope_to_authentication_agent); while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &agent)) @@ -2043,7 +2036,7 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority, const gchar *gettext_domain; gchar *s; - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + priv = polkit_backend_interactive_authority_get_instance_private (authority); message = NULL; icon_name = NULL; @@ -2285,7 +2278,7 @@ authentication_agent_initiate_challenge (AuthenticationAgent *agent, AuthenticationAgentCallback callback, gpointer user_data) { - PolkitBackendInteractiveAuthorityPrivate *priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority); + PolkitBackendInteractiveAuthorityPrivate *priv = polkit_backend_interactive_authority_get_instance_private (authority); AuthenticationSession *session; GList *l; GList *identities; @@ -2490,7 +2483,7 @@ polkit_backend_interactive_authority_register_authentication_agent (PolkitBacken agent = NULL; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); if (POLKIT_IS_UNIX_SESSION (subject)) { @@ -2643,7 +2636,7 @@ polkit_backend_interactive_authority_unregister_authentication_agent (PolkitBack gchar *scope_str; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); ret = FALSE; session_for_caller = NULL; @@ -2802,7 +2795,7 @@ polkit_backend_interactive_authority_authentication_agent_response (PolkitBacken gboolean ret; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); ret = FALSE; user_of_caller = NULL; @@ -2886,7 +2879,7 @@ polkit_backend_interactive_authority_system_bus_name_owner_changed (PolkitBacken PolkitBackendInteractiveAuthorityPrivate *priv; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); //g_debug ("name-owner-changed: '%s' '%s' '%s'", name, old_owner, new_owner); @@ -3287,7 +3280,7 @@ polkit_backend_interactive_authority_enumerate_temporary_authorizations (PolkitB GTimeVal real_now; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); ret = NULL; session_for_caller = NULL; @@ -3371,7 +3364,7 @@ polkit_backend_interactive_authority_revoke_temporary_authorizations (PolkitBack guint num_removed; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); ret = FALSE; session_for_caller = NULL; @@ -3451,7 +3444,7 @@ polkit_backend_interactive_authority_revoke_temporary_authorization_by_id (Polki guint num_removed; interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority); - priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (interactive_authority); + priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority); ret = FALSE; session_for_caller = NULL; diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c index 097dcc5..d60d607 100644 --- a/src/polkitbackend/polkitbackendjsauthority.c +++ b/src/polkitbackend/polkitbackendjsauthority.c @@ -145,7 +145,7 @@ static PolkitImplicitAuthorization polkit_backend_js_authority_check_authorizati PolkitDetails *details, PolkitImplicitAuthorization implicit); -G_DEFINE_TYPE (PolkitBackendJsAuthority, polkit_backend_js_authority, POLKIT_BACKEND_TYPE_INTERACTIVE_AUTHORITY); +G_DEFINE_TYPE_WITH_PRIVATE (PolkitBackendJsAuthority, polkit_backend_js_authority, POLKIT_BACKEND_TYPE_INTERACTIVE_AUTHORITY); /* ---------------------------------------------------------------------------------------------------- */ @@ -216,9 +216,6 @@ static void report_error (JSContext *cx, static void polkit_backend_js_authority_init (PolkitBackendJsAuthority *authority) { - authority->priv = G_TYPE_INSTANCE_GET_PRIVATE (authority, - POLKIT_BACKEND_TYPE_JS_AUTHORITY, - PolkitBackendJsAuthorityPrivate); } static gint @@ -252,17 +249,20 @@ rules_file_name_cmp (const gchar *a, static void load_scripts (PolkitBackendJsAuthority *authority) { + PolkitBackendJsAuthorityPrivate *priv; GList *files = NULL; GList *l; guint num_scripts = 0; GError *error = NULL; guint n; + priv = polkit_backend_js_authority_get_instance_private (authority); + files = NULL; - for (n = 0; authority->priv->rules_dirs != NULL && authority->priv->rules_dirs[n] != NULL; n++) + for (n = 0; priv->rules_dirs != NULL && priv->rules_dirs[n] != NULL; n++) { - const gchar *dir_name = authority->priv->rules_dirs[n]; + const gchar *dir_name = priv->rules_dirs[n]; GDir *dir = NULL; polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), @@ -303,14 +303,9 @@ load_scripts (PolkitBackendJsAuthority *authority) #endif #if JS_VERSION == 186 - script = JS_CompileUTF8File (authority->priv->cx, - authority->priv->js_global, - filename); - + script = JS_CompileUTF8File (priv->cx, priv->js_global, filename); #else - script = JS_CompileFile (authority->priv->cx, - authority->priv->js_global, - filename); + script = JS_CompileFile (priv->cx, priv->js_global, filename); #endif if (script == NULL) { @@ -346,17 +341,16 @@ load_scripts (PolkitBackendJsAuthority *authority) static void reload_scripts (PolkitBackendJsAuthority *authority) { + PolkitBackendJsAuthorityPrivate *priv; jsval argv[1] = {JSVAL_NULL}; jsval rval = JSVAL_NULL; - JS_BeginRequest (authority->priv->cx); + priv = polkit_backend_js_authority_get_instance_private (authority); + + JS_BeginRequest (priv->cx); - if (!JS_CallFunctionName(authority->priv->cx, - authority->priv->js_polkit, - "_deleteRules", - 0, - argv, - &rval)) + if (!JS_CallFunctionName (priv->cx, priv->js_polkit, "_deleteRules", 0, argv, + &rval)) { polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Error deleting old rules, not loading new ones"); @@ -366,9 +360,9 @@ reload_scripts (PolkitBackendJsAuthority *authority) polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Collecting garbage unconditionally..."); #if JS_VERSION == 186 - JS_GC (authority->priv->rt); + JS_GC (priv->rt); #else - JS_GC (authority->priv->cx); + JS_GC (priv->cx); #endif load_scripts (authority); @@ -376,7 +370,7 @@ reload_scripts (PolkitBackendJsAuthority *authority) /* Let applications know we have new rules... */ g_signal_emit_by_name (authority, "changed"); out: - JS_EndRequest (authority->priv->cx); + JS_EndRequest (priv->cx); } static void @@ -418,17 +412,20 @@ on_dir_monitor_changed (GFileMonitor *monitor, static void setup_file_monitors (PolkitBackendJsAuthority *authority) { + PolkitBackendJsAuthorityPrivate *priv; guint n; GPtrArray *p; + priv = polkit_backend_js_authority_get_instance_private (authority); + p = g_ptr_array_new (); - for (n = 0; authority->priv->rules_dirs != NULL && authority->priv->rules_dirs[n] != NULL; n++) + for (n = 0; priv->rules_dirs != NULL && priv->rules_dirs[n] != NULL; n++) { GFile *file; GError *error; GFileMonitor *monitor; - file = g_file_new_for_path (authority->priv->rules_dirs[n]); + file = g_file_new_for_path (priv->rules_dirs[n]); error = NULL; monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, @@ -437,8 +434,7 @@ setup_file_monitors (PolkitBackendJsAuthority *authority) g_object_unref (file); if (monitor == NULL) { - g_warning ("Error monitoring directory %s: %s", - authority->priv->rules_dirs[n], + g_warning ("Error monitoring directory %s: %s", priv->rules_dirs[n], error->message); g_clear_error (&error); } @@ -452,68 +448,62 @@ setup_file_monitors (PolkitBackendJsAuthority *authority) } } g_ptr_array_add (p, NULL); - authority->priv->dir_monitors = (GFileMonitor**) g_ptr_array_free (p, FALSE); + priv->dir_monitors = (GFileMonitor**) g_ptr_array_free (p, FALSE); } static void polkit_backend_js_authority_constructed (GObject *object) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object); + PolkitBackendJsAuthorityPrivate *priv; gboolean entered_request = FALSE; - authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L); - if (authority->priv->rt == NULL) + priv = polkit_backend_js_authority_get_instance_private (authority); + + priv->rt = JS_NewRuntime (8L * 1024L * 1024L); + if (priv->rt == NULL) goto fail; - authority->priv->cx = JS_NewContext (authority->priv->rt, 8192); - if (authority->priv->cx == NULL) + priv->cx = JS_NewContext (priv->rt, 8192); + if (priv->cx == NULL) goto fail; /* TODO: JIT'ing doesn't work will with killing runaway scripts... I think * this is just a SpiderMonkey bug. So disable the JIT for now. */ - JS_SetOptions (authority->priv->cx, - JSOPTION_VAROBJFIX - /* | JSOPTION_JIT | JSOPTION_METHODJIT*/); - JS_SetVersion(authority->priv->cx, JSVERSION_LATEST); - JS_SetErrorReporter(authority->priv->cx, report_error); - JS_SetContextPrivate (authority->priv->cx, authority); - - JS_BeginRequest(authority->priv->cx); + JS_SetOptions (priv->cx, + JSOPTION_VAROBJFIX /* | JSOPTION_JIT | JSOPTION_METHODJIT*/); + JS_SetVersion (priv->cx, JSVERSION_LATEST); + JS_SetErrorReporter (priv->cx, report_error); + JS_SetContextPrivate (priv->cx, authority); + + JS_BeginRequest (priv->cx); entered_request = TRUE; - authority->priv->js_global = + priv->js_global = #if JS_VERSION == 186 - JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL); + JS_NewGlobalObject (priv->cx, &js_global_class, NULL); #else - JS_NewCompartmentAndGlobalObject (authority->priv->cx, &js_global_class, NULL); + JS_NewCompartmentAndGlobalObject (priv->cx, &js_global_class, NULL); #endif - if (authority->priv->js_global == NULL) + if (priv->js_global == NULL) goto fail; - JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global); + JS_AddObjectRoot (priv->cx, &priv->js_global); - if (!JS_InitStandardClasses (authority->priv->cx, authority->priv->js_global)) + if (!JS_InitStandardClasses (priv->cx, priv->js_global)) goto fail; - authority->priv->js_polkit = JS_DefineObject (authority->priv->cx, - authority->priv->js_global, - "polkit", - &js_polkit_class, - NULL, - JSPROP_ENUMERATE); - if (authority->priv->js_polkit == NULL) + priv->js_polkit = JS_DefineObject (priv->cx, priv->js_global, "polkit", + &js_polkit_class, NULL, JSPROP_ENUMERATE); + if (priv->js_polkit == NULL) goto fail; - JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_polkit); + JS_AddObjectRoot (priv->cx, &priv->js_polkit); - if (!JS_DefineFunctions (authority->priv->cx, - authority->priv->js_polkit, - js_polkit_functions)) + if (!JS_DefineFunctions (priv->cx, priv->js_polkit, js_polkit_functions)) goto fail; - if (!JS_EvaluateScript (authority->priv->cx, - authority->priv->js_global, - init_js, strlen (init_js), /* init.js */ + if (!JS_EvaluateScript (priv->cx, priv->js_global, init_js, strlen (init_js), "init.js", /* filename */ 0, /* lineno */ NULL)) /* rval */ @@ -521,31 +511,31 @@ polkit_backend_js_authority_constructed (GObject *object) goto fail; } - if (authority->priv->rules_dirs == NULL) + if (priv->rules_dirs == NULL) { - authority->priv->rules_dirs = g_new0 (gchar *, 3); - authority->priv->rules_dirs[0] = g_strdup (PACKAGE_SYSCONF_DIR "/polkit-1/rules.d"); - authority->priv->rules_dirs[1] = g_strdup (PACKAGE_DATA_DIR "/polkit-1/rules.d"); + priv->rules_dirs = g_new0 (gchar *, 3); + priv->rules_dirs[0] = g_strdup (PACKAGE_SYSCONF_DIR "/polkit-1/rules.d"); + priv->rules_dirs[1] = g_strdup (PACKAGE_DATA_DIR "/polkit-1/rules.d"); } - g_mutex_init (&authority->priv->rkt_init_mutex); - g_cond_init (&authority->priv->rkt_init_cond); - g_mutex_init (&authority->priv->rkt_timeout_pending_mutex); + g_mutex_init (&priv->rkt_init_mutex); + g_cond_init (&priv->rkt_init_cond); + g_mutex_init (&priv->rkt_timeout_pending_mutex); - authority->priv->runaway_killer_thread = g_thread_new ("runaway-killer-thread", - runaway_killer_thread_func, - authority); + priv->runaway_killer_thread = g_thread_new ("runaway-killer-thread", + runaway_killer_thread_func, + authority); /* wait for runaway_killer_thread to set up its GMainContext */ - g_mutex_lock (&authority->priv->rkt_init_mutex); - while (authority->priv->rkt_context == NULL) - g_cond_wait (&authority->priv->rkt_init_cond, &authority->priv->rkt_init_mutex); - g_mutex_unlock (&authority->priv->rkt_init_mutex); + g_mutex_lock (&priv->rkt_init_mutex); + while (priv->rkt_context == NULL) + g_cond_wait (&priv->rkt_init_cond, &priv->rkt_init_mutex); + g_mutex_unlock (&priv->rkt_init_mutex); setup_file_monitors (authority); load_scripts (authority); - JS_EndRequest (authority->priv->cx); + JS_EndRequest (priv->cx); entered_request = FALSE; G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->constructed (object); @@ -553,7 +543,7 @@ polkit_backend_js_authority_constructed (GObject *object) fail: if (entered_request) - JS_EndRequest (authority->priv->cx); + JS_EndRequest (priv->cx); g_critical ("Error initializing JavaScript environment"); g_assert_not_reached (); } @@ -562,36 +552,39 @@ static void polkit_backend_js_authority_finalize (GObject *object) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object); + PolkitBackendJsAuthorityPrivate *priv; guint n; - g_mutex_clear (&authority->priv->rkt_init_mutex); - g_cond_clear (&authority->priv->rkt_init_cond); - g_mutex_clear (&authority->priv->rkt_timeout_pending_mutex); + priv = polkit_backend_js_authority_get_instance_private (authority); + + g_mutex_clear (&priv->rkt_init_mutex); + g_cond_clear (&priv->rkt_init_cond); + g_mutex_clear (&priv->rkt_timeout_pending_mutex); /* shut down the killer thread */ - g_assert (authority->priv->rkt_loop != NULL); - g_main_loop_quit (authority->priv->rkt_loop); - g_thread_join (authority->priv->runaway_killer_thread); - g_assert (authority->priv->rkt_loop == NULL); + g_assert (priv->rkt_loop != NULL); + g_main_loop_quit (priv->rkt_loop); + g_thread_join (priv->runaway_killer_thread); + g_assert (priv->rkt_loop == NULL); - for (n = 0; authority->priv->dir_monitors != NULL && authority->priv->dir_monitors[n] != NULL; n++) + for (n = 0; priv->dir_monitors != NULL && priv->dir_monitors[n] != NULL; n++) { - GFileMonitor *monitor = authority->priv->dir_monitors[n]; + GFileMonitor *monitor = priv->dir_monitors[n]; g_signal_handlers_disconnect_by_func (monitor, G_CALLBACK (on_dir_monitor_changed), authority); g_object_unref (monitor); } - g_free (authority->priv->dir_monitors); - g_strfreev (authority->priv->rules_dirs); + g_free (priv->dir_monitors); + g_strfreev (priv->rules_dirs); - JS_BeginRequest (authority->priv->cx); - JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_polkit); - JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_global); - JS_EndRequest (authority->priv->cx); + JS_BeginRequest (priv->cx); + JS_RemoveObjectRoot (priv->cx, &priv->js_polkit); + JS_RemoveObjectRoot (priv->cx, &priv->js_global); + JS_EndRequest (priv->cx); - JS_DestroyContext (authority->priv->cx); - JS_DestroyRuntime (authority->priv->rt); + JS_DestroyContext (priv->cx); + JS_DestroyRuntime (priv->rt); /* JS_ShutDown (); */ G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->finalize (object); @@ -604,12 +597,15 @@ polkit_backend_js_authority_set_property (GObject *object, GParamSpec *pspec) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object); + PolkitBackendJsAuthorityPrivate *priv; + + priv = polkit_backend_js_authority_get_instance_private (authority); switch (property_id) { case PROP_RULES_DIRS: - g_assert (authority->priv->rules_dirs == NULL); - authority->priv->rules_dirs = (gchar **) g_value_dup_boxed (value); + g_assert (priv->rules_dirs == NULL); + priv->rules_dirs = (gchar **) g_value_dup_boxed (value); break; default: @@ -665,9 +661,6 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass) NULL, G_TYPE_STRV, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); - - - g_type_class_add_private (klass, sizeof (PolkitBackendJsAuthorityPrivate)); } /* ---------------------------------------------------------------------------------------------------- */ @@ -679,11 +672,15 @@ set_property_str (PolkitBackendJsAuthority *authority, const gchar *name, const gchar *value) { + PolkitBackendJsAuthorityPrivate *priv; JSString *value_jsstr; jsval value_jsval; - value_jsstr = JS_NewStringCopyZ (authority->priv->cx, value); + + priv = polkit_backend_js_authority_get_instance_private (authority); + + value_jsstr = JS_NewStringCopyZ (priv->cx, value); value_jsval = STRING_TO_JSVAL (value_jsstr); - JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); + JS_SetProperty (priv->cx, obj, name, &value_jsval); } /* authority->priv->cx must be within a request */ @@ -693,24 +690,27 @@ set_property_strv (PolkitBackendJsAuthority *authority, const gchar *name, GPtrArray *value) { + PolkitBackendJsAuthorityPrivate *priv; jsval value_jsval; JSObject *array_object; guint n; - array_object = JS_NewArrayObject (authority->priv->cx, 0, NULL); + priv = polkit_backend_js_authority_get_instance_private (authority); + + array_object = JS_NewArrayObject (priv->cx, 0, NULL); for (n = 0; n < value->len; n++) { JSString *jsstr; jsval val; - jsstr = JS_NewStringCopyZ (authority->priv->cx, g_ptr_array_index(value, n)); + jsstr = JS_NewStringCopyZ (priv->cx, g_ptr_array_index (value, n)); val = STRING_TO_JSVAL (jsstr); - JS_SetElement (authority->priv->cx, array_object, n, &val); + JS_SetElement (priv->cx, array_object, n, &val); } value_jsval = OBJECT_TO_JSVAL (array_object); - JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); + JS_SetProperty (priv->cx, obj, name, &value_jsval); } /* authority->priv->cx must be within a request */ @@ -720,9 +720,13 @@ set_property_int32 (PolkitBackendJsAuthority *authority, const gchar *name, gint32 value) { + PolkitBackendJsAuthorityPrivate *priv; jsval value_jsval; + + priv = polkit_backend_js_authority_get_instance_private (authority); + value_jsval = INT_TO_JSVAL ((gint32) value); - JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); + JS_SetProperty (priv->cx, obj, name, &value_jsval); } /* authority->priv->cx must be within a request */ @@ -732,9 +736,13 @@ set_property_bool (PolkitBackendJsAuthority *authority, const gchar *name, gboolean value) { + PolkitBackendJsAuthorityPrivate *priv; jsval value_jsval; + + priv = polkit_backend_js_authority_get_instance_private (authority); + value_jsval = BOOLEAN_TO_JSVAL ((JSBool) value); - JS_SetProperty (authority->priv->cx, obj, name, &value_jsval); + JS_SetProperty (priv->cx, obj, name, &value_jsval); } /* ---------------------------------------------------------------------------------------------------- */ @@ -749,6 +757,7 @@ subject_to_jsval (PolkitBackendJsAuthority *authority, jsval *out_jsval, GError **error) { + PolkitBackendJsAuthorityPrivate *priv; gboolean ret = FALSE; jsval ret_jsval; const char *src; @@ -761,13 +770,12 @@ subject_to_jsval (PolkitBackendJsAuthority *authority, char *seat_str = NULL; char *session_str = NULL; + priv = polkit_backend_js_authority_get_instance_private (authority); + src = "new Subject();"; - if (!JS_EvaluateScript (authority->priv->cx, - authority->priv->js_global, - src, strlen (src), - __FILE__, __LINE__, - &ret_jsval)) + if (!JS_EvaluateScript (priv->cx, priv->js_global, src, strlen (src), + __FILE__, __LINE__, &ret_jsval)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Evaluating '%s' failed", src); goto out; @@ -880,6 +888,7 @@ action_and_details_to_jsval (PolkitBackendJsAuthority *authority, jsval *out_jsval, GError **error) { + PolkitBackendJsAuthorityPrivate *priv; gboolean ret = FALSE; jsval ret_jsval; const char *src; @@ -887,12 +896,11 @@ action_and_details_to_jsval (PolkitBackendJsAuthority *authority, gchar **keys; guint n; + priv = polkit_backend_js_authority_get_instance_private (authority); + src = "new Action();"; - if (!JS_EvaluateScript (authority->priv->cx, - authority->priv->js_global, - src, strlen (src), - __FILE__, __LINE__, - &ret_jsval)) + if (!JS_EvaluateScript (priv->cx, priv->js_global, src, strlen (src), + __FILE__, __LINE__, &ret_jsval)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Evaluating '%s' failed", src); goto out; @@ -929,25 +937,28 @@ static gpointer runaway_killer_thread_func (gpointer user_data) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data); + PolkitBackendJsAuthorityPrivate *priv; + + priv = polkit_backend_js_authority_get_instance_private (authority); - g_mutex_lock (&authority->priv->rkt_init_mutex); + g_mutex_lock (&priv->rkt_init_mutex); - authority->priv->rkt_context = g_main_context_new (); - authority->priv->rkt_loop = g_main_loop_new (authority->priv->rkt_context, FALSE); - g_main_context_push_thread_default (authority->priv->rkt_context); + priv->rkt_context = g_main_context_new (); + priv->rkt_loop = g_main_loop_new (priv->rkt_context, FALSE); + g_main_context_push_thread_default (priv->rkt_context); /* Signal the main thread that we're done constructing */ - g_cond_signal (&authority->priv->rkt_init_cond); - g_mutex_unlock (&authority->priv->rkt_init_mutex); + g_cond_signal (&priv->rkt_init_cond); + g_mutex_unlock (&priv->rkt_init_mutex); - g_main_loop_run (authority->priv->rkt_loop); + g_main_loop_run (priv->rkt_loop); - g_main_context_pop_thread_default (authority->priv->rkt_context); + g_main_context_pop_thread_default (priv->rkt_context); - g_main_loop_unref (authority->priv->rkt_loop); - authority->priv->rkt_loop = NULL; - g_main_context_unref (authority->priv->rkt_context); - authority->priv->rkt_context = NULL; + g_main_loop_unref (priv->rkt_loop); + priv->rkt_loop = NULL; + g_main_context_unref (priv->rkt_context); + priv->rkt_context = NULL; return NULL; } @@ -958,30 +969,33 @@ static JSBool js_operation_callback (JSContext *cx) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); + PolkitBackendJsAuthorityPrivate *priv; JSString *val_str; jsval val; + priv = polkit_backend_js_authority_get_instance_private (authority); + /* This callback can be called by the runtime at any time without us causing * it by JS_TriggerOperationCallback(). */ - g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); - if (!authority->priv->rkt_timeout_pending) + g_mutex_lock (&priv->rkt_timeout_pending_mutex); + if (!priv->rkt_timeout_pending) { - g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); + g_mutex_unlock (&priv->rkt_timeout_pending_mutex); return JS_TRUE; } - authority->priv->rkt_timeout_pending = FALSE; - g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); + priv->rkt_timeout_pending = FALSE; + g_mutex_unlock (&priv->rkt_timeout_pending_mutex); /* Log that we are terminating the script */ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Terminating runaway script"); /* Throw an exception - this way the JS code can ignore the runaway script handling */ - JS_SetOperationCallback (authority->priv->cx, NULL); + JS_SetOperationCallback (priv->cx, NULL); val_str = JS_NewStringCopyZ (cx, "Terminating runaway script"); val = STRING_TO_JSVAL (val_str); - JS_SetPendingException (authority->priv->cx, val); - JS_SetOperationCallback (authority->priv->cx, js_operation_callback); + JS_SetPendingException (priv->cx, val); + JS_SetOperationCallback (priv->cx, js_operation_callback); return JS_FALSE; } @@ -989,16 +1003,19 @@ static gboolean rkt_on_timeout (gpointer user_data) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data); + PolkitBackendJsAuthorityPrivate *priv; + + priv = polkit_backend_js_authority_get_instance_private (authority); - g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); - authority->priv->rkt_timeout_pending = TRUE; - g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); + g_mutex_lock (&priv->rkt_timeout_pending_mutex); + priv->rkt_timeout_pending = TRUE; + g_mutex_unlock (&priv->rkt_timeout_pending_mutex); /* Supposedly this is thread-safe... */ #if JS_VERSION == 186 - JS_TriggerOperationCallback (authority->priv->rt); + JS_TriggerOperationCallback (priv->rt); #else - JS_TriggerOperationCallback (authority->priv->cx); + JS_TriggerOperationCallback (priv->cx); #endif /* keep source around so we keep trying to kill even if the JS bit catches the exception @@ -1010,29 +1027,37 @@ rkt_on_timeout (gpointer user_data) static void runaway_killer_setup (PolkitBackendJsAuthority *authority) { - g_assert (authority->priv->rkt_source == NULL); + PolkitBackendJsAuthorityPrivate *priv; + + priv = polkit_backend_js_authority_get_instance_private (authority); + + g_assert (priv->rkt_source == NULL); /* set-up timer for runaway scripts, will be executed in runaway_killer_thread */ - g_mutex_lock (&authority->priv->rkt_timeout_pending_mutex); - authority->priv->rkt_timeout_pending = FALSE; - g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex); - authority->priv->rkt_source = g_timeout_source_new_seconds (15); - g_source_set_callback (authority->priv->rkt_source, rkt_on_timeout, authority, NULL); - g_source_attach (authority->priv->rkt_source, authority->priv->rkt_context); + g_mutex_lock (&priv->rkt_timeout_pending_mutex); + priv->rkt_timeout_pending = FALSE; + g_mutex_unlock (&priv->rkt_timeout_pending_mutex); + priv->rkt_source = g_timeout_source_new_seconds (15); + g_source_set_callback (priv->rkt_source, rkt_on_timeout, authority, NULL); + g_source_attach (priv->rkt_source, priv->rkt_context); /* ... rkt_on_timeout() will then poke the JSContext so js_operation_callback() is * called... and from there we throw an exception */ - JS_SetOperationCallback (authority->priv->cx, js_operation_callback); + JS_SetOperationCallback (priv->cx, js_operation_callback); } static void runaway_killer_teardown (PolkitBackendJsAuthority *authority) { - JS_SetOperationCallback (authority->priv->cx, NULL); - g_source_destroy (authority->priv->rkt_source); - g_source_unref (authority->priv->rkt_source); - authority->priv->rkt_source = NULL; + PolkitBackendJsAuthorityPrivate *priv; + + priv = polkit_backend_js_authority_get_instance_private (authority); + + JS_SetOperationCallback (priv->cx, NULL); + g_source_destroy (priv->rkt_source); + g_source_unref (priv->rkt_source); + priv->rkt_source = NULL; } static JSBool @@ -1044,13 +1069,13 @@ execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority, #endif jsval *rval) { + PolkitBackendJsAuthorityPrivate *priv; JSBool ret; + priv = polkit_backend_js_authority_get_instance_private (authority); + runaway_killer_setup (authority); - ret = JS_ExecuteScript (authority->priv->cx, - authority->priv->js_global, - script, - rval); + ret = JS_ExecuteScript (priv->cx, priv->js_global, script, rval); runaway_killer_teardown (authority); return ret; @@ -1063,14 +1088,14 @@ call_js_function_with_runaway_killer (PolkitBackendJsAuthority *authority, jsval *argv, jsval *rval) { + PolkitBackendJsAuthorityPrivate *priv; JSBool ret; + + priv = polkit_backend_js_authority_get_instance_private (authority); + runaway_killer_setup (authority); - ret = JS_CallFunctionName(authority->priv->cx, - authority->priv->js_polkit, - function_name, - argc, - argv, - rval); + ret = JS_CallFunctionName (priv->cx, priv->js_polkit, function_name, + argc, argv, rval); runaway_killer_teardown (authority); return ret; } @@ -1088,6 +1113,7 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA PolkitDetails *details) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (_authority); + PolkitBackendJsAuthorityPrivate *priv; GList *ret = NULL; jsval argv[2] = {JSVAL_NULL, JSVAL_NULL}; jsval rval = JSVAL_NULL; @@ -1097,7 +1123,9 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA gchar *ret_str = NULL; gchar **ret_strs = NULL; - JS_BeginRequest (authority->priv->cx); + priv = polkit_backend_js_authority_get_instance_private (authority); + + JS_BeginRequest (priv->cx); if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error)) { @@ -1141,7 +1169,7 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA } ret_jsstr = JSVAL_TO_STRING (rval); - ret_str = g_utf16_to_utf8 (JS_GetStringCharsZ (authority->priv->cx, ret_jsstr), -1, NULL, NULL, NULL); + ret_str = g_utf16_to_utf8 (JS_GetStringCharsZ (priv->cx, ret_jsstr), -1, NULL, NULL, NULL); if (ret_str == NULL) { g_warning ("Error converting resulting string to UTF-8: %s", error->message); @@ -1176,9 +1204,9 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA if (ret == NULL) ret = g_list_prepend (ret, polkit_unix_user_new (0)); - JS_MaybeGC (authority->priv->cx); + JS_MaybeGC (priv->cx); - JS_EndRequest (authority->priv->cx); + JS_EndRequest (priv->cx); return ret; } @@ -1197,6 +1225,7 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu PolkitImplicitAuthorization implicit) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (_authority); + PolkitBackendJsAuthorityPrivate *priv; PolkitImplicitAuthorization ret = implicit; jsval argv[2] = {JSVAL_NULL, JSVAL_NULL}; jsval rval = JSVAL_NULL; @@ -1206,7 +1235,9 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu gchar *ret_str = NULL; gboolean good = FALSE; - JS_BeginRequest (authority->priv->cx); + priv = polkit_backend_js_authority_get_instance_private (authority); + + JS_BeginRequest (priv->cx); if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error)) { @@ -1257,7 +1288,7 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu } ret_jsstr = JSVAL_TO_STRING (rval); - ret_utf16 = JS_GetStringCharsZ (authority->priv->cx, ret_jsstr); + ret_utf16 = JS_GetStringCharsZ (priv->cx, ret_jsstr); ret_str = g_utf16_to_utf8 (ret_utf16, -1, NULL, NULL, &error); if (ret_str == NULL) { @@ -1282,9 +1313,9 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu ret = POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED; g_free (ret_str); - JS_MaybeGC (authority->priv->cx); + JS_MaybeGC (priv->cx); - JS_EndRequest (authority->priv->cx); + JS_EndRequest (priv->cx); return ret; } diff --git a/src/polkitbackend/polkitbackendjsauthority.h b/src/polkitbackend/polkitbackendjsauthority.h index 6fd283b..bdad84c 100644 --- a/src/polkitbackend/polkitbackendjsauthority.h +++ b/src/polkitbackend/polkitbackendjsauthority.h @@ -51,7 +51,6 @@ struct _PolkitBackendJsAuthority { /*< private >*/ PolkitBackendInteractiveAuthority parent_instance; - PolkitBackendJsAuthorityPrivate *priv; }; /** -- 2.4.3