[krb5-auth-dialog] Hide configuration tickets by default



commit 7f2bb5af6272060b63243fd9a69d7a6199da9b33
Author: Guido Günther <agx sigxcpu org>
Date:   Sat Mar 16 16:37:21 2013 +0100

    Hide configuration tickets by default
    
    Based on a patch by Mantas Mikulėnas
    BZ: #649830

 src/ka-applet-priv.h                    |    1 +
 src/ka-applet.c                         |   31 +++++++++++++++++++++++++++----
 src/ka-kerberos.c                       |   18 +++++++++++-------
 src/ka-kerberos.h                       |    3 ++-
 src/ka-main-window.c                    |   16 +++++++++++-----
 src/ka-main-window.h                    |    2 +-
 src/ka-settings.c                       |    1 +
 src/ka-settings.h                       |    1 +
 src/org.gnome.KrbAuthDialog.gschema.xml |    5 +++++
 9 files changed, 60 insertions(+), 18 deletions(-)
---
diff --git a/src/ka-applet-priv.h b/src/ka-applet-priv.h
index 0a8f021..25fe281 100644
--- a/src/ka-applet-priv.h
+++ b/src/ka-applet-priv.h
@@ -64,6 +64,7 @@ void ka_applet_set_msg (KaApplet *self, const char *msg);
 #define KA_PROP_NAME_TGT_FORWARDABLE "tgt-forwardable"
 #define KA_PROP_NAME_TGT_PROXIABLE   "tgt-proxiable"
 #define KA_PROP_NAME_TGT_RENEWABLE   "tgt-renewable"
+#define KA_PROP_NAME_CONF_TICKETS    "conf-tickets"
 
 /* create the applet */
 KaApplet *ka_applet_create (void);
diff --git a/src/ka-applet.c b/src/ka-applet.c
index 697c06d..669e9b5 100644
--- a/src/ka-applet.c
+++ b/src/ka-applet.c
@@ -50,6 +50,7 @@ enum {
     KA_PROP_TGT_FORWARDABLE,
     KA_PROP_TGT_PROXIABLE,
     KA_PROP_TGT_RENEWABLE,
+    KA_PROP_CONF_TICKETS,
 };
 
 
@@ -101,6 +102,7 @@ struct _KaAppletPrivate {
     gboolean tgt_forwardable;   /* request a forwardable ticket */
     gboolean tgt_renewable;     /* request a renewable ticket */
     gboolean tgt_proxiable;     /* request a proxiable ticket */
+    gboolean conf_tickets;      /* whether to display configuration tickets */
 
     GSettings *settings;         /* GSettings client */
 };
@@ -112,9 +114,11 @@ static gboolean is_initialized;
 static void
 ka_applet_activate (GApplication *application G_GNUC_UNUSED)
 {
+    KaApplet *self = KA_APPLET(application);
+
     if (is_initialized) {
         KA_DEBUG ("Main window activated");
-        ka_main_window_show ();
+        ka_main_window_show (self);
     } else
         is_initialized = TRUE;
 }
@@ -244,6 +248,12 @@ ka_applet_set_property (GObject *object,
                   self->priv->tgt_renewable ? "True" : "False");
         break;
 
