mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-28 07:24:19 +00:00
Merge pull request #2483 from wipedlifepotato/openssl
openbsd: fix a issue from IRC chat
This commit is contained in:
+18
-2
@@ -12,10 +12,10 @@
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
# include<unistd.h>
|
||||
# include<filesystem>
|
||||
#endif
|
||||
|
||||
#include "Daemon.h"
|
||||
|
||||
#include "Config.h"
|
||||
#include "Log.h"
|
||||
#include "FS.h"
|
||||
@@ -140,15 +140,31 @@ namespace util
|
||||
};
|
||||
auto unveil_path = [](std::string path, std::string rules = "r")
|
||||
{
|
||||
// https://stackoverflow.com/questions/83439/remove-spaces-from-stdstring-in-c
|
||||
path.erase(remove_if(path.begin(), path.end(), isspace), path.end());
|
||||
if(path=="")
|
||||
{
|
||||
LogPrint(eLogDebug, "empty path for unveil");
|
||||
return;
|
||||
}
|
||||
if ( (!std::filesystem::exists(path) && !std::filesystem::is_directory(path)) )
|
||||
{
|
||||
{
|
||||
std::ofstream f{path};
|
||||
if(!f)
|
||||
{
|
||||
LogPrint(eLogError, "can't create an empty file " + path);
|
||||
throw std::runtime_error("Can't create a file and it's not directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( unveil(path.c_str(), rules.c_str()) == -1 )
|
||||
{
|
||||
LogPrint(eLogError, "Can't unveil " + path + " with rules " + rules);
|
||||
throw std::runtime_error("can't unveil");
|
||||
bool ignore_unveil;
|
||||
i2p::config::GetOption("openbsd.unveil_ignore", ignore_unveil);
|
||||
if(!ignore_unveil)
|
||||
throw std::runtime_error("can't unveil");
|
||||
}
|
||||
LogPrint(eLogInfo, "unveil " + path + " with rules " + rules);
|
||||
};
|
||||
|
||||
@@ -410,6 +410,7 @@ namespace config {
|
||||
("openbsd.unveil_file", value<std::string>()->default_value(""), "OpenBSD file with unveil rules")
|
||||
("openbsd.unveil_enabled", value<bool>()->default_value(true), "use unveil rues")
|
||||
("openbsd.pledge_enabled", value<bool>()->default_value(true), "use pledge rules")
|
||||
("openbsd.unveil_ignore", value<bool>()->default_value(false), "ignore unveil errors")
|
||||
;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user