krb5-auth-dialog r129 - in trunk: . po src



Author: guidog
Date: Wed Mar 11 16:25:47 2009
New Revision: 129
URL: http://svn.gnome.org/viewvc/krb5-auth-dialog?rev=129&view=rev

Log:
add a pwdialog gobject

Added:
   trunk/src/krb5-auth-pwdialog.c
   trunk/src/krb5-auth-pwdialog.h
Modified:
   trunk/ChangeLog
   trunk/po/POTFILES.in
   trunk/src/Makefile.am
   trunk/src/krb5-auth-applet.c
   trunk/src/krb5-auth-applet.h
   trunk/src/krb5-auth-dbus.c
   trunk/src/krb5-auth-dialog.c
   trunk/src/krb5-auth-dialog.glade
   trunk/src/krb5-auth-dialog.h

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Wed Mar 11 16:25:47 2009
@@ -1,5 +1,6 @@
 src/krb5-auth-dialog.glade
 src/krb5-auth-dialog.c
+src/krb5-auth-pwdialog.c
 src/dummy-strings.c
 src/krb5-auth-applet.c
 src/krb5-auth-dialog.desktop.in

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Wed Mar 11 16:25:47 2009
@@ -22,6 +22,8 @@
 	krb5-auth-dialog.h      \
 	krb5-auth-applet.c	\
 	krb5-auth-applet.h	\
+	krb5-auth-pwdialog.c    \
+	krb5-auth-pwdialog.h    \
 	krb5-auth-gconf.c	\
 	krb5-auth-gconf.h	\
 	krb5-auth-dbus.c	\

Modified: trunk/src/krb5-auth-applet.c
==============================================================================
--- trunk/src/krb5-auth-applet.c	(original)
+++ trunk/src/krb5-auth-applet.c	Wed Mar 11 16:25:47 2009
@@ -64,12 +64,8 @@
 	const char* icons[3]; 		/* for invalid, expiring and valid tickts */
 	gboolean show_trayicon;		/* show the trayicon */
 
-	/* The password dialog */
-	GtkWidget* pw_dialog;		/* the password dialog itself */
-	GladeXML*  pw_xml;		/* the dialog's glade xml */
-	GtkWidget* pw_label;		/* the wrong password/timeout label */
+	KaPwDialog* pwdialog;		/* the password dialog */
 	int	   pw_prompt_secs;	/* when to start prompting for a password */
-	gboolean   pw_dialog_persist;	/* don't hide the dialog when creds are still valid */
 
 #ifdef HAVE_LIBNOTIFY
 	NotifyNotification* notification;/* notification messages */
@@ -160,9 +156,9 @@
 		g_object_unref(applet->priv->tray_icon);
 		applet->priv->tray_icon = NULL;
 	}
-	if (applet->priv->pw_xml) {
-		g_object_unref(applet->priv->pw_xml);
-		applet->priv->pw_xml = NULL;
+	if (applet->priv->pwdialog) {
+		g_object_unref(applet->priv->pwdialog);
+		applet->priv->pwdialog = NULL;
 	}
 
 	if (parent_class->dispose != NULL)
@@ -243,7 +239,8 @@
 }
 
 
-KaApplet *ka_applet_new(void)
+static KaApplet*
+ka_applet_new(void)
 {
 	return g_object_new (KA_TYPE_APPLET, NULL);
 }
@@ -497,7 +494,6 @@
 	return TRUE;
 }
 
-
 static int
 ka_applet_setup_icons (KaApplet* applet)
 {
@@ -510,27 +506,6 @@
 	return TRUE;
 }
 
-
-static gboolean
-ka_applet_glade_init(KaApplet *applet)
-{
-	KaAppletPrivate *priv = applet->priv;
-
-	priv->pw_xml = glade_xml_new (KA_DATA_DIR G_DIR_SEPARATOR_S
-				      PACKAGE ".glade", NULL, NULL);
-	priv->pw_label = glade_xml_get_widget (priv->pw_xml, "krb5_wrong_label");
-	priv->pw_dialog = glade_xml_get_widget (priv->pw_xml, "krb5_dialog");
-
-	return TRUE;
-}
-
-
-GladeXML*
-ka_applet_get_pwdialog_xml(const KaApplet* applet)
-{
-	return applet->priv->pw_xml;
-}
-
 guint
 ka_applet_get_pw_prompt_secs(const KaApplet* applet)
 {
@@ -555,39 +530,18 @@
 	return applet->priv->renewable;
 }
 
