diff options
| author | Zousar Shaker <[email protected]> | 2021-11-28 22:06:42 -0700 |
|---|---|---|
| committer | Zousar Shaker <[email protected]> | 2021-11-29 00:18:31 -0700 |
| commit | 777b1bad59af06c2367b0f39c4e3d6c90ba6368d (patch) | |
| tree | 527b7c563c1e454b5c8f97075c896cda90899eb1 /zenutil/zenserverprocess.cpp | |
| parent | Address review feedback. (diff) | |
| download | zen-777b1bad59af06c2367b0f39c4e3d6c90ba6368d.tar.xz zen-777b1bad59af06c2367b0f39c4e3d6c90ba6368d.zip | |
Allow ZenMap to fallback to local shared memory when running non elevated.
Diffstat (limited to 'zenutil/zenserverprocess.cpp')
| -rw-r--r-- | zenutil/zenserverprocess.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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 @@ -108,6 +116,16 @@ ZenServerState::Initialize() 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; |