Browse Source

rework of storing certificates path (#1642)

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1677/head
R4SAS 3 years ago
parent
commit
e8ad7b4f79
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 6
      daemon/Daemon.cpp
  2. 20
      libi2pd/FS.cpp
  3. 18
      libi2pd/FS.h
  4. 8
      libi2pd/Family.cpp
  5. 8
      libi2pd/Reseed.cpp

6
daemon/Daemon.cpp

@ -94,6 +94,11 @@ namespace util @@ -94,6 +94,11 @@ namespace util
i2p::config::GetOption("daemon", isDaemon);
std::string certsdir; i2p::config::GetOption("certsdir", certsdir);
i2p::fs::SetCertsDir(certsdir);
certsdir = i2p::fs::GetCertsDir();
std::string logs = ""; i2p::config::GetOption("log", logs);
std::string logfile = ""; i2p::config::GetOption("logfile", logfile);
std::string loglevel = ""; i2p::config::GetOption("loglevel", loglevel);
@ -132,6 +137,7 @@ namespace util @@ -132,6 +137,7 @@ namespace util
LogPrint(eLogNone, "i2pd v", VERSION, " starting");
LogPrint(eLogDebug, "FS: main config file: ", config);
LogPrint(eLogDebug, "FS: data directory: ", datadir);
LogPrint(eLogDebug, "FS: certificates directory: ", certsdir);
bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation);
bool aesni; i2p::config::GetOption("cpuext.aesni", aesni);

20
libi2pd/FS.cpp

@ -24,6 +24,7 @@ namespace i2p { @@ -24,6 +24,7 @@ namespace i2p {
namespace fs {
std::string appName = "i2pd";
std::string dataDir = "";
std::string certsDir = "";
#ifdef _WIN32
std::string dirSep = "\\";
#else
@ -42,6 +43,10 @@ namespace fs { @@ -42,6 +43,10 @@ namespace fs {
return dataDir;
}
const std::string & GetCertsDir () {
return certsDir;
}
const std::string GetUTF8DataDir () {
#ifdef _WIN32
boost::filesystem::wpath path (dataDir);
@ -126,6 +131,21 @@ namespace fs { @@ -126,6 +131,21 @@ namespace fs {
#endif
}
void SetCertsDir(const std::string & cmdline_certsdir) {
if (cmdline_certsdir != "")
{
if (cmdline_certsdir[cmdline_certsdir.length()-1] == '/')
certsDir = cmdline_certsdir.substr(0, cmdline_certsdir.size()-1); // strip trailing slash
else
certsDir = cmdline_certsdir;
}
else
{
certsDir = i2p::fs::DataDirPath("certificates");
}
return;
}
bool Init() {
if (!boost::filesystem::exists(dataDir))
boost::filesystem::create_directory(dataDir);

18
libi2pd/FS.h

@ -75,6 +75,9 @@ namespace fs { @@ -75,6 +75,9 @@ namespace fs {
/** @brief Returns datadir path */
const std::string & GetDataDir();
/** @brief Returns certsdir path */
const std::string & GetCertsDir();
/** @brief Returns datadir path in UTF-8 encoding */
const std::string GetUTF8DataDir();
@ -90,7 +93,20 @@ namespace fs { @@ -90,7 +93,20 @@ namespace fs {
* Mac: /Library/Application Support/i2pd/ or ~/Library/Application Support/i2pd/
* Unix: /var/lib/i2pd/ (system=1) >> ~/.i2pd/ or /tmp/i2pd/
*/
void DetectDataDir(const std::string & cmdline_datadir, bool isService = false);
void DetectDataDir(const std::string & cmdline_datadir, bool isService = false);
/**
* @brief Set certsdir either from cmdline option or using autodetection
* @param cmdline_param Value of cmdline parameter --certsdir=<something>
*
* Examples of autodetected paths:
*
* Windows < Vista: C:\Documents and Settings\Username\Application Data\i2pd\certificates
* Windows >= Vista: C:\Users\Username\AppData\Roaming\i2pd\certificates
* Mac: /Library/Application Support/i2pd/ or ~/Library/Application Support/i2pd/certificates
* Unix: /var/lib/i2pd/certificates (system=1) >> ~/.i2pd/ or /tmp/i2pd/certificates
*/
void SetCertsDir(const std::string & cmdline_certsdir);
/**
* @brief Create subdirectories inside datadir

8
libi2pd/Family.cpp

@ -99,13 +99,7 @@ namespace data @@ -99,13 +99,7 @@ namespace data
void Families::LoadCertificates ()
{
std::string certDir;
std::string certsdir; i2p::config::GetOption("certsdir", certsdir);
if (!i2p::config::IsDefault("certsdir"))
certDir = certsdir + i2p::fs::dirSep + "family";
if (certDir.empty() || !i2p::fs::Exists(certDir))
certDir = i2p::fs::DataDirPath("certificates", "family");
std::string certDir = i2p::fs::GetCertsDir() + i2p::fs::dirSep + "family";
std::vector<std::string> files;
int numCertificates = 0;

8
libi2pd/Reseed.cpp

@ -497,13 +497,7 @@ namespace data @@ -497,13 +497,7 @@ namespace data
void Reseeder::LoadCertificates ()
{
std::string certDir;
std::string certsdir; i2p::config::GetOption("certsdir", certsdir);
if (!i2p::config::IsDefault("certsdir"))
certDir = certsdir + i2p::fs::dirSep + "reseed";
if (certDir.empty() || !i2p::fs::Exists(certDir))
certDir = i2p::fs::DataDirPath("certificates", "reseed");
std::string certDir = i2p::fs::GetCertsDir() + i2p::fs::dirSep + "reseed";
std::vector<std::string> files;
int numCertificates = 0;

Loading…
Cancel
Save