2004-09-07 Christopher Aillon <caillon@redhat.com>
authorcaillon <caillon@517b70f8-ed25-0410-8bf6-f5db08f7b76e>
Tue, 7 Sep 2004 19:51:30 +0000 (19:51 +0000)
committercaillon <caillon@517b70f8-ed25-0410-8bf6-f5db08f7b76e>
Tue, 7 Sep 2004 19:51:30 +0000 (19:51 +0000)
        * src/krb5-auth-dialog.c: Check whether we are running in a
        kerberos environment before entering the timeout to see when
        the tickets expire.

        * src/krb5-auth-dialog.c: Use g_get_user_name and other code
        cleanup.

git-svn-id: http://svn.gnome.org/svn/krb5-auth-dialog/trunk@23 517b70f8-ed25-0410-8bf6-f5db08f7b76e

ChangeLog
src/krb5-auth-dialog.c

index 3d8bb6a212aa3596baebc688cf68735a7a518fa7..61f8345783a4aa9c2fe84f2dd4897596fb6afa8e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-09-07  Christopher Aillon <caillon@redhat.com>
+       * src/krb5-auth-dialog.c: Check whether we are running in a
+       kerberos environment before entering the timeout to see when
+       the tickets expire.
+
+       * src/krb5-auth-dialog.c: Use g_get_user_name and other code
+       cleanup.
+
 2004-09-02  Colin Walters  <walters@verbum.org>
 
        * configure.in: Check for NetworkManager.
@@ -14,7 +22,7 @@
 2004-08-28  Diego Gonzalez  <diego@pemas.net>
 
        * configure.ac: add --with-heimdal
-       * krb5-auth-dialog: modify to support heimdal if enabled
+       * krb5-auth-dialog.c: modify to support heimdal if enabled
        * krb5-auth-dialog.glade: center the dialog
 
 2004-08-19  Kjartan Maraas  <kmaraas@gnome.org>
index 7af2c8b15a366ca4a447ca1eb7548414534809f4..fa262ab3446f14d3e381d5f1d37584d722ea7456 100644 (file)
 #include <time.h>
 #include <krb5.h>
 #include <stdio.h>
+#include <sys/wait.h>
 #include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <pwd.h>
 #include "config.h"
 
 #ifdef HAVE_NETWORKMANAGER
@@ -48,23 +46,6 @@ static gint creds_expiry;
 
 static int renew_credentials ();
 
-static int
-whoami (const char **username)
-{
-  struct passwd *p;
-  uid_t uid;
-
-  uid = geteuid();
-  if (!(p = getpwuid(uid)))
-    {
-      return -1;
-    }
-
-  *username = p->pw_name;
-
-  return 0;
-}
-
 static void
 setup_dialog (GladeXML    *xml,
              GtkWidget   *dialog,
@@ -311,17 +292,17 @@ credentials_expiring_real (void)
          do_v4_ccache(0);
 #endif
       }
-      exit(1);
+      gtk_exit(1);
     }
 
   if ((code = krb5_cc_get_principal(kcontext, cache, &princ)))
-    exit(1);
+    gtk_exit(1);
 
   if ((code = krb5_unparse_name(kcontext, princ, &defname)))
-    exit(1);
+    gtk_exit(1);
 
   if ((code = krb5_cc_start_seq_get(kcontext, cache, &cur)))
-    exit(1);
+    gtk_exit(1);
 
   while (!(code = krb5_cc_next_cred(kcontext, cache, &cur, &my_creds)))
     {
@@ -341,17 +322,17 @@ credentials_expiring_real (void)
       flags = KRB5_TC_OPENCLOSE;  /* turns on OPENCLOSE mode, from klist.c */
 #endif
       if ((code = krb5_cc_set_flags(kcontext, cache, flags)))
-        exit(1);
+        gtk_exit(1);
 #ifdef KRB5_KRB4_COMPAT
       if (name == NULL && !status_only)
         do_v4_ccache(0);
 #endif
       if (exit_status)
-       exit(exit_status);
+       gtk_exit(exit_status);
     }
   else
     {
-      exit(1);
+      gtk_exit(1);
     }
 
   return retval;
@@ -360,8 +341,8 @@ credentials_expiring_real (void)
 static gboolean
 credentials_expiring (gpointer *data)
 {
-  if (credentials_expiring_real() && am_online ())
-    renew_credentials();
+  if (credentials_expiring_real () && am_online ())
+    renew_credentials ();
 
   return TRUE;
 }
@@ -373,7 +354,6 @@ renew_credentials (void)
   krb5_get_init_creds_opt options;
   krb5_creds my_creds;
   krb5_ccache ccache;
-  const char *username;
 
   memset(&my_creds, 0, sizeof(my_creds));
   krb5_get_init_creds_opt_init(&options);
@@ -382,11 +362,7 @@ renew_credentials (void)
   if (retval)
     return retval;
 
-  retval = whoami(&username);
-  if (retval)
-    return retval;
-
-  retval = krb5_parse_name(kcontext, username, &kprincipal);
+  retval = krb5_parse_name(kcontext, g_get_user_name (), &kprincipal);
   if (retval)
     return retval;
 
@@ -421,6 +397,33 @@ renew_credentials (void)
   return 0;
 }
 
+gboolean
+using_krb5()
+{
+  const gchar *krb5ccname;
+
+  gboolean success;
+  int exit_status;
+  GError *error;
+
+  /* See if we have a credential cache specified. */
+  krb5ccname = g_getenv("KRB5CCNAME");
+  if (krb5ccname != NULL)
+    return TRUE;
+
+  /* Nope, let's see if we have any prior tickets. */
+  success = g_spawn_command_line_sync("klist -s",
+                                     NULL, NULL,
+                                     &exit_status,
+                                     &error);
+
+  if (success == TRUE && error == NULL &&
+      WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == 0)
+    return TRUE;
+
+  return FALSE;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -433,15 +436,19 @@ main (int argc, char *argv[])
   client = gnome_master_client ();
   gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY);
 
-  g_signal_connect (G_OBJECT (client), "die",
-                    G_CALLBACK (gtk_main_quit), NULL);
+  if (using_krb5 ())
+    {
+      g_signal_connect (G_OBJECT (client), "die",
+                       G_CALLBACK (gtk_main_quit), NULL);
+
+      xml = glade_xml_new (GLADEDIR "krb5-auth-dialog.glade", NULL, NULL);
+      dialog = glade_xml_get_widget (xml, "krb5_dialog");
 
-  xml = glade_xml_new (GLADEDIR "krb5-auth-dialog.glade", NULL, NULL);
-  dialog = glade_xml_get_widget (xml, "krb5_dialog");
+      g_timeout_add (CREDENTIAL_CHECK_INTERVAL, (GSourceFunc)credentials_expiring, NULL);
+      credentials_expiring (NULL);
 
-  g_timeout_add (CREDENTIAL_CHECK_INTERVAL, (GSourceFunc)credentials_expiring, NULL);
-  credentials_expiring (NULL);
-  gtk_main();
+      gtk_main ();
+    }
 
   return 0;
 }