+    case KA_PROP_CONF_TICKETS:
+        self->priv->conf_tickets = g_value_get_boolean (value);
+        KA_DEBUG ("%s: %s", pspec->name,
+                  self->priv->tgt_renewable ? "True" : "False");
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -288,6 +298,10 @@ ka_applet_get_property (GObject *object,
         g_value_set_boolean (value, self->priv->tgt_renewable);
         break;
 
+    case KA_PROP_CONF_TICKETS:
+        g_value_set_boolean (value, self->priv->conf_tickets);
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -417,6 +431,15 @@ ka_applet_class_init (KaAppletClass *klass)
                                   G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
     g_object_class_install_property (object_class,
                                      KA_PROP_TGT_RENEWABLE, pspec);
+
+    pspec = g_param_spec_boolean (KA_PROP_NAME_CONF_TICKETS,
+                                  "Configuration tickets",
+                                  "wether to show configuration tickets",
+                                  FALSE,
+                                  G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
+    g_object_class_install_property (object_class,
+                                     KA_PROP_CONF_TICKETS, pspec);
+
     for (i=0; i < KA_SIGNAL_COUNT-1; i++) {
         guint signalId;
 
@@ -568,7 +591,7 @@ ka_notify_ticket_action_cb (NotifyNotification *notification G_GNUC_UNUSED,
         ka_destroy_ccache (self);
     } else if (strcmp (action, "ka-list-tickets") == 0) {
         KA_DEBUG ("Showing main window");
-        ka_main_window_show ();
+        ka_main_window_show (self);
     } else {
         g_warning ("unkonwn action for callback");
     }
@@ -840,9 +863,9 @@ ka_applet_destroy_ccache_cb (GtkMenuItem *menuitem G_GNUC_UNUSED,
 
 static void
 ka_applet_show_tickets_cb (GtkMenuItem *menuitem G_GNUC_UNUSED,
-                           gpointer user_data G_GNUC_UNUSED)
+                           gpointer user_data)
 {
-    ka_main_window_show ();
+    ka_main_window_show (KA_APPLET(user_data));
 }
 
 
diff --git a/src/ka-kerberos.c b/src/ka-kerberos.c
index c74b20b..db5cddd 100644
--- a/src/ka-kerberos.c
+++ b/src/ka-kerberos.c
@@ -287,7 +287,7 @@ ka_format_time (time_t t, gchar *ts, size_t len)
 
 /* fill in service tickets data */
 gboolean
-ka_get_service_tickets (GtkListStore * tickets)
+ka_get_service_tickets (GtkListStore * tickets, gboolean hide_conf_tickets)
 {
     krb5_cc_cursor cursor;
     krb5_creds creds;
@@ -314,8 +314,7 @@ ka_get_service_tickets (GtkListStore * tickets)
         if (!g_file_test (ka_ccache_filename (), G_FILE_TEST_EXISTS))
             gtk_list_store_append (tickets, &iter);
             gtk_list_store_set (tickets, &iter,
-                                PRINCIPAL_COLUMN,
-                                _("Your ticket cache is currently empty"),
+                                PRINCIPAL_COLUMN, _("Your ticket cache is currently empty"),
                                 FORWARDABLE_COLUMN, FALSE,
                                 RENEWABLE_COLUMN, FALSE,
                                 PROXIABLE_COLUMN, FALSE, -1);
@@ -326,6 +325,13 @@ ka_get_service_tickets (GtkListStore * tickets)
     while ((ret = krb5_cc_next_cred (kcontext, ccache, &cursor, &creds)) == 0) {
         gboolean renewable, proxiable, forwardable;
 
+
+        if (hide_conf_tickets && krb5_is_config_principal (kcontext,
+                                                           creds.server)) {
+            krb5_free_cred_contents (kcontext, &creds);
+            continue;
+        }
+
         if (creds.times.starttime)
             ka_format_time (creds.times.starttime, start_time,
                             sizeof (start_time));
@@ -338,10 +344,8 @@ ka_get_service_tickets (GtkListStore * tickets)
             strcpy (end_time_markup, end_time);
         else
             g_snprintf (end_time_markup, sizeof (end_time_markup),
-                        "%s <span foreground=\"red\" "
-                        "style=\"italic\">(%s)</span>",
-                        end_time,
-                        _("Expired"));
+                        "%s <span foreground=\"red\" style=\"italic\">(%s)</span>",
+                        end_time, _("Expired"));
 
         forwardable = get_cred_forwardable (&creds);
         renewable = get_cred_renewable (&creds);
diff --git a/src/ka-kerberos.h b/src/ka-kerberos.h
index 504cc14..aa70c90 100644
--- a/src/ka-kerberos.h
+++ b/src/ka-kerberos.h
@@ -29,7 +29,8 @@ gboolean ka_kerberos_destroy (void);
 gboolean ka_destroy_ccache (KaApplet* applet);
 gboolean ka_grab_credentials(KaApplet* applet);
 gboolean ka_check_credentials (KaApplet *applet, const char* principal);
-gboolean ka_get_service_tickets(GtkListStore *tickets);
+gboolean ka_get_service_tickets(GtkListStore *tickets,
+                                gboolean hide_service_tickets);
 char* ka_unparse_name(void);
 int ka_tgt_valid_seconds(void);
 #endif
diff --git a/src/ka-main-window.c b/src/ka-main-window.c
index b841b3e..807512d 100644
--- a/src/ka-main-window.c
+++ b/src/ka-main-window.c
@@ -2,7 +2,7 @@
  *
  * Krb5 Auth Applet -- Acquire and release kerberos tickets
  *
- * (C) 2009,2011 Guido Guenther <agx sigxcpu org>
+ * (C) 2009,2011,2013 Guido Guenther <agx sigxcpu org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,11 +34,14 @@ static GtkListStore *tickets;
 static GtkWindow *main_window;
 
 static void
-ccache_changed_cb (KaApplet* applet G_GNUC_UNUSED,
+ccache_changed_cb (KaApplet* applet,
                    gpointer user_data G_GNUC_UNUSED)
 {
+    gboolean conf_tickets;
+
     KA_DEBUG("Refreshing ticket list");
-    ka_get_service_tickets (tickets);
+    g_object_get(applet, KA_PROP_NAME_CONF_TICKETS, &conf_tickets, NULL);
+    ka_get_service_tickets (tickets, !conf_tickets);
 }
 
 static void
@@ -164,9 +167,12 @@ ka_main_window_create (KaApplet *applet, GtkBuilder *xml)
 }
 
 void
-ka_main_window_show ()
+ka_main_window_show (KaApplet *applet)
 {
-    if (ka_get_service_tickets (tickets)) {
+    gboolean conf_tickets;
+
+    g_object_get(applet, KA_PROP_NAME_CONF_TICKETS, &conf_tickets, NULL);
+    if (ka_get_service_tickets (tickets, !conf_tickets)) {
         gtk_window_present (main_window);
     } else {
         GtkWidget *message_dialog;
diff --git a/src/ka-main-window.h b/src/ka-main-window.h
index bc5b191..484a850 100644
--- a/src/ka-main-window.h
+++ b/src/ka-main-window.h
@@ -35,7 +35,7 @@ enum ticket_columns {
 
 
 GtkWindow *ka_main_window_create (KaApplet *applet, GtkBuilder *xml);
-void ka_main_window_show (void);
+void ka_main_window_show (KaApplet *applet);
 void ka_main_window_hide (void);
 
 
diff --git a/src/ka-settings.c b/src/ka-settings.c
index d93d30d..a2baab4 100644
--- a/src/ka-settings.c
+++ b/src/ka-settings.c
@@ -42,6 +42,7 @@ ka_setup_bindings(KaApplet* applet,
     do_binding(TGT_FORWARDABLE);
     do_binding(TGT_PROXIABLE);
     do_binding(TGT_RENEWABLE);
+    do_binding(CONF_TICKETS);
 }
 
 #undef do_binding
diff --git a/src/ka-settings.h b/src/ka-settings.h
index bbdd5fe..029c429 100644
--- a/src/ka-settings.h
+++ b/src/ka-settings.h
@@ -31,6 +31,7 @@
 #define KA_SETTING_KEY_TGT_FORWARDABLE  "forwardable"
 #define KA_SETTING_KEY_TGT_RENEWABLE    "renewable"
 #define KA_SETTING_KEY_TGT_PROXIABLE    "proxiable"
+#define KA_SETTING_KEY_CONF_TICKETS     "conf-tickets"
 #define KA_SETTING_CHILD_NOTIFY         "notify"
 #define KA_SETTING_KEY_NOTIFY_VALID     "valid"
 #define KA_SETTING_KEY_NOTIFY_EXPIRED   "expired"
diff --git a/src/org.gnome.KrbAuthDialog.gschema.xml b/src/org.gnome.KrbAuthDialog.gschema.xml
index c63d7db..4764744 100644
--- a/src/org.gnome.KrbAuthDialog.gschema.xml
+++ b/src/org.gnome.KrbAuthDialog.gschema.xml
@@ -35,6 +35,11 @@
       <summary>Proxiable ticket</summary>
       <description>Requested tickets should be proxiable</description>
     </key>
+    <key name="conf-tickets" type="b">
+      <default>false</default>
+      <summary>Configuration tickets</summary>
+      <description>Show configuration tickets</description>
+    </key>
     <child name="notify" schema="org.gnome.KrbAuthDialog.notify"/>
     <child name="plugins" schema="org.gnome.KrbAuthDialog.plugins"/>
   </schema>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]