-gint ka_applet_run_pw_dialog(const KaApplet* applet)
+KaPwDialog*
+ka_applet_get_pwdialog(const KaApplet* applet)
 {
-	return gtk_dialog_run (GTK_DIALOG (applet->priv->pw_dialog));
-}
-
-void
-ka_applet_hide_pw_dialog(KaApplet* applet, gboolean force)
-{
-	KA_DEBUG("PW Dialog persist: %d", applet->priv->pw_dialog_persist);
-	if (!applet->priv->pw_dialog_persist || force)
-		gtk_widget_hide(applet->priv->pw_dialog);
-}
-
-void
-ka_applet_set_pw_dialog_persist(KaApplet* applet, gboolean persist)
-{
-	applet->priv->pw_dialog_persist = persist;
-}
-
-GtkWidget*
-ka_applet_get_pw_label(const KaApplet* applet)
-{
-	return applet->priv->pw_label;
+	return applet->priv->pwdialog;
 }
 
 /* create the tray icon applet */
 KaApplet*
-ka_applet_create()
+ka_applet_create(GladeXML* xml)
 {
 	KaApplet* applet = ka_applet_new();
 
-	ka_applet_glade_init(applet);
-
 	if (!(ka_applet_setup_icons (applet)))
 		g_error ("Failure to setup icons");
 	if (!ka_applet_create_tray_icon (applet))
@@ -598,6 +552,9 @@
 	g_signal_connect (applet, "notify::show-trayicon",
 	                  G_CALLBACK (ka_applet_cb_show_trayicon), NULL);
 
+	applet->priv->pwdialog = ka_pwdialog_create(xml);
+	g_return_val_if_fail (applet->priv->pwdialog != NULL, NULL);
+
 	return applet;
 }
 

Modified: trunk/src/krb5-auth-applet.h
==============================================================================
--- trunk/src/krb5-auth-applet.h	(original)
+++ trunk/src/krb5-auth-applet.h	Wed Mar 11 16:25:47 2009
@@ -32,6 +32,7 @@
 #include <krb5.h>
 
 #include "config.h"
+#include "krb5-auth-pwdialog.h"
 
 G_BEGIN_DECLS
 
@@ -52,28 +53,21 @@
 typedef struct _KaAppletPrivate KaAppletPrivate;
 
 GType ka_applet_get_type (void);
-KaApplet* ka_applet_new(void) G_GNUC_MALLOC;
 
 /* public functions */
 gboolean ka_applet_get_show_trayicon(const KaApplet* applet);
 void ka_applet_set_tgt_renewable(KaApplet* applet, gboolean renewable);
 gboolean ka_applet_get_tgt_renewable(const KaApplet* applet);
 guint ka_applet_get_pw_prompt_secs(const KaApplet* applet);
-
-/* password dialog */
-gint ka_applet_run_pw_dialog(const KaApplet* applet);
-GladeXML* ka_applet_get_pwdialog_xml(const KaApplet* applet);
-void ka_applet_hide_pw_dialog(KaApplet* applet, gboolean force);
-GtkWidget* ka_applet_get_pw_label(const KaApplet* applet);
-void ka_applet_set_pw_dialog_persist(KaApplet* applet, gboolean persist);
-
-G_END_DECLS
+KaPwDialog* ka_applet_get_pwdialog(const KaApplet* applet);
 
 /* create the applet */
-KaApplet* ka_applet_create();
+KaApplet* ka_applet_create(GladeXML* xml);
 /* update tooltip and icon */
 int ka_applet_update_status(KaApplet* applet, krb5_timestamp expiry);
 
