Skip to content

Commit

Permalink
v2.10.10
Browse files Browse the repository at this point in the history
  • Loading branch information
bernerdad committed May 15, 2024
1 parent b39def1 commit 2974d6d
Show file tree
Hide file tree
Showing 122 changed files with 1,542 additions and 997 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ bool KernelModuleCommunicator::start(const std::string &deviceName)

bool KernelModuleCommunicator::stop()
{
// Bring down utun420 via nmcli first, or NetworkManager/GNOME may throw up a scary looking "error".
// This is a workaround for #996; this is not really our bug but it's a bad user experience otherwise.
Utils::executeCommand("nmcli", {"con", "down", deviceName_.c_str()});

wg_del_device(deviceName_.c_str());
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion backend/mac/helper/helper-info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleName</key>
<string>WindscribeHelper</string>
<key>CFBundleVersion</key>
<string>62</string>
<string>63</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2024 Windscribe Limited. All rights reserved.</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 4 additions & 0 deletions backend/mac/helper/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ void Server::run()
return;
}

system("mkdir -p /var/run");
system("mkdir -p /etc/windscribe");
Utils::createWindscribeUserAndGroup();

xpc_connection_t listener = xpc_connection_create_mach_service("com.windscribe.helper.macos", NULL, XPC_CONNECTION_MACH_SERVICE_LISTENER);
if (!listener) {
LOG("xpc_connection_create_mach_service failed");
Expand Down
30 changes: 23 additions & 7 deletions backend/windows/windscribe_install_helper/command_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
#include "command_parser.h"

#include <filesystem>

#include "install_service_command.h"

static std::wstring getInstallDir()
{
wchar_t buffer[MAX_PATH];
DWORD pathLen = ::GetModuleFileName(NULL, buffer, MAX_PATH);
if (pathLen == 0) {
Logger::WSDebugMessage(L"Windscribe install helper GetModuleFileName failed (%lu)", ::GetLastError());
return std::wstring();
}

std::filesystem::path path(buffer);
return path.parent_path().native();
}

CommandParser::CommandParser()
{
}
Expand All @@ -13,13 +28,14 @@ CommandParser::~CommandParser()
BasicCommand *CommandParser::parse(int argc, wchar_t* argv[])
{
// Command for install helper
// /InstallService log_path service_path
if (argc == 4 && wcscmp(argv[1], L"/InstallService") == 0)
{
Logger *logger = new Logger(argv[2]);
logger->outCmdLine(argc, argv);
InstallServiceCommand *cmd = new InstallServiceCommand(logger, argv[3]);
return cmd;
// /InstallService
if (argc == 2 && wcscmp(argv[1], L"/InstallService") == 0) {
const auto installDir = getInstallDir();
if (!installDir.empty()) {
Logger *logger = new Logger(installDir.c_str());
InstallServiceCommand *cmd = new InstallServiceCommand(logger, installDir);
return cmd;
}
}

return nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "install_service_command.h"

#include <sstream>
#include <system_error>

#include "servicecontrolmanager.h"

using namespace std;

InstallServiceCommand::InstallServiceCommand(Logger *logger, const wchar_t *servicePath) :
BasicCommand(logger), servicePath_(servicePath)
InstallServiceCommand::InstallServiceCommand(Logger *logger, const wstring &installDir)
: BasicCommand(logger),
installDir_(installDir)
{
}

Expand All @@ -23,25 +25,31 @@ void InstallServiceCommand::execute()

const wstring serviceName(L"WindscribeService");
if (scm.isServiceInstalled(serviceName.c_str())) {
logger_->outStr(L"Remove previous instance of Windscribe Service\n");
scm.deleteService(serviceName.c_str());
logger_->outStr(L"Removing previous instance of Windscribe service");
std::error_code ec;
if (!scm.deleteService(serviceName.c_str(), ec)) {
// We'll still try to reinstall the service even if the delete failed/timed out.
logger_->outStr(L"Failed to delete existing Windscribe service (%d)", ec.value());
}
}

if (!servicePath_.starts_with(L'\"')) {
servicePath_.insert(0, L"\"");
wstring serviceCmdLine;
{
wostringstream stream;
stream << L"\"" << installDir_ << L"\\WindscribeService.exe\"";
serviceCmdLine = stream.str();
}

if (!servicePath_.ends_with(L'\"')) {
servicePath_.append(L"\"");
}

scm.installService(serviceName.c_str(), servicePath_.c_str(),
scm.installService(serviceName.c_str(), serviceCmdLine.c_str(),
L"Windscribe Service", L"Manages the firewall and controls the VPN tunnel",
SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, L"Nsi\0TcpIp\0", true);

scm.setServiceSIDType(SERVICE_SID_TYPE_UNRESTRICTED);
scm.openService(serviceName.c_str(), SERVICE_QUERY_STATUS | SERVICE_START);
scm.startService();

logger_->outStr(L"Reinstalled Windscribe service");
}
catch (system_error& ex) {
logger_->outStr(L"WARNING: failed to reinstall the Windscribe service - %s\n", ex.what());
logger_->outStr(L"WARNING: failed to reinstall the Windscribe service - %s", ex.what());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once

#include "basic_command.h"

class InstallServiceCommand : public BasicCommand
{
public:
InstallServiceCommand(Logger *logger, const wchar_t *servicePath);
InstallServiceCommand(Logger *logger, const std::wstring &installDir);
~InstallServiceCommand() override;

void execute() override;

private:
std::wstring servicePath_;
const std::wstring installDir_;
};
31 changes: 18 additions & 13 deletions backend/windows/windscribe_install_helper/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
#include <Windows.h>

#include <cstdarg>
#include <filesystem>

using namespace std;

static void WSDebugMessage(const wchar_t* format, ...)
Logger::Logger(const wchar_t *installDir)
{
va_list arg_list;
va_start(arg_list, format);
wchar_t szMsg[1024];
_vsnwprintf_s(szMsg, 1024, _TRUNCATE, format, arg_list);
va_end(arg_list);
std::filesystem::path logFile(installDir);
logFile.append(L"logwindscribeinstallhelper.txt");

::OutputDebugString(szMsg);
}

Logger::Logger(const wchar_t *path)
{
errno_t result = _wfopen_s(&file_, path, L"wt,ccs=UTF-8");
errno_t result = _wfopen_s(&file_, logFile.native().c_str(), L"wt,ccs=UTF-8");
if ((result != 0) || (file_ == nullptr)) {
WSDebugMessage(L"Windscribe install helper failed to open its log file '%s' (%d)", path, result);
WSDebugMessage(L"Windscribe install helper failed to open its log file '%s' (%d)", logFile.native().c_str(), result);
}
}

Expand Down Expand Up @@ -54,8 +47,20 @@ void Logger::outStr(const wchar_t* format, ...)

if (file_) {
fputws(szMsg, file_);
fputws(L"\n", file_);
}
else {
::OutputDebugString(szMsg);
}
}

void Logger::WSDebugMessage(const wchar_t* format, ...)
{
va_list arg_list;
va_start(arg_list, format);
wchar_t szMsg[1024];
_vsnwprintf_s(szMsg, 1024, _TRUNCATE, format, arg_list);
va_end(arg_list);

::OutputDebugString(szMsg);
}
4 changes: 3 additions & 1 deletion backend/windows/windscribe_install_helper/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
class Logger
{
public:
explicit Logger(const wchar_t *path);
explicit Logger(const wchar_t *installDir);
virtual ~Logger();
Logger(const Logger &) = delete;
Logger &operator=(const Logger &) = delete;

void outStr(const wchar_t* format, ...);
void outCmdLine(int argc, wchar_t* argv[]);

static void WSDebugMessage(const wchar_t* format, ...);

private:
FILE *file_ = nullptr;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

#include "command_parser.h"

// Set the DLL load directory to the system directory before entering WinMain().
struct LoadSystemDLLsFromSystem32
{
LoadSystemDLLsFromSystem32()
{
// Remove the current directory from the search path for dynamically loaded
// DLLs as a precaution. This call has no effect for delay load DLLs.
SetDllDirectory(L"");
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
}
} loadSystemDLLs;

int _tmain(int argc, _TCHAR* argv[])
{
CommandParser parser;
Expand Down
2 changes: 2 additions & 0 deletions backend/windows/windscribe_service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_definitions(-DUNICODE -D_UNICODE -DWINDSCRIBE_SERVICE)
project(Service)

find_package(Boost REQUIRED COMPONENTS serialization)
find_path(WINREG_INCLUDE_DIRS "winreg/WinReg.hpp")

add_subdirectory(../../../libs/wsnet wsnet)

Expand Down Expand Up @@ -95,6 +96,7 @@ target_link_libraries(WindscribeService
target_include_directories(WindscribeService PRIVATE
${WINDSCRIBE_BUILD_LIBS_PATH}/wintun/include
../../../client/common/
${WINREG_INCLUDE_DIRS}
)

install(TARGETS WindscribeService wsnet
Expand Down
9 changes: 1 addition & 8 deletions backend/windows/windscribe_service/ipc/serialize_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template<class Archive>
void serialize(Archive & ar, CMD_TASK_KILL & g, const unsigned int version)
{
UNREFERENCED_PARAMETER(version);
ar & g.szExecutableName;
ar & g.target;
}

template<class Archive>
Expand All @@ -32,13 +32,6 @@ void serialize(Archive & ar, CMD_SET_METRIC & g, const unsigned int version)
ar & g.szMetricNumber;
}

template<class Archive>
void serialize(Archive & ar, CMD_WMIC_ENABLE & g, const unsigned int version)
{
UNREFERENCED_PARAMETER(version);
ar & g.szAdapterName;
}

template<class Archive>
void serialize(Archive & ar, CMD_WMIC_GET_CONFIG_ERROR_CODE & g, const unsigned int version)
{
Expand Down
13 changes: 6 additions & 7 deletions backend/windows/windscribe_service/ipc/servicecommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define AA_COMMAND_ENUM_PROCESSES 26
#define AA_COMMAND_TASK_KILL 27
#define AA_COMMAND_SET_METRIC 28
#define AA_COMMAND_WMIC_ENABLE 29
#define AA_COMMAND_WMIC_ENABLE 29 // deprecated
#define AA_COMMAND_WMIC_GET_CONFIG_ERROR_CODE 30
#define AA_COMMAND_ENABLE_BFE 31
#define AA_COMMAND_RUN_OPENVPN 32
Expand Down Expand Up @@ -60,6 +60,10 @@
#include <string>
#include <vector>

enum CmdKillTarget {
kTargetOpenVpn
};

struct CMD_FIREWALL_ON
{
bool allowLanTraffic = false;
Expand Down Expand Up @@ -95,7 +99,7 @@ struct CMD_SUSPEND_UNBLOCKING_CMD

struct CMD_TASK_KILL
{
std::wstring szExecutableName;
CmdKillTarget target;
};

struct CMD_SET_METRIC
Expand All @@ -105,11 +109,6 @@ struct CMD_SET_METRIC
std::wstring szMetricNumber;
};

struct CMD_WMIC_ENABLE
{
std::wstring szAdapterName;
};

struct CMD_WMIC_GET_CONFIG_ERROR_CODE
{
std::wstring szAdapterName;
Expand Down
1 change: 1 addition & 0 deletions backend/windows/windscribe_service/ovpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool writeOVPNFile(std::wstring &filename, int port, const std::wstring &config,
file << L"management 127.0.0.1 " + std::to_wstring(port) + L"\r\n";
file << L"management-query-passwords\r\n";
file << L"management-hold\r\n";
file << L"verb 3\r\n";

if (httpProxy.length() > 0) {
file << L"http-proxy " + httpProxy + L" " + std::to_wstring(httpPort) + L" auto\r\n";
Expand Down
Loading

0 comments on commit 2974d6d

Please sign in to comment.