Esempio n. 1
0
static void
stop_operation (void)
{
	if (operations == 1)
		start_killtimer ();
	operations --;
}
Esempio n. 2
0
static gboolean
register_mechanism (GConfDefaults *mechanism)
{
        GError *error = NULL;

        mechanism->priv->auth = polkit_authority_get ();

        error = NULL;
        mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
        if (mechanism->priv->system_bus_connection == NULL) {
                if (error != NULL) {
                        g_critical ("error getting system bus: %s", error->message);
                        g_error_free (error);
                }
                goto error;
        }

        dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/",
                                             G_OBJECT (mechanism));

        mechanism->priv->system_bus_proxy = dbus_g_proxy_new_for_name (mechanism->priv->system_bus_connection,
                                                                      DBUS_SERVICE_DBUS,
                                                                      DBUS_PATH_DBUS,
                                                                      DBUS_INTERFACE_DBUS);

        start_killtimer ();

        return TRUE;

error:
        return FALSE;
}
Esempio n. 3
0
void
gconf_defaults_unset_mandatory (GConfDefaults          *mechanism,
                                const char            **includes,
                                const char            **excludes,
                                DBusGMethodInvocation  *context)
{
	const char *annotation_key;
	const char *default_action;
	int i;
	const char *action;
	GError *error;
	GError *error2;

	stop_killtimer ();

	annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix"; 
	default_action = "org.gnome.gconf.defaults.set-mandatory";

	for (i = 0; includes[i]; i++) {
		action = polkit_action_for_gconf_path (mechanism, annotation_key, includes[i]);
		if (action == NULL) 
			action = default_action;

		if (!check_polkit_for_action (mechanism, context, action)) 
			goto out;
	}

	error = NULL;
	unset_in_db (mechanism, "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory", 
		     includes, excludes, &error);

	if (error) {
		error2 = g_error_new_literal (GCONF_DEFAULTS_ERROR,
					      GCONF_DEFAULTS_ERROR_GENERAL,
					      error->message);
		g_error_free (error);

		dbus_g_method_return_error (context, error2);
		g_error_free (error2);
	}
	else
        	dbus_g_method_return (context);
out:
	start_killtimer();
}
Esempio n. 4
0
static gboolean
register_mechanism (GConfDefaults *mechanism)
{
	GError *error = NULL;

	mechanism->priv->pol_ctx = polkit_context_new ();
	polkit_context_set_io_watch_functions (mechanism->priv->pol_ctx, pk_io_add_watch, pk_io_remove_watch);
	if (!polkit_context_init (mechanism->priv->pol_ctx, NULL)) {
		g_critical ("cannot initialize libpolkit");
		goto error;
	}

	error = NULL;
	mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
	if (mechanism->priv->system_bus_connection == NULL) {
		if (error != NULL) {
			g_critical ("error getting system bus: %s", error->message);
			g_error_free (error);
		}
		goto error;
	}

	dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/",
					     G_OBJECT (mechanism));

	mechanism->priv->system_bus_proxy = dbus_g_proxy_new_for_name (mechanism->priv->system_bus_connection,
								       DBUS_SERVICE_DBUS,
								       DBUS_PATH_DBUS,
								       DBUS_INTERFACE_DBUS);

	start_killtimer ();

	return TRUE;