+G_END_DECLS
+
 #ifdef ENABLE_DEBUG
 #define KA_DEBUG(fmt,...) \
     g_printf ("DEBUG: %s: " fmt "\n", __func__, ##__VA_ARGS__)

Modified: trunk/src/krb5-auth-dbus.c
==============================================================================
--- trunk/src/krb5-auth-dbus.c	(original)
+++ trunk/src/krb5-auth-dbus.c	Wed Mar 11 16:25:47 2009
@@ -22,6 +22,7 @@
 
 #include <dbus/dbus-glib.h>
 #include "krb5-auth-applet.h"
+#include "krb5-auth-dialog.h"
 #include "krb5-auth-dbus.h"
 #include "krb5-auth-applet-dbus-glue.h"
 

Modified: trunk/src/krb5-auth-dialog.c
==============================================================================
--- trunk/src/krb5-auth-dialog.c	(original)
+++ trunk/src/krb5-auth-dialog.c	Wed Mar 11 16:25:47 2009
@@ -38,6 +38,7 @@
 
 #include "krb5-auth-dialog.h"
 #include "krb5-auth-applet.h"
+#include "krb5-auth-pwdialog.h"
 #include "krb5-auth-gconf.h"
 #include "krb5-auth-dbus.h"
 
@@ -158,6 +159,7 @@
 #endif
 }
 
+
 /* ***************************************************************** */
 /* ***************************************************************** */
 
@@ -197,50 +199,16 @@
 }
 
 
-static gchar* minutes_to_expiry_text (int minutes)
-{
-	gchar *expiry_text;
-	gchar *tmp;
-
-	if (minutes > 0) {
-		expiry_text = g_strdup_printf (ngettext("Your credentials expire in %d minute",
-		                                        "Your credentials expire in %d minutes",
-		                                        minutes),
-		                               minutes);
-	} else {
-		expiry_text = g_strdup (_("Your credentials have expired"));
-		tmp = g_strdup_printf ("<span foreground=\"red\">%s</span>", expiry_text);
-		g_free (expiry_text);
-		expiry_text = tmp;
-	}
-
-	return expiry_text;
-}
-
-
-static gboolean
-krb5_auth_dialog_wrong_label_update_expiry (GtkWidget* label)
+/* time in seconds the tgt will be still valid */
+int
+ka_tgt_valid_seconds()
 {
-	int minutes_left;
 	krb5_timestamp now;
-	gchar *expiry_text;
-	gchar *expiry_markup;
 
-	g_return_val_if_fail (label!= NULL, FALSE);
+	if (krb5_timeofday(kcontext, &now))
+		return 0;
 
-	if (krb5_timeofday(kcontext, &now) != 0) {
-		return TRUE;
-	}
-
-	minutes_left = (creds_expiry - now) / 60;
-	expiry_text = minutes_to_expiry_text (minutes_left);
-
-	expiry_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", expiry_text);
-	gtk_label_set_markup (GTK_LABEL (label), expiry_markup);
-	g_free (expiry_text);
-	g_free (expiry_markup);
-
-	return TRUE;
+	return (creds_expiry - now);
 }
 
 
@@ -249,88 +217,19 @@
 krb5_auth_dialog_do_updates (gpointer data)
 {
 	KaApplet* applet = KA_APPLET(data);
+	KaPwDialog* pwdialog = ka_applet_get_pwdialog(applet);
 
-	g_return_val_if_fail (applet != NULL, FALSE);
+	g_return_val_if_fail (pwdialog != NULL, FALSE);
 	/* Update creds_expiry and close the applet if we got the creds by other means (e.g. kinit) */
 	if (!credentials_expiring_real(applet))
-		ka_applet_hide_pw_dialog(applet, FALSE);
+		ka_pwdialog_hide(pwdialog, FALSE);
 
 	/* Update the expiry information in the dialog */
-	krb5_auth_dialog_wrong_label_update_expiry (ka_applet_get_pw_label(applet));
+	ka_pwdialog_status_update (pwdialog);
 	return TRUE;
 }
 
 
