Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce export file permissions and overwrite it #308

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/aegis.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <glib.h>
#include <gcrypt.h>
#include <jansson.h>
#include <sys/stat.h>
#include <time.h>
#include <uuid/uuid.h>
#include "../imports.h"
Expand Down Expand Up @@ -372,7 +373,9 @@ export_aegis (const gchar *export_path,
gcry_cipher_close (hd);
}

mode_t old_umask = umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
FILE *fp = fopen (export_path, "w");
umask(old_umask);
if (fp == NULL) {
g_set_error (&err, generic_error_gquark (), GENERIC_ERRCODE, "couldn't create the file object");
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/common/andotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gio/gio.h>
#include <gcrypt.h>
#include <jansson.h>
#include <sys/stat.h>
#include <time.h>
#include <glib/gi18n.h>
#include "../file-size.h"
Expand Down Expand Up @@ -220,7 +221,9 @@ export_andotp (const gchar *export_path,

// if plaintext export is needed, then write the file and exit
if (password == NULL) {
mode_t old_umask = umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
FILE *fp = fopen (export_path, "w");
umask(old_umask);
if (fp == NULL) {
g_set_error (&err, generic_error_gquark (), GENERIC_ERRCODE, "couldn't create the file object");
goto end;
Expand Down Expand Up @@ -276,7 +279,7 @@ export_andotp (const gchar *export_path,
gcry_cipher_close (hd);

GFile *out_gfile = g_file_new_for_path (export_path);
GFileOutputStream *out_stream = g_file_append_to (out_gfile, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &err);
GFileOutputStream *out_stream = g_file_replace (out_gfile, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION | G_FILE_CREATE_PRIVATE, NULL, &err);
if (err != NULL) {
goto cleanup_before_exiting;
}
Expand Down
4 changes: 3 additions & 1 deletion src/common/freeotp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <glib.h>
#include <gcrypt.h>
#include <jansson.h>
#include <sys/stat.h>
#include <time.h>
#include "../file-size.h"
#include "../parse-uri.h"
Expand Down Expand Up @@ -37,8 +38,9 @@ export_freeotpplus (const gchar *export_path,
{
json_t *db_obj;
gsize index;

mode_t old_umask = umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
FILE *fp = fopen (export_path, "w");
umask(old_umask);
if (fp == NULL) {
return g_strdup ("couldn't create the file object");
}
Expand Down
Loading