error:
	return FALSE;
}
Esempio n. 5
0
static void
do_set_value (GConfDefaults          *mechanism,
              gboolean                mandatory,
              const char             *path,
              const char             *value,
              DBusGMethodInvocation  *context,
              GConfChangeSet        **changeset_out)
{
	GConfClient *dest = NULL;
	GConfChangeSet *changes = NULL;
	GConfEngine *engine;
	GConfValue *gvalue;
	GError *error;
	GError *error2;
	const char *action;
	const char *annotation_key;
	const char *default_action;
	const char *dest_address;

	if (changeset_out)
		*changeset_out = NULL;

	stop_killtimer ();

	if (mandatory) {
		annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix";
		default_action = "org.gnome.gconf.defaults.set-mandatory";
		dest_address = "xml:merged:/etc/gconf/gconf.xml.mandatory";
	}
	else {
		annotation_key = "org.gnome.gconf.defaults.set-system.prefix";
		default_action = "org.gnome.gconf.defaults.set-system";
		dest_address = "xml:merged:/etc/gconf/gconf.xml.system";
	}

	action = polkit_action_for_gconf_path (mechanism, annotation_key, path);
	if (action == NULL)
		action = default_action;

	if (!check_polkit_for_action (mechanism, context, action))
		goto out;

	error = NULL;
	engine = gconf_engine_get_local (dest_address, &error);
	if (error)
		goto cleanup;

	dest = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	changes = gconf_change_set_new ();

	gvalue = gconf_value_decode (value);
	if (!gvalue)
		goto cleanup;

	gconf_change_set_set (changes, path, gvalue);
	gconf_value_free (gvalue);

	gconf_client_commit_change_set (dest, changes, FALSE, &error);
	gconf_client_suggest_sync (dest, NULL);

	if (changeset_out) {
		*changeset_out = changes;
		changes = NULL;
	}

cleanup:
	if (changes)
		gconf_change_set_unref (changes);
	if (dest)
		g_object_unref (dest);

	if (error) {
		g_print ("failed to set GConf values:  %s\n", error->message);
		error2 = g_error_new_literal (GCONF_DEFAULTS_ERROR,
					      GCONF_DEFAULTS_ERROR_GENERAL,
					      error->message);
		g_error_free (error);

		dbus_g_method_return_error (context, error2);
		g_error_free (error2);
	}
	else
		dbus_g_method_return (context);

out:
	start_killtimer ();
}
Esempio n. 6
0
static void
do_copy (GConfDefaults          *mechanism,
	 gboolean                mandatory,
	 const char            **includes,
	 const char            **excludes,
	 DBusGMethodInvocation  *context,
	 GConfChangeSet        **changeset_out)
{
        char *address = NULL;
	GConfClient *source = NULL;
	GConfClient *dest = NULL;
	GConfChangeSet *changes = NULL;
	GConfEngine *engine;
	GError *error;
	GError *error2;
	const char *action;
	const char *annotation_key;
	const char *default_action;
	const char *dest_address;
	int i;

	if (changeset_out)
		*changeset_out = NULL;

        stop_killtimer ();

	/* check privileges for each include */
	if (mandatory) {
		annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix"; 
		default_action = "org.gnome.gconf.defaults.set-mandatory";
		dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory";
	}
	else {
		annotation_key = "org.gnome.gconf.defaults.set-system.prefix";
		default_action = "org.gnome.gconf.defaults.set-system";
		dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.system";
	}

	for (i = 0; includes[i]; i++) {
		action = polkit_action_for_gconf_path (mechanism, annotation_key, includes[i]);
		if (action == NULL)
			action = default_action;

		if (!check_polkit_for_action (mechanism, context, action))
			goto out;
	}

	error = NULL;
	engine = gconf_engine_get_local (dest_address, &error);
	if (error)
		goto cleanup;

	dest = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	/* find the address to from the caller id */
	address = gconf_address_for_caller (mechanism, context, &error);
	if (error)
		goto cleanup;

	engine = gconf_engine_get_local (address, &error);
	if (error)
		goto cleanup;

	source = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	changes = gconf_change_set_new ();

 	/* recursively copy each include, leaving out the excludes */
	for (i = 0; includes[i]; i++) {
		if (gconf_client_dir_exists (source, includes[i], NULL))
			copy_tree (source, includes[i], changes, excludes);
		else
			copy_entry (source, includes[i], changes, excludes);
	}

	gconf_client_commit_change_set (dest, changes, FALSE, &error);
	gconf_client_suggest_sync (dest, NULL);

	if (changeset_out) {
		*changeset_out = changes;
		changes = NULL;
	}

cleanup:
	g_free (address);
	if (changes)
		gconf_change_set_unref (changes);
	if (dest)
		g_object_unref (dest);
	if (source)
		g_object_unref (source);

	if (error) {
		g_print ("failed to set GConf values:  %s\n", error->message);
		error2 = g_error_new_literal (GCONF_DEFAULTS_ERROR,
					      GCONF_DEFAULTS_ERROR_GENERAL,
					      error->message);
		g_error_free (error);

		dbus_g_method_return_error (context, error2);
		g_error_free (error2);
	}
	else
		dbus_g_method_return (context);

out:
	start_killtimer ();
}