-static void
-krb5_auth_dialog_setup (KaApplet *applet,
-                        const gchar *krb5prompt,
-                        gboolean hide_password)
-{
-	GtkWidget *entry;
-	GtkWidget *label;
-	gchar *wrong_text;
-	gchar *wrong_markup;
-	gchar *prompt;
-	int pw4len;
-
-	if (krb5prompt == NULL) {
-		prompt = g_strdup (_("Please enter your Kerberos password."));
-	} else {
-		/* Kerberos's prompts are a mess, and basically impossible to
-		 * translate.  There's basically no way short of doing a lot of
-		 * string parsing to translate them.  The most common prompt is
-		 * "Password for $uid:".  We special case that one at least.  We
-		 * cannot do any of the fancier strings (like challenges),
-		 * though. */
-		pw4len = strlen ("Password for ");
-		if (strncmp (krb5prompt, "Password for ", pw4len) == 0) {
-			gchar *uid = (gchar *) (krb5prompt + pw4len);
-			prompt = g_strdup_printf (_("Please enter the password for '%s'"), uid);
-		} else {
-			prompt = g_strdup (krb5prompt);
-		}
-	}
-
-	/* Clear the password entry field */
-	entry = glade_xml_get_widget (ka_applet_get_pwdialog_xml(applet),
-                                      "krb5_entry");
-	gtk_secure_entry_set_text (GTK_SECURE_ENTRY (entry), "");
-
-	/* Use the prompt label that krb5 provides us */
-	label = glade_xml_get_widget (ka_applet_get_pwdialog_xml(applet),
-                                      "krb5_message_label");
-	gtk_label_set_text (GTK_LABEL (label), prompt);
-
-	/* Add our extra message hints, if any */
-	wrong_text = NULL;
-
-	if (ka_applet_get_pw_label(applet)) {
-		if (invalid_auth) {
-			wrong_text = g_strdup (_("The password you entered is invalid"));
-		} else {
-			krb5_timestamp now;
-			int minutes_left;
-
-			if (krb5_timeofday(kcontext, &now) == 0)
-				minutes_left = (creds_expiry - now) / 60;
-			else
-				minutes_left = 0;
-			wrong_text = minutes_to_expiry_text (minutes_left);
-		}
-	}
-
-	if (wrong_text) {
-		wrong_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", wrong_text);
-		gtk_label_set_markup (GTK_LABEL (ka_applet_get_pw_label(applet)), wrong_markup);
-		g_free(wrong_text);
-		g_free(wrong_markup);
-	} else {
-		gtk_label_set_text (GTK_LABEL (ka_applet_get_pw_label(applet)), "");
-	}
-	g_free (prompt);
-}
-
-
 static krb5_error_code
 auth_dialog_prompter (krb5_context ctx,
                       void *data,
@@ -339,7 +238,8 @@
                       int num_prompts,
                       krb5_prompt prompts[])
 {
-	KaApplet* applet = KA_APPLET(data);
+	KaApplet *applet = KA_APPLET(data);
+	KaPwDialog *pwdialog = ka_applet_get_pwdialog(applet);
 	krb5_error_code errcode;
 	int i;
 
@@ -353,20 +253,15 @@
 		int response;
 		guint32 source_id;
 
-		GtkWidget *entry;
-
 		errcode = KRB5_LIBOS_CANTREADPWD;
 
-		krb5_auth_dialog_setup (applet, (gchar *) prompts[i].prompt, prompts[i].hidden);
-		entry = glade_xml_get_widget (ka_applet_get_pwdialog_xml(applet), "krb5_entry");
-		gtk_widget_grab_focus (entry);
-
 		source_id = g_timeout_add_seconds (5, (GSourceFunc)krb5_auth_dialog_do_updates, applet);
-		response = ka_applet_run_pw_dialog (applet);
+		ka_pwdialog_setup (pwdialog, (gchar *) prompts[i].prompt, prompts[i].hidden, invalid_auth);
+		response = ka_pwdialog_run (pwdialog);
 		switch (response)
 		{
 			case GTK_RESPONSE_OK:
-				password = gtk_secure_entry_get_text (GTK_SECURE_ENTRY (entry));
+				password = ka_pwdialog_get_password(pwdialog);
 				password_len = strlen (password);
 				break;
 			case GTK_RESPONSE_CANCEL:
@@ -393,7 +288,7 @@
 		errcode = 0;
 	}
 cleanup:
-	ka_applet_hide_pw_dialog (applet, TRUE);
+	ka_pwdialog_hide (pwdialog, TRUE);
 	/* Reset this, so we know the next time we get a TRUE value, it is accurate. */
 	invalid_auth = FALSE;
 
@@ -573,9 +468,6 @@
 	krb5_get_init_creds_opt *opt = NULL;
 	gchar *pk_userid = NULL;
 
-	g_object_get(applet, "pk-userid", &pk_userid,
-			     NULL);
-
 	memset(&my_creds, 0, sizeof(my_creds));
 
 	if (kprincipal == NULL) {
@@ -588,6 +480,7 @@
 	if (retval)
 		goto out2;
 
+	g_object_get(applet, "pk-userid", &pk_userid, NULL);
 #if ENABLE_PKINIT
 	if (pk_userid && strlen(pk_userid)) { /* try pkinit */
 #else
@@ -792,7 +685,6 @@
 gboolean
 ka_check_credentials (KaApplet *applet, const char* newprincipal)
 {
-	gboolean renewable;
 	gboolean success = FALSE;
 	int retval;
 	char* principal;
@@ -843,8 +735,9 @@
 	int retval;
 	gboolean retry;
 	int success = FALSE;
+	KaPwDialog *pwdialog = ka_applet_get_pwdialog(applet);
 
-	ka_applet_set_pw_dialog_persist(applet, TRUE);
+	ka_pwdialog_set_persist(pwdialog, TRUE);
 	do {
 		retry = TRUE;
 		retval = grab_credentials (applet);
@@ -865,17 +758,55 @@
 		}
 	} while(retry);
 
-	ka_applet_set_pw_dialog_persist(applet, FALSE);
+	ka_pwdialog_set_persist(pwdialog, FALSE);
 	credentials_expiring_real(applet);
 
 	return success;
 }
 
 
+static void
+ka_secmem_init ()
+{
+	/* Initialize secure memory.  1 is too small, so the default size
+	will be used.  */
+	secmem_init (1);
+	secmem_set_flags (SECMEM_WARN);
+	drop_privs ();
+
+	if (atexit (secmem_term))
+		g_error("Couln't register atexit handler");
+}
+
+
+static gboolean
+ka_nm_init()
+{
+#ifdef ENABLE_NETWORK_MANAGER
+	libnm_glib_ctx *nm_context;
+	guint32 nm_callback_id;
+
+	nm_context = libnm_glib_init ();
+	if (!nm_context) {
+		g_warning ("Could not initialize libnm_glib");
+	} else {
+		nm_callback_id = libnm_glib_register_callback (nm_context, network_state_cb, &is_online, NULL);
+		if (nm_callback_id == 0) {
+			libnm_glib_shutdown (nm_context);
+			nm_context = NULL;
+
+			g_warning ("Could not connect to NetworkManager, connection status will not be managed!");
+		}
+	}
+#endif /* ENABLE_NETWORK_MANAGER */
+	return TRUE;
+}
+
+
 static GtkWidget*
 ka_create_gtk_secure_entry (GladeXML *xml, gchar *func_name, gchar *name,
-				gchar *s1, gchar *s2, gint i1, gint i2,
-				gpointer user_data)
+			    gchar *s1, gchar *s2, gint i1, gint i2,
+			    gpointer user_data)
 {
 	GtkWidget* entry = NULL;
 
@@ -890,26 +821,13 @@
 }
 
 
-static void
-ka_secmem_init ()
-{
-	/* Initialize secure memory.  1 is too small, so the default size
-	will be used.  */
-	secmem_init (1);
-	secmem_set_flags (SECMEM_WARN);
-	drop_privs ();
-
-	if (atexit (secmem_term))
-		g_error("Couln't register atexit handler");
-}
-
-
 int
 main (int argc, char *argv[])
 {
 	KaApplet *applet;
 	GOptionContext *context;
 	GError *error = NULL;
+	GladeXML *xml;
 
 	guint status = 0;
 	gboolean run_auto = FALSE, run_always = FALSE;
@@ -923,10 +841,6 @@
   		{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
 	};
 
-#ifdef ENABLE_NETWORK_MANAGER
-	libnm_glib_ctx *nm_context;
-	guint32 nm_callback_id;	
-#endif
 	context = g_option_context_new ("- Kerberos 5 credential checking");
 	g_option_context_add_main_entries (context, options, NULL);
 	g_option_context_add_group (context, gtk_get_option_group (TRUE));
@@ -951,35 +865,23 @@
 	}
 	if (using_krb5 () || always_run) {
 		g_set_application_name (_("Network Authentication"));
-		glade_set_custom_handler (&ka_create_gtk_secure_entry, NULL);
 
-		applet = ka_applet_create ();
+		glade_set_custom_handler (&ka_create_gtk_secure_entry, NULL);
+		xml = glade_xml_new (KA_DATA_DIR G_DIR_SEPARATOR_S
+				     PACKAGE ".glade", NULL, NULL);
+		applet = ka_applet_create (xml);
 		if (!applet)
 			return 1;
 		if (!ka_gconf_init (applet, argc, argv))
 			return 1;
-
-#ifdef ENABLE_NETWORK_MANAGER
-		nm_context = libnm_glib_init ();
-		if (!nm_context) {
-			g_warning ("Could not initialize libnm_glib");
-		} else {
-			nm_callback_id = libnm_glib_register_callback (nm_context, network_state_cb, &is_online, NULL);
-			if (nm_callback_id == 0) {
-				libnm_glib_shutdown (nm_context);
-				nm_context = NULL;
-
-				g_warning ("Could not connect to NetworkManager, connection status will not be managed!");
-			}
-		}
-#endif /* ENABLE_NETWORK_MANAGER */
+		ka_nm_init();
 
 		if (credentials_expiring ((gpointer)applet)) {
 			g_timeout_add_seconds (CREDENTIAL_CHECK_INTERVAL, (GSourceFunc)credentials_expiring, applet);
 		}
 		ka_dbus_service(applet);
 		gtk_main ();
+		g_object_unref(xml);
 	}
-
 	return 0;
 }

