...and one more forgotten NULL check.
[claws.git] / src / passwordstore.c
index 97f44d3f57da4fbf25d8c8bcbfcc9a8d01218a28..0564d473b0ea982944d2de8ae4788b21ecfb8a19 100644 (file)
@@ -37,6 +37,7 @@
 #include "prefs_common.h"
 #include "prefs_gtk.h"
 #include "prefs_migration.h"
+#include "file-utils.h"
 
 static GSList *_password_store;
 
@@ -121,11 +122,6 @@ gboolean passwd_store_set(PasswordBlockType block_type,
        else
                p = password;
 
-       debug_print("%s password '%s' in block (%d/%s)%s\n",
-                       (p == NULL ? "Deleting" : "Storing"),
-                       password_id, block_type, block_name,
-                       (encrypted ? ", already encrypted" : "") );
-
        /* find correct block (create if needed) */
        if ((block = _get_block(block_type, block_name)) == NULL) {
                /* If caller wants to delete a password, and even its block
@@ -140,6 +136,11 @@ gboolean passwd_store_set(PasswordBlockType block_type,
                }
        }
 
+       debug_print("%s password for '%s' in block (%d/%s)%s\n",
+                       (p == NULL ? "Deleting" : "Storing"),
+                       password_id, block_type, block_name,
+                       (encrypted ? ", already encrypted" : "") );
+
        if (p == NULL) {
                /* NULL password was passed to us, so delete the entry with
                 * corresponding id */
@@ -306,7 +307,7 @@ void passwd_store_reencrypt_all(const gchar *old_mpwd,
                debug_print("Reencrypting passwords in block (%d/%s).\n",
                                block->block_type, block->block_name);
 
-               if (g_hash_table_size(block->entries) == 0)
+               if (block->entries == NULL || g_hash_table_size(block->entries) == 0)
                        continue;
 
                keys = g_hash_table_get_keys(block->entries);
@@ -348,16 +349,16 @@ static gint _write_to_file(FILE *fp)
 
        /* Write out the config_version */
        line = g_strdup_printf("[config_version:%d]\n", CLAWS_CONFIG_VERSION);
-       if (fputs(line, fp) == EOF) {
-               FILE_OP_ERROR("password store, config_version", "fputs");
+       if (claws_fputs(line, fp) == EOF) {
+               FILE_OP_ERROR("password store, config_version", "claws_fputs");
                g_free(line);
                return -1;
        }
        g_free(line);
 
        /* Add a newline if needed */
-       if (_password_store != NULL && fputs("\n", fp) == EOF) {
-               FILE_OP_ERROR("password store", "fputs");
+       if (_password_store != NULL && claws_fputs("\n", fp) == EOF) {
+               FILE_OP_ERROR("password store", "claws_fputs");
                return -1;
        }
 
@@ -368,7 +369,7 @@ static gint _write_to_file(FILE *fp)
                        continue; /* Just in case. */
 
                /* Do not save empty blocks. */
-               if (g_hash_table_size(block->entries) == 0)
+               if (block->entries == NULL || g_hash_table_size(block->entries) == 0)
                        continue;
 
                /* Prepare the section header string and write it out. */
@@ -382,8 +383,8 @@ static gint _write_to_file(FILE *fp)
                }
                line = g_strdup_printf("[%s:%s]\n", typestr, block->block_name);
 
-               if (fputs(line, fp) == EOF) {
-                       FILE_OP_ERROR("password store", "fputs");
+               if (claws_fputs(line, fp) == EOF) {
+                       FILE_OP_ERROR("password store", "claws_fputs");
                        g_free(line);
                        return -1;
                }
@@ -397,8 +398,8 @@ static gint _write_to_file(FILE *fp)
                                continue;
 
                        line = g_strdup_printf("%s %s\n", key, pwd);
-                       if (fputs(line, fp) == EOF) {
-                               FILE_OP_ERROR("password store", "fputs");
+                       if (claws_fputs(line, fp) == EOF) {
+                               FILE_OP_ERROR("password store", "claws_fputs");
                                g_free(line);
                                return -1;
                        }
@@ -407,8 +408,8 @@ static gint _write_to_file(FILE *fp)
                g_list_free(keys);
 
                /* Add a separating new line if there is another block remaining */
-               if (item->next != NULL && fputs("\n", fp) == EOF) {
-                       FILE_OP_ERROR("password store", "fputs");
+               if (item->next != NULL && claws_fputs("\n", fp) == EOF) {
+                       FILE_OP_ERROR("password store", "claws_fputs");
                        return -1;
                }