From 0757cc9c328b12944d8f2a44a454dff72f370f97 Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Wed, 23 Jan 2019 07:39:08 +0000 Subject: [PATCH] Set permissions to config.json file after creating (#1621) --- nano/lib/jsonconfig.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nano/lib/jsonconfig.hpp b/nano/lib/jsonconfig.hpp index b1267802ab..cd2e36c4fa 100644 --- a/nano/lib/jsonconfig.hpp +++ b/nano/lib/jsonconfig.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace nano { @@ -118,16 +119,19 @@ class jsonconfig : public nano::error_aware<> boost::property_tree::read_json (stream_a, tree); } - /** Open confiruation file, create if necessary */ + /** Open configuration file, create if necessary */ void open_or_create (std::fstream & stream_a, std::string const & path_a) { - stream_a.open (path_a, std::ios_base::in); - if (stream_a.fail ()) + if (!boost::filesystem::exists (path_a)) { - stream_a.open (path_a, std::ios_base::out); + // Create temp stream to first create the file + std::ofstream stream (path_a); + + // Set permissions before opening otherwise Windows only has read permissions + nano::set_secure_perm_file (path_a); } - stream_a.close (); - stream_a.open (path_a, std::ios_base::in | std::ios_base::out); + + stream_a.open (path_a); } /** Returns the boost property node managed by this instance */