Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Messaging / System / Messaging / AccessControlList.cs / 1305376 / AccessControlList.cs
using System;
using System.Security.Permissions;
using System.Security;
using System.Collections;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Text;
using System.Messaging.Interop;
namespace System.Messaging {
///
///
/// [To be supplied.]
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1039:ListsAreStronglyTyped")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public class AccessControlList : CollectionBase {
internal static readonly int UnknownEnvironment = 0;
internal static readonly int W2kEnvironment = 1;
internal static readonly int NtEnvironment = 2;
internal static readonly int NonNtEnvironment = 3;
private static int environment = UnknownEnvironment;
private static object staticLock = new object();
///
public AccessControlList() {
}
internal static int CurrentEnvironment {
get {
if (environment == UnknownEnvironment) {
lock (AccessControlList.staticLock) {
if (environment == UnknownEnvironment) {
//SECREVIEW: [....]- need to assert Environment permissions here
// the environment check is not exposed as a public
// method
EnvironmentPermission environmentPermission = new EnvironmentPermission(PermissionState.Unrestricted);
environmentPermission.Assert();
try {
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
if (Environment.OSVersion.Version.Major >= 5)
environment = W2kEnvironment;
else
environment = NtEnvironment;
}
else
environment = NonNtEnvironment;
}
finally {
EnvironmentPermission.RevertAssert();
}
}
}
}
return environment;
}
}
///
///
/// [To be supplied.]
///
public int Add(AccessControlEntry entry) {
return List.Add(entry);
}
///
///
/// [To be supplied.]
///
public void Insert(int index, AccessControlEntry entry) {
List.Insert(index, entry);
}
///
///
/// [To be supplied.]
///
public int IndexOf(AccessControlEntry entry) {
return List.IndexOf(entry);
}
internal static void CheckEnvironment() {
if (CurrentEnvironment == NonNtEnvironment)
throw new PlatformNotSupportedException(Res.GetString(Res.WinNTRequired));
}
///
///
/// [To be supplied.]
///
public bool Contains(AccessControlEntry entry) {
return List.Contains(entry);
}
///
///
/// [To be supplied.]
///
public void Remove(AccessControlEntry entry) {
List.Remove(entry);
}
///
///
/// [To be supplied.]
///
public void CopyTo(AccessControlEntry[] array, int index) {
List.CopyTo(array, index);
}
internal IntPtr MakeAcl(IntPtr oldAcl) {
CheckEnvironment();
int ACECount = List.Count;
IntPtr newAcl;
NativeMethods.ExplicitAccess[] entries = new NativeMethods.ExplicitAccess[ACECount];
GCHandle mem = GCHandle.Alloc(entries, GCHandleType.Pinned);
try {
for (int i = 0; i < ACECount; i++) {
int sidSize = 0;
int sidtype;
int domainSize = 0;
AccessControlEntry ace = (AccessControlEntry)List[i];
if (ace.Trustee == null)
throw new InvalidOperationException(Res.GetString(Res.InvalidTrustee));
string name = ace.Trustee.Name;
if (name == null)
throw new InvalidOperationException(Res.GetString(Res.InvalidTrusteeName));
if ((ace.Trustee.TrusteeType == TrusteeType.Computer) && !name.EndsWith("$"))
name += "$";
if (!UnsafeNativeMethods.LookupAccountName(ace.Trustee.SystemName, name, (IntPtr)0, ref sidSize, null, ref domainSize, out sidtype)) {
int errval = Marshal.GetLastWin32Error();
if (errval != 122)
throw new InvalidOperationException(Res.GetString(Res.CouldntResolve ,ace.Trustee.Name, errval));
}
entries[i].data = (IntPtr)Marshal.AllocHGlobal(sidSize);
StringBuilder domainName = new StringBuilder(domainSize);
if (!UnsafeNativeMethods.LookupAccountName(ace.Trustee.SystemName, name, entries[i].data, ref sidSize, domainName, ref domainSize, out sidtype))
throw new InvalidOperationException(Res.GetString(Res.CouldntResolveName, ace.Trustee.Name));
entries[i].grfAccessPermissions = ace.accessFlags;
entries[i].grfAccessMode = (int)ace.EntryType;
entries[i].grfInheritance = 0;
entries[i].pMultipleTrustees = (IntPtr)0;
entries[i].MultipleTrusteeOperation = NativeMethods.NO_MULTIPLE_TRUSTEE;
entries[i].TrusteeForm = NativeMethods.TRUSTEE_IS_SID;
entries[i].TrusteeType = (int)ace.Trustee.TrusteeType;
}
int err = SafeNativeMethods.SetEntriesInAclW(ACECount, (IntPtr)mem.AddrOfPinnedObject(), oldAcl, out newAcl);
if (err != NativeMethods.ERROR_SUCCESS)
throw new Win32Exception(err);
}
finally {
mem.Free();
for (int i = 0; i < ACECount; i++)
if (entries[i].data != (IntPtr)0)
Marshal.FreeHGlobal(entries[i].data);
}
return newAcl;
}
internal static void FreeAcl(IntPtr acl) {
SafeNativeMethods.LocalFree(acl);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Security.Permissions;
using System.Security;
using System.Collections;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Text;
using System.Messaging.Interop;
namespace System.Messaging {
///
///
/// [To be supplied.]
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1039:ListsAreStronglyTyped")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public class AccessControlList : CollectionBase {
internal static readonly int UnknownEnvironment = 0;
internal static readonly int W2kEnvironment = 1;
internal static readonly int NtEnvironment = 2;
internal static readonly int NonNtEnvironment = 3;
private static int environment = UnknownEnvironment;
private static object staticLock = new object();
///
public AccessControlList() {
}
internal static int CurrentEnvironment {
get {
if (environment == UnknownEnvironment) {
lock (AccessControlList.staticLock) {
if (environment == UnknownEnvironment) {
//SECREVIEW: [....]- need to assert Environment permissions here
// the environment check is not exposed as a public
// method
EnvironmentPermission environmentPermission = new EnvironmentPermission(PermissionState.Unrestricted);
environmentPermission.Assert();
try {
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
if (Environment.OSVersion.Version.Major >= 5)
environment = W2kEnvironment;
else
environment = NtEnvironment;
}
else
environment = NonNtEnvironment;
}
finally {
EnvironmentPermission.RevertAssert();
}
}
}
}
return environment;
}
}
///
///
/// [To be supplied.]
///
public int Add(AccessControlEntry entry) {
return List.Add(entry);
}
///
///
/// [To be supplied.]
///
public void Insert(int index, AccessControlEntry entry) {
List.Insert(index, entry);
}
///
///
/// [To be supplied.]
///
public int IndexOf(AccessControlEntry entry) {
return List.IndexOf(entry);
}
internal static void CheckEnvironment() {
if (CurrentEnvironment == NonNtEnvironment)
throw new PlatformNotSupportedException(Res.GetString(Res.WinNTRequired));
}
///
///
/// [To be supplied.]
///
public bool Contains(AccessControlEntry entry) {
return List.Contains(entry);
}
///
///
/// [To be supplied.]
///
public void Remove(AccessControlEntry entry) {
List.Remove(entry);
}
///
///
/// [To be supplied.]
///
public void CopyTo(AccessControlEntry[] array, int index) {
List.CopyTo(array, index);
}
internal IntPtr MakeAcl(IntPtr oldAcl) {
CheckEnvironment();
int ACECount = List.Count;
IntPtr newAcl;
NativeMethods.ExplicitAccess[] entries = new NativeMethods.ExplicitAccess[ACECount];
GCHandle mem = GCHandle.Alloc(entries, GCHandleType.Pinned);
try {
for (int i = 0; i < ACECount; i++) {
int sidSize = 0;
int sidtype;
int domainSize = 0;
AccessControlEntry ace = (AccessControlEntry)List[i];
if (ace.Trustee == null)
throw new InvalidOperationException(Res.GetString(Res.InvalidTrustee));
string name = ace.Trustee.Name;
if (name == null)
throw new InvalidOperationException(Res.GetString(Res.InvalidTrusteeName));
if ((ace.Trustee.TrusteeType == TrusteeType.Computer) && !name.EndsWith("$"))
name += "$";
if (!UnsafeNativeMethods.LookupAccountName(ace.Trustee.SystemName, name, (IntPtr)0, ref sidSize, null, ref domainSize, out sidtype)) {
int errval = Marshal.GetLastWin32Error();
if (errval != 122)
throw new InvalidOperationException(Res.GetString(Res.CouldntResolve ,ace.Trustee.Name, errval));
}
entries[i].data = (IntPtr)Marshal.AllocHGlobal(sidSize);
StringBuilder domainName = new StringBuilder(domainSize);
if (!UnsafeNativeMethods.LookupAccountName(ace.Trustee.SystemName, name, entries[i].data, ref sidSize, domainName, ref domainSize, out sidtype))
throw new InvalidOperationException(Res.GetString(Res.CouldntResolveName, ace.Trustee.Name));
entries[i].grfAccessPermissions = ace.accessFlags;
entries[i].grfAccessMode = (int)ace.EntryType;
entries[i].grfInheritance = 0;
entries[i].pMultipleTrustees = (IntPtr)0;
entries[i].MultipleTrusteeOperation = NativeMethods.NO_MULTIPLE_TRUSTEE;
entries[i].TrusteeForm = NativeMethods.TRUSTEE_IS_SID;
entries[i].TrusteeType = (int)ace.Trustee.TrusteeType;
}
int err = SafeNativeMethods.SetEntriesInAclW(ACECount, (IntPtr)mem.AddrOfPinnedObject(), oldAcl, out newAcl);
if (err != NativeMethods.ERROR_SUCCESS)
throw new Win32Exception(err);
}
finally {
mem.Free();
for (int i = 0; i < ACECount; i++)
if (entries[i].data != (IntPtr)0)
Marshal.FreeHGlobal(entries[i].data);
}
return newAcl;
}
internal static void FreeAcl(IntPtr acl) {
SafeNativeMethods.LocalFree(acl);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ActionMismatchAddressingException.cs
- SafeFileMappingHandle.cs
- LookupBindingPropertiesAttribute.cs
- RegexTypeEditor.cs
- _CookieModule.cs
- XamlToRtfParser.cs
- RecordBuilder.cs
- ClientEventManager.cs
- ColumnMapCopier.cs
- AngleUtil.cs
- Container.cs
- HttpCacheVaryByContentEncodings.cs
- WorkflowOperationErrorHandler.cs
- RecordManager.cs
- EncoderFallback.cs
- SizeF.cs
- CodeMethodReturnStatement.cs
- IdentityNotMappedException.cs
- TextEffect.cs
- SecurityDocument.cs
- DbDataAdapter.cs
- DateTimeConverter2.cs
- CodeIndexerExpression.cs
- DataBoundLiteralControl.cs
- documentation.cs
- BinHexEncoder.cs
- DocumentApplication.cs
- MexTcpBindingElement.cs
- KeyPullup.cs
- FunctionImportMapping.ReturnTypeRenameMapping.cs
- XmlNotation.cs
- DuplicateWaitObjectException.cs
- CommittableTransaction.cs
- CorrelationHandle.cs
- FileUtil.cs
- SqlStatistics.cs
- ModelItemImpl.cs
- UICuesEvent.cs
- MarkupCompilePass2.cs
- ProjectedSlot.cs
- TextSpan.cs
- Parser.cs
- DataControlButton.cs
- ObservableDictionary.cs
- AllowedAudienceUriElementCollection.cs
- QueryContinueDragEventArgs.cs
- BackgroundWorker.cs
- RuleSettings.cs
- DataGridViewCellPaintingEventArgs.cs
- EndpointAddressElementBase.cs
- OleDbSchemaGuid.cs
- oledbmetadatacollectionnames.cs
- ZipPackage.cs
- HitTestWithGeometryDrawingContextWalker.cs
- ObjectItemLoadingSessionData.cs
- Scene3D.cs
- DelegateSerializationHolder.cs
- PolygonHotSpot.cs
- JavaScriptString.cs
- GraphicsPath.cs
- XPathDescendantIterator.cs
- _NtlmClient.cs
- MdImport.cs
- SamlConstants.cs
- Geometry3D.cs
- DataListItemEventArgs.cs
- TypeExtensionConverter.cs
- AuthenticateEventArgs.cs
- HitTestFilterBehavior.cs
- RotateTransform.cs
- WebBrowserContainer.cs
- compensatingcollection.cs
- WsatAdminException.cs
- ECDiffieHellmanCng.cs
- TrailingSpaceComparer.cs
- OdbcException.cs
- CuspData.cs
- LogEntryDeserializer.cs
- HttpProfileBase.cs
- XmlConvert.cs
- HtmlInputReset.cs
- AttributeData.cs
- RequestCachePolicy.cs
- PropertyConverter.cs
- ConnectivityStatus.cs
- TransformedBitmap.cs
- PropertyKey.cs
- SafeCoTaskMem.cs
- RenamedEventArgs.cs
- FlowDecision.cs
- MatrixAnimationUsingKeyFrames.cs
- FontDriver.cs
- IPipelineRuntime.cs
- ListViewUpdateEventArgs.cs
- XamlSerializationHelper.cs
- EntityDesignerDataSourceView.cs
- FillRuleValidation.cs
- SiteMap.cs
- SpeakProgressEventArgs.cs
- UIPropertyMetadata.cs