gnome-power-manager r2848 - in trunk: . src



Author: rhughes
Date: Sun Jul 27 10:00:21 2008
New Revision: 2848
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2848&view=rev

Log:
2008-07-27  Richard Hughes  <richard hughsie com>

* configure.ac:
* src/Makefile.am:
* src/gpm-control.c: (gpm_control_is_user_privileged),
(gpm_control_allowed_suspend), (gpm_control_allowed_hibernate),
(gpm_control_allowed_shutdown), (gpm_control_allowed_reboot),
(gpm_control_finalize), (gpm_control_init):
* src/gpm-polkit.c:
* src/gpm-polkit.h:
Use polkit-simple to simplify the PolicyKit bits.
This wasn't around when the support in g-p-m was added, but now it is.


Removed:
   trunk/src/gpm-polkit.c
   trunk/src/gpm-polkit.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/Makefile.am
   trunk/src/gpm-control.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sun Jul 27 10:00:21 2008
@@ -165,6 +165,11 @@
 AC_MSG_CHECKING([whether to support PolicyKit])
 have_polkit=no
 if test x$enable_polkit = xyes ; then
+    PKG_CHECK_MODULES(POLKIT, \
+                      polkit-grant >= $POLKIT_GNOME_REQUIRED\
+                      polkit-dbus >= $POLKIT_GNOME_REQUIRED)
+    AC_SUBST(POLKIT_CFLAGS)
+    AC_SUBST(POLKIT_LIBS)
     have_polkit=yes
     AC_DEFINE(HAVE_POLKIT, 1, [Define if we use PolicyKit])
 fi
@@ -208,7 +213,7 @@
 dnl ---------------------------------------------------------------------------
 dnl - Build gconf default button?
 dnl ---------------------------------------------------------------------------