Modified: trunk/src/krb5-auth-dialog.glade
==============================================================================
--- trunk/src/krb5-auth-dialog.glade	(original)
+++ trunk/src/krb5-auth-dialog.glade	Wed Mar 11 16:25:47 2009
@@ -202,7 +202,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="krb5_wrong_label">
+			<widget class="GtkLabel" id="krb5_status_label">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="no">&lt;span size=&quot;smaller&quot;&gt; &lt;/span&gt;</property>
 			  <property name="use_underline">False</property>

Modified: trunk/src/krb5-auth-dialog.h
==============================================================================
--- trunk/src/krb5-auth-dialog.h	(original)
+++ trunk/src/krb5-auth-dialog.h	Wed Mar 11 16:25:47 2009
@@ -26,5 +26,6 @@
 void ka_destroy_cache (GtkMenuItem  *menuitem, gpointer user_data);
 gboolean ka_grab_credentials(KaApplet* applet);
 gboolean ka_check_credentials (KaApplet *applet, const char* principal);
+int ka_tgt_valid_seconds();
 #endif
 

Added: trunk/src/krb5-auth-pwdialog.c
==============================================================================
--- (empty file)
+++ trunk/src/krb5-auth-pwdialog.c	Wed Mar 11 16:25:47 2009
@@ -0,0 +1,186 @@
+/* Krb5 Auth Applet -- Acquire and release kerberos tickets
+ *
+ * (C) 2009 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "krb5-auth-applet.h"
+#include "krb5-auth-dialog.h"
+#include "krb5-auth-pwdialog.h"
+
+struct _KaPwDialog {
+  GObject parent;
+
+  KaPwDialogPrivate *priv;
+};
+
+struct _KaPwDialogClass {
+  GObjectClass parent;
+};
+
+G_DEFINE_TYPE(KaPwDialog, ka_pwdialog, G_TYPE_OBJECT);
+
+struct _KaPwDialogPrivate
+{
+	/* The password dialog */
+	GtkWidget* dialog;		/* the password dialog itself */
+	GtkWidget* status_label;	/* the wrong password/timeout label */
+	GtkWidget* krb_label;		/* krb5 passwort prompt label */
+	GtkWidget* pw_entry;		/* password entry field */
+	gboolean   persist;		/* don't hide the dialog when creds are still valid */
+};
+
+
+static void
+ka_pwdialog_init(KaPwDialog *pwdialog)
+{
+	pwdialog->priv = G_TYPE_INSTANCE_GET_PRIVATE(pwdialog,
+						   KA_TYPE_PWDIALOG,
+						   KaPwDialogPrivate);
+}
+
+static void
+ka_pwdialog_class_init(KaPwDialogClass *klass)
+{
+	g_type_class_add_private(klass, sizeof(KaPwDialogPrivate));
+
+}
+
+static KaPwDialog*
+ka_pwdialog_new(void)
+{
+	return g_object_new (KA_TYPE_PWDIALOG, NULL);
+}
+
+
+gint
+ka_pwdialog_run(KaPwDialog* pwdialog)
+{
+	GtkWidget* dialog = pwdialog->priv->dialog;
+
+	gtk_widget_grab_focus (pwdialog->priv->pw_entry);
+	gtk_widget_show(dialog);
+	return gtk_dialog_run (GTK_DIALOG(dialog));
+}
+
+void
+ka_pwdialog_set_persist (KaPwDialog* pwdialog, gboolean persist)
+{
+	pwdialog->priv->persist = persist;
+}
+
+void
+ka_pwdialog_hide (const KaPwDialog* pwdialog, gboolean force)
+{
+	KA_DEBUG("PW Dialog persist: %d", pwdialog->priv->persist);
+	if (!pwdialog->priv->persist || force)
+		gtk_widget_hide(pwdialog->priv->dialog);
+}
+
+const gchar*
+ka_pwdialog_get_password(KaPwDialog *pwdialog)
+{
+	return gtk_secure_entry_get_text (GTK_SECURE_ENTRY (pwdialog->priv->pw_entry));
+}
+
+gboolean
+ka_pwdialog_status_update (KaPwDialog* pwdialog)
+{
+	gchar *expiry_text;
+	gchar *expiry_markup;
+	int minutes_left = ka_tgt_valid_seconds() / 60;
+
+	g_return_val_if_fail (pwdialog != NULL, FALSE);
+	if (minutes_left > 0) {
+		expiry_text = g_strdup_printf (ngettext("Your credentials expire in %d minute",
+		                                        "Your credentials expire in %d minutes",
+		                                        minutes_left), minutes_left);
+	} else {
+		expiry_text = g_strdup_printf ("<span foreground=\"red\">%s</span>",
+				               _("Your credentials have expired"));
+	}
+	expiry_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", expiry_text);
+	gtk_label_set_markup (GTK_LABEL(pwdialog->priv->status_label), expiry_markup);
+	g_free (expiry_text);
+	g_free (expiry_markup);
+
+	return TRUE;
+}
+
+void
+ka_pwdialog_setup (KaPwDialog* pwdialog, const gchar *krb5prompt,
+                   gboolean hide_password, gboolean invalid_auth)
+{
+	KaPwDialogPrivate *priv = pwdialog->priv;
+	gchar *wrong_markup = NULL;
+	gchar *prompt;
+	int pw4len;
+
+	if (krb5prompt == NULL) {
+		prompt = g_strdup (_("Please enter your Kerberos password."));
+	} else {
+		/* Kerberos's prompts are a mess, and basically impossible to
+		 * translate.  There's basically no way short of doing a lot of
+		 * string parsing to translate them.  The most common prompt is
+		 * "Password for $uid:".  We special case that one at least.  We
+		 * cannot do any of the fancier strings (like challenges),
+		 * though. */
+		pw4len = strlen ("Password for ");
+		if (strncmp (krb5prompt, "Password for ", pw4len) == 0) {
+			gchar *uid = (gchar *) (krb5prompt + pw4len);
+			prompt = g_strdup_printf (_("Please enter the password for '%s'"), uid);
+		} else {
+			prompt = g_strdup (krb5prompt);
+		}
+	}
+
+	/* Clear the password entry field */
+	gtk_secure_entry_set_text (GTK_SECURE_ENTRY (priv->pw_entry), "");
+
+	/* Use the prompt label that krb5 provides us */
+	gtk_label_set_text (GTK_LABEL (priv->krb_label), prompt);
+
+	/* Add our extra message hints */
+	if (invalid_auth) {
+		wrong_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>",
+		                                _("The password you entered is invalid"));
+		gtk_label_set_markup (GTK_LABEL (priv->status_label), wrong_markup);
+	} else
+		ka_pwdialog_status_update (pwdialog);
+
+	g_free(wrong_markup);
+	g_free (prompt);
+}
+
+KaPwDialog*
+ka_pwdialog_create(GladeXML* xml)
+{
+	KaPwDialog *pwdialog = ka_pwdialog_new();
+	KaPwDialogPrivate *priv = pwdialog->priv;
+
+	priv->dialog = glade_xml_get_widget (xml, "krb5_dialog");
+	priv->status_label = glade_xml_get_widget (xml, "krb5_status_label");
+	priv->pw_entry = glade_xml_get_widget (xml, "krb5_entry");
+	priv->krb_label = glade_xml_get_widget (xml, "krb5_message_label");
+
+	return pwdialog;
+}
+

