Actually, SetSecurityInfo takes handles to more than just wait objects.
So, it's probably more clear to prototype SetSecurityInfo with SafeHandle.

SafeWaitHandle derives from SafeHandleZeroOrMinusOneIsInvalid which then
derives from SafeHandle.  So, using SafeWaitHandle means you can then pass
a SafeWaitHandle to SetSecurityInfo.

The .NET 2.0 framework actually internally declares SetSecurityInfo as
follows:
<DllImport("advapi32.dll"EntryPoint="SetSecurityInfo",
CharSet=CharSet.Unicode, SetLastError=True)> _
Friend Shared Function SetSecurityInfoByHandle(ByVal handle As SafeHandle,
ByVal objectType As System.UInt32, ByVal securityInformation As
System.UInt32, ByVal owner As Byte(), ByVal group As Byte(), ByVal dacl As
Byte(), ByVal sacl As Byte()) As System.UInt32
End Function

Now, the logical next question is: do you really need to use
SetSecurityInfo anymore?

In .NET 2.0 they've added the NativeObjectSecurity class (in the, also
new, System.Security.AccessControl namespace) which has a derivative
MutexSecurity.  If you're using the .NET Mutex class, .NET 2.0 added the
[S|G]etAccessControl() methods that get an associated MutexSecurity object
for the Mutex object.

One benefit of using the framework instead of importing SetSecurityInfo is
that the framework is pretty much guaranteed to be FullTrust so you don't
have to worry about deploying to, or being run in, a partial trust
scenario and having either the preparatory Assert call being denied or the
call to SetSecurityInfo being denied based on policy.

There's a few examples of using MutexSecurity around like:
http://www.codecomments.com/message715583.html

While they don't discuss MutexSecurity directly, the following articles
discuss the .NET 2.0 Windows object access control additions in general:
http://msdn.microsoft.com/msdnmag/issues/04/11/AccessControlinNET/default.a
spx
http://msdn.microsoft.com/msdnmag/issues/06/00/SecurityBriefs/

On Fri, 24 Mar 2006 07:04:06 +0100, Mattias Sjögren <[EMAIL PROTECTED]>
wrote:

>Matthew,
>
> > SetSecurityInfo seems to need an IntPtr
>
>You can change the handle parameter type to a SafeWaitHandle instead.
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to