From 8de2d887916cbdd3c2d756e77116585babd026f2 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 28 Feb 2018 23:51:46 +0100 Subject: prefs_common.use_master_password added --- libsylph/imap.c | 23 +++++++++++------------ libsylph/prefs_common.c | 6 +++++- libsylph/prefs_common.h | 3 +++ src/prefs_common_dialog.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/send_message.c | 25 +++++++++++++------------ 5 files changed, 79 insertions(+), 25 deletions(-) diff --git a/libsylph/imap.c b/libsylph/imap.c index a61dc2b..0cd4409 100644 --- a/libsylph/imap.c +++ b/libsylph/imap.c @@ -707,17 +707,17 @@ static gint imap_session_connect(IMAPSession *session) log_message(_("creating IMAP4 connection to %s:%d ...\n"), SESSION(session)->server, SESSION(session)->port); - if (account->master_password != NULL) { - if (decrypt_data(&pass, - account->passwd, - account->master_password, - strlen(account->passwd)) != RC_OK) { - session_destroy(session); - return -1; - } - } else { - pass = account->passwd; - } + if (prefs_common.use_master_password && account->master_password != NULL) { + if (decrypt_data(&pass, + account->passwd, + account->master_password, + strlen(account->passwd) + 1) != RC_OK) { + session_destroy(session); + return -1; + } + } else { + pass = account->passwd; + } if (!pass) pass = account->tmp_pass; if (!pass) { @@ -731,7 +731,6 @@ static gint imap_session_connect(IMAPSession *session) account->tmp_pass = tmp_pass; pass = account->tmp_pass; } - if (account->use_socks && account->use_socks_for_recv && account->proxy_host) { socks_info = socks_info_new(account->socks_type, account->proxy_host, account->proxy_port, account->use_proxy_auth ? account->proxy_name : NULL, account->use_proxy_auth ? account->proxy_pass : NULL); diff --git a/libsylph/prefs_common.c b/libsylph/prefs_common.c index 91814fd..68f72fa 100644 --- a/libsylph/prefs_common.c +++ b/libsylph/prefs_common.c @@ -415,9 +415,13 @@ static PrefParam param[] = { #ifdef G_OS_WIN32 {"show_gpg_warning", "FALSE", &prefs_common.gpg_warning, P_BOOL}, #else - {"show_gpg_warning", "TRUE", &prefs_common.gpg_warning, P_BOOL}, + {"show_gpg_warning", "TRUE", &prefs_common.gpg_warning, P_BOOL}, #endif + /* Master password */ + {"use_master_password", "FALSE", &prefs_common.use_master_password, + P_BOOL}, + /* Interface */ {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL}, {"separate_message", "FALSE", &prefs_common.sep_msg, P_BOOL}, diff --git a/libsylph/prefs_common.h b/libsylph/prefs_common.h index 910f370..ef5bb9b 100644 --- a/libsylph/prefs_common.h +++ b/libsylph/prefs_common.h @@ -249,6 +249,9 @@ struct _PrefsCommon gboolean passphrase_grab; gboolean gpg_warning; + /* Master password */ + gboolean use_master_password; + /* Interface */ gboolean sep_folder; gboolean sep_msg; diff --git a/src/prefs_common_dialog.c b/src/prefs_common_dialog.c index fa4be4e..dada1b1 100644 --- a/src/prefs_common_dialog.c +++ b/src/prefs_common_dialog.c @@ -216,6 +216,12 @@ static struct Privacy { } privacy; #endif +#if USE_SSL +static struct MasterPassword { + GtkWidget *checkbtn_use_master_password; +} master_password; +#endif + static struct Interface { GtkWidget *checkbtn_always_show_msg; GtkWidget *checkbtn_always_mark_read; @@ -563,6 +569,11 @@ static PrefsUIData ui_data[] = { prefs_set_data_from_toggle, prefs_set_toggle}, #endif /* USE_GPGME */ +#if USE_SSL + {"use_master_password", &master_password.checkbtn_use_master_password, + prefs_set_data_from_toggle, prefs_set_toggle}, +#endif + /* Interface */ {"always_show_message_when_selected", &iface.checkbtn_always_show_msg, @@ -693,6 +704,9 @@ static void prefs_junk_create (void); #if USE_GPGME static void prefs_privacy_create (void); #endif +#if USE_SSL +static void prefs_master_password_create (void); +#endif static void prefs_details_create (void); static GtkWidget *prefs_other_create (void); static GtkWidget *prefs_extcmd_create (void); @@ -852,6 +866,10 @@ static void prefs_common_create(void) #if USE_GPGME prefs_privacy_create(); SET_NOTEBOOK_LABEL(dialog.notebook, _("Privacy"), page++); +#endif +#if USE_SSL + prefs_master_password_create(); + SET_NOTEBOOK_LABEL(dialog.notebook, _("Master password"), page++); #endif prefs_details_create(); SET_NOTEBOOK_LABEL(dialog.notebook, _("Details"), page++); @@ -2648,6 +2666,35 @@ static void prefs_privacy_create(void) } #endif /* USE_GPGME */ +#if USE_SSL +static void prefs_master_password_create(void) +{ + GtkWidget *vbox1; + GtkWidget *vbox2; + GtkWidget *hbox1; + GtkWidget *checkbtn_use_master_password; + + vbox1 = gtk_vbox_new (FALSE, VSPACING); + gtk_widget_show (vbox1); + gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1); + gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER); + + vbox2 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox2); + gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0); + + PACK_CHECK_BUTTON (vbox2, checkbtn_use_master_password, + _("Use master password")); + + hbox1 = gtk_hbox_new (FALSE, 8); + gtk_widget_show (hbox1); + gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0); + + master_password.checkbtn_use_master_password + = checkbtn_use_master_password; +} +#endif /* USE_SSL */ + static void prefs_details_create(void) { GtkWidget *vbox1; diff --git a/src/send_message.c b/src/send_message.c index 695246a..7b66423 100644 --- a/src/send_message.c +++ b/src/send_message.c @@ -649,18 +649,19 @@ static gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp) if (ac_prefs->smtp_userid) { smtp_session->user = g_strdup(ac_prefs->smtp_userid); if (ac_prefs->smtp_passwd) { - if(ac_prefs->master_password != NULL) { - if (decrypt_data(&(smtp_session->pass), - ac_prefs->smtp_passwd, - ac_prefs->master_password, - strlen(ac_prefs->smtp_passwd)) != RC_OK) { - session_destroy(session); - return -1; - } - } else { - smtp_session->pass = - g_strdup(ac_prefs->smtp_passwd); - } + if(prefs_common.use_master_password && + ac_prefs->master_password != NULL) { + if (decrypt_data(&(smtp_session->pass), + ac_prefs->smtp_passwd, + ac_prefs->master_password, + strlen(ac_prefs->smtp_passwd) + 1) != RC_OK) { + session_destroy(session); + return -1; + } + } else { + smtp_session->pass = + g_strdup(ac_prefs->smtp_passwd); + } } else if (ac_prefs->tmp_smtp_pass) { smtp_session->pass = g_strdup(ac_prefs->tmp_smtp_pass); -- cgit v1.3