Re: Mutex Permissions

From: Pavel Lebedinsky (m_pll)
Date: 04/06/04


Date: Mon, 5 Apr 2004 18:30:00 -0700


"Kris" wrote:

> namespace MyWin32API
> {
>
> // Required SecurityAttributes Structure LPSECURITY_ATTRIBUTES
> [StructLayout(LayoutKind.Sequential)]
> public class SecurityAttributes
> {
> public int nLength = Marshal.SizeOf(typeof(SecurityAttributes));
> public long lpSecurityDescriptor;
> public bool bInheritHandle;
> }

lpSecurityDescriptor is pointer sized so it should be declared as IntPtr.

> // Win 32 Masked Method - does not use return handle currently
> public UInt32 Win32CreateMutex(bool InitialOwner, string MutexName)
> {
> SecurityAttributes sa = new SecurityAttributes();
> sa.bInheritHandle = false;
> sa.lpSecurityDescriptor = CWin32.MUTEX_ALL_ACCESS;

This is wrong - lpSecurityDescriptor should be a pointer to a
SECURITY_DESCRIPTOR structure, not an access mask.

I don't think current versions of .NET have built in support for working
with security descriptors but you can probably find some code on the
net that does this, or write your own.

If you decide to write your own code, consider using
ConvertStringSecurityDescriptorToSecurityDescriptor API - this might be
easier than the standard low level approach
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/s
ecurity/creating_a_security_descriptor_for_a_new_object_in_c__.asp)