From: Charles Lehner Date: Mon, 14 Mar 2016 04:55:49 +0000 (-0400) Subject: Migrate managesieve to passwordstore X-Git-Tag: 3.14.0~135^2~20 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=e66c916e5661be4fd7024801f73f1f83d747a521 Migrate managesieve to passwordstore --- diff --git a/src/plugins/managesieve/managesieve.c b/src/plugins/managesieve/managesieve.c index 9739a0ef0..131117291 100644 --- a/src/plugins/managesieve/managesieve.c +++ b/src/plugins/managesieve/managesieve.c @@ -25,6 +25,7 @@ #include "claws.h" #include "account.h" +#include "passwordstore.h" #include "gtk/inputdialog.h" #include "md5.h" #include "utils.h" @@ -1055,10 +1056,10 @@ static void sieve_session_reset(SieveSession *session) g_free(session->pass); if (config->auth == SIEVEAUTH_NONE) { session->pass = NULL; - } else if (reuse_auth && account->passwd) { - session->pass = g_strdup(account->passwd); - } else if (config->passwd && config->passwd[0]) { - session->pass = g_strdup(config->passwd); + } else if (reuse_auth && (session->pass = passwd_store_get(PWS_ACCOUNT, + account->account_name, PWS_ACCOUNT_RECV))) { + } else if ((session->pass = passwd_store_get(PWS_ACCOUNT, + account->account_name, "sieve"))) { } else if (password_get(session->user, session->host, "sieve", session->port, &session->pass)) { } else { diff --git a/src/plugins/managesieve/sieve_prefs.c b/src/plugins/managesieve/sieve_prefs.c index 0d537627f..9bc2a1857 100644 --- a/src/plugins/managesieve/sieve_prefs.c +++ b/src/plugins/managesieve/sieve_prefs.c @@ -32,6 +32,8 @@ #include "gtk/combobox.h" #include "alertpanel.h" #include "passcrypt.h" +#include "password.h" +#include "passwordstore.h" #include "utils.h" #include "prefs.h" #include "prefs_gtk.h" @@ -113,6 +115,7 @@ static void sieve_prefs_account_create_widget_func(PrefsPage *_page, struct SieveAccountPage *page = (struct SieveAccountPage *) _page; PrefsAccount *account = (PrefsAccount *) data; SieveAccountConfig *config; + gchar *pass; GtkWidget *page_vbox, *sieve_vbox; GtkWidget *hbox; @@ -288,8 +291,12 @@ static void sieve_prefs_account_create_widget_func(PrefsPage *_page, gtk_entry_set_text(GTK_ENTRY(host_entry), config->host); if (config->userid != NULL) gtk_entry_set_text(GTK_ENTRY(uid_entry), config->userid); - if (config->passwd != NULL) - gtk_entry_set_text(GTK_ENTRY(pass_entry), config->passwd); + if ((pass = passwd_store_get(PWS_ACCOUNT, account->account_name, + "sieve")) != NULL) { + gtk_entry_set_text(GTK_ENTRY(pass_entry), pass); + memset(pass, 0, strlen(pass)); + g_free(pass); + } combobox_select_by_data(GTK_COMBO_BOX(auth_menu), config->auth_type); @@ -363,9 +370,14 @@ static gint sieve_prefs_account_apply(struct SieveAccountPage *page) SIEVE_TLS_MAYBE : SIEVE_TLS_YES; + g_free(config->host); + g_free(config->userid); + config->host = gtk_editable_get_chars(GTK_EDITABLE(page->host_entry), 0, -1); config->userid = gtk_editable_get_chars(GTK_EDITABLE(page->uid_entry), 0, -1); - config->passwd = gtk_editable_get_chars(GTK_EDITABLE(page->pass_entry), 0, -1); + passwd_store_set(PWS_ACCOUNT, page->account->account_name, "sieve", + gtk_editable_get_chars(GTK_EDITABLE(page->pass_entry), 0, -1), + FALSE); config->auth_type = combobox_get_active_data(GTK_COMBO_BOX(page->auth_menu)); sieve_prefs_account_set_config(page->account, config); @@ -484,7 +496,6 @@ struct SieveAccountConfig *sieve_prefs_account_get_config( config->auth = SIEVEAUTH_REUSE; config->auth_type = SIEVEAUTH_AUTO; config->userid = NULL; - config->passwd = NULL; confstr = prefs_account_get_privacy_prefs(account, "sieve"); if (confstr == NULL) @@ -527,8 +538,14 @@ struct SieveAccountConfig *sieve_prefs_account_get_config( } config->userid = g_base64_decode(enc_userid, &len); - config->passwd = g_base64_decode(enc_passwd, &len); - passcrypt_decrypt(config->passwd, len); + if (enc_passwd[0]) { + // migrate password from passcrypt to passwordstore + gchar *pass = g_base64_decode(enc_passwd, &len); + passcrypt_decrypt(pass, len); + passwd_store_set(PWS_ACCOUNT, account->account_name, "sieve", + pass, FALSE); + g_free(pass); + } return config; } @@ -538,8 +555,6 @@ void sieve_prefs_account_set_config( { gchar *confstr = NULL; gchar *enc_userid = NULL; - gchar *enc_passwd = NULL; - gchar *tmp; gsize len; if (config->userid) { @@ -547,14 +562,6 @@ void sieve_prefs_account_set_config( enc_userid = g_base64_encode(config->userid, len); } - if (config->passwd) { - tmp = g_strdup(config->passwd); - len = strlen(tmp); - passcrypt_encrypt(tmp, len); - enc_passwd = g_base64_encode(tmp, len); - g_free(tmp); - } - confstr = g_strdup_printf("%c%c %s %c%hu %hhu %hhu %hhu %s %s", config->enable ? 'y' : 'n', config->use_host ? 'y' : 'n', @@ -565,12 +572,10 @@ void sieve_prefs_account_set_config( config->auth, config->auth_type, enc_userid ? enc_userid : "", - enc_passwd ? enc_passwd : ""); + ""); if (enc_userid) g_free(enc_userid); - if (enc_passwd) - g_free(enc_passwd); prefs_account_set_privacy_prefs(account, "sieve", confstr); @@ -583,7 +588,6 @@ void sieve_prefs_account_free_config(SieveAccountConfig *config) { g_free(config->host); g_free(config->userid); - g_free(config->passwd); g_free(config); } diff --git a/src/plugins/managesieve/sieve_prefs.h b/src/plugins/managesieve/sieve_prefs.h index c1d9f2de1..e378d6ac6 100644 --- a/src/plugins/managesieve/sieve_prefs.h +++ b/src/plugins/managesieve/sieve_prefs.h @@ -44,7 +44,6 @@ struct SieveAccountConfig SieveAuthType auth_type; SieveTLSType tls_type; gchar *userid; - gchar *passwd; }; extern SieveConfig sieve_config;