network-manager-applet r724 - in trunk: . src/connection-editor



Author: dcbw
Date: Mon May 12 14:04:10 2008
New Revision: 724
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=724&view=rev

Log:
2008-05-12  Dan Williams  <dcbw redhat com>

	* configure.ac
		- Handle PolicyKit 0.6 and grab PK version for later use
		- Split out PK CFLAGS and LIBS from main NMA flags and libs

	* src/connection-editor/Makefile.am
		- Use split out PK CFLAGS and LIBS
		- Build in PK 0.6 helpers when needed

	* src/connection-editor/polkit-06-helpers.c
	  src/connection-editor/polkit-06-helpers.h
		- (polkit_gnome_auth_obtain): re-implement for PK 0.6 using ShowDialog
			instead

	* src/connection-editor/nm-connection-list.c
		- Use polkit-06-helpers when needed



Added:
   trunk/src/connection-editor/polkit-06-helpers.c
   trunk/src/connection-editor/polkit-06-helpers.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/connection-editor/Makefile.am
   trunk/src/connection-editor/nm-connection-list.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Mon May 12 14:04:10 2008
@@ -76,8 +76,7 @@
 		 gmodule-export-2.0
 		 gconf-2.0
 		 gnome-keyring-1
-		 libnotify >= 0.4.3
-		 polkit-gnome])
+		 libnotify >= 0.4.3])
 
 ##### Find out the version of DBUS we're using
 dbus_version=`pkg-config --modversion dbus-1`
@@ -112,6 +111,48 @@
 fi
 AC_SUBST(DBUS_CFLAGS)
 
