Use account ID instead of name in passwordstorerc.
authorAndrej Kacian <ticho@claws-mail.org>
Mon, 14 Mar 2016 19:46:59 +0000 (20:46 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Mon, 14 Mar 2016 19:46:59 +0000 (20:46 +0100)
src/imap.c
src/inc.c
src/news.c
src/passwordstore.c
src/passwordstore.h
src/plugins/managesieve/managesieve.c
src/plugins/managesieve/sieve_prefs.c
src/prefs_account.c
src/send_message.c
src/wizard.c

index 68865dc..57bff79 100644 (file)
@@ -1288,7 +1288,7 @@ static gint imap_session_authenticate(IMAPSession *session,
                Xstrdup_a(acc_pass, pass, {g_free(pass); return MAILIMAP_NO_ERROR;});
                g_free(pass);
        } else {
-               acc_pass = passwd_store_get(PWS_ACCOUNT, account->account_name,
+               acc_pass = passwd_store_get_account(account->account_id,
                                PWS_ACCOUNT_RECV);
        }
 try_again:
index cf86ebd..5e99408 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -575,8 +575,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                                        "pop3", pop3_get_port(pop3_session),
                                        &(pop3_session->pass))) {
                        /* NOP */;
-               } else if ((pop3_session->pass = passwd_store_get(PWS_ACCOUNT,
-                                       pop3_session->ac_prefs->account_name, PWS_ACCOUNT_RECV)) == NULL) {
+               } else if ((pop3_session->pass = passwd_store_get_account(
+                                               pop3_session->ac_prefs->account_id, PWS_ACCOUNT_RECV)) == NULL) {
                        gchar *pass;
 
                        if (inc_dialog->show_dialog)
index cc07d17..3bfbce4 100644 (file)
@@ -405,11 +405,12 @@ static Session *news_session_new_for_folder(Folder *folder)
                userid = ac->userid;
                if (password_get(userid, ac->nntp_server, "nntp", port, &passwd)) {
                        /* NOP */;
-               } else if ((passwd = passwd_store_get(PWS_ACCOUNT, ac->account_name,
-                                       PWS_ACCOUNT_RECV)) == NULL)
+               } else if ((passwd = passwd_store_get_account(ac->account_id,
+                                       PWS_ACCOUNT_RECV)) == NULL) {
                        passwd = input_dialog_query_password_keep(ac->nntp_server,
                                                                  userid,
                                                                  &(ac->session_passwd));
+               }
        }
 
        if (session != NULL)
index 8e3942a..a518b7c 100644 (file)
@@ -197,6 +197,27 @@ gchar *passwd_store_get(PasswordBlockType block_type,
        return password;
 }
 
+gboolean passwd_store_set_account(gint account_id,
+               const gchar *password_id,
+               const gchar *password,
+               gboolean encrypted)
+{
+       gchar *uid = g_strdup_printf("%d", account_id);
+       gboolean ret = passwd_store_set(PWS_ACCOUNT, uid,
+                       password_id, password, encrypted);
+       g_free(uid);
+       return ret;
+}
+
+gchar *passwd_store_get_account(gint account_id,
+               const gchar *password_id)
+{
+       gchar *uid = g_strdup_printf("%d", account_id);
+       gchar *ret = passwd_store_get(PWS_ACCOUNT, uid, password_id);
+       g_free(uid);
+       return ret;
+}
+
 /* Reencrypts all stored passwords. */
 void passwd_store_reencrypt_all(const gchar *old_mpwd,
                const gchar *new_mpwd)
