Commit 4362e6cf authored by Vincent Untz's avatar Vincent Untz
Browse files

[clock] Use the polkit helper from g-s-d to set time/timezone

gnome-clock-applet-mechanism has moved to gnome-settings-daemon (since
2.31.4) and is now named gsd-datetime-mechanism. The D-Bus interface is
the same, except for the name of the service and the name of the
interface. So we simply need to remove a lot of code that is now
duplicated.

Note that this means polkit is not needed anymore to build gnome-panel.
parent 2543d346
......@@ -29,16 +29,6 @@ CALENDAR_SOURCES = \
calendar-debug.h
endif
if HAVE_POLKIT
SETTIME_SOURCES = \
set-timezone.c \
set-timezone.h
else
SETTIME_SOURCES = \
set-timezone-dummy.c \
set-timezone.h
endif
CLOCK_SOURCES = \
calendar-window.c \
calendar-window.h \
......@@ -56,11 +46,12 @@ CLOCK_SOURCES = \
clock-sunpos.h \
clock-utils.c \
clock-utils.h \
set-timezone.c \
set-timezone.h \
system-timezone.c \
system-timezone.h \
$(BUILT_SOURCES) \
$(CALENDAR_SOURCES) \
$(SETTIME_SOURCES)
$(CALENDAR_SOURCES)
CLOCK_LDADD = \
../../libpanel-applet/libpanel-applet-3.la \
......@@ -112,31 +103,6 @@ clock-typebuiltins.h: @REBUILD@ $(clock_enum_headers)
--eprod "GType @enum_name@_get_type (void);\n" \
$(clock_enum_headers) > $@
gnome-clock-applet-mechanism-glue.h: $(srcdir)/gnome-clock-applet-mechanism.xml
$(AM_V_GEN)dbus-binding-tool \
--prefix=gnome_clock_applet_mechanism --mode=glib-server \
--output=gnome-clock-applet-mechanism-glue.h \
$(srcdir)/gnome-clock-applet-mechanism.xml
gnome_clock_applet_mechanism_SOURCES = \
gnome-clock-applet-mechanism.c \
gnome-clock-applet-mechanism.h \
gnome-clock-applet-mechanism-main.c \
system-timezone.c \
system-timezone.h
if HAVE_POLKIT
BUILT_SOURCES += gnome-clock-applet-mechanism-glue.h
endif
gnome_clock_applet_mechanism_INCLUDES = \
$(CLOCK_MECHANISM_CFLAGS) \
$(POLKIT_CFLAGS)
gnome_clock_applet_mechanism_LDADD = \
$(CLOCK_MECHANISM_LIBS) \
$(POLKIT_LIBS)
if CLOCK_INPROCESS
APPLET_IN_PROCESS = true
APPLET_LOCATION = $(pkglibdir)/libclock-applet.so
......@@ -161,10 +127,6 @@ clock_applet_CFLAGS =
$(clock_applet_OBJECTS): $(BUILT_SOURCES)
endif
if HAVE_POLKIT
libexec_PROGRAMS += gnome-clock-applet-mechanism
endif
uidir = $(datadir)/gnome-panel/ui
ui_DATA = clock.ui
......@@ -213,30 +175,6 @@ else
install-data-local:
endif
dbus_servicesdir = $(datadir)/dbus-1/system-services
dbus_confdir = $(sysconfdir)/dbus-1/system.d
polkitdir = $(datadir)/polkit-1/actions
dbus_services_in_files = org.gnome.ClockApplet.Mechanism.service.in
polkit_in_files = org.gnome.clockapplet.mechanism.policy.in
if HAVE_POLKIT
dbus_services_DATA = $(dbus_services_in_files:.service.in=.service)
$(dbus_services_DATA): $(dbus_services_in_files)
$(AM_V_GEN)sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" $< > $@
dbus_conf_DATA = org.gnome.ClockApplet.Mechanism.conf
@INTLTOOL_POLICY_RULE@
polkit_DATA = $(polkit_in_files:.policy.in=.policy)
else
dbus_services_DATA =
dbus_conf_DATA =
polkit_DATA =
endif
noinst_PROGRAMS = test-system-timezone
test_system_timezone_SOURCES = \
......@@ -255,11 +193,7 @@ EXTRA_DIST = \
$(xmlui_DATA) \
$(ui_DATA) \
clock-marshallers.list \
$(service_in_files) \
$(dbus_services_in_files) \
org.gnome.ClockApplet.Mechanism.conf \
$(polkit_in_files) \
gnome-clock-applet-mechanism.xml
$(service_in_files)
CLEANFILES = \
$(BUILT_SOURCES) \
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 David Zeuthen <david@fubar.dk>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "gnome-clock-applet-mechanism.h"
static DBusGProxy *
get_bus_proxy (DBusGConnection *connection)
{
DBusGProxy *bus_proxy;
bus_proxy = dbus_g_proxy_new_for_name (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
return bus_proxy;
}
#define BUS_NAME "org.gnome.ClockApplet.Mechanism"
static gboolean
acquire_name_on_proxy (DBusGProxy *bus_proxy)
{
GError *error;
guint result;
gboolean res;
gboolean ret;
ret = FALSE;
if (bus_proxy == NULL) {
goto out;
}
error = NULL;
res = dbus_g_proxy_call (bus_proxy,
"RequestName",
&error,
G_TYPE_STRING, BUS_NAME,
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &result,
G_TYPE_INVALID);
if (! res) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", BUS_NAME);
}
goto out;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", BUS_NAME);
}
goto out;
}
ret = TRUE;
out:
return ret;
}
static DBusGConnection *
get_system_bus (void)
{
GError *error;
DBusGConnection *bus;
error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
}
return bus;
}
int
main (int argc, char **argv)
{
GMainLoop *loop;
GnomeClockAppletMechanism *mechanism;
DBusGProxy *bus_proxy;
DBusGConnection *connection;
int ret;
ret = 1;
if (! g_thread_supported ()) {
g_thread_init (NULL);
}
dbus_g_thread_init ();
g_type_init ();
connection = get_system_bus ();
if (connection == NULL) {
goto out;
}
bus_proxy = get_bus_proxy (connection);
if (bus_proxy == NULL) {
g_warning ("Could not construct bus_proxy object; bailing out");
goto out;
}
if (!acquire_name_on_proxy (bus_proxy) ) {
g_warning ("Could not acquire name; bailing out");
goto out;
}
mechanism = gnome_clock_applet_mechanism_new ();
if (mechanism == NULL) {
goto out;
}
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_object_unref (mechanism);
g_main_loop_unref (loop);
ret = 0;
out:
return ret;
}
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 David Zeuthen <david@fubar.dk>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef GNOME_CLOCK_APPLET_MECHANISM_H
#define GNOME_CLOCK_APPLET_MECHANISM_H
#include <glib-object.h>
#include <dbus/dbus-glib.h>
G_BEGIN_DECLS
#define GNOME_CLOCK_APPLET_TYPE_MECHANISM (gnome_clock_applet_mechanism_get_type ())
#define GNOME_CLOCK_APPLET_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNOME_CLOCK_APPLET_TYPE_MECHANISM, GnomeClockAppletMechanism))
#define GNOME_CLOCK_APPLET_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GNOME_CLOCK_APPLET_TYPE_MECHANISM, GnomeClockAppletMechanismClass))
#define GNOME_CLOCK_APPLET_IS_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNOME_CLOCK_APPLET_TYPE_MECHANISM))
#define GNOME_CLOCK_APPLET_IS_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNOME_CLOCK_APPLET_TYPE_MECHANISM))
#define GNOME_CLOCK_APPLET_MECHANISM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNOME_CLOCK_APPLET_TYPE_MECHANISM, GnomeClockAppletMechanismClass))
typedef struct GnomeClockAppletMechanismPrivate GnomeClockAppletMechanismPrivate;
typedef struct
{
GObject parent;
GnomeClockAppletMechanismPrivate *priv;
} GnomeClockAppletMechanism;
typedef struct
{
GObjectClass parent_class;
} GnomeClockAppletMechanismClass;
typedef enum
{
GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL,
GNOME_CLOCK_APPLET_MECHANISM_ERROR_NOT_PRIVILEGED,
GNOME_CLOCK_APPLET_MECHANISM_ERROR_INVALID_TIMEZONE_FILE,
GNOME_CLOCK_APPLET_MECHANISM_NUM_ERRORS
} GnomeClockAppletMechanismError;
#define GNOME_CLOCK_APPLET_MECHANISM_ERROR gnome_clock_applet_mechanism_error_quark ()
GType gnome_clock_applet_mechanism_error_get_type (void);
#define GNOME_CLOCK_APPLET_MECHANISM_TYPE_ERROR (gnome_clock_applet_mechanism_error_get_type ())
GQuark gnome_clock_applet_mechanism_error_quark (void);
GType gnome_clock_applet_mechanism_get_type (void);
GnomeClockAppletMechanism *gnome_clock_applet_mechanism_new (void);
/* exported methods */
gboolean gnome_clock_applet_mechanism_set_timezone (GnomeClockAppletMechanism *mechanism,
const char *zone_file,
DBusGMethodInvocation *context);
gboolean gnome_clock_applet_mechanism_can_set_timezone (GnomeClockAppletMechanism *mechanism,
DBusGMethodInvocation *context);
gboolean gnome_clock_applet_mechanism_set_time (GnomeClockAppletMechanism *mechanism,
gint64 seconds_since_epoch,
DBusGMethodInvocation *context);
gboolean gnome_clock_applet_mechanism_can_set_time (GnomeClockAppletMechanism *mechanism,
DBusGMethodInvocation *context);
gboolean gnome_clock_applet_mechanism_adjust_time (GnomeClockAppletMechanism *mechanism,
gint64 seconds_to_add,
DBusGMethodInvocation *context);
gboolean gnome_clock_applet_mechanism_get_hardware_clock_using_utc (GnomeClockAppletMechanism *mechanism,
DBusGMethodInvocation *context);
gboolean gnome_clock_applet_mechanism_set_hardware_clock_using_utc (GnomeClockAppletMechanism *mechanism,
gboolean using_utc,
DBusGMethodInvocation *context);
G_END_DECLS
#endif /* GNOME_CLOCK_APPLET_MECHANISM_H */
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/">
<interface name="org.gnome.ClockApplet.Mechanism">
<method name="SetTimezone">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="zonefile" direction="in" type="s"/>
</method>
<method name="CanSetTimezone">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="value" direction="out" type="i">
<doc:doc>
<doc:summary>Whether the caller can set the timezone</doc:summary>
<doc:description>
<doc:para>
The return value is not a boolean, but an integer with the following meaning:
<doc:list>
<doc:item>
<doc:term>0</doc:term>
<doc:definition>the caller cannot set the timezone</doc:definition>
</doc:item>
<doc:item>
<doc:term>1</doc:term>
<doc:definition>the caller will be challenged before being able to set the timezone</doc:definition>
</doc:item>
<doc:item>
<doc:term>2</doc:term>
<doc:definition>the caller is authorized to set the timezone</doc:definition>
</doc:item>
</doc:list>
</doc:para>
</doc:description>
</doc:doc>
</arg>
</method>
<method name="SetTime">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="seconds_since_epoch" direction="in" type="x"/>
</method>
<method name="CanSetTime">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="value" direction="out" type="i">
<doc:doc>
<doc:summary>Whether the caller can set the time</doc:summary>
<doc:description>
<doc:para>
The return value is not a boolean, but an integer with the following meaning:
<doc:list>
<doc:item>
<doc:term>0</doc:term>
<doc:definition>the caller cannot set the time</doc:definition>
</doc:item>
<doc:item>
<doc:term>1</doc:term>
<doc:definition>the caller will be challenged before being able to set the time</doc:definition>
</doc:item>
<doc:item>
<doc:term>2</doc:term>
<doc:definition>the caller is authorized to set the time</doc:definition>
</doc:item>
</doc:list>
</doc:para>
</doc:description>
</doc:doc>
</arg>
</method>
<method name="AdjustTime">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="seconds_to_add" direction="in" type="x"/>
</method>
<method name="GetHardwareClockUsingUtc">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="is_using_utc" direction="out" type="b"/>
</method>
<method name="SetHardwareClockUsingUtc">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="is_using_utc" direction="in" type="b"/>
</method>
</interface>
</node>
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root can own the service -->
<policy user="root">
<allow own="org.gnome.ClockApplet.Mechanism"/>
<allow send_destination="org.gnome.ClockApplet.Mechanism"/>
</policy>
<!-- Allow anyone to invoke methods on the interfaces -->
<policy context="default">
<allow send_destination="org.gnome.ClockApplet.Mechanism"/>
</policy>
</busconfig>
[D-BUS Service]
Name=org.gnome.ClockApplet.Mechanism
Exec=@LIBEXECDIR@/gnome-clock-applet-mechanism
User=root
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
<vendor>The GNOME Project</vendor>
<vendor_url>http://www.gnome.org/</vendor_url>
<icon_name>gnome-panel-clock</icon_name>
<action id="org.gnome.clockapplet.mechanism.settimezone">
<_description>Change system time zone</_description>
<_message>Privileges are required to change the system time zone.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_self_keep</allow_active>
</defaults>
</action>
<action id="org.gnome.clockapplet.mechanism.settime">
<_description>Change system time</_description>
<_message>Privileges are required to change the system time.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
<action id="org.gnome.clockapplet.mechanism.configurehwclock">
<_description>Configure hardware clock</_description>
<_message>Privileges are required to configure the hardware clock.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
</policyconfig>
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <glib.h>
#include "set-timezone.h"
gint
can_set_system_timezone (void)
{
return 0;
}
gint
can_set_system_time (void)
{
return 0;
}
void
set_system_time_async (gint64 time,
GFunc callback,
gpointer data,
GDestroyNotify notify)
{
GError *error;
if (callback) {
error = g_error_new_literal (G_SPAWN_ERROR,
G_SPAWN_ERROR_FAILED,
"Time setting is not supported");
callback (data, error);
}
if (notify)
notify (data);
}
void
set_system_timezone_async (const gchar *filename,
GFunc callback,
gpointer d,
GDestroyNotify notify)
{
GError *error;
if (filename == NULL)
return;
if (callback) {
error = g_error_new_literal (G_SPAWN_ERROR,
G_SPAWN_ERROR_FAILED,
"Timezone setting is not supported");
callback (d, error);
}
if (notify)
notify (d);
}
......@@ -86,9 +86,9 @@ refresh_can_do (const gchar *action, CanDoFunc callback)
return;
proxy = dbus_g_proxy_new_for_name (bus,
"org.gnome.ClockApplet.Mechanism",
"org.gnome.SettingsDaemon.DateTimeMechanism",
"/",
"org.gnome.ClockApplet.Mechanism");
"org.gnome.SettingsDaemon.DateTimeMechanism");