[gnome-packagekit/polkit1: 3/92] Port to PolicyKit1
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-packagekit/polkit1: 3/92] Port to PolicyKit1
- Date: Tue, 16 Jun 2009 06:21:11 -0400 (EDT)
commit 501035eba3f9539c25e7def267dcc29e608332cb
Author: Richard Hughes <richard hughsie com>
Date: Thu May 14 13:26:46 2009 +0100
Port to PolicyKit1
configure.ac | 6 --
src/Makefile.am | 2 -
src/gpk-application.c | 1 -
src/gpk-common.c | 1 -
src/gpk-consolekit.c | 135 ++-----------------------------------------------
src/gpk-dbus-task.c | 1 -
src/gpk-dbus.c | 99 ++++++++++++++++++++++--------------
src/gpk-watch.c | 50 ++++++------------
8 files changed, 80 insertions(+), 215 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b120124..bfbc71c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,7 +84,6 @@ DBUS_REQUIRED=1.1.2
GCONF_REQUIRED=0.22
DBUS_GLIB_REQUIRED=0.73
LIBNOTIFY_REQUIRED=0.4.3
-POLKIT_GNOME_REQUIRED=0.8
UNIQUE_REQUIRED=1.0.0
GNOME_MENUS_REQUIRED=2.24.1
GIO_REQUIRED=2.18.0
@@ -101,7 +100,6 @@ AC_SUBST(GTK_REQUIRED)
AC_SUBST(DBUS_REQUIRED)
AC_SUBST(DBUS_GLIB_REQUIRED)
AC_SUBST(LIBNOTIFY_REQUIRED)
-AC_SUBST(POLKIT_GNOME_REQUIRED)
AC_SUBST(UNIQUE_REQUIRED)
AC_SUBST(GNOME_MENUS_REQUIRED)
AC_SUBST(GIO_REQUIRED)
@@ -113,10 +111,6 @@ PKG_CHECK_MODULES(PACKAGEKIT, packagekit-glib >= $PACKAGEKIT_REQUIRED)
AC_SUBST(PACKAGEKIT_CFLAGS)
AC_SUBST(PACKAGEKIT_LIBS)
-PKG_CHECK_MODULES(POLKIT_GNOME, polkit-gnome >= $POLKIT_GNOME_REQUIRED)
-AC_SUBST(POLKIT_GNOME_CFLAGS)
-AC_SUBST(POLKIT_GNOME_LIBS)
-
PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gobject-2.0)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
diff --git a/src/Makefile.am b/src/Makefile.am
index 57302d2..18290ac 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,6 @@ INCLUDES = \
$(LIBNOTIFY_CFLAGS) \
$(PACKAGEKIT_CFLAGS) \
$(UNIQUE_CFLAGS) \
- $(POLKIT_GNOME_CFLAGS) \
$(GTK_CFLAGS) \
$(GNOME_MENUS_CFLAGS) \
-DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE \
@@ -115,7 +114,6 @@ shared_LIBS = \
$(LIBNOTIFY_LIBS) \
$(PACKAGEKIT_LIBS) \
$(UNIQUE_LIBS) \
- $(POLKIT_GNOME_LIBS) \
$(GNOME_MENUS_LIBS) \
$(DEVKIT_LIBS) \
$(CANBERRA_LIBS) \
diff --git a/src/gpk-application.c b/src/gpk-application.c
index ea349a1..307cc6d 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -28,7 +28,6 @@
#include <gconf/gconf-client.h>
#include <math.h>
#include <string.h>
-#include <polkit-gnome/polkit-gnome.h>
#include <packagekit-glib/packagekit.h>
#include "egg-debug.h"
diff --git a/src/gpk-common.c b/src/gpk-common.c
index 1b34353..271f5c3 100644
--- a/src/gpk-common.c
+++ b/src/gpk-common.c
@@ -29,7 +29,6 @@
#include <sys/types.h>
#include <gtk/gtk.h>
#include <dbus/dbus-glib.h>
-#include <polkit-gnome/polkit-gnome.h>
#include <packagekit-glib/packagekit.h>
#include <locale.h>
diff --git a/src/gpk-consolekit.c b/src/gpk-consolekit.c
index 430edac..74231dc 100644
--- a/src/gpk-consolekit.c
+++ b/src/gpk-consolekit.c
@@ -26,7 +26,6 @@
#include <string.h>
#include <unistd.h>
#include <dbus/dbus-glib.h>
-#include <polkit-gnome/polkit-gnome.h>
#include "egg-debug.h"
#include "gpk-common.h"
@@ -34,101 +33,6 @@
#include "gpk-error.h"
/**
- * gpk_consolekit_try_system_restart:
- **/
-static gboolean
-gpk_consolekit_try_system_restart (DBusGProxy *proxy, GError **error)
-{
- return dbus_g_proxy_call_with_timeout (proxy, "Restart", INT_MAX,
- error, G_TYPE_INVALID, G_TYPE_INVALID);
-}
-
-/**
- * gpk_consolekit_get_action_from_error:
- **/
-static PolKitAction *
-gpk_consolekit_get_action_from_error (GError *error)
-{
- PolKitAction *action;
- gchar *paction, *p;
-
- action = polkit_action_new ();
-
- paction = NULL;
- if (g_str_has_prefix (error->message, "Not privileged for action: ")) {
- paction = g_strdup (error->message + strlen ("Not privileged for action: "));
- p = strchr (paction, ' ');
- if (p)
- *p = '\0';
- }
- polkit_action_set_action_id (action, paction);
-
- g_free (paction);
-
- return action;
-}
-
-/**
- * gpk_consolekit_get_result_from_error:
- **/
-static PolKitResult
-gpk_consolekit_get_result_from_error (GError *error)
-{
- PolKitResult result = POLKIT_RESULT_UNKNOWN;
- const char *p;
-
- p = strrchr (error->message, ' ');
- if (p) {
- p++;
- polkit_result_from_string_representation (p, &result);
- }
-
- return result;
-}
-
-/**
- * gpk_consolekit_system_restart_auth_cb:
- **/
-static void
-gpk_consolekit_system_restart_auth_cb (PolKitAction *action, gboolean gained_privilege,
- GError *error, DBusGProxy *proxy)
-{
- GError *local_error;
- gboolean res;
-
- if (!gained_privilege) {
- if (error != NULL) {
- egg_warning ("Not privileged to restart system: %s", error->message);
- }
- return;
- }
-
- local_error = NULL;
- res = gpk_consolekit_try_system_restart (proxy, &local_error);
- if (!res) {
- egg_warning ("Unable to restart system: %s", local_error->message);
- g_error_free (local_error);
- }
-}
-
-/**
- * gpk_consolekit_request_restart_priv:
- **/
-static gboolean
-gpk_consolekit_request_restart_priv (DBusGProxy *proxy, PolKitAction *action, GError **error)
-{
- guint xid;
- pid_t pid;
-
- xid = 0;
- pid = getpid ();
-
- return polkit_gnome_auth_obtain (action, xid, pid,
- (PolKitGnomeAuthCB) gpk_consolekit_system_restart_auth_cb,
- proxy, error);
-}
-
-/**
* gpk_restart_system:
*
* Return value: if we succeeded
@@ -140,9 +44,6 @@ gpk_restart_system (void)
DBusGConnection *connection;
GError *error = NULL;
gboolean ret;
- PolKitAction *action;
- PolKitAction *action2;
- PolKitResult result;
/* check dbus connections, exit if not valid */
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
@@ -163,39 +64,11 @@ gpk_restart_system (void)
}
/* do the method */
- ret = gpk_consolekit_try_system_restart (proxy, &error);
+ ret = dbus_g_proxy_call_with_timeout (proxy, "Restart", INT_MAX,
+ &error, G_TYPE_INVALID, G_TYPE_INVALID);
if (!ret) {
- if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
- action = gpk_consolekit_get_action_from_error (error);
- result = gpk_consolekit_get_result_from_error (error);
-
- if (result == POLKIT_RESULT_NO) {
- action2 = polkit_action_new ();
- polkit_action_set_action_id (action2,
- "org.freedesktop.consolekit.system.restart-multiple-users");
- if (polkit_action_equal (action, action2)) {
- /* TRANSLATORS: could not restart the computer */
- gpk_error_dialog (_("Failed to restart"),
- /* TRANSLATORS: more than one user is using this computer */
- _("You are not allowed to restart the computer "
- "because multiple users are logged in"), NULL);
- }
-
- g_error_free (error);
-
- polkit_action_unref (action);
- polkit_action_unref (action2);
-
- return FALSE;
- }
- g_clear_error (&error);
- ret = gpk_consolekit_request_restart_priv (proxy, action, &error);
- polkit_action_unref (action);
- }
- if (!ret) {
- egg_warning ("Unable to restart system: %s", error->message);
- g_error_free (error);
- }
+ egg_warning ("Unable to restart system: %s", error->message);
+ g_error_free (error);
}
g_object_unref (G_OBJECT (proxy));
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index 51068ac..ea28fa3 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -31,7 +31,6 @@
#include <fontconfig/fontconfig.h>
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
-#include <polkit-gnome/polkit-gnome.h>
#include <libnotify/notify.h>
#include <packagekit-glib/packagekit.h>
diff --git a/src/gpk-dbus.c b/src/gpk-dbus.c
index c3b037b..c2a3fc6 100644
--- a/src/gpk-dbus.c
+++ b/src/gpk-dbus.c
@@ -38,8 +38,6 @@
#include <glib/gi18n.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <polkit/polkit.h>
-#include <polkit-dbus/polkit-dbus.h>
#include <packagekit-glib/packagekit.h>
#include <gconf/gconf-client.h>
@@ -61,6 +59,8 @@ struct GpkDbusPrivate
gint timeout_tmp;
GpkX11 *x11;
GPtrArray *array;
+ DBusGConnection *connection;
+ DBusGProxy *proxy_pid;
};
G_DEFINE_TYPE (GpkDbus, gpk_dbus, G_TYPE_OBJECT)
@@ -103,52 +103,67 @@ gpk_dbus_error_get_type (void)
}
/**
- * gpk_dbus_get_exec_for_sender:
+ * gpk_dbus_get_pid:
**/
-static gchar *
-gpk_dbus_get_exec_for_sender (const gchar *sender)
+static guint
+gpk_dbus_get_pid (GpkDbus *dbus, const gchar *sender)
{
- pid_t pid;
- gchar exec[128];
- PolKitCaller *caller = NULL;
- DBusError dbus_error;
- gboolean ret = FALSE;
- gint retval;
- DBusConnection *connection;
- gchar *sender_exe = NULL;
-
- /* get a connection */
- connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
- if (connection == NULL)
- egg_error ("fatal, no system dbus");
-
- dbus_error_init (&dbus_error);
- caller = polkit_caller_new_from_dbus_name (connection, sender, &dbus_error);
- if (caller == NULL) {
- egg_warning ("cannot get caller from sender %s: %s", sender, dbus_error.message);
- dbus_error_free (&dbus_error);
- goto out;
- }
-
- ret = polkit_caller_get_pid (caller, &pid);
+ guint pid;
+ gboolean ret;
+ GError *error = NULL;
+
+ g_return_val_if_fail (PK_IS_DBUS (dbus), G_MAXUINT);
+ g_return_val_if_fail (dbus->priv->proxy_pid != NULL, G_MAXUINT);
+ g_return_val_if_fail (sender != NULL, G_MAXUINT);
+
+ /* get pid from DBus (quite slow) */
+ ret = dbus_g_proxy_call (dbus->priv->proxy_pid, "GetConnectionUnixProcessID", &error,
+ G_TYPE_STRING, sender,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &pid,
+ G_TYPE_INVALID);
if (!ret) {
- egg_warning ("cannot get pid from sender %p", sender);
+ egg_error ("failed to get pid: %s", error->message);
+ g_error_free (error);
goto out;
}
+out:
+ return pid;
+}
+
- retval = polkit_sysdeps_get_exe_for_pid (pid, exec, 128);
- if (retval == -1) {
- egg_warning ("cannot get exec for pid %i", pid);
+/**
+ * gpk_dbus_get_exec_for_sender:
+ **/
+static gchar *
+gpk_dbus_get_exec_for_sender (GpkDbus *dbus, const gchar *sender)
+{
+ gboolean ret;
+ gchar *filename = NULL;
+ gchar *cmdline = NULL;
+ GError *error = NULL;
+ guint pid;
+
+ g_return_val_if_fail (PK_IS_DBUS (dbus), NULL);
+ g_return_val_if_fail (sender != NULL, NULL);
+
+ /* get pid */
+ pid = gpk_dbus_get_pid (dbus, sender);
+ if (pid == G_MAXUINT) {
+ egg_warning ("failed to get PID");
goto out;
}
- /* make a copy */
- sender_exe = g_strdup (exec);
-
+ /* get command line from proc */
+ filename = g_strdup_printf ("/proc/%i/cmdline", pid);
+ ret = g_file_get_contents (filename, &cmdline, NULL, &error);
+ if (!ret) {
+ egg_warning ("failed to get cmdline: %s", error->message);
+ g_error_free (error);
+ }
out:
- if (caller != NULL)
- polkit_caller_unref (caller);
- return sender_exe;
+ g_free (filename);
+ return cmdline;
}
/**
@@ -288,7 +303,7 @@ gpk_dbus_create_task (GpkDbus *dbus, guint32 xid, const gchar *interaction, DBus
/* get the program name and set */
sender = dbus_g_method_get_sender (context);
- exec = gpk_dbus_get_exec_for_sender (sender);
+ exec = gpk_dbus_get_exec_for_sender (dbus, sender);
gpk_dbus_task_set_exec (task, exec);
/* unref on delete */
@@ -415,6 +430,11 @@ gpk_dbus_init (GpkDbus *dbus)
dbus->priv->gconf_client = gconf_client_get_default ();
dbus->priv->array = g_ptr_array_new ();
dbus->priv->x11 = gpk_x11_new ();
+ dbus->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+ dbus->priv->proxy_pid = dbus_g_proxy_new_for_name_owner (dbus->priv->connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus/Bus",
+ "org.freedesktop.DBus", NULL);
}
/**
@@ -433,6 +453,7 @@ gpk_dbus_finalize (GObject *object)
g_ptr_array_free (dbus->priv->array, TRUE);
g_object_unref (dbus->priv->gconf_client);
g_object_unref (dbus->priv->x11);
+ g_object_unref (dbus->priv->proxy_pid);
G_OBJECT_CLASS (gpk_dbus_parent_class)->finalize (object);
}
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index 5d8c284..a97dfa8 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -37,7 +37,6 @@
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
#include <libnotify/notify.h>
-#include <polkit-gnome/polkit-gnome.h>
#include <packagekit-glib/packagekit.h>
#include "egg-debug.h"
@@ -74,7 +73,6 @@ struct GpkWatchPrivate
PkTaskList *tlist;
PkRestartEnum restart;
GConfClient *gconf_client;
- PolKitGnomeAction *restart_action;
guint set_proxy_timeout;
gchar *error_details;
};
@@ -776,15 +774,6 @@ gpk_watch_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 times
}
/**
- * gpk_watch_restart_cb:
- **/
-static void
-gpk_watch_restart_cb (PolKitGnomeAction *action, gpointer data)
-{
- gpk_restart_system ();
-}
-
-/**
* gpk_watch_menu_show_messages_cb:
**/
static void
@@ -1202,12 +1191,19 @@ gpk_watch_menu_hide_restart_cb (GtkMenuItem *item, gpointer data)
static void
gpk_watch_menu_log_out_cb (GtkMenuItem *item, gpointer data)
{
- GpkWatch *watch = GPK_WATCH (data);
- g_return_if_fail (GPK_IS_WATCH (watch));
gpk_session_logout ();
}
/**
+ * gpk_watch_menu_restart_cb:
+ **/
+static void
+gpk_watch_menu_restart_cb (GtkMenuItem *item, gpointer data)
+{
+ gpk_restart_system ();
+}
+
+/**
* gpk_watch_activate_status_cb:
* @button: Which buttons are pressed
*
@@ -1244,6 +1240,7 @@ gpk_watch_activate_status_cb (GtkStatusIcon *status_icon, GpkWatch *watch)
/* log out session */
if (watch->priv->restart == PK_RESTART_ENUM_SESSION) {
+ /* TRANSLATORS: log out of the session */
widget = gtk_image_menu_item_new_with_mnemonic (_("_Log out"));
image = gtk_image_new_from_icon_name ("system-log-out", GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
@@ -1255,7 +1252,12 @@ gpk_watch_activate_status_cb (GtkStatusIcon *status_icon, GpkWatch *watch)
/* restart computer */
if (watch->priv->restart == PK_RESTART_ENUM_SYSTEM) {
- widget = gtk_action_create_menu_item (GTK_ACTION (watch->priv->restart_action));
+ /* TRANSLATORS: this menu item restarts the computer after an update */
+ widget = gtk_image_menu_item_new_with_mnemonic (_("_Restart computer"));
+ image = gtk_image_new_from_icon_name ("system-shutdown", GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
+ g_signal_connect (G_OBJECT (widget), "activate",
+ G_CALLBACK (gpk_watch_menu_restart_cb), watch);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
show_hide = TRUE;
}
@@ -1549,8 +1551,6 @@ static void
gpk_watch_init (GpkWatch *watch)
{
GtkStatusIcon *status_icon;
- PolKitAction *pk_action;
- PolKitGnomeAction *restart_action;
watch->priv = GPK_WATCH_GET_PRIVATE (watch);
watch->priv->error_details = NULL;
@@ -1616,23 +1616,6 @@ gpk_watch_init (GpkWatch *watch)
if (pk_connection_valid (watch->priv->pconnection))
pk_connection_changed_cb (watch->priv->pconnection, TRUE, watch);
- pk_action = polkit_action_new ();
- polkit_action_set_action_id (pk_action, "org.freedesktop.consolekit.system.restart");
-
- restart_action = polkit_gnome_action_new_default ("restart-system", pk_action,
- /* TRANSLATORS: This button restarts the computer after an update */
- _("_Restart computer"), NULL);
- g_object_set (restart_action,
- "no-icon-name", "system-shutdown",
- "auth-icon-name", "system-shutdown",
- "yes-icon-name","system-shutdown",
- "self-blocked-icon-name", "system-shutdown",
- NULL);
- polkit_action_unref (pk_action);
- g_signal_connect (restart_action, "activate",
- G_CALLBACK (gpk_watch_restart_cb), NULL);
- watch->priv->restart_action = restart_action;
-
/* watch proxy keys */
gconf_client_add_dir (watch->priv->gconf_client, GPK_WATCH_GCONF_PROXY_HTTP,
GCONF_CLIENT_PRELOAD_NONE, NULL);
@@ -1681,7 +1664,6 @@ gpk_watch_finalize (GObject *object)
g_object_unref (watch->priv->control);
g_object_unref (watch->priv->pconnection);
g_object_unref (watch->priv->gconf_client);
- g_object_unref (watch->priv->restart_action);
g_object_unref (watch->priv->client_primary);
g_object_unref (watch->priv->dialog);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]