+#### PolicyKit checks; need at least 0.6 or later
+PKG_CHECK_EXISTS(polkit-gnome,[have_polkit_gnome=yes],[have_polkit_gnome=no])
+if test x"$have_polkit_gnome" = "xyes"; then
+	PKG_CHECK_MODULES(POLKIT, polkit-gnome)
+else
+	PKG_CHECK_MODULES(POLKIT, [polkit >= 0.6])
+	AC_DEFINE([NO_POLKIT_GNOME],[1],[Define if you don't have PolicyKit-gnome 0.7 or later])
+fi
+AM_CONDITIONAL(NO_POLKIT_GNOME, test x"$have_polkit_gnome" = "xno")
+
+##### Find out the version of PolicyKit we're using
+polkit_version=`pkg-config --modversion polkit`
+POLKIT_VERSION_MAJOR=`echo $polkit_version | awk -F. '{print $1}'`
+POLKIT_VERSION_MINOR=`echo $polkit_version | awk -F. '{print $2}'`
+POLKIT_VERSION_MICRO=`echo $polkit_version | awk -F. '{print $3}'`
+if test "z$POLKIT_VERSION_MAJOR" = "z"; then
+	POLKIT_VERSION_MAJOR="0"
+fi
+if test "z$POLKIT_VERSION_MINOR" = "z"; then
+	POLKIT_VERSION_MINOR="0"
+fi
+if test "z$POLKIT_VERSION_MICRO" = "z"; then
+	POLKIT_VERSION_MICRO="0"
+fi
+
+if test "z$POLKIT_VERSION_MAJOR" = "z0" -a "z$POLKIT_VERSION_MINOR" = "z0" -a "z$POLKIT_VERSION_MICRO" = "z0"; then
+	echo "Error: Couldn't determine the version of your PolicyKit package."
+	echo "  This is probably an error in this script, please report it"
+	echo "  along with the following information:"
+	echo "      Base PolicyKit version ='$polkit_version'"
+	echo "      POLKIT_VERSION_MAJOR='$POLKIT_VERSION_MAJOR'"
+	echo "      POLKIT_VERSION_MINOR='$POLKIT_VERSION_MINOR'"
+	echo "      POLKIT_VERSION_MICRO='$POLKIT_VERSION_MICRO'"
+	exit 1
+else
+	echo "Your PolicyKit version is $POLKIT_VERSION_MAJOR,$POLKIT_VERSION_MINOR,$POLKIT_VERSION_MICRO."
+	POLKIT_CFLAGS="$POLKIT_CFLAGS -DPOLKIT_VERSION_MAJOR=$POLKIT_VERSION_MAJOR"
+	POLKIT_CFLAGS="$POLKIT_CFLAGS -DPOLKIT_VERSION_MINOR=$POLKIT_VERSION_MINOR"
+	POLKIT_CFLAGS="$POLKIT_CFLAGS -DPOLKIT_VERSION_MICRO=$POLKIT_VERSION_MICRO"
+fi
+AC_SUBST(POLKIT_CFLAGS)
+
 AC_MSG_CHECKING([Linux Wireless Extensions >= 18])
 AC_TRY_COMPILE([#ifndef __user
                 #define __user

Modified: trunk/src/connection-editor/Makefile.am
==============================================================================
--- trunk/src/connection-editor/Makefile.am	(original)
+++ trunk/src/connection-editor/Makefile.am	Mon May 12 14:04:10 2008
@@ -10,6 +10,7 @@
 	-DSYSCONFDIR=\""$(sysconfdir)"\"	\
 	-DNMALOCALEDIR=\"$(datadir)/locale\"	\
 	$(DBUS_CFLAGS)				\
+	$(POLKIT_CFLAGS) \
 	$(DISABLE_DEPRECATED)			\
 	-I${top_srcdir}/src/gconf-helpers  \
 	-I${top_srcdir}/src/utils \
@@ -43,11 +44,18 @@
 	page-ppp.h \
 	page-ppp.c
 
+if NO_POLKIT_GNOME
+nm_connection_editor_SOURCES += \
+	polkit-06-helpers.c \
+	polkit-06-helpers.h
+endif
+
 nm_connection_editor_LDADD = \
 	$(top_builddir)/src/gconf-helpers/libgconf-helpers.la \
 	${top_builddir}/src/wireless-security/libwireless-security.la \
 	${top_builddir}/src/utils/libutils.la \
-	$(NMA_LIBS)
+	$(NMA_LIBS) \
+	$(POLKIT_LIBS)
 
 gladedir = $(datadir)/nm-applet
 glade_DATA = \

Modified: trunk/src/connection-editor/nm-connection-list.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-list.c	(original)
+++ trunk/src/connection-editor/nm-connection-list.c	Mon May 12 14:04:10 2008
@@ -20,6 +20,7 @@
  * (C) Copyright 2004-2005 Red Hat, Inc.
  */
 
+#include <config.h>
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -33,9 +34,14 @@
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkstock.h>
 #include <gconf/gconf-client.h>
-#include <polkit-gnome/polkit-gnome.h>
 #include <glib/gi18n.h>
 
+#ifdef NO_POLKIT_GNOME
+#include "polkit-06-helpers.h"
+#else
+#include <polkit-gnome/polkit-gnome.h>
+#endif
+
 #include <nm-setting-connection.h>
 #include <nm-connection.h>
 #include <nm-setting.h>

Added: trunk/src/connection-editor/polkit-06-helpers.c
==============================================================================
--- (empty file)
+++ trunk/src/connection-editor/polkit-06-helpers.c	Mon May 12 14:04:10 2008
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2008 Red Hat, Inc.
+ */
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+#include "polkit-06-helpers.h"
+
+typedef struct {
+        PolKitAction *action;
+        PolKitGnomeAuthCB callback;
+        gpointer user_data;
+} DialogResponseInfo;
+
+static void
+pk_auth_dialog_response_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+	GError *error = NULL;
+	DialogResponseInfo *info = (DialogResponseInfo *) user_data;
+	gboolean gained_privilege = FALSE;
+
+	if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &gained_privilege, G_TYPE_INVALID))
+		gained_privilege = FALSE;
+
+	/* perform the callback */
+	info->callback (info->action, gained_privilege, error, info->user_data);
+
+	g_object_unref (proxy);
+	polkit_action_unref (info->action);
+}
+
+gboolean
+polkit_gnome_auth_obtain (PolKitAction *pk_action,
+                          guint xid,
+                          pid_t pid,
+                          PolKitGnomeAuthCB callback,
+                          gpointer user_data,
+                          GError **error)
+{
+	char *polkit_action_id;
+	DialogResponseInfo *info;
+	DBusGConnection *session_bus;
+	DBusGProxy *polkit_gnome_proxy;
+	gboolean ret = TRUE;
+
+	if ((session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error)) == NULL)
+		return FALSE;
+
+	/* TODO: this can fail.. */
+	polkit_action_get_action_id (pk_action, &polkit_action_id);
+
+	polkit_gnome_proxy = dbus_g_proxy_new_for_name (session_bus,
+	                                                "org.freedesktop.PolicyKit.AuthenticationAgent", /* bus name */
+	                                                "/",                                             /* object */
+	                                                "org.freedesktop.PolicyKit.AuthenticationAgent");/* interface */
+
+	info = g_malloc0 (sizeof (DialogResponseInfo));
+	info->action = polkit_action_ref (pk_action);
+	info->callback = callback;
+	info->user_data = user_data;	
+
+	/* now use PolicyKit-gnome to bring up an auth dialog */
+	if (!dbus_g_proxy_begin_call_with_timeout (polkit_gnome_proxy,
+	                                           "ShowDialog",
+	                                           pk_auth_dialog_response_cb,
+	                                           info,
+	                                           g_free,
+	                                           INT_MAX,
+	                                           /* parameters: */
+	                                           G_TYPE_STRING, polkit_action_id,  /* action_id */
+	                                           G_TYPE_UINT, xid, /* X11 window ID */
+	                                           G_TYPE_INVALID)) {
+		ret = FALSE;
+	}
+
+	dbus_g_connection_unref (session_bus);
+	return ret;
+}
+
+

Added: trunk/src/connection-editor/polkit-06-helpers.h
==============================================================================
--- (empty file)
+++ trunk/src/connection-editor/polkit-06-helpers.h	Mon May 12 14:04:10 2008
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2008 Red Hat, Inc.
+ */
+
+#ifndef POLKIT_06_HELPERS_H
+#define POLKIT_06_HELPERS_H
+
+#include <glib.h>
+#include <polkit/polkit.h>
+
+typedef void (*PolKitGnomeAuthCB) (PolKitAction *action, gboolean gained_privilege, GError *error, gpointer user_data);
+
+gboolean polkit_gnome_auth_obtain (PolKitAction *pk_action,
+                                   guint xid,
+                                   pid_t pid,
+                                   PolKitGnomeAuthCB callback,
+                                   gpointer user_data,
+                                   GError **error);
+
+#endif /* POLKIT_06_HELPERS_H */



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