From 777b1bad59af06c2367b0f39c4e3d6c90ba6368d Mon Sep 17 00:00:00 2001 From: Zousar Shaker Date: Sun, 28 Nov 2021 22:06:42 -0700 Subject: Allow ZenMap to fallback to local shared memory when running non elevated. --- zenutil/zenserverprocess.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'zenutil/zenserverprocess.cpp') diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index 4098954a8..b43e86f00 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -89,11 +89,19 @@ ZenServerState::Initialize() { // TODO: there's a small chance of a race here, this logic could be tightened up with a mutex to // ensure only a single process at a time creates the mapping + // TODO: the fallback to Local instead of Global has a flaw where if you start a non-elevated instance + // first then start an elevated instance second you'll have the first instance with a local + // mapping and the second instance with a global mapping. This kind of elevated/non-elevated + // shouldn't be common, but handling for it should be improved in the future. if (HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Global\\ZenMap")) { m_hMapFile = hMap; } + else if (HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) + { + m_hMapFile = hMap; + } else { // Security attributes to enable any user to access state @@ -106,6 +114,16 @@ ZenServerState::Initialize() m_MaxEntryCount * sizeof(ZenServerEntry), // maximum object size (low-order DWORD) L"Global\\ZenMap"); // name of mapping object + if (hMap == NULL) + { + hMap = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file + Attrs.Attributes(), // allow anyone to access + PAGE_READWRITE, // read/write access + 0, // maximum object size (high-order DWORD) + m_MaxEntryCount * sizeof(ZenServerEntry), // maximum object size (low-order DWORD) + L"Local\\ZenMap"); // name of mapping object + } + if (hMap == NULL) { ThrowLastError("Could not open or create file mapping object for Zen server state"); @@ -136,6 +154,10 @@ ZenServerState::InitializeReadOnly() { m_hMapFile = hMap; } + else if (HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) + { + m_hMapFile = hMap; + } else { return false; -- cgit v1.2.3 From 25c2eec10f64d22ee64a84a6bfb34e7933443c79 Mon Sep 17 00:00:00 2001 From: Zousar Shaker Date: Mon, 29 Nov 2021 23:27:18 -0700 Subject: Address review feedback and fix issue when deploying. --- zenutil/zenserverprocess.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'zenutil/zenserverprocess.cpp') diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index b43e86f00..dbe27ef20 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -98,9 +98,9 @@ ZenServerState::Initialize() { m_hMapFile = hMap; } - else if (HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) + else if (HANDLE hLocalMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) { - m_hMapFile = hMap; + m_hMapFile = hLocalMap; } else { @@ -154,9 +154,9 @@ ZenServerState::InitializeReadOnly() { m_hMapFile = hMap; } - else if (HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) + else if (HANDLE hLocalMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) { - m_hMapFile = hMap; + m_hMapFile = hLocalMap; } else { -- cgit v1.2.3