evolution-3.6.4/smime/gui/component.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Chris Toshok <toshok@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include "component.h"
 28 
 29 #include <gtk/gtk.h>
 30 
 31 #include <glib/gi18n.h>
 32 #include <libedataserverui/libedataserverui.h>
 33 
 34 #include "ca-trust-dialog.h"
 35 #include "e-cert-db.h"
 36 #include "pk11func.h"
 37 
 38 static gboolean
 39 smime_pk11_passwd (ECertDB *db,
 40                    PK11SlotInfo *slot,
 41                    gboolean retry,
 42                    gchar **passwd,
 43                    gpointer arg)
 44 {
 45 	gchar *prompt;
 46 	gchar *slot_name = g_strdup (PK11_GetSlotName (slot));
 47 
 48 	g_strchomp (slot_name);
 49 
 50 	prompt = g_strdup_printf (_("Enter the password for '%s'"), slot_name);
 51 	g_free (slot_name);
 52 
 53 	*passwd = e_passwords_ask_password (
 54 		_("Enter password"), NULL, "", prompt,
 55 		E_PASSWORDS_REMEMBER_NEVER | E_PASSWORDS_SECRET,
 56 		NULL, NULL);
 57 
 58 	g_free (prompt);
 59 
 60 	/* this should return FALSE if they canceled. */
 61 	return TRUE;
 62 }
 63 
 64 static gboolean
 65 smime_pk11_change_passwd (ECertDB *db,
 66                           gchar **old_passwd,
 67                           gchar **passwd,
 68                           gpointer arg)
 69 {
 70 	gchar *prompt;
 71 
 72 	/* XXX need better strings here, just copy mozilla's? */
 73 
 74 	if (!old_passwd) {
 75 		/* we're setting the password initially */
 76 		prompt = _("Enter new password for certificate database");
 77 
 78 		*passwd = e_passwords_ask_password (
 79 			_("Enter new password"), NULL, "", prompt,
 80 			E_PASSWORDS_REMEMBER_NEVER | E_PASSWORDS_SECRET,
 81 			NULL, NULL);
 82 	}
 83 	else {
 84 		/* we're changing the password */
 85 		/* XXX implement this... */
 86 	}
 87 
 88 	/* this should return FALSE if they canceled. */
 89 	return TRUE;
 90 }
 91 
 92 static gboolean
 93 smime_confirm_ca_cert_import (ECertDB *db,
 94                               ECert *cert,
 95                               gboolean *trust_ssl,
 96                               gboolean *trust_email,
 97                               gboolean *trust_objsign,
 98                               gpointer arg)
 99 {
100 	GtkWidget *dialog = ca_trust_dialog_show (cert, TRUE);
101 	gint response;
102 
103 	response = gtk_dialog_run (GTK_DIALOG (dialog));
104 
105 	ca_trust_dialog_get_trust (dialog, trust_ssl, trust_email, trust_objsign);
106 
107 	gtk_widget_destroy (dialog);
108 
109 	return response != GTK_RESPONSE_CANCEL;
110 }
111 
112 void
113 smime_component_init (void)
114 {
115 	static gboolean init_done = FALSE;
116 	if (init_done)
117 		return;
118 
119 	init_done = TRUE;
120 	g_signal_connect (
121 		e_cert_db_peek (), "pk11_passwd",
122 		G_CALLBACK (smime_pk11_passwd), NULL);
123 
124 	g_signal_connect (
125 		e_cert_db_peek (), "pk11_change_passwd",
126 		G_CALLBACK (smime_pk11_change_passwd), NULL);
127 
128 	g_signal_connect (
129 		e_cert_db_peek (), "confirm_ca_cert_import",
130 		G_CALLBACK (smime_confirm_ca_cert_import), NULL);
131 }