[Commits] [SCM] claws branch, master, updated. 3.13.2-71-g0a7b456

ticho at claws-mail.org ticho at claws-mail.org
Mon Mar 14 20:47:33 CET 2016


The branch, master has been updated
       via  0a7b4563cce30d0274ac3d20742411706f8d2fca (commit)
      from  e66c916e5661be4fd7024801f73f1f83d747a521 (commit)

Summary of changes:
 src/imap.c                            |    2 +-
 src/inc.c                             |    4 ++--
 src/news.c                            |    5 +++--
 src/passwordstore.c                   |   21 +++++++++++++++++++++
 src/passwordstore.h                   |    9 +++++++++
 src/plugins/managesieve/managesieve.c |    8 ++++----
 src/plugins/managesieve/sieve_prefs.c |    6 +++---
 src/prefs_account.c                   |   27 +++++++++++++--------------
 src/send_message.c                    |    6 +++---
 src/wizard.c                          |   16 ++++------------
 10 files changed, 63 insertions(+), 41 deletions(-)


- Log -----------------------------------------------------------------
commit 0a7b4563cce30d0274ac3d20742411706f8d2fca
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Mon Mar 14 20:46:59 2016 +0100

    Use account ID instead of name in passwordstorerc.

diff --git a/src/imap.c b/src/imap.c
index 68865dc..57bff79 100644
--- a/src/imap.c
+++ b/src/imap.c
@@ -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:
diff --git a/src/inc.c b/src/inc.c
index cf86ebd..5e99408 100644
--- 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)
diff --git a/src/news.c b/src/news.c
index cc07d17..3bfbce4 100644
--- a/src/news.c
+++ b/src/news.c
@@ -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)
diff --git a/src/passwordstore.c b/src/passwordstore.c
index 8e3942a..a518b7c 100644
--- a/src/passwordstore.c
+++ b/src/passwordstore.c
@@ -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)
diff --git a/src/passwordstore.h b/src/passwordstore.h
index 731027c..373116b 100644
--- a/src/passwordstore.h
+++ b/src/passwordstore.h
@@ -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"
diff --git a/src/plugins/managesieve/managesieve.c b/src/plugins/managesieve/managesieve.c
index 1311172..0fb4ac7 100644
--- a/src/plugins/managesieve/managesieve.c
+++ b/src/plugins/managesieve/managesieve.c
@@ -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 {
diff --git a/src/plugins/managesieve/sieve_prefs.c b/src/plugins/managesieve/sieve_prefs.c
index 9bc2a18..381596a 100644
--- a/src/plugins/managesieve/sieve_prefs.c
+++ b/src/plugins/managesieve/sieve_prefs.c
@@ -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);
 	}
diff --git a/src/prefs_account.c b/src/prefs_account.c
index 89b7a32..1d9b412 100644
--- a/src/prefs_account.c
+++ b/src/prefs_account.c
@@ -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);
 	}
 
diff --git a/src/send_message.c b/src/send_message.c
index 43eef33..75bdd20 100644
--- a/src/send_message.c
+++ b/src/send_message.c
@@ -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,
diff --git a/src/wizard.c b/src/wizard.c
index 8d6ba93..6517b31 100644
--- a/src/wizard.c
+++ b/src/wizard.c
@@ -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

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list