Migrate managesieve to passwordstore
authorCharles Lehner <charles@claws-mail.org>
Mon, 14 Mar 2016 04:55:49 +0000 (00:55 -0400)
committerCharles Lehner <charles@claws-mail.org>
Mon, 14 Mar 2016 04:55:49 +0000 (00:55 -0400)
src/plugins/managesieve/managesieve.c
src/plugins/managesieve/sieve_prefs.c
src/plugins/managesieve/sieve_prefs.h

index 9739a0e..1311172 100644 (file)
@@ -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 {
index 0d53762..9bc2a18 100644 (file)
@@ -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);
 }
 
index c1d9f2d..e378d6a 100644 (file)
@@ -44,7 +44,6 @@ struct SieveAccountConfig
        SieveAuthType   auth_type;
        SieveTLSType    tls_type;
        gchar           *userid;
-       gchar           *passwd;
 };
 
 extern SieveConfig sieve_config;