index 731027c..373116b 100644 (file)
@@ -66,6 +66,15 @@ void passwd_store_reencrypt_all(const gchar *old_mpwd,
 void passwd_store_write_config(void);
 void passwd_store_read_config(void);
 
+/* Convenience wrappers for handling account passwords.
+ * (This is to save some boilerplate code converting account_id to
+ * a string and freeing the string afterwards.) */
+gboolean passwd_store_set_account(gint account_id,
+               const gchar *password_id,
+               const gchar *password,
+               gboolean encrypted);
+gchar *passwd_store_get_account(gint account_id, const gchar *block_name);
+
 /* Macros for standard, predefined password IDs. */
 #define PWS_ACCOUNT_RECV      "recv"
 #define PWS_ACCOUNT_SEND      "send"
index 1311172..0fb4ac7 100644 (file)
@@ -1056,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 && (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 (reuse_auth && (session->pass = passwd_store_get_account(
+                                account->account_id, PWS_ACCOUNT_RECV))) {
+       } else if ((session->pass = passwd_store_get_account(
+                                account->account_id, "sieve"))) {
        } else if (password_get(session->user, session->host, "sieve",
                                session->port, &session->pass)) {
        } else {
index 9bc2a18..381596a 100644 (file)
@@ -291,7 +291,7 @@ 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 ((pass = passwd_store_get(PWS_ACCOUNT, account->account_name,
+       if ((pass = passwd_store_get_account(account->account_id,
                                     "sieve")) != NULL) {
                gtk_entry_set_text(GTK_ENTRY(pass_entry), pass);
                memset(pass, 0, strlen(pass));
@@ -375,7 +375,7 @@ static gint sieve_prefs_account_apply(struct SieveAccountPage *page)
 
        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);
-       passwd_store_set(PWS_ACCOUNT, page->account->account_name, "sieve",
+       passwd_store_set_account(page->account->account_id, "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));
@@ -542,7 +542,7 @@ struct SieveAccountConfig *sieve_prefs_account_get_config(
                // 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",
+               passwd_store_set_account(account->account_id, "sieve",
                                pass, FALSE);
                g_free(pass);
        }
index 89b7a32..1d9b412 100644 (file)
@@ -1364,7 +1364,7 @@ static void basic_create_widget_func(PrefsPage * _page,
                prefs_set_dialog(basic_param);
 
                /* Passwords are handled outside of PrefParams. */
-               buf = passwd_store_get(PWS_ACCOUNT, ac_prefs->account_name,
+               buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_RECV);
                gtk_entry_set_text(GTK_ENTRY(page->pass_entry), buf);
                g_free(buf);
@@ -1901,7 +1901,7 @@ static void send_create_widget_func(PrefsPage * _page,
                prefs_set_dialog(send_param);
 
                /* Passwords are handled outside of PrefParams. */
-               buf = passwd_store_get(PWS_ACCOUNT, ac_prefs->account_name,
+               buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_SEND);
                gtk_entry_set_text(GTK_ENTRY(page->smtp_pass_entry), buf);
                g_free(buf);
@@ -2629,11 +2629,11 @@ static void ssl_create_widget_func(PrefsPage * _page,
                prefs_set_dialog(ssl_param);
 
                /* Passwords are handled outside of PrefParams. */
-               buf = passwd_store_get(PWS_ACCOUNT, ac_prefs->account_name,
+               buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_RECV_CERT);
                gtk_entry_set_text(GTK_ENTRY(page->entry_in_cert_pass), buf);
                g_free(buf);
-               buf = passwd_store_get(PWS_ACCOUNT, ac_prefs->account_name,
+               buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_SEND_CERT);
                gtk_entry_set_text(GTK_ENTRY(page->entry_out_cert_pass), buf);
                g_free(buf);
@@ -2974,7 +2974,7 @@ static gint prefs_basic_apply(void)
        prefs_set_data_from_dialog(basic_param);
 
        /* Passwords are stored outside of PrefParams. */
-       passwd_store_set(PWS_ACCOUNT, tmp_ac_prefs.account_name,
+       passwd_store_set_account(tmp_ac_prefs.account_id,
                        PWS_ACCOUNT_RECV,
                        gtk_entry_get_text(GTK_ENTRY(basic_page.pass_entry)),
                        FALSE);
@@ -3003,7 +3003,7 @@ static gint prefs_send_apply(void)
        prefs_set_data_from_dialog(send_param);
 
        /* Passwords are stored outside of PrefParams. */
-       passwd_store_set(PWS_ACCOUNT, tmp_ac_prefs.account_name,
+       passwd_store_set_account(tmp_ac_prefs.account_id,
                        PWS_ACCOUNT_SEND,
                        gtk_entry_get_text(GTK_ENTRY(send_page.smtp_pass_entry)),
                        FALSE);
@@ -3035,11 +3035,11 @@ static gint prefs_ssl_apply(void)
        prefs_set_data_from_dialog(ssl_param);
 
        /* Passwords are stored outside of PrefParams. */
-       passwd_store_set(PWS_ACCOUNT, tmp_ac_prefs.account_name,
+       passwd_store_set_account(tmp_ac_prefs.account_id,
                        PWS_ACCOUNT_RECV_CERT,
                        gtk_entry_get_text(GTK_ENTRY(ssl_page.entry_in_cert_pass)),
                        FALSE);
-       passwd_store_set(PWS_ACCOUNT, tmp_ac_prefs.account_name,
+       passwd_store_set_account(tmp_ac_prefs.account_id,
                        PWS_ACCOUNT_SEND_CERT,
                        gtk_entry_get_text(GTK_ENTRY(ssl_page.entry_out_cert_pass)),
                        FALSE);
@@ -3431,8 +3431,7 @@ static gboolean sslcert_get_client_cert_hook(gpointer source, gpointer data)
                pwd_id = PWS_ACCOUNT_RECV_CERT;
        }
 
-       hookdata->password = passwd_store_get(PWS_ACCOUNT,
-                       account->account_name, pwd_id);
+       hookdata->password = passwd_store_get_account(account->account_id, pwd_id);
        return TRUE;
 }
 
@@ -3599,21 +3598,21 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
        }
 
        if (ac_prefs->passwd != NULL && strlen(ac_prefs->passwd) > 1) {
-               passwd_store_set(PWS_ACCOUNT, ac_prefs->account_name,
+               passwd_store_set_account(ac_prefs->account_id,
                                PWS_ACCOUNT_RECV, ac_prefs->passwd, TRUE);
        }
        if (ac_prefs->smtp_passwd != NULL && strlen(ac_prefs->smtp_passwd) > 1) {
-               passwd_store_set(PWS_ACCOUNT, ac_prefs->account_name,
+               passwd_store_set_account(ac_prefs->account_id,
                                PWS_ACCOUNT_SEND, ac_prefs->smtp_passwd, TRUE);
        }
        if (ac_prefs->in_ssl_client_cert_pass != NULL
                        && strlen(ac_prefs->in_ssl_client_cert_pass) > 1) {
-               passwd_store_set(PWS_ACCOUNT, ac_prefs->account_name,
+               passwd_store_set_account(ac_prefs->account_id,
                                PWS_ACCOUNT_RECV_CERT, ac_prefs->in_ssl_client_cert_pass, TRUE);
        }
        if (ac_prefs->out_ssl_client_cert_pass != NULL
                        && strlen(ac_prefs->out_ssl_client_cert_pass) > 1) {
-               passwd_store_set(PWS_ACCOUNT, ac_prefs->account_name,
+               passwd_store_set_account(ac_prefs->account_id,
                                PWS_ACCOUNT_SEND_CERT, ac_prefs->out_ssl_client_cert_pass, TRUE);
        }
 
index 43eef33..75bdd20 100644 (file)
@@ -305,7 +305,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                                        &(smtp_session->pass))) {
                                        /* NOP */;
                                } else if ((smtp_session->pass =
-                                               passwd_store_get(PWS_ACCOUNT, ac_prefs->account_name,
+                                               passwd_store_get_account(ac_prefs->account_id,
                                                                PWS_ACCOUNT_SEND)) == NULL) {
                                        smtp_session->pass =
                                                input_dialog_query_password_keep
@@ -323,8 +323,8 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                                        ac_prefs->smtp_server, "smtp", port,
                                                        &(smtp_session->pass))) {
                                        /* NOP */;
-                               } else if ((smtp_session->pass = passwd_store_get(PWS_ACCOUNT,
-                                                       ac_prefs->account_name, PWS_ACCOUNT_RECV)) == NULL) {
+                               } else if ((smtp_session->pass = passwd_store_get_account(
+                                                       ac_prefs->account_id, PWS_ACCOUNT_RECV)) == NULL) {
                                        smtp_session->pass =
                                                input_dialog_query_password_keep
                                                        (ac_prefs->smtp_server,
index 8d6ba93..6517b31 100644 (file)
@@ -760,14 +760,10 @@ static gboolean wizard_write_config(WizardWindow *wizard)
        prefs_account->smtp_userid = g_strdup(
                                gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)));
 
-       passwd_store_set(PWS_ACCOUNT,
-                       prefs_account->account_name,
-                       PWS_ACCOUNT_RECV,
+       passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_RECV,
                        gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)),
                        FALSE);
-       passwd_store_set(PWS_ACCOUNT,
-                       prefs_account->account_name,
-                       PWS_ACCOUNT_SEND,
+       passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_SEND,
                        gtk_entry_get_text(GTK_ENTRY(wizard->smtp_password)),
                        FALSE);
 
@@ -804,14 +800,10 @@ static gboolean wizard_write_config(WizardWindow *wizard)
        prefs_account->in_ssl_client_cert_file = g_strdup(
                                gtk_entry_get_text(GTK_ENTRY(wizard->recv_ssl_cert_file)));
 
-       passwd_store_set(PWS_ACCOUNT,
-                       prefs_account->account_name,
-                       PWS_ACCOUNT_SEND_CERT,
+       passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_SEND_CERT,
                        gtk_entry_get_text(GTK_ENTRY(wizard->smtp_ssl_cert_pass)),
                        FALSE);
-       passwd_store_set(PWS_ACCOUNT,
-                       prefs_account->account_name,
-                       PWS_ACCOUNT_RECV_CERT,
+       passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_RECV_CERT,
                        gtk_entry_get_text(GTK_ENTRY(wizard->recv_ssl_cert_pass)),
                        FALSE);
 #endif