aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/shared.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/shared.cc')
-rw-r--r--winsup/cygwin/shared.cc96
1 files changed, 69 insertions, 27 deletions
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 654ac57..4f9acc1 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -67,7 +67,8 @@ static char *offsets[] =
};
void * __stdcall
-open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locations m)
+open_shared (const char *name, int n, HANDLE &shared_h, DWORD size,
+ shared_locations m, PSECURITY_ATTRIBUTES psa)
{
void *shared;
@@ -96,7 +97,7 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locat
TRUE, mapname);
}
if (!shared_h &&
- !(shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_all,
+ !(shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, psa,
PAGE_READWRITE, 0, size, mapname)))
api_fatal ("CreateFileMapping, %E. Terminating.");
}
@@ -144,6 +145,71 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locat
return shared;
}
+void
+user_shared_initialize ()
+{
+ char name[UNLEN + 1] = "";
+
+ /* Temporary code. Will be cleaned up later */
+ if (wincap.has_security ())
+ {
+ HANDLE ptok = NULL;
+ DWORD siz;
+ cygsid tu;
+
+ if (cygwin_mount_h) /* Reinit */
+ tu = cygheap->user.sid ();
+ else
+ {
+ if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
+ &ptok))
+ system_printf ("OpenProcessToken(): %E");
+ else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz))
+ system_printf ("GetTokenInformation (TokenUser): %E");
+ else
+ tu.string (name);
+ if (ptok)
+ CloseHandle (ptok);
+ }
+ tu.string (name);
+ }
+ else
+ strcpy (name, cygheap->user.name ());
+
+ if (cygwin_mount_h)
+ {
+ if (!UnmapViewOfFile (mount_table))
+ debug_printf("UnmapViewOfFile %E");
+ if (!ForceCloseHandle (cygwin_mount_h))
+ debug_printf("CloseHandle %E");
+ cygwin_mount_h = NULL;
+ }
+
+ mount_table = (mount_info *) open_shared (name, MOUNT_VERSION,
+ cygwin_mount_h, sizeof (mount_info),
+ SH_MOUNT_TABLE, &sec_none);
+ debug_printf ("opening mount table for '%s' at %p", name,
+ mount_table);
+ ProtectHandleINH (cygwin_mount_h);
+ debug_printf ("mount table version %x at %p", mount_table->version, mount_table);
+
+ /* Initialize the Cygwin per-user mount table, if necessary */
+ if (!mount_table->version)
+ {
+ mount_table->version = MOUNT_VERSION_MAGIC;
+ debug_printf ("initializing mount table");
+ mount_table->cb = sizeof (*mount_table);
+ if (mount_table->cb != MOUNT_INFO_CB)
+ system_printf ("size of mount table region changed from %u to %u",
+ MOUNT_INFO_CB, mount_table->cb);
+ mount_table->init (); /* Initialize the mount table. */
+ }
+ else if (mount_table->version != MOUNT_VERSION_MAGIC)
+ multiple_cygwin_problem ("mount", mount_table->version, MOUNT_VERSION);
+ else if (mount_table->cb != MOUNT_INFO_CB)
+ multiple_cygwin_problem ("mount table size", mount_table->cb, MOUNT_INFO_CB);
+}
+
void
shared_info::initialize (const char *user_name)
{
@@ -208,31 +274,7 @@ memory_init ()
cygheap->shared_h = shared_h;
ProtectHandleINH (cygheap->shared_h);
- /* Allocate memory for the per-user mount table */
- mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION,
- cygwin_mount_h, sizeof (mount_info),
- SH_MOUNT_TABLE);
- debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (),
- mount_table);
- ProtectHandleINH (cygwin_mount_h);
- debug_printf ("mount table version %x at %p", mount_table->version, mount_table);
-
- /* Initialize the Cygwin per-user mount table, if necessary */
- if (!mount_table->version)
- {
- mount_table->version = MOUNT_VERSION_MAGIC;
- debug_printf ("initializing mount table");
- mount_table->cb = sizeof (*mount_table);
- if (mount_table->cb != MOUNT_INFO_CB)
- system_printf ("size of mount table region changed from %u to %u",
- MOUNT_INFO_CB, mount_table->cb);
- mount_table->init (); /* Initialize the mount table. */
- }
- else if (mount_table->version != MOUNT_VERSION_MAGIC)
- multiple_cygwin_problem ("mount", mount_table->version, MOUNT_VERSION);
- else if (mount_table->cb != MOUNT_INFO_CB)
- multiple_cygwin_problem ("mount table size", mount_table->cb, MOUNT_INFO_CB);
-
+ user_shared_initialize ();
}
unsigned