aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwalters <walters@517b70f8-ed25-0410-8bf6-f5db08f7b76e>2004-09-02 05:00:59 +0000
committerwalters <walters@517b70f8-ed25-0410-8bf6-f5db08f7b76e>2004-09-02 05:00:59 +0000
commita9b7b2c3c1f51a29c1d3197cbe21183b92d5c73b (patch)
tree51728c3334897cac4d4971789b5d17c4ea9ffb49
parent6129bf9e4b9fa1aafd4ff1f59ff6f4315d7ec6fa (diff)
2004-09-02 Colin Walters <walters@verbum.org>
* configure.in: Check for NetworkManager. * Makefile.am: Add NETWORKMANAGER_LIBS. * src/krb5-auth-dialog.c (am_online): New function, uses NetworkManager over D-BUS to determine whether or not we're online. * src/krb5-auth-dialog.c (credentials_expiring): Don't try to renew credentials if we're not online. git-svn-id: http://svn.gnome.org/svn/krb5-auth-dialog/trunk@22 517b70f8-ed25-0410-8bf6-f5db08f7b76e
-rw-r--r--ChangeLog14
-rw-r--r--configure.ac20
-rw-r--r--src/Makefile.am2
-rw-r--r--src/krb5-auth-dialog.c110
4 files changed, 141 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 76da25e..3d8bb6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-09-02 Colin Walters <walters@verbum.org>
+
+ * configure.in: Check for NetworkManager.
+
+ * Makefile.am: Add NETWORKMANAGER_LIBS.
+
+ * src/krb5-auth-dialog.c (am_online): New function,
+ uses NetworkManager over D-BUS to determine
+ whether or not we're online.
+
+ * src/krb5-auth-dialog.c (credentials_expiring): Don't
+ try to renew credentials if we're not online.
+
2004-08-28 Diego Gonzalez <diego@pemas.net>
* configure.ac: add --with-heimdal
@@ -15,7 +28,6 @@
* src/krb5-auth-dialog.c: Display status text for bad passwords
and display remaining time until expiry
-
Tue Aug 17 15:27:33 2004 Jonathan Blandford <jrb@redhat.com>
* src/krb5-auth-dialog.c: Use gettext
diff --git a/configure.ac b/configure.ac
index efb5895..5518227 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,9 +41,25 @@ 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)
+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
+fi
-CFLAGS="$GNOME_CFLAGS $KRB5_CFLAGS $CFLAGS"
-
+CFLAGS="$GNOME_CFLAGS $KRB5_CFLAGS $NETWORKMANAGER_CFLAGS $CFLAGS"
AC_OUTPUT([
Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index abe9677..8000362 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 = @KRB5_LIBS@ @GNOME_LIBS@
+krb5_auth_dialog_LDADD = @NETWORKMANAGER_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 0b0c5ac..7af2c8b 100644
--- a/src/krb5-auth-dialog.c
+++ b/src/krb5-auth-dialog.c
@@ -31,6 +31,10 @@
#include <pwd.h>
#include "config.h"
+#ifdef HAVE_NETWORKMANAGER
+#include <dbus/dbus.h>
+#endif
+
#define CREDENTIAL_CHECK_INTERVAL 30000 /* milliseconds */
#define SECONDS_BEFORE_PROMPTING 1800
@@ -172,6 +176,110 @@ krb5_gtk_prompter (krb5_context ctx,
}
static gboolean
+am_online (void)
+{
+#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);
+ }
+
+ msg = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager",
+ "org.freedesktop.NetworkManager",
+ "getActiveDevice");
+
+ reply = dbus_connection_send_with_reply_and_block (connection, msg, -1, &dbus_error);
+ dbus_message_unref (msg);
+
+ if (dbus_error_is_set (&dbus_error))
+ {
+ 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);
+ }
+ }
+ if (reply)
+ dbus_message_unref (reply);
+
+ return ret;
+#else
+ return TRUE;
+#endif
+}
+
+static gboolean
credentials_expiring_real (void)
{
krb5_ccache cache = NULL;
@@ -252,7 +360,7 @@ credentials_expiring_real (void)
static gboolean
credentials_expiring (gpointer *data)
{
- if (credentials_expiring_real())
+ if (credentials_expiring_real() && am_online ())
renew_credentials();
return TRUE;