Added: trunk/src/krb5-auth-pwdialog.h
==============================================================================
--- (empty file)
+++ trunk/src/krb5-auth-pwdialog.h	Wed Mar 11 16:25:47 2009
@@ -0,0 +1,66 @@
+/* Krb5 Auth Applet -- Acquire and release kerberos tickets
+ *
+ * (C) 2009 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef KRB5_AUTH_PWDIALOG_H
+#define KRB5_AUTH_PWDIALOG_H
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <glade/glade.h>
+
+#include "config.h"
+#include "gtksecentry.h"
+
+G_BEGIN_DECLS
+
+#define KA_TYPE_PWDIALOG            (ka_pwdialog_get_type ())
+#define KA_PWDIALOG(obj)            \
+    (G_TYPE_CHECK_INSTANCE_CAST ((obj), KA_TYPE_PWDIALOG, KaPwDialog))
+#define KA_PWDIALOG_CLASS(klass)    \
+    (G_TYPE_CHECK_CLASS_CAST ((klass), KA_TYPE_PWDIALOG, KaPwDialogClass))
+#define KA_IS_PWDIALOG(obj)         \
+    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KA_TYPE_PWDIALOG))
+#define KA_IS_PWDIALOG_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_TYPE ((klass), KA_TYPE_PWDIALOG))
+#define KA_PWDIALOG_GET_CLASS(obj)  \
+    (G_TYPE_INSTANCE_GET_CLASS ((obj), KA_TYPE_PWDIALOG, KaPwDialogClass))
+
+typedef struct _KaPwDialog        KaPwDialog;
+typedef struct _KaPwDialogClass   KaPwDialogClass;
+typedef struct _KaPwDialogPrivate KaPwDialogPrivate;
+
+GType ka_pwdialog_get_type (void);
+
+/* public functions */
+KaPwDialog* ka_pwdialog_create(GladeXML *xml);
+/* setup everything for the next prompting */
+void ka_pwdialog_setup (KaPwDialog* pwdialog, const gchar *krb5prompt,
+                        gboolean hide_password, gboolean invalid_auth);
+gint ka_pwdialog_run(KaPwDialog *applet);
+void ka_pwdialog_hide(const KaPwDialog *applet, gboolean force);
+void ka_pwdialog_set_persist(KaPwDialog *applet, gboolean persist);
+/* update the expiry information in the status entry */
+gboolean ka_pwdialog_status_update (KaPwDialog *pwdialog);
+const gchar* ka_pwdialog_get_password(KaPwDialog *dialog);
+
+G_END_DECLS
+
+#endif



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