New Mutex constructor with MutexSecurity

S

Steven Kilby

Hi,

With .NET 2.0 a new Mutex constructor was added that takes a MutexSecurity
object as a parameter. The interesting thing is the following statement
from the MSDN documentation:

If the named mutex has already been created with access control security,
and the caller does not have MutexRights.FullControl, an exception is
thrown.

I wrote two test programs. The first runs as an Administrator and calls the
constructor with a MutexSecurity object that contains an Allow rule for
'Everyone' with MutexRights.Synchronize | MutexRights.Modify. The second
program runs as a normal user and also calls the constructor. Based on the
MSDN documentation I would expect an exception when the second program runs,
but it works fine. Things got more odd when I added a deny rule for
'Everyone' with MutexRights.FullControl. With that, I got the exception I
expected. That implies the default rule for a MutexSecurity object is
FullControl, but I know that isn't true.

Can anyone explain the behavior I am seeing?

Thanks!
Steven
 
M

Michael Nemtsev, MVP

Hello Steven,

Did you create global mutex?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


SK> MutexSecurity object as a parameter. The interesting thing is the
SK> following statement from the MSDN documentation:
SK>
SK> If the named mutex has already been created with access control
SK> security, and the caller does not have MutexRights.FullControl, an
SK> exception is thrown.
SK>
SK> I wrote two test programs. The first runs as an Administrator and
SK> calls the constructor with a MutexSecurity
SK>
 
S

Steven Kilby

Hi,

Yes, the mutex is global. AFAIK the MSDN documentation doesn't call out
global mutexes as a special case. Is there a difference?

Thanks
Steven
 
M

Michael Nemtsev, MVP

Hello Steven,

SK> I wrote two test programs. The first runs as an Administrator and
SK> calls the constructor with a MutexSecurity object that contains an
SK> Allow rule for 'Everyone' with MutexRights.Synchronize |
SK> MutexRights.Modify. The second program runs as a normal user and
SK> also calls the constructor. Based on the MSDN documentation I would
SK> expect an exception when the second program runs, but it works fine.

Could your refer to the documentation which implies this?

See MutexAccessRule class sample

what is u doing just allows user to have access, not block the user


// Add a rule that grants the current user the
// right to enter or release the mutex.
MutexAccessRule rule = new MutexAccessRule(user,
MutexRights.Synchronize | MutexRights.Modify,
AccessControlType.Allow);
mSec.AddAccessRule(rule);




---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
S

Steven Kilby

Hi,

The documentation is at:
http://msdn2.microsoft.com/en-us/library/9zf2f5bz.aspx. If that link
doesn't work you can find it by using these search terms in Google: "Mutex
MutexRights.FullControl". The relevant text from this page is:

If the named mutex has already been created with access control security,
and the caller does not have
System.Security.AccessControl.MutexRights.FullControl, an exception is
thrown. To open an existing named mutex with only those permissions needed
for synchronizing thread activities, see the OpenExisting method.

Thanks
Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top