Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set permissions on log directory #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/libcommon/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
#include "filesystem.h"
#include "string.h"
#include "error.h"
#include <mullvad-nsis.h>

namespace common::fs
{

// Calls into rust to recursively create directories with total access for admins and read-only access for authenticated users.
// If any or all directories already exists will attempt to set the correct permissions on them and if successful will not error.
void CreatePrivilegedDirectory(std::filesystem::path path)
{
const wchar_t* w_path = path.wstring().c_str();
auto result = create_privileged_directory(reinterpret_cast<const uint16_t*>(w_path));

if (Status::Ok != result)
{
THROW_ERROR("Failed to create privileged directory");
}
}

void Mkdir(const std::wstring &path)
{
if (path.empty())
Expand Down Expand Up @@ -51,7 +65,6 @@ void Mkdir(const std::wstring &path)
lastError = (CreateDirectoryW(target.c_str(), nullptr) ? ERROR_SUCCESS : GetLastError());
}
while (it != dirs.end());

if (ERROR_SUCCESS != lastError && ERROR_ALREADY_EXISTS != lastError)
{
auto msg = std::string("Failed to create directory: ").append(common::string::ToAnsi(target));
Expand Down
3 changes: 3 additions & 0 deletions src/libcommon/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#include <string>
#include <windows.h>
#include <shlobj.h>
#include <filesystem>

namespace common::fs
{

void Mkdir(const std::wstring &path);

void CreatePrivilegedDirectory(std::filesystem::path path);

std::wstring GetKnownFolderPath(REFKNOWNFOLDERID folderId, DWORD flags = KF_FLAG_DEFAULT, HANDLE userToken = nullptr);

class ScopedNativeFileSystem
Expand Down
26 changes: 22 additions & 4 deletions src/libcommon/libcommon.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)../</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -160,6 +160,12 @@
<Lib>
<AdditionalDependencies>ntdll.lib</AdditionalDependencies>
</Lib>
<PreBuildEvent>
<Command>cargo build --target i686-pc-windows-msvc --release -p mullvad-nsis</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Build mullvad-nsis library</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -170,7 +176,7 @@
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)../</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -179,6 +185,10 @@
<Lib>
<AdditionalDependencies>ntdll.lib</AdditionalDependencies>
</Lib>
<PreBuildEvent>
<Command>cargo build --target x86_64-pc-windows-msvc --release -p mullvad-nsis</Command>
<Message>Build mullvad-nsis library</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -191,7 +201,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)../</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -202,6 +212,10 @@
<Lib>
<AdditionalDependencies>ntdll.lib</AdditionalDependencies>
</Lib>
<PreBuildEvent>
<Command>cargo build --target i686-pc-windows-msvc --release -p mullvad-nsis</Command>
<Message>Build mullvad-nsis library</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -214,7 +228,7 @@
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(ProjectDir)../</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -225,6 +239,10 @@
<Lib>
<AdditionalDependencies>ntdll.lib</AdditionalDependencies>
</Lib>
<PreBuildEvent>
<Command>cargo build --target x86_64-pc-windows-msvc --release -p mullvad-nsis</Command>
<Message>Build mullvad-nsis library</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
13 changes: 0 additions & 13 deletions windows-libraries.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcommon", "src\libcommon\libcommon.vcxproj", "{B52E2D10-A94A-4605-914A-2DCEF6A757EF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-libcommon", "src\test-libcommon\test-libcommon.vcxproj", "{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}"
ProjectSection(ProjectDependencies) = postProject
{B52E2D10-A94A-4605-914A-2DCEF6A757EF} = {B52E2D10-A94A-4605-914A-2DCEF6A757EF}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -26,14 +21,6 @@ Global
{B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x64.Build.0 = Release|x64
{B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x86.ActiveCfg = Release|Win32
{B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x86.Build.0 = Release|Win32
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x64.ActiveCfg = Debug|x64
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x64.Build.0 = Debug|x64
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x86.ActiveCfg = Debug|Win32
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x86.Build.0 = Debug|Win32
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x64.ActiveCfg = Release|x64
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x64.Build.0 = Release|x64
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x86.ActiveCfg = Release|Win32
{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down