mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Make config and cookie files only readable/writable by current user
This commit is contained in:
parent
bddde5b0da
commit
cb2395b0ba
@ -16,6 +16,7 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <rhash.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
struct gameSpecificConfig
|
||||
{
|
||||
@ -34,6 +35,7 @@ namespace Util
|
||||
int getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory = std::string());
|
||||
int replaceString(std::string& str, const std::string& to_replace, const std::string& replace_with);
|
||||
void filepathReplaceReservedStrings(std::string& str, const std::string& gamename, const unsigned int& platformId = 0, const std::string& dlcname = "");
|
||||
void setFilePermissions(const boost::filesystem::path& path, const boost::filesystem::perms& permissions);
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
||||
|
6
main.cpp
6
main.cpp
@ -416,6 +416,10 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Make sure that config file and cookie file are only readable/writable by owner
|
||||
Util::setFilePermissions(config.sConfigFilePath, boost::filesystem::owner_read | boost::filesystem::owner_write);
|
||||
Util::setFilePermissions(config.sCookiePath, boost::filesystem::owner_read | boost::filesystem::owner_write);
|
||||
|
||||
if (config.bSaveConfig || iLoginResult == 1)
|
||||
{
|
||||
if (iLoginResult == 1)
|
||||
@ -472,6 +476,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
ofs.close();
|
||||
Util::setFilePermissions(config.sConfigFilePath, boost::filesystem::owner_read | boost::filesystem::owner_write);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
@ -491,6 +496,7 @@ int main(int argc, char *argv[])
|
||||
ofs << "secret = " << config.sSecret << std::endl;
|
||||
}
|
||||
ofs.close();
|
||||
Util::setFilePermissions(config.sConfigFilePath, boost::filesystem::owner_read | boost::filesystem::owner_write);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
@ -41,6 +41,8 @@ Downloader::~Downloader()
|
||||
delete gogAPI;
|
||||
curl_easy_cleanup(curlhandle);
|
||||
curl_global_cleanup();
|
||||
// Make sure that cookie file is only readable/writable by owner
|
||||
Util::setFilePermissions(config.sCookiePath, boost::filesystem::owner_read | boost::filesystem::owner_write);
|
||||
}
|
||||
|
||||
|
||||
|
20
src/util.cpp
20
src/util.cpp
@ -314,3 +314,23 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g
|
||||
while (Util::replaceString(str, "%platform%", platform));
|
||||
while (Util::replaceString(str, "//", "/")); // Replace any double slashes with single slash
|
||||
}
|
||||
|
||||
void Util::setFilePermissions(const boost::filesystem::path& path, const boost::filesystem::perms& permissions)
|
||||
{
|
||||
if (boost::filesystem::exists(path))
|
||||
{
|
||||
if (boost::filesystem::is_regular_file(path))
|
||||
{
|
||||
boost::filesystem::file_status s = boost::filesystem::status(path);
|
||||
if (s.permissions() != permissions)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::permissions(path, permissions, ec);
|
||||
if (ec)
|
||||
{
|
||||
std::cout << "Failed to set file permissions for " << path.string() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user