lib/common: Move DataDirectories to barrier namespace

This commit is contained in:
Povilas Kanapickas 2021-11-01 04:29:49 +02:00
parent 677612d342
commit 298980fa86
12 changed files with 34 additions and 16 deletions

View File

@ -442,7 +442,7 @@ void MainWindow::checkFingerprint(const QString& line)
barrier::string::from_hex(fingerprintRegex.cap(2).toStdString()) barrier::string::from_hex(fingerprintRegex.cap(2).toStdString())
}; };
auto db_path = DataDirectories::trusted_servers_ssl_fingerprints_path(); auto db_path = barrier::DataDirectories::trusted_servers_ssl_fingerprints_path();
// We compare only SHA256 fingerprints, but show both SHA1 and SHA256 so that the users can // We compare only SHA256 fingerprints, but show both SHA1 and SHA256 so that the users can
// still verify fingerprints on old Barrier servers. This way the only time when we are exposed // still verify fingerprints on old Barrier servers. This way the only time when we are exposed
@ -564,7 +564,7 @@ void MainWindow::startBarrier()
// launched the process (e.g. when launched with elevation). setting the // launched the process (e.g. when launched with elevation). setting the
// profile dir on launch ensures it uses the same profile dir is used // profile dir on launch ensures it uses the same profile dir is used
// no matter how its relaunched. // no matter how its relaunched.
args << "--profile-dir" << QString::fromStdString("\"" + DataDirectories::profile() + "\""); args << "--profile-dir" << QString::fromStdString("\"" + barrier::DataDirectories::profile() + "\"");
#endif #endif
if ((barrierType() == barrierClient && !clientArgs(args, app)) if ((barrierType() == barrierClient && !clientArgs(args, app))
@ -1020,7 +1020,7 @@ void MainWindow::updateSSLFingerprint()
return; return;
} }
auto local_path = DataDirectories::local_ssl_fingerprints_path(); auto local_path = barrier::DataDirectories::local_ssl_fingerprints_path();
if (!QFile::exists(QString::fromStdString(local_path))) { if (!QFile::exists(QString::fromStdString(local_path))) {
return; return;
} }

View File

