2004-09-02 Colin Walters <walters@verbum.org>
authorwalters <walters@517b70f8-ed25-0410-8bf6-f5db08f7b76e>
Thu, 2 Sep 2004 05:00:59 +0000 (05:00 +0000)
committerwalters <walters@517b70f8-ed25-0410-8bf6-f5db08f7b76e>
Thu, 2 Sep 2004 05:00:59 +0000 (05:00 +0000)
* 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

ChangeLog
configure.ac
src/Makefile.am
src/krb5-auth-dialog.c

index 76da25ee9255afb64d76e57edabf1c68df8907c3..3d8bb6a212aa3596baebc688cf68735a7a518fa7 100644 (file)
--- 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
index efb5895c8980875ed9f580eb95b1b84a2f204b35..5518227ff7a30aabbbb59edc485bec3c2c6cee29 100644 (file)
@@ -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
index abe9677105a3b4c46a33804b9d51753e81377cd3..8000362f863d39f50092e6a3a7173cdde6560efd 100644 (file)
@@ -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 =                   \
index 0b0c5acbc005fb2e264f4acecf005038e5b6a138..7af2c8b15a366ca4a447ca1eb7548414534809f4 100644 (file)
 #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
 
@@ -171,6 +175,110 @@ krb5_gtk_prompter (krb5_context ctx,
   return errcode;
 }
 
+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)
 {
@@ -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;