Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / System.ServiceModel.Activation / System / ServiceModel / Activation / Interop / SafeNativeMethods.cs / 1305376 / SafeNativeMethods.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Activation.Interop
{
using System;
using System.Security;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Runtime.Versioning;
using System.Runtime;
[SuppressUnmanagedCodeSecurity]
static class SafeNativeMethods
{
public const int ERROR_NO_TOKEN = 1008;
const string ADVAPI32 = "advapi32.dll";
const string KERNEL32 = "kernel32.dll";
[DllImport(ADVAPI32, SetLastError = true, EntryPoint = "OpenThreadToken")]
[ResourceExposure(ResourceScope.None)]
static extern bool OpenThreadTokenCritical(
[In] IntPtr ThreadHandle,
[In] TokenAccessLevels DesiredAccess,
[In] bool OpenAsSelf,
[Out] out SafeCloseHandleCritical TokenHandle);
[DllImport(KERNEL32, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static extern IntPtr GetCurrentThread();
[Fx.Tag.SecurityNote(Critical = "Calls two safe native methods: GetCurrentThread and OpenThreadToken." +
"Marshal.GetLastWin32Error captures current thread token in a SecurityCritical field.")]
[SecurityCritical]
internal static bool OpenCurrentThreadTokenCritical(TokenAccessLevels desiredAccess, bool openAsSelf, out SafeCloseHandleCritical tokenHandle, out int error)
{
bool result = OpenThreadTokenCritical(GetCurrentThread(), desiredAccess, openAsSelf, out tokenHandle);
error = Marshal.GetLastWin32Error();
return result;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Activation.Interop
{
using System;
using System.Security;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Runtime.Versioning;
using System.Runtime;
[SuppressUnmanagedCodeSecurity]
static class SafeNativeMethods
{
public const int ERROR_NO_TOKEN = 1008;
const string ADVAPI32 = "advapi32.dll";
const string KERNEL32 = "kernel32.dll";
[DllImport(ADVAPI32, SetLastError = true, EntryPoint = "OpenThreadToken")]
[ResourceExposure(ResourceScope.None)]
static extern bool OpenThreadTokenCritical(
[In] IntPtr ThreadHandle,
[In] TokenAccessLevels DesiredAccess,
[In] bool OpenAsSelf,
[Out] out SafeCloseHandleCritical TokenHandle);
[DllImport(KERNEL32, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static extern IntPtr GetCurrentThread();
[Fx.Tag.SecurityNote(Critical = "Calls two safe native methods: GetCurrentThread and OpenThreadToken." +
"Marshal.GetLastWin32Error captures current thread token in a SecurityCritical field.")]
[SecurityCritical]
internal static bool OpenCurrentThreadTokenCritical(TokenAccessLevels desiredAccess, bool openAsSelf, out SafeCloseHandleCritical tokenHandle, out int error)
{
bool result = OpenThreadTokenCritical(GetCurrentThread(), desiredAccess, openAsSelf, out tokenHandle);
error = Marshal.GetLastWin32Error();
return result;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EmptyControlCollection.cs
- PathSegmentCollection.cs
- ChannelManager.cs
- InstanceDataCollectionCollection.cs
- MetadataUtilsSmi.cs
- WebPartDisplayModeCollection.cs
- BatchServiceHost.cs
- ThicknessKeyFrameCollection.cs
- RegularExpressionValidator.cs
- InfoCardArgumentException.cs
- UIElementHelper.cs
- COMException.cs
- CommandID.cs
- XmlAutoDetectWriter.cs
- WorkflowServiceHost.cs
- QueryCacheManager.cs
- OutputScopeManager.cs
- ReadWriteObjectLock.cs
- UnauthorizedWebPart.cs
- JobPageOrder.cs
- HttpCookieCollection.cs
- RadioButtonList.cs
- EngineSite.cs
- EmptyReadOnlyDictionaryInternal.cs
- FixedNode.cs
- _ContextAwareResult.cs
- SoapEnvelopeProcessingElement.cs
- CharEnumerator.cs
- ParseNumbers.cs
- ToolStripSplitButton.cs
- FieldAccessException.cs
- NetDataContractSerializer.cs
- ColumnClickEvent.cs
- NativeMethods.cs
- ErrorStyle.cs
- ReflectionHelper.cs
- AnnotationResourceChangedEventArgs.cs
- TextRenderer.cs
- ACL.cs
- AxHost.cs
- WindowShowOrOpenTracker.cs
- QueryOperator.cs
- CssStyleCollection.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- WebException.cs
- RenderDataDrawingContext.cs
- StructuredType.cs
- Page.cs
- AttributeAction.cs
- InteropAutomationProvider.cs
- TrustSection.cs
- EditorServiceContext.cs
- _AuthenticationState.cs
- RangeExpression.cs
- TextSelectionProcessor.cs
- EnlistmentTraceIdentifier.cs
- LayoutTableCell.cs
- ClientCultureInfo.cs
- CellNormalizer.cs
- StringResourceManager.cs
- SafeReadContext.cs
- FastEncoderWindow.cs
- ParamArrayAttribute.cs
- TypeToken.cs
- UIElementAutomationPeer.cs
- SinglePhaseEnlistment.cs
- SoapHeader.cs
- HttpModuleActionCollection.cs
- ProxyGenerationError.cs
- DataConnectionHelper.cs
- TimeIntervalCollection.cs
- ContextMenu.cs
- XmlQueryOutput.cs
- HtmlTableRowCollection.cs
- x509store.cs
- XPathNavigatorKeyComparer.cs
- SharedUtils.cs
- TiffBitmapEncoder.cs
- RewritingPass.cs
- HttpChannelHelpers.cs
- sqlnorm.cs
- EmptyEnumerable.cs
- DisableDpiAwarenessAttribute.cs
- TypeElementCollection.cs
- EncryptedPackage.cs
- ThreadExceptionDialog.cs
- ClientSideProviderDescription.cs
- Cursors.cs
- GraphicsPathIterator.cs
- TagElement.cs
- GridEntryCollection.cs
- DSASignatureFormatter.cs
- DictionarySectionHandler.cs
- WorkflowMarkupSerializer.cs
- PrtCap_Builder.cs
- StringConverter.cs
- TypeLibConverter.cs
- DataGridViewColumnEventArgs.cs
- TransformerTypeCollection.cs
- PageThemeParser.cs