talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 07c41544264fbc6779d654372acca453d243d68a
parent e727be6329c2589a739f2260bbf164c43701ba77
Author: Colin Leroy <colin@colino.net>
Date:   Thu, 11 Feb 2016 14:32:44 +0100

Add a plugin method to allow updating stored passwords on master password change.
GData is still untested.

Diffstat:
Msrc/common/plugin.c | 18++++++++++++++++++
Msrc/common/plugin.h | 2++
Msrc/password.c | 6++++++
Msrc/plugins/gdata/cm_gdata_prefs.c | 13+++++++++++++
Msrc/plugins/gdata/cm_gdata_prefs.h | 1+
Msrc/plugins/gdata/gdata_plugin.c | 5+++++
Msrc/plugins/spam_report/plugin.def | 2+-
Msrc/plugins/spam_report/spam_report.c | 5+++++
Msrc/plugins/spam_report/spam_report_prefs.c | 15+++++++++++++++
Msrc/plugins/spam_report/spam_report_prefs.h | 1+
Msrc/plugins/vcalendar/plugin.c | 5+++++
Msrc/plugins/vcalendar/plugin.def | 1+
Msrc/plugins/vcalendar/vcal_prefs.c | 18++++++++++++++++++
Msrc/plugins/vcalendar/vcal_prefs.h | 2++
14 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/src/common/plugin.c b/src/common/plugin.c @@ -51,6 +51,7 @@ struct _Plugin const gchar *(*version) (void); const gchar *(*type) (void); const gchar *(*licence) (void); + void (*master_password_change) (const gchar *oldp, const gchar *newp); struct PluginFeature *(*provides) (void); GSList *rdeps; @@ -419,6 +420,8 @@ Plugin *plugin_load(const gchar *filename, gchar **error) const gchar *(*plugin_type)(void); const gchar *(*plugin_licence)(void); struct PluginFeature *(*plugin_provides)(void); + void (*plugin_master_password_change) (const gchar *oldp, const gchar *newp) = NULL; + gint ok; START_TIMING((filename?filename:"NULL plugin")); cm_return_val_if_fail(filename != NULL, NULL); @@ -474,6 +477,9 @@ init_plugin: g_free(plugin); return NULL; } + + /* Optional methods */ + g_module_symbol(plugin->module, "plugin_master_password_change", (gpointer)&plugin_master_password_change); if (plugin_licence_check(plugin_licence()) != TRUE) { *error = g_strdup(_("This module is not licensed under a GPL v3 or later compatible license.")); @@ -506,6 +512,7 @@ init_plugin: plugin->type = plugin_type; plugin->licence = plugin_licence; plugin->provides = plugin_provides; + plugin->master_password_change = plugin_master_password_change; plugin->filename = g_strdup(filename); plugin->error = NULL; @@ -745,6 +752,17 @@ const gchar *plugin_get_error(Plugin *plugin) return plugin->error; } +void plugins_master_password_change(const gchar *oldp, const gchar *newp) { + Plugin *plugin = NULL; + GSList *cur; + for (cur = plugin_get_list(); cur; cur = g_slist_next(cur)) { + plugin = (Plugin *)cur->data; + if (plugin->master_password_change != NULL) { + plugin->master_password_change(oldp, newp); + } + } +} + /* Generally called in plugin_init() function of each plugin. It check the * minimal and compiled version of claws binary required by the plugin. * If (@minimum_claws_version == 0 || @compiled_claws_version == 0), don't diff --git a/src/common/plugin.h b/src/common/plugin.h @@ -59,6 +59,8 @@ void plugin_unload_all (const gchar *type); void plugin_save_list (void); void plugin_load_standard_plugins (void); +void plugins_master_password_change(const gchar *oldp, const gchar *newp); + GSList *plugin_get_list (void); GSList *plugin_get_unloaded_list(void); const gchar *plugin_get_name (Plugin *plugin); diff --git a/src/password.c b/src/password.c @@ -36,6 +36,7 @@ #endif #include "common/passcrypt.h" +#include "common/plugin.h" #include "common/utils.h" #include "account.h" #include "alertpanel.h" @@ -210,6 +211,11 @@ void master_password_change(const gchar *newp) } } + /* Now reencrypt all plugins passwords fields + * FIXME: Unloaded plugins won't be able to update their stored passwords + */ + plugins_master_password_change(oldp, newp); + master_password_forget(); } #endif diff --git a/src/plugins/gdata/cm_gdata_prefs.c b/src/plugins/gdata/cm_gdata_prefs.c @@ -151,3 +151,16 @@ void cm_gdata_prefs_done(void) prefs_gtk_unregister_page((PrefsPage*) &gdata_page); } } + +void cm_gdata_master_password_change(const gchar *oldp, const gchar *newp) { + gchar *pass; + int i; + + pass = password_decrypt(cm_gdata_config.oauth2_refresh_token, oldp); + if (pass != NULL) { + g_free(cm_gdata_config.oauth2_refresh_token); + cm_gdata_config.oauth2_refresh_token = password_encrypt(pass, newp); + memset(pass, 0, strlen(pass)); + } + g_free(pass); +} diff --git a/src/plugins/gdata/cm_gdata_prefs.h b/src/plugins/gdata/cm_gdata_prefs.h @@ -33,5 +33,6 @@ extern PrefParam cm_gdata_param[]; void cm_gdata_prefs_init(void); void cm_gdata_prefs_done(void); +void cm_gdata_master_password_change(const gchar *oldp, const gchar *newp); #endif /* CM_GDATA_PREFS_H_ */ diff --git a/src/plugins/gdata/gdata_plugin.c b/src/plugins/gdata/gdata_plugin.c @@ -181,6 +181,11 @@ const gchar *plugin_version(void) return VERSION; } +void plugin_master_password_change (const gchar *oldp, const gchar *newp) +{ + cm_gdata_prefs_master_password_change(oldp, newp); +} + struct PluginFeature *plugin_provides(void) { static struct PluginFeature features[] = diff --git a/src/plugins/spam_report/plugin.def b/src/plugins/spam_report/plugin.def @@ -7,4 +7,4 @@ EXPORTS plugin_type plugin_provides plugin_version - + plugin_master_password_change diff --git a/src/plugins/spam_report/spam_report.c b/src/plugins/spam_report/spam_report.c @@ -407,6 +407,11 @@ const gchar *plugin_version(void) return VERSION; } +void plugin_master_password_change (const gchar *oldp, const gchar *newp) +{ + spamreport_master_password_change(oldp, newp); +} + struct PluginFeature *plugin_provides(void) { static struct PluginFeature features[] = diff --git a/src/plugins/spam_report/spam_report_prefs.c b/src/plugins/spam_report/spam_report_prefs.c @@ -232,3 +232,18 @@ static void save_spamreport_prefs(PrefsPage *page) } else prefs_file_close(pref_file); } + +void spamreport_master_password_change(const gchar *oldp, const gchar *newp) { + gchar *pass; + int i; + + for (i = 0; i < INTF_LAST; i++) { + pass = password_decrypt(spamreport_prefs.pass[i], oldp); + if (pass != NULL) { + g_free(spamreport_prefs.pass[i]); + spamreport_prefs.pass[i] = password_encrypt(pass, newp); + memset(pass, 0, strlen(pass)); + } + g_free(pass); + } +} diff --git a/src/plugins/spam_report/spam_report_prefs.h b/src/plugins/spam_report/spam_report_prefs.h @@ -65,5 +65,6 @@ extern SpamReportPrefs spamreport_prefs; void spamreport_prefs_init(void); void spamreport_prefs_done(void); +void spamreport_master_password_change(const gchar *oldp, const gchar *newp); #endif diff --git a/src/plugins/vcalendar/plugin.c b/src/plugins/vcalendar/plugin.c @@ -99,6 +99,11 @@ const gchar *plugin_version(void) return VERSION; } +void plugin_master_password_change (const gchar *oldp, const gchar *newp) +{ + vcal_prefs_master_password_change(oldp, newp); +} + struct PluginFeature *plugin_provides(void) { static struct PluginFeature features[] = diff --git a/src/plugins/vcalendar/plugin.def b/src/plugins/vcalendar/plugin.def @@ -7,4 +7,5 @@ EXPORTS plugin_type plugin_provides plugin_version + plugin_master_password_change diff --git a/src/plugins/vcalendar/vcal_prefs.c b/src/plugins/vcalendar/vcal_prefs.c @@ -723,6 +723,24 @@ static void vcal_prefs_save_func(PrefsPage * _page) vcal_folder_export(NULL); } +void vcal_prefs_master_password_change(const gchar *oldp, const gchar *newp) { + gchar *pass; + pass = password_decrypt(vcalprefs.export_pass, oldp); + if (pass != NULL) { + g_free(vcalprefs.export_pass); + vcalprefs.export_pass = password_encrypt(pass, newp); + memset(pass, 0, strlen(pass)); + } + g_free(pass); + pass = password_decrypt(vcalprefs.export_freebusy_pass, oldp); + if (pass != NULL) { + g_free(vcalprefs.export_freebusy_pass); + vcalprefs.export_freebusy_pass = password_encrypt(pass, newp); + memset(pass, 0, strlen(pass)); + } + g_free(pass); +} + void vcal_prefs_init(void) { static gchar *path[3]; diff --git a/src/plugins/vcalendar/vcal_prefs.h b/src/plugins/vcalendar/vcal_prefs.h @@ -51,4 +51,6 @@ extern VcalendarPrefs vcalprefs; void vcal_prefs_init (void); void vcal_prefs_done (void); void vcal_prefs_save (void); +void vcal_prefs_master_password_change(const gchar *oldp, const gchar *newp); + #endif