@ -38,7 +38,7 @@ static const char kSslDir[] = "SSL";
SslCertificate::SslCertificate(QObject *parent) : SslCertificate::SslCertificate(QObject *parent) :
QObject(parent) QObject(parent)
{ {
m_ProfileDir = DataDirectories::profile(); m_ProfileDir = barrier::DataDirectories::profile();
if (m_ProfileDir.empty()) { if (m_ProfileDir.empty()) {
emit error(tr("Failed to get profile directory.")); emit error(tr("Failed to get profile directory."));
} }
@ -73,7 +73,7 @@ void SslCertificate::generateCertificate()
void SslCertificate::generateFingerprint(const std::string& cert_path) void SslCertificate::generateFingerprint(const std::string& cert_path)
{ {
try { try {
auto local_path = DataDirectories::local_ssl_fingerprints_path(); auto local_path = barrier::DataDirectories::local_ssl_fingerprints_path();
barrier::FingerprintDatabase db; barrier::FingerprintDatabase db;
db.add_trusted(barrier::get_pem_file_cert_fingerprint(cert_path, db.add_trusted(barrier::get_pem_file_cert_fingerprint(cert_path,
barrier::FingerprintType::SHA1)); barrier::FingerprintType::SHA1));

View File

@ -164,7 +164,7 @@ App::initApp(int argc, const char** argv)
// parse command line // parse command line
parseArgs(argc, argv); parseArgs(argc, argv);
DataDirectories::profile(argsBase().m_profileDirectory.u8string()); barrier::DataDirectories::profile(argsBase().m_profileDirectory.u8string());
// set log filter // set log filter
if (!CLOG->setFilter(argsBase().m_logFilter)) { if (!CLOG->setFilter(argsBase().m_logFilter)) {

View File

@ -130,11 +130,11 @@ ServerApp::help()
// refer to custom profile directory even if not saved yet // refer to custom profile directory even if not saved yet
barrier::fs::path profile_path = argsBase().m_profileDirectory; barrier::fs::path profile_path = argsBase().m_profileDirectory;
if (profile_path.empty()) { if (profile_path.empty()) {
profile_path = barrier::fs::u8path(DataDirectories::profile()); profile_path = barrier::fs::u8path(barrier::DataDirectories::profile());
} }
auto usr_config_path = (profile_path / barrier::fs::u8path(USR_CONFIG_NAME)).u8string(); auto usr_config_path = (profile_path / barrier::fs::u8path(USR_CONFIG_NAME)).u8string();
auto sys_config_path = (barrier::fs::u8path(DataDirectories::systemconfig()) / auto sys_config_path = (barrier::fs::u8path(barrier::DataDirectories::systemconfig()) /
barrier::fs::u8path(SYS_CONFIG_NAME)).u8string(); barrier::fs::u8path(SYS_CONFIG_NAME)).u8string();
std::ostringstream buffer; std::ostringstream buffer;
@ -197,7 +197,7 @@ ServerApp::loadConfig()
// load the default configuration if no explicit file given // load the default configuration if no explicit file given
else { else {
auto path = barrier::fs::u8path(DataDirectories::profile()); auto path = barrier::fs::u8path(barrier::DataDirectories::profile());
if (!path.empty()) { if (!path.empty()) {
// complete path // complete path
path /= barrier::fs::u8path(USR_CONFIG_NAME); path /= barrier::fs::u8path(USR_CONFIG_NAME);
@ -210,7 +210,7 @@ ServerApp::loadConfig()
} }
if (!loaded) { if (!loaded) {
// try the system-wide config file // try the system-wide config file
path = barrier::fs::u8path(DataDirectories::systemconfig()); path = barrier::fs::u8path(barrier::DataDirectories::systemconfig());
if (!path.empty()) { if (!path.empty()) {
path /= barrier::fs::u8path(SYS_CONFIG_NAME); path /= barrier::fs::u8path(SYS_CONFIG_NAME);
if (loadConfig(path.u8string())) { if (loadConfig(path.u8string())) {

View File

@ -245,7 +245,7 @@ DaemonApp::logFilename()
{ {
string logFilename = ARCH->setting("LogFilename"); string logFilename = ARCH->setting("LogFilename");
if (logFilename.empty()) if (logFilename.empty())
logFilename = DataDirectories::global() + "\\" + LOG_FILENAME; logFilename = barrier::DataDirectories::global() + "\\" + LOG_FILENAME;
MSWindowsUtil::createDirectory(logFilename, true); MSWindowsUtil::createDirectory(logFilename, true);
return logFilename; return logFilename;
} }

View File

@ -15,10 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #ifndef BARRIER_LIB_COMMON_DATA_DIRECTORIES_H
#define BARRIER_LIB_COMMON_DATA_DIRECTORIES_H
#include <string> #include <string>
namespace barrier {
class DataDirectories class DataDirectories
{ {
public: public:
@ -40,3 +43,7 @@ private:
static std::string _global; static std::string _global;
static std::string _systemconfig; static std::string _systemconfig;
}; };
} // namespace barrier
#endif

View File

@ -17,7 +17,8 @@
#include "DataDirectories.h" #include "DataDirectories.h"
// static member namespace barrier {
std::string DataDirectories::_profile; std::string DataDirectories::_profile;
std::string DataDirectories::_global; std::string DataDirectories::_global;
std::string DataDirectories::_systemconfig; std::string DataDirectories::_systemconfig;
@ -46,3 +47,5 @@ std::string DataDirectories::trusted_clients_ssl_fingerprints_path()
{ {
return ssl_fingerprints_path() + "/" + kFingerprintsTrustedClientsFilename; return ssl_fingerprints_path() + "/" + kFingerprintsTrustedClientsFilename;
} }
} // namespace barrier

View File

@ -22,6 +22,8 @@
#include <sys/types.h> // getpwuid(_r) #include <sys/types.h> // getpwuid(_r)
#include <pwd.h> // getpwuid(_r) #include <pwd.h> // getpwuid(_r)
namespace barrier {
const std::string ProfileSubdir = "/barrier"; const std::string ProfileSubdir = "/barrier";
static std::string pw_dir(struct passwd* pwentp) static std::string pw_dir(struct passwd* pwentp)
@ -112,3 +114,5 @@ const std::string& DataDirectories::systemconfig(const std::string& path)
_systemconfig = path; _systemconfig = path;
return _systemconfig; return _systemconfig;
} }
} // namespace barrier

View File

@ -20,6 +20,8 @@
#include <Shlobj.h> #include <Shlobj.h>
namespace barrier {
std::string known_folder_path(const KNOWNFOLDERID& id) std::string known_folder_path(const KNOWNFOLDERID& id)
{ {
std::string path; std::string path;
@ -71,3 +73,5 @@ const std::string& DataDirectories::systemconfig(const std::string& path)
_systemconfig = path; _systemconfig = path;
return _systemconfig; return _systemconfig;
} }
} // namespace barrier

View File

@ -56,7 +56,7 @@ SecureListenSocket::accept()
} }
std::string certificateFilename = barrier::string::sprintf("%s/%s/%s", std::string certificateFilename = barrier::string::sprintf("%s/%s/%s",
DataDirectories::profile().c_str(), barrier::DataDirectories::profile().c_str(),
s_certificateDir, s_certificateDir,
s_certificateFilename); s_certificateFilename);

View File

@ -674,7 +674,7 @@ SecureSocket::verifyCertFingerprint()
barrier::format_ssl_fingerprint(fingerprint_sha1.data).c_str(), barrier::format_ssl_fingerprint(fingerprint_sha1.data).c_str(),
barrier::format_ssl_fingerprint(fingerprint_sha256.data).c_str())); barrier::format_ssl_fingerprint(fingerprint_sha256.data).c_str()));
auto fingerprint_db_path = DataDirectories::trusted_servers_ssl_fingerprints_path(); auto fingerprint_db_path = barrier::DataDirectories::trusted_servers_ssl_fingerprints_path();
// Provide debug hint as to what file is being used to verify fingerprint trust // Provide debug hint as to what file is being used to verify fingerprint trust
LOG((CLOG_NOTE "fingerprint_db_path: %s", fingerprint_db_path.c_str())); LOG((CLOG_NOTE "fingerprint_db_path: %s", fingerprint_db_path.c_str()));

View File

@ -574,7 +574,7 @@ MSWindowsHook::install()
g_fakeServerInput = false; g_fakeServerInput = false;
// setup immune keys // setup immune keys
g_immuneKeysPath = DataDirectories::profile() + "\\ImmuneKeys.txt"; g_immuneKeysPath = barrier::DataDirectories::profile() + "\\ImmuneKeys.txt";
g_immuneKeys = immune_keys_list(); g_immuneKeys = immune_keys_list();
LOG((CLOG_DEBUG "Found %u immune keys in %s", g_immuneKeys.size(), g_immuneKeysPath.c_str())); LOG((CLOG_DEBUG "Found %u immune keys in %s", g_immuneKeys.size(), g_immuneKeysPath.c_str()));