Add a plugin method to allow updating stored passwords on master password change.
[claws.git] / src / plugins / vcalendar / vcal_prefs.c
index 64ea6da..680e807 100644 (file)
@@ -30,6 +30,7 @@
 #include "defs.h"
 
 #include "mainwindow.h"
+#include "password.h"
 #include "prefs.h"
 #include "prefs_gtk.h"
 #include "prefswindow.h"
@@ -268,6 +269,8 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
 
        GtkWidget *frame_ssl_options;
        GtkWidget *ssl_verify_peer_checkbtn;
+       gchar *export_pass = NULL;
+       gchar *export_freebusy_pass = NULL;
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
@@ -415,6 +418,9 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
        gtk_widget_show (register_orage_checkbtn);
        gtk_box_pack_start(GTK_BOX (hbox3), register_orage_checkbtn, TRUE, TRUE, 0);
 
+       hbox3 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox3);
+       gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
        calendar_server_checkbtn = gtk_check_button_new_with_label(_("Export as GNOME shell calendar server"));
        CLAWS_SET_TIP(calendar_server_checkbtn,
                      _("Register D-Bus calendar server interface to export Claws Mail's calendar"));
@@ -556,10 +562,23 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
        if (!vcalprefs.export_freebusy_pass)
                vcalprefs.export_freebusy_pass = g_strdup("");
 
+       export_pass = password_decrypt(vcalprefs.export_pass, NULL);
+       export_freebusy_pass = password_decrypt(vcalprefs.export_freebusy_pass, NULL);
+       
        gtk_entry_set_text(GTK_ENTRY(export_user_entry), vcalprefs.export_user);
-       gtk_entry_set_text(GTK_ENTRY(export_pass_entry), vcalprefs.export_pass);
+       gtk_entry_set_text(GTK_ENTRY(export_pass_entry), (export_pass != NULL ? export_pass : ""));
        gtk_entry_set_text(GTK_ENTRY(export_freebusy_user_entry), vcalprefs.export_freebusy_user);
-       gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), vcalprefs.export_freebusy_pass);
+       gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), (export_freebusy_pass != NULL ? export_freebusy_pass : ""));
+
+       if (export_pass != NULL) {
+               memset(export_pass, 0, strlen(export_pass));
+       }
+       g_free(export_pass);
+
+       if (export_freebusy_pass != NULL) {
+               memset(export_freebusy_pass, 0, strlen(export_freebusy_pass));
+       }
+       g_free(export_freebusy_pass);
 
        g_signal_connect(G_OBJECT(export_enable_checkbtn),
                         "toggled", G_CALLBACK(path_changed), page);
@@ -609,6 +628,7 @@ void vcal_prefs_save(void)
 {
        PrefFile *pfile;
        gchar *rcpath;
+
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
        pfile = prefs_write_open(rcpath);
        g_free(rcpath);
@@ -630,6 +650,7 @@ void vcal_prefs_save(void)
 static void vcal_prefs_save_func(PrefsPage * _page)
 {
        struct VcalendarPage *page = (struct VcalendarPage *) _page;
+       gchar *pass;
 
 /* alert */
        vcalprefs.alert_enable =
@@ -660,8 +681,11 @@ static void vcal_prefs_save_func(PrefsPage * _page)
        vcalprefs.export_user =
            gtk_editable_get_chars(GTK_EDITABLE(page->export_user_entry), 0, -1);
        g_free(vcalprefs.export_pass);
-       vcalprefs.export_pass =
-           gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
+       pass = gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
+       
+       vcalprefs.export_pass = password_encrypt(pass, NULL);
+       memset(pass, 0, strlen(pass));
+       g_free(pass);
        
 /* free/busy export */
        vcalprefs.export_freebusy_enable = 
@@ -680,9 +704,10 @@ static void vcal_prefs_save_func(PrefsPage * _page)
        vcalprefs.export_freebusy_user =
            gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_user_entry), 0, -1);
        g_free(vcalprefs.export_freebusy_pass);
-       vcalprefs.export_freebusy_pass =
-           gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
-       
+       pass = gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
+       vcalprefs.export_freebusy_pass = password_encrypt(pass, NULL);
+       memset(pass, 0, strlen(pass));
+       g_free(pass);
 
 /* free/busy import */
        g_free(vcalprefs.freebusy_get_url);
@@ -698,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];