summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/shm.cpp161
1 files changed, 81 insertions, 80 deletions
diff --git a/compat/shm.cpp b/compat/shm.cpp
index c11e48e7..4bd89d35 100644
--- a/compat/shm.cpp
+++ b/compat/shm.cpp
@@ -7,7 +7,7 @@
#include "shm.h"
-#if defined(_WIN32)
+#if defined _WIN32
#include <cstring>
#include <stdio.h>
@@ -32,6 +32,86 @@ struct secattr final
~secattr();
};
+void secattr::cleanup()
+{
+ if (pEveryoneSID)
+ FreeSid(pEveryoneSID);
+ if (pACL)
+ LocalFree(pACL);
+ if (pSD)
+ LocalFree(pSD);
+ success = false;
+ pSD = nullptr;
+ pEveryoneSID = nullptr;
+ pACL = nullptr;
+}
+
+secattr::secattr(DWORD perms) : success(true), pSD(nullptr), pEveryoneSID(nullptr), pACL(nullptr)
+{
+ SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
+ EXPLICIT_ACCESS ea;
+
+ if(!AllocateAndInitializeSid(&SIDAuthWorld, 1,
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &pEveryoneSID))
+ {
+ fprintf(stderr, "AllocateAndInitializeSid: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ memset(&ea, 0, sizeof(ea));
+
+ ea.grfAccessPermissions = perms;
+ ea.grfAccessMode = SET_ACCESS;
+ ea.grfInheritance = NO_INHERITANCE;
+ ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
+ ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
+ ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;
+
+ if (SetEntriesInAcl(1, &ea, NULL, &pACL) != ERROR_SUCCESS)
+ {
+ fprintf(stderr, "SetEntriesInAcl: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ pSD = (SECURITY_DESCRIPTOR*) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
+ if (pSD == nullptr)
+ {
+ fprintf(stderr, "LocalAlloc: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ if (!InitializeSecurityDescriptor(pSD,
+ SECURITY_DESCRIPTOR_REVISION))
+ {
+ fprintf(stderr, "InitializeSecurityDescriptor: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ if (!SetSecurityDescriptorDacl(pSD,
+ TRUE,
+ pACL,
+ FALSE))
+ {
+ fprintf(stderr, "SetSecurityDescriptorDacl: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ attrs.bInheritHandle = false;
+ attrs.lpSecurityDescriptor = pSD;
+ attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
+
+ return;
+cleanup:
+ cleanup();
+}
+
+secattr::~secattr()
+{
+ cleanup();
+}
+
shm_wrapper::shm_wrapper(const char* shm_name, const char* mutex_name, int map_size)
{
secattr sa(GENERIC_ALL|SYNCHRONIZE);
@@ -158,82 +238,3 @@ bool shm_wrapper::success()
#endif
}
-void secattr::cleanup()
-{
- if (pEveryoneSID)
- FreeSid(pEveryoneSID);
- if (pACL)
- LocalFree(pACL);
- if (pSD)
- LocalFree(pSD);
- success = false;
- pSD = nullptr;
- pEveryoneSID = nullptr;
- pACL = nullptr;
-}
-
-secattr::secattr(DWORD perms) : success(true), pSD(nullptr), pEveryoneSID(nullptr), pACL(nullptr)
-{
- SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
- EXPLICIT_ACCESS ea;
-
- if(!AllocateAndInitializeSid(&SIDAuthWorld, 1,
- SECURITY_WORLD_RID,
- 0, 0, 0, 0, 0, 0, 0,
- &pEveryoneSID))
- {
- fprintf(stderr, "AllocateAndInitializeSid: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- memset(&ea, 0, sizeof(ea));
-
- ea.grfAccessPermissions = perms;
- ea.grfAccessMode = SET_ACCESS;
- ea.grfInheritance = NO_INHERITANCE;
- ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
- ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
- ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;
-
- if (SetEntriesInAcl(1, &ea, NULL, &pACL) != ERROR_SUCCESS)
- {
- fprintf(stderr, "SetEntriesInAcl: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- pSD = (SECURITY_DESCRIPTOR*) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
- if (pSD == nullptr)
- {
- fprintf(stderr, "LocalAlloc: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- if (!InitializeSecurityDescriptor(pSD,
- SECURITY_DESCRIPTOR_REVISION))
- {
- fprintf(stderr, "InitializeSecurityDescriptor: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- if (!SetSecurityDescriptorDacl(pSD,
- TRUE,
- pACL,
- FALSE))
- {
- fprintf(stderr, "SetSecurityDescriptorDacl: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- attrs.bInheritHandle = false;
- attrs.lpSecurityDescriptor = pSD;
- attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
-
- return;
-cleanup:
- cleanup();
-}
-
-secattr::~secattr()
-{
- cleanup();
-}