From 24df035335633957c64fcf198ea7b733e61de61a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Jun 10 2009 04:51:27 +0000 Subject: Port to PolicyKit 1 --- diff --git a/gnome-applets.spec b/gnome-applets.spec index 9a9047b..14c3a7e 100644 --- a/gnome-applets.spec +++ b/gnome-applets.spec @@ -150,6 +150,7 @@ and more. %patch40 -p1 -b .battstat-null %patch41 -p1 -b .no-mixer-icon %patch42 -p1 -b .network +%patch43 -p1 -b .polkit1 # We don't ship gnome-system-tools rm -rf modemlights diff --git a/polkit1.patch b/polkit1.patch new file mode 100644 index 0000000..2b6ac8e --- /dev/null +++ b/polkit1.patch @@ -0,0 +1,710 @@ +diff -u -r gnome-applets-2.26.1/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c hacked/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c +--- gnome-applets-2.26.1/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c 2009-03-16 19:39:11.000000000 -0400 ++++ hacked/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c 2009-05-14 23:45:38.384939252 -0400 +@@ -17,7 +17,7 @@ + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +-#include ++#include + #include + + #include "cpufreq-selector.h" +@@ -37,7 +37,7 @@ + DBusGConnection *system_bus; + + /* PolicyKit */ +- PolKitContext *pk_context; ++ PolkitAuthority *authority; + }; + + struct _CPUFreqSelectorServiceClass { +@@ -99,9 +99,9 @@ + service->selectors_max = -1; + } + +- if (service->pk_context) { +- polkit_context_unref (service->pk_context); +- service->pk_context = NULL; ++ if (service->authority) { ++ g_object_unref (service->authority); ++ service->authority = NULL; + } + + G_OBJECT_CLASS (cpufreq_selector_service_parent_class)->finalize (object); +@@ -153,42 +153,6 @@ + NULL); + } + +-static gboolean +-pk_io_watch_have_data (GIOChannel *channel, +- GIOCondition condition, +- PolKitContext *pk_context) +-{ +- polkit_context_io_func (pk_context, +- g_io_channel_unix_get_fd (channel)); +- return TRUE; +-} +- +-static int +-pk_add_io_watch (PolKitContext *pk_context, +- int watch_id) +-{ +- GIOChannel *channel; +- guint id = 0; +- +- channel = g_io_channel_unix_new (watch_id); +- if (!channel) +- return 0; +- +- id = g_io_add_watch (channel, G_IO_IN, +- (GIOFunc)pk_io_watch_have_data, +- pk_context); +- g_io_channel_unref (channel); +- +- return id; +-} +- +-static void +-pk_remove_io_watch (PolKitContext *pk_context, +- int watch_id) +-{ +- g_source_remove (watch_id); +-} +- + gboolean + cpufreq_selector_service_register (CPUFreqSelectorService *service, + GError **error) +@@ -198,7 +162,6 @@ + gboolean res; + guint result; + GError *err = NULL; +- PolKitError *pk_err = NULL; + + if (service->system_bus) { + g_set_error (error, +@@ -268,30 +231,7 @@ + return FALSE; + } + +- service->pk_context = polkit_context_new (); +- polkit_context_set_io_watch_functions (service->pk_context, +- pk_add_io_watch, +- pk_remove_io_watch); +- if (!polkit_context_init (service->pk_context, &pk_err)) { +- polkit_context_unref (service->pk_context); +- service->pk_context = NULL; +- +- if (polkit_error_is_set (pk_err)) { +- g_set_error (error, +- CPUFREQ_SELECTOR_SERVICE_ERROR, +- SERVICE_ERROR_GENERAL, +- "Cannot initialize libpolkit: %s", +- polkit_error_get_error_message (pk_err)); +- polkit_error_free (pk_err); +- } else { +- g_set_error (error, +- CPUFREQ_SELECTOR_SERVICE_ERROR, +- SERVICE_ERROR_GENERAL, +- "Cannot initialize libpolkit"); +- } +- +- return FALSE; +- } ++ service->authority = polkit_authority_get (); + + service->system_bus = connection; + +@@ -330,62 +270,39 @@ + DBusGMethodInvocation *context, + GError **error) + { +- PolKitAction *pk_action; +- PolKitCaller *pk_caller; +- PolKitResult pk_result; ++ PolkitSubject *subject; ++ PolkitAuthorizationResult *result; + gchar *sender; + DBusConnection *connection; +- DBusError dbus_error; +- PolKitError *pk_error = NULL; ++ gboolean ret; + + sender = dbus_g_method_get_sender (context); + connection = dbus_g_connection_get_connection (service->system_bus); + +- dbus_error_init (&dbus_error); +- pk_caller = polkit_caller_new_from_dbus_name (connection, sender, &dbus_error); +- if (!pk_caller) { +- g_set_error (error, +- CPUFREQ_SELECTOR_SERVICE_ERROR, +- SERVICE_ERROR_DBUS, +- "Error getting information about caller: %s: %s", +- dbus_error.name, dbus_error.message); +- dbus_error_free (&dbus_error); +- g_free (sender); ++ subject = polkit_system_bus_name_new (sender); ++ result = polkit_authority_check_authorization_sync (service->authority, ++ service, ++ "org.gnome.cpufreqselector", ++ NULL, ++ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, ++ NULL, NULL); ++ g_object_unref (subject); + +- return FALSE; +- } +- g_free (sender); +- +- pk_action = polkit_action_new (); +- polkit_action_set_action_id (pk_action, "org.gnome.cpufreqselector"); +- pk_result = polkit_context_is_caller_authorized (service->pk_context, +- pk_action, pk_caller, +- TRUE, &pk_error); +- polkit_caller_unref (pk_caller); +- polkit_action_unref (pk_action); +- +- if (polkit_error_is_set (pk_error)) { ++ if (!polkit_authorization_result_get_is_authorized (result)) { + g_set_error (error, + CPUFREQ_SELECTOR_SERVICE_ERROR, +- SERVICE_ERROR_GENERAL, +- "Could not determine if caller is authorized: %s", +- polkit_error_get_error_message (pk_error)); +- polkit_error_free (pk_error); ++ SERVICE_ERROR_NOT_AUTHORIZED, ++ "Caller is not authorized"); + +- return FALSE; ++ ret = FALSE; ++ } ++ else { ++ ret = TRUE; + } + +- if (pk_result != POLKIT_RESULT_YES) { +- g_set_error (error, +- CPUFREQ_SELECTOR_SERVICE_ERROR, +- SERVICE_ERROR_NOT_AUTHORIZED, +- "Caller is not authorized: %s", +- polkit_result_to_string_representation (pk_result)); ++ g_object_unref (result); + +- return FALSE; +- } +- +- return TRUE; ++ return ret; + } + + /* D-BUS interface */ +@@ -518,3 +435,43 @@ + + return TRUE; + } ++ ++ ++gboolean ++cpufreq_selector_service_can_set (CPUFreqSelectorService *service, ++ DBusGMethodInvocation *context) ++{ ++ PolkitSubject *subject; ++ PolkitAuthorizationResult *result; ++ gchar *sender; ++ DBusConnection *connection; ++ gboolean ret; ++ ++ reset_killtimer (); ++ ++ sender = dbus_g_method_get_sender (context); ++ connection = dbus_g_connection_get_connection (service->system_bus); ++ ++ subject = polkit_system_bus_name_new (sender); ++ result = polkit_authority_check_authorization_sync (service->authority, ++ service, ++ "org.gnome.cpufreqselector", ++ NULL, ++ 0, ++ NULL, NULL); ++ g_object_unref (subject); ++ ++ if (polkit_authorization_result_get_is_authorized (result)) { ++ ret = TRUE; ++ } ++ else if (polkit_authorization_result_get_is_challenge (result)) { ++ ret = TRUE; ++ } ++ else { ++ ret = FALSE; ++ } ++ ++ g_object_unref (result); ++ ++ return ret; ++} +diff -u -r gnome-applets-2.26.1/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h hacked/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h +--- gnome-applets-2.26.1/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h 2009-03-16 19:39:11.000000000 -0400 ++++ hacked/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h 2009-05-14 23:39:52.716688684 -0400 +@@ -62,6 +62,8 @@ + guint cpu, + const gchar *governor, + DBusGMethodInvocation *context); ++gboolean cpufreq_selector_service_can_set (CPUFreqSelectorService *service, ++ DBusGMethodInvocation *context); + + G_END_DECLS + +diff -u -r gnome-applets-2.26.1/cpufreq/src/cpufreq-selector/cpufreq-selector-service.xml hacked/cpufreq/src/cpufreq-selector/cpufreq-selector-service.xml +--- gnome-applets-2.26.1/cpufreq/src/cpufreq-selector/cpufreq-selector-service.xml 2009-03-16 19:39:11.000000000 -0400 ++++ hacked/cpufreq/src/cpufreq-selector/cpufreq-selector-service.xml 2009-05-14 23:38:41.683938881 -0400 +@@ -13,6 +13,10 @@ + + + +- ++ ++ ++ ++ ++ + + +diff -u -r gnome-applets-2.26.1/cpufreq/src/cpufreq-selector.c hacked/cpufreq/src/cpufreq-selector.c +--- gnome-applets-2.26.1/cpufreq/src/cpufreq-selector.c 2009-03-16 19:39:11.000000000 -0400 ++++ hacked/cpufreq/src/cpufreq-selector.c 2009-05-14 23:58:36.989938814 -0400 +@@ -19,19 +19,18 @@ + + #include + +-#ifdef HAVE_POLKIT_GNOME ++#ifdef HAVE_POLKIT + #include +-#endif /* HAVE_POLKIT_GNOME */ ++#endif /* HAVE_POLKIT */ + + #include "cpufreq-selector.h" + + struct _CPUFreqSelector { + GObject parent; + +-#ifdef HAVE_POLKIT_GNOME ++#ifdef HAVE_POLKIT + DBusGConnection *system_bus; +- DBusGConnection *session_bus; +-#endif /* HAVE_POLKIT_GNOME */ ++#endif /* HAVE_POLKIT */ + }; + + struct _CPUFreqSelectorClass { +@@ -45,10 +44,9 @@ + { + CPUFreqSelector *selector = CPUFREQ_SELECTOR (object); + +-#ifdef HAVE_POLKIT_GNOME ++#ifdef HAVE_POLKIT + selector->system_bus = NULL; +- selector->session_bus = NULL; +-#endif /* HAVE_POLKIT_GNOME */ ++#endif /* HAVE_POLKIT */ + + G_OBJECT_CLASS (cpufreq_selector_parent_class)->finalize (object); + } +@@ -77,7 +75,7 @@ + return selector; + } + +-#ifdef HAVE_POLKIT_GNOME ++#ifdef HAVE_POLKIT + typedef enum { + FREQUENCY, + GOVERNOR +@@ -114,90 +112,12 @@ + { + if (selector->system_bus) + return TRUE; +- ++ + selector->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); + + return (selector->system_bus != NULL); + } + +-static gboolean +-cpufreq_selector_connect_to_session_bus (CPUFreqSelector *selector, +- GError **error) +-{ +- if (selector->session_bus) +- return TRUE; +- +- selector->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error); +- +- return (selector->session_bus != NULL); +-} +- +-static void +-dbus_auth_call_notify_cb (DBusGProxy *proxy, +- DBusGProxyCall *call, +- gpointer user_data) +-{ +- SelectorAsyncData *data; +- gboolean gained_privilege; +- GError *error = NULL; +- +- data = (SelectorAsyncData *)user_data; +- +- if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &gained_privilege, G_TYPE_INVALID)) { +- g_warning ("%s", error->message); +- g_error_free (error); +- +- selector_async_data_free (data); +- +- return; +- } +- +- if (gained_privilege) { +- switch (data->call) { +- case FREQUENCY: +- selector_set_frequency_async (data); +- break; +- case GOVERNOR: +- selector_set_governor_async (data); +- break; +- default: +- g_assert_not_reached (); +- } +- } else { +- selector_async_data_free (data); +- } +-} +- +-static void +-do_auth_async (SelectorAsyncData *data) +-{ +- DBusGProxy *proxy; +- GError *error = NULL; +- +- if (!cpufreq_selector_connect_to_session_bus (data->selector, &error)) { +- g_warning ("%s", error->message); +- g_error_free (error); +- +- selector_async_data_free (data); +- +- return; +- } +- +- proxy = dbus_g_proxy_new_for_name (data->selector->session_bus, +- "org.gnome.PolicyKit", +- "/org/gnome/PolicyKit/Manager", +- "org.gnome.PolicyKit.Manager"); +- +- dbus_g_proxy_begin_call_with_timeout (proxy, +- "ShowDialog", +- dbus_auth_call_notify_cb, +- data, NULL, +- INT_MAX, +- G_TYPE_STRING, "org.gnome.cpufreqselector", +- G_TYPE_UINT, data->parent_xid, +- G_TYPE_INVALID); +-} +- + static void + dbus_set_call_notify_cb (DBusGProxy *proxy, + DBusGProxyCall *call, +@@ -213,12 +133,6 @@ + return; + } + +- if (error->domain == DBUS_GERROR && DBUS_GERROR_REMOTE_EXCEPTION && +- dbus_g_error_has_name (error, "org.gnome.CPUFreqSelector.NotAuthorized")) { +- do_auth_async (data); +- return; +- } +- + selector_async_data_free (data); + g_warning ("%s", error->message); + g_error_free (error); +@@ -229,13 +143,13 @@ + { + DBusGProxy *proxy; + GError *error = NULL; +- ++ + if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) { + g_warning ("%s", error->message); + g_error_free (error); + + selector_async_data_free (data); +- ++ + return; + } + +@@ -243,7 +157,7 @@ + "org.gnome.CPUFreqSelector", + "/org/gnome/cpufreq_selector/selector", + "org.gnome.CPUFreqSelector"); +- ++ + dbus_g_proxy_begin_call_with_timeout (proxy, "SetFrequency", + dbus_set_call_notify_cb, + data, NULL, +@@ -321,7 +235,7 @@ + + selector_set_governor_async (data); + } +-#else /* !HAVE_POLKIT_GNOME */ ++#else /* !HAVE_POLKIT */ + static void + cpufreq_selector_run_command (CPUFreqSelector *selector, + const gchar *args) +@@ -372,4 +286,4 @@ + cpufreq_selector_run_command (selector, args); + g_free (args); + } +-#endif /* HAVE_POLKIT_GNOME */ ++#endif /* HAVE_POLKIT */ +diff -u -r gnome-applets-2.26.1/cpufreq/src/cpufreq-utils.c hacked/cpufreq/src/cpufreq-utils.c +--- gnome-applets-2.26.1/cpufreq/src/cpufreq-utils.c 2009-03-16 19:39:11.000000000 -0400 ++++ hacked/cpufreq/src/cpufreq-utils.c 2009-05-15 00:00:16.374688984 -0400 +@@ -21,13 +21,6 @@ + + #include + +-#ifdef HAVE_POLKIT_GNOME +-#include +-#include +-#include +-#include +-#endif +- + #include + #include + #include +@@ -39,6 +32,10 @@ + + #include "cpufreq-utils.h" + ++#ifdef HAVE_POLKIT ++#include ++#endif /* HAVE_POLKIT */ ++ + guint + cpufreq_utils_get_n_cpus (void) + { +@@ -108,56 +105,16 @@ + gtk_widget_show (dialog); + } + +-#ifdef HAVE_POLKIT_GNOME ++#ifdef HAVE_POLKIT + #define CACHE_VALIDITY_SEC 2 + + static gboolean +-pk_io_watch_have_data (GIOChannel *channel, +- GIOCondition condition, +- PolKitContext *pk_context) +-{ +- polkit_context_io_func (pk_context, +- g_io_channel_unix_get_fd (channel)); +- return TRUE; +-} +- +-static int +-pk_add_io_watch (PolKitContext *pk_context, +- int watch_id) +-{ +- GIOChannel *channel; +- guint id = 0; +- +- channel = g_io_channel_unix_new (watch_id); +- if (!channel) +- return 0; +- +- id = g_io_add_watch (channel, G_IO_IN, +- (GIOFunc)pk_io_watch_have_data, +- pk_context); +- g_io_channel_unref (channel); +- +- return id; +-} +- +-static void +-pk_remove_io_watch (PolKitContext *pk_context, +- int watch_id) +-{ +- g_source_remove (watch_id); +-} +- +-static gboolean +-selector_is_available (const gchar *action) ++selector_is_available (void) + { ++ DBusGProxy *proxy; + static DBusGConnection *system_bus = NULL; +- static PolKitContext *pk_context = NULL; +- PolKitCaller *pk_caller; +- PolKitAction *pk_action; +- PolKitResult pk_result; +- PolKitError *pk_error = NULL; + GError *error = NULL; +- DBusError dbus_error; ++ gboolean result; + + if (!system_bus) { + system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); +@@ -169,54 +126,19 @@ + } + } + +- if (!pk_context) { +- PolKitError *pk_error = NULL; +- +- pk_context = polkit_context_new (); +- polkit_context_set_io_watch_functions (pk_context, +- pk_add_io_watch, +- pk_remove_io_watch); +- if (!polkit_context_init (pk_context, &pk_error)) { +- polkit_context_unref (pk_context); +- pk_context = NULL; +- +- if (polkit_error_is_set (pk_error)) { +- g_warning ("%s", polkit_error_get_error_message (pk_error)); +- polkit_error_free (pk_error); +- } else { +- g_warning ("Cannot initialize libpolkit"); +- } +- +- return FALSE; +- } +- } +- +- dbus_error_init (&dbus_error); +- pk_caller = polkit_caller_new_from_pid (dbus_g_connection_get_connection (system_bus), +- getpid (), &dbus_error); +- if (!pk_caller) { +- g_warning ("Cannot get caller from dbus name"); ++ proxy = dbus_g_proxy_new_for_name (system_bus, ++ "org.gnome.CPUFreqSelector", ++ "/org/gnome/cpufreq_selector/selector", ++ "org.gnome.CPUFreqSelector"); ++ ++ dbus_g_proxy_call (proxy, "CanSet", NULL, ++ G_TYPE_INVALID, ++ &result, ++ G_TYPE_INVALID); + +- return FALSE; +- } +- +- pk_action = polkit_action_new (); +- polkit_action_set_action_id (pk_action, action); +- pk_result = polkit_context_is_caller_authorized (pk_context, +- pk_action, pk_caller, +- FALSE, &pk_error); +- +- polkit_caller_unref (pk_caller); +- polkit_action_unref (pk_action); +- +- if (polkit_error_is_set (pk_error)) { +- g_warning ("%s", polkit_error_get_error_message (pk_error)); +- polkit_error_free (pk_error); +- +- return FALSE; +- } ++ g_object_unref (proxy); + +- return !(pk_result == POLKIT_RESULT_UNKNOWN || pk_result == POLKIT_RESULT_NO); ++ return result; + } + + gboolean +@@ -228,13 +150,13 @@ + + time (&now); + if (ABS (now - last_refreshed) > CACHE_VALIDITY_SEC) { +- cache = selector_is_available ("org.gnome.cpufreqselector"); ++ cache = selector_is_available (); + last_refreshed = now; + } + + return cache; + } +-#else /* !HAVE_POLKIT_GNOME */ ++#else /* !HAVE_POLKIT */ + gboolean + cpufreq_utils_selector_is_available (void) + { +diff -u -r gnome-applets-2.26.1/cpufreq/src/Makefile.am hacked/cpufreq/src/Makefile.am +--- gnome-applets-2.26.1/cpufreq/src/Makefile.am 2009-03-16 19:39:11.000000000 -0400 ++++ hacked/cpufreq/src/Makefile.am 2009-05-14 23:14:18.926939010 -0400 +@@ -9,10 +9,6 @@ + $(GNOME_LIBS2_CFLAGS) \ + $(LIBGLADE_CFLAGS) + +-if HAVE_POLKIT_GNOME +-INCLUDES += $(POLKIT_GNOME_CFLAGS) +-endif +- + libexec_PROGRAMS = cpufreq-applet + + if HAVE_LIBCPUFREQ +@@ -38,8 +34,4 @@ + $(LIBGLADE_LIBS) \ + $(LIBCPUFREQ_LIBS) + +-if HAVE_POLKIT_GNOME +-cpufreq_applet_LDADD += $(POLKIT_GNOME_LIBS) +-endif +- + +--- gnome-applets-2.26.1/configure.in 2009-05-15 00:01:14.206719170 -0400 ++++ hacked/configure.in 2009-05-14 23:13:29.129939391 -0400 +@@ -35,7 +35,7 @@ + GWEATHER_REQUIRED=2.22.1 + GUCHARMAP2_REQUIRED=2.23.0 + GUCHARMAP_REQUIRED=1.4.0 +-POLKIT_REQUIRED=0.7 ++POLKIT_REQUIRED=0.92 + NETWORKMANAGER_REQUIRED=0.7 + GST10_REQUIRED=0.10.2 + dnl *************************************************************************** +@@ -217,7 +217,7 @@ + enable_polkit=$enableval, + enable_polkit=auto) + if test "x$enable_polkit" != "xno"; then +- PKG_CHECK_MODULES(POLKIT, polkit >= $POLKIT_REQUIRED polkit-dbus >= $POLKIT_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED, HAVE_POLKIT=yes, HAVE_POLKIT=no) ++ PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= $POLKIT_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED, HAVE_POLKIT=yes, HAVE_POLKIT=no) + if test "x$enable_polkit" = "xyes" -a "x$HAVE_POLKIT" = "xno"; then + AC_MSG_ERROR([PolicyKit support explicitly requested but dependencies not found]) + fi +@@ -233,22 +233,6 @@ + AC_SUBST(POLKIT_CFLAGS) + AC_SUBST(POLKIT_LIBS) + +-POLKIT_GNOME_CFLAGS= +-POLKIT_GNOME_LIBS= +-polkit_gnome=no +-if test "x$enable_polkit" != "xno"; then +- PKG_CHECK_MODULES(POLKIT_GNOME, polkit-gnome >= $POLKIT_REQUIRED, polkit_gnome=yes, polkit_gnome=no) +- if test "x$enable_polkit" = "xyes" -a "x$polkit_gnome" = "xno"; then +- AC_MSG_ERROR([PolicyKit-gnome support explicitly requested but dependencies not found]) +- fi +-fi +-if test "x$polkit_gnome" = "xyes"; then +- AC_DEFINE(HAVE_POLKIT_GNOME, [1], [PolicyKit-gnome available]) +-fi +-AM_CONDITIONAL(HAVE_POLKIT_GNOME, test "x$polkit_gnome" = "xyes") +-AC_SUBST(POLKIT_GNOME_CFLAGS) +-AC_SUBST(POLKIT_GNOME_LIBS) +- + + dnl -- check for libhal (optional) -------------------------------------------- + HAL_CFLAGS= +@@ -797,7 +781,6 @@ + - cpufreq $build_cpufreq_applet + - building selector $enable_selector + - using PolicyKit $HAVE_POLKIT +- - using PolicyKit-gnome $polkit_gnome + - enabling suid bit $suid + - drivemount always + - geyes always