aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcaillon <caillon@517b70f8-ed25-0410-8bf6-f5db08f7b76e>2005-10-29 18:42:16 +0000
committercaillon <caillon@517b70f8-ed25-0410-8bf6-f5db08f7b76e>2005-10-29 18:42:16 +0000
commit1717d07cc0ce625f990ef70577dfceaef2acf181 (patch)
tree49df0cb0e8e104c2e9d92a88c04624d63c99d19c
parentfbcd6b2231f03dc3ac03527a55ba2c185a9bba15 (diff)
2005-10-29 Christopher Aillon <caillon@redhat.com>
* configure.ac: * src/Makefile.am: * src/krb5-auth-dialog.c: Use libnm-glib for NetworkManager support instead of the NetworkManager D-BUS API. git-svn-id: http://svn.gnome.org/svn/krb5-auth-dialog/trunk@27 517b70f8-ed25-0410-8bf6-f5db08f7b76e
-rw-r--r--ChangeLog7
-rw-r--r--configure.ac35
-rw-r--r--src/Makefile.am2
-rw-r--r--src/krb5-auth-dialog.c152
4 files changed, 76 insertions, 120 deletions
diff --git a/ChangeLog b/ChangeLog
index 0bf5e80..443cbd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2005-10-29 Christopher Aillon <caillon@redhat.com>
+ * configure.ac:
+ * src/Makefile.am:
+ * src/krb5-auth-dialog.c: Use libnm-glib for NetworkManager support
+ instead of the NetworkManager D-BUS API.
+
+2005-10-29 Christopher Aillon <caillon@redhat.com>
+
* src/krb5-auth-dialog.c: Reformat using tabs instead of spaces
2004-09-07 Christopher Aillon <caillon@redhat.com>
diff --git a/configure.ac b/configure.ac
index 5518227..3463e64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,25 +41,28 @@ if test "x$KRB5_CONFIG" != "xnone"; then
AC_SUBST(KRB5_LIBS)
fi
-AC_ARG_WITH(networkmanager, [--with-networkmanager Use NetworkManager to detect online status], ac_networkmanager=$withval, ac_networkmanager=auto)
-if test x"$ac_networkmanager" != xno; then
- PKG_CHECK_MODULES(NETWORKMANAGER, [ NetworkManager >= 0.2 ], have_networkmanager=yes, have_networkmanager=no)
+dnl NetworkManager
+
+AC_MSG_CHECKING([whether to enable NetworkManager support])
+AC_ARG_ENABLE([network-manager],
+ AS_HELP_STRING([--enable-network-manager],[Whether to enable automatic network status with NetworkManager]),
+ [],[enable_network_manager=autodetect])
+AC_MSG_RESULT([$enable_network_manager])
+
+if test "x$enable_network_manager" != "xno"; then
+ PKG_CHECK_MODULES([NETWORK_MANAGER],[libnm_glib >= 0.5],
+ [enable_network_manager=yes],[enable_network_manager=no])
+ AC_SUBST([NETWORK_MANAGER_CFLAGS])
+ AC_SUBST([NETWORK_MANAGER_LIBS])
fi
-if test x"$ac_networkmanager" = xno; then
- if test x"$have_networkmanager" = xyes; then
- AC_MSG_ERROR([NetworkManager support explicitly requested but not found on system])
- fi
- ac_networkmanager=no
-else
- if test x"$have_networkmanager" != xno; then
- AC_DEFINE(HAVE_NETWORKMANAGER, 1, [Define if you have NetworkManager])
- NETWORKMANAGER_CFLAGS="-DDBUS_API_SUBJECT_TO_CHANGE $NETWORKMANAGER_CFLAGS"
- AC_SUBST(NETWORKMANAGER_CFLAGS)
- AC_SUBST(NETWORKMANAGER_LIBS)
- fi
+
+if test "x$enable_network_manager" = "xyes"; then
+ AC_DEFINE([ENABLE_NETWORK_MANAGER],[1],[Define for NetworkManager support])
fi
-CFLAGS="$GNOME_CFLAGS $KRB5_CFLAGS $NETWORKMANAGER_CFLAGS $CFLAGS"
+AM_CONDITIONAL([ENABLE_NETWORK_MANAGER],[test "x$enable_network_manager" = "xyes"])
+
+CFLAGS="$GNOME_CFLAGS $KRB5_CFLAGS $NETWORK_MANAGER_CFLAGS $CFLAGS"
AC_OUTPUT([
Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 8000362..2bbde01 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,7 +6,7 @@ bin_PROGRAMS = krb5-auth-dialog
krb5_auth_dialog_SOURCES = \
krb5-auth-dialog.c
-krb5_auth_dialog_LDADD = @NETWORKMANAGER_LIBS@ @KRB5_LIBS@ @GNOME_LIBS@
+krb5_auth_dialog_LDADD = @NETWORK_MANAGER_LIBS@ @KRB5_LIBS@ @GNOME_LIBS@
gladedir = $(datadir)/krb5-auth-dialog
glade_DATA = \
diff --git a/src/krb5-auth-dialog.c b/src/krb5-auth-dialog.c
index 2fccb2e..7a84e98 100644
--- a/src/krb5-auth-dialog.c
+++ b/src/krb5-auth-dialog.c
@@ -29,8 +29,8 @@
#include <string.h>
#include "config.h"
-#ifdef HAVE_NETWORKMANAGER
-#include <dbus/dbus.h>
+#ifdef ENABLE_NETWORK_MANAGER
+#include <libnm_glib.h>
#endif
#define CREDENTIAL_CHECK_INTERVAL 30000 /* milliseconds */
@@ -43,9 +43,9 @@ static char* defname = NULL;
static gboolean invalid_password;
static gint creds_expiry;
-
static int renew_credentials ();
+
static void
setup_dialog (GladeXML *xml,
GtkWidget *dialog,
@@ -156,111 +156,35 @@ krb5_gtk_prompter (krb5_context ctx,
return errcode;
}
-static gboolean
-am_online (void)
+static gboolean is_online = TRUE;
+
+#ifdef ENABLE_NETWORK_MANAGER
+static void
+network_state_cb (libnm_glib_ctx *context,
+ gpointer data)
{
-#ifdef HAVE_NETWORKMANAGER
- static DBusConnection *connection = NULL;
- DBusMessage *msg, *reply;
- DBusError dbus_error;
- gboolean ret;
-
- ret = TRUE;
- dbus_error_init (&dbus_error);
- if (connection == NULL)
- {
- connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
- if (connection == NULL)
- {
- g_warning ("Couldn't connect to system bus: %s",
- dbus_error.message);
- dbus_error_free (&dbus_error);
- return ret;
- }
- dbus_connection_set_change_sigpipe (TRUE);
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
- }
+ gboolean *online = (gboolean*) data;
- msg = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
- "/org/freedesktop/NetworkManager",
- "org.freedesktop.NetworkManager",
- "getActiveDevice");
+ libnm_glib_state state;
- reply = dbus_connection_send_with_reply_and_block (connection, msg, -1, &dbus_error);
- dbus_message_unref (msg);
+ state = libnm_glib_get_network_state (context);
- if (dbus_error_is_set (&dbus_error))
+ switch (state)
{
- if (strcmp (dbus_error.name, "org.freedesktop.DBus.Error.ServiceDoesNotExist") == 0)
- g_warning ("NetworkManager is not running");
- else if (strcmp (dbus_error.name, "org.freedesktop.NetworkManager.NoActiveDevice") == 0)
- ret = FALSE;
- else
- g_warning ("Unknown error %s: %s", dbus_error.name, dbus_error.message);
-
- dbus_error_free (&dbus_error);
- }
- else if (reply == NULL)
- {
- g_warning ("no reply to org.freedesktop.NetworkManager.getActiveDevice");
- }
- else
- {
- char *active_device;
-
- if (!dbus_message_get_args (reply, &dbus_error,
- DBUS_TYPE_STRING, &active_device,
- DBUS_TYPE_INVALID))
- {
- g_warning ("couldn't parse reply to org.freedesktop.NetworkManager.getActiveDevice");
- }
- else
- {
- msg = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
- active_device,
- "org.freedesktop.NetworkManager.Devices",
- "getLinkActive");
- reply = dbus_connection_send_with_reply_and_block (connection, msg, -1, &dbus_error);
- dbus_message_unref (msg);
-
- if (dbus_error_is_set (&dbus_error))
- {
- g_warning ("Error %s: %s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- }
- else if (reply == NULL)
- {
- g_warning ("no reply to getLinkActive");
- }
- else
- {
- gboolean in_the_wired;
-
- if (!dbus_message_get_args (reply, &dbus_error,
- DBUS_TYPE_BOOLEAN, &in_the_wired,
- DBUS_TYPE_INVALID))
- {
- g_warning ("couldn't parse reply to getActiveDevice");
- }
- else
- {
- ret = in_the_wired;
- }
- }
-
- if (reply)
- dbus_message_unref (reply);
- }
+ case LIBNM_NO_DBUS:
+ case LIBNM_NO_NETWORKMANAGER:
+ case LIBNM_INVALID_CONTEXT:
+ /* do nothing */
+ break;
+ case LIBNM_NO_NETWORK_CONNECTION:
+ *online = FALSE;
+ break;
+ case LIBNM_ACTIVE_NETWORK_CONNECTION:
+ *online = TRUE;
+ break;
}
-
- if (reply)
- dbus_message_unref (reply);
-
- return ret;
-#else
- return TRUE;
-#endif
}
+#endif
static gboolean
credentials_expiring_real (void)
@@ -345,7 +269,7 @@ credentials_expiring_real (void)
static gboolean
credentials_expiring (gpointer *data)
{
- if (credentials_expiring_real () && am_online ())
+ if (credentials_expiring_real () && is_online)
renew_credentials ();
return TRUE;
@@ -432,6 +356,11 @@ main (int argc, char *argv[])
GtkWidget *dialog;
GnomeClient *client;
+#ifdef ENABLE_NETWORK_MANAGER
+ libnm_glib_ctx *nm_context;
+ guint32 nm_callback_id;
+#endif
+
gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
argc, argv, GNOME_PARAM_NONE);
@@ -441,7 +370,24 @@ main (int argc, char *argv[])
if (using_krb5 ())
{
g_signal_connect (G_OBJECT (client), "die",
- G_CALLBACK (gtk_main_quit), NULL);
+ G_CALLBACK (gtk_main_quit), NULL);
+
+#ifdef ENABLE_NETWORK_MANAGER
+ nm_context = libnm_glib_init ();
+ if (!nm_context)
+ g_warning ("Could not initialize libnm_glib");
+ else
+ {
+ nm_callback_id = libnm_glib_register_callback (nm_context, network_state_cb, &is_online, NULL);
+ if (nm_callback_id == 0)
+ {
+ libnm_glib_shutdown (nm_context);
+ nm_context = NULL;
+
+ g_warning ("Could not connect to NetworkManager, connection status will not be managed!\n");
+ }
+ }
+#endif /* ENABLE_NETWORK_MANAGER */
xml = glade_xml_new (GLADEDIR "krb5-auth-dialog.glade", NULL, NULL);
dialog = glade_xml_get_widget (xml, "krb5_dialog");