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:
"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)
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)
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)
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"
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 {
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));
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));
// 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);
}
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);
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);
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);
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);
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);
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);
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;
}
}
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);
}
&(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
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,
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);
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