aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/krb5-auth-dialog.c110
2 files changed, 110 insertions, 2 deletions
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;