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 68865dc2b2f8a4ca1a90a8affe1d39ee58cab5c0..57bff7926cb40ae47aadd1d67728da8184494f61 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 cf86ebd09d038cfa58fbf7e5c18c5f3617bca08d..5e994086c04fad5d3ec6974024de8a9f36e222f1 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 cc07d1703c94daacc95654612afd499747eee622..3bfbce46b496a2f3d9b728ccb8705d9c04c7a7ba 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 8e3942a314f37303b47a676b597503dbc3236c81..a518b7c20baeb00ee3ac09757981e10a5fd51be9 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 731027ca2ac41ed235f23ccd96353f5e4e78e906..373116bf4f4dfaf8bdb889b7e6570e4fa6abfb60 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 1311172912c1373c9a818525f2e06f6677ad6c24..0fb4ac74d1bce9d71ff286ae7d9eb2819f569543 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 9bc2a1857ee638bbe512b007436466cfdfdd2fee..381596a9a4e8edf3afe33b069559a8c6cbcad625 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 89b7a329a5531b7236185e61c34fa672889a10f4..1d9b4122183c39a56d9c44b50aa98a160165ae1a 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 43eef3356560832857dc56f3b96aec42054d5b4c..75bdd2016c184e825abc4b8157c35cc7ffcb3f88 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 8d6ba936742b28a6e27489cb737df4912da43fc5..6517b31b1046aeab2692e611e77e8e1aa43054b3 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