-AC_ARG_ENABLE(gconfdefaults, [  --gconf-defaults        Allow setting gconf default settings],
+AC_ARG_ENABLE(gconfdefaults, [  --enable-gconf-defaults        Allow setting gconf default settings],
               enable_gconfdefaults=$enableval,enable_gconfdefaults=yes)
 AC_MSG_CHECKING([whether to support gconf defaults])
 have_gconfdefaults=no

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sun Jul 27 10:00:21 2008
@@ -18,6 +18,7 @@
 	$(LIBNOTIFY_CFLAGS)				\
 	$(UNIQUE_CFLAGS)				\
 	$(GSTREAMER_CFLAGS)				\
+	$(POLKIT_CFLAGS)				\
 	$(POLKIT_GNOME_CFLAGS)				\
 	-DBINDIR=\"$(bindir)\"			 	\
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"	\
@@ -171,8 +172,6 @@
 	gpm-refcount.c					\
 	gpm-button.h					\
 	gpm-button.c					\
-	gpm-polkit.h					\
-	gpm-polkit.c					\
 	gpm-brightness.h				\
 	gpm-brightness.c				\
 	gpm-brightness-hal.h				\
@@ -220,6 +219,7 @@
 	$(GSTREAMER_LIBS)				\
 	$(GNOME_LIBS)					\
 	$(HAL_LIBS)					\
+	$(POLKIT_LIBS)					\
 	$(DBUS_LIBS)					\
 	$(XRANDR_LIBS)					\
 	$(GPM_EXTRA_LIBS)				\
@@ -256,8 +256,6 @@
 	gpm-screensaver.c				\
 	gpm-engine.h					\
 	gpm-engine.c					\
-	gpm-polkit.h					\
-	gpm-polkit.c					\
 	gpm-phone.h					\
 	gpm-phone.c					\
 	gpm-cell.h					\

Modified: trunk/src/gpm-control.c
==============================================================================
--- trunk/src/gpm-control.c	(original)
+++ trunk/src/gpm-control.c	Sun Jul 27 10:00:21 2008
@@ -44,12 +44,16 @@
 
 #include <libhal-gpower.h>
 
+#ifdef HAVE_POLKIT
+#include <polkit/polkit.h>
+#include <polkit-dbus/polkit-dbus.h>
+#endif
+
 #include "gpm-conf.h"
 #include "gpm-screensaver.h"
 #include "gpm-common.h"
 #include "gpm-debug.h"
 #include "gpm-control.h"
-#include "gpm-polkit.h"
 #include "gpm-networkmanager.h"
 
 #define GPM_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_CONTROL, GpmControlPrivate))
@@ -58,7 +62,6 @@
 {
 	GpmConf			*conf;
 	HalGPower		*hal_power;
-	GpmPolkit		*polkit;
 };
 
 enum {
@@ -89,6 +92,29 @@
 }
 
 /**
+ * gpm_control_is_user_privileged:
+ * @polkit: This polkit class instance
+ * Return value: Success value.
+ **/
+gboolean
+gpm_control_is_user_privileged (GpmControl *control, const gchar *privilege)
+{
+	gboolean ret = TRUE;
+#ifdef HAVE_POLKIT
+	polkit_uint64_t mask;
+	pid_t pid;
+
+	pid = getpid ();
+	mask = polkit_check_auth (pid, privilege, NULL);
+	if (mask == 0) {
+		gpm_warning ("failed to authorise for privilege");
+		ret = FALSE;
+	}
+#endif
+	return ret;
+}
+
+/**
  * gpm_control_check_foreground_console:
  * @manager: This class instance
  * @action: The action we want to do, e.g. "suspend"
@@ -144,9 +170,7 @@
 	*can = FALSE;
 	gpm_conf_get_bool (control->priv->conf, GPM_CONF_CAN_SUSPEND, &conf_ok);
 	hal_ok = hal_gpower_can_suspend (control->priv->hal_power);
-	if (control->priv->polkit) {
-		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-suspend");
-	}
+	polkit_ok = gpm_control_is_user_privileged (control, "hal-power-suspend");
 	fg = gpm_control_check_foreground_console (control);
 	if (conf_ok && hal_ok && polkit_ok && fg) {
 		*can = TRUE;
@@ -178,9 +202,7 @@
 	gpm_conf_get_bool (control->priv->conf, GPM_CONF_CAN_HIBERNATE, &conf_ok);
 	hal_ok = hal_gpower_can_hibernate (control->priv->hal_power);
 	fg = gpm_control_check_foreground_console (control);
-	if (control->priv->polkit) {
-		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-hibernate");
-	}
+	polkit_ok = gpm_control_is_user_privileged (control, "hal-power-hibernate");
 	if (conf_ok && hal_ok && polkit_ok && fg) {
 		*can = TRUE;
 	}
@@ -203,9 +225,7 @@
 	g_return_val_if_fail (can, FALSE);
 	*can = FALSE;
 	fg = gpm_control_check_foreground_console (control);
-	if (control->priv->polkit) {
-		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-shutdown");
-	}
+	polkit_ok = gpm_control_is_user_privileged (control, "hal-power-shutdown");
 	if (polkit_ok && fg) {
 		*can = TRUE;
 	}
@@ -229,9 +249,7 @@
 	g_return_val_if_fail (can, FALSE);
 	*can = FALSE;
 	fg = gpm_control_check_foreground_console (control);
-	if (control->priv->polkit) {
-		polkit_ok = gpm_polkit_is_user_privileged (control->priv->polkit, "hal-power-reboot");
-	}
+	polkit_ok = gpm_control_is_user_privileged (control, "hal-power-reboot");
 	if (polkit_ok && fg) {
 		*can = TRUE;
 	}
@@ -540,9 +558,6 @@
 
 	g_object_unref (control->priv->conf);
 	g_object_unref (control->priv->hal_power);
-	if (control->priv->polkit) {
-		g_object_unref (control->priv->polkit);
-	}
 
 	g_return_if_fail (control->priv != NULL);
 	G_OBJECT_CLASS (gpm_control_parent_class)->finalize (object);
@@ -600,20 +615,13 @@
 /**
  * gpm_control_init:
  * @control: This control class instance
- *
- * initialises the control class. NOTE: We expect control objects
- * to *NOT* be removed or added during the session.
- * We only control the first control object if there are more than one.
  **/
 static void
 gpm_control_init (GpmControl *control)
 {
 	control->priv = GPM_CONTROL_GET_PRIVATE (control);
 
-	/* this will be NULL if we don't compile in support */
-	control->priv->polkit = gpm_polkit_new ();
 	control->priv->hal_power = hal_gpower_new ();
-
 	control->priv->conf = gpm_conf_new ();
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]