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
- CompiledQuery.cs
- RuleInfoComparer.cs
- Membership.cs
- MappingModelBuildProvider.cs
- AbstractDataSvcMapFileLoader.cs
- WebScriptMetadataFormatter.cs
- CreateUserWizardStep.cs
- sqlmetadatafactory.cs
- LayoutTableCell.cs
- EntitySqlQueryCacheEntry.cs
- ConfigurationLocationCollection.cs
- MessagePropertyDescription.cs
- ControlCachePolicy.cs
- XmlSchemaComplexType.cs
- TextServicesCompartmentEventSink.cs
- BamlMapTable.cs
- SoapUnknownHeader.cs
- EllipseGeometry.cs
- EndEvent.cs
- Rotation3DAnimationUsingKeyFrames.cs
- Annotation.cs
- ImpersonateTokenRef.cs
- RegexInterpreter.cs
- OracleBFile.cs
- DbQueryCommandTree.cs
- DesignRelationCollection.cs
- SmtpDigestAuthenticationModule.cs
- ComplexPropertyEntry.cs
- SecurityIdentifierElementCollection.cs
- assemblycache.cs
- UrlAuthorizationModule.cs
- FlowDocumentPage.cs
- TraceFilter.cs
- StrokeFIndices.cs
- _SecureChannel.cs
- ChannelHandler.cs
- ContextMenu.cs
- ToolBarButtonClickEvent.cs
- SessionSwitchEventArgs.cs
- FixedDocumentPaginator.cs
- X509SubjectKeyIdentifierClause.cs
- BuilderInfo.cs
- ObjectToIdCache.cs
- MessageLogger.cs
- Transactions.cs
- PageClientProxyGenerator.cs
- InputScopeConverter.cs
- AsyncOperation.cs
- OrthographicCamera.cs
- SemanticResultValue.cs
- ToolBarOverflowPanel.cs
- PKCS1MaskGenerationMethod.cs
- ScriptDescriptor.cs
- InstanceNameConverter.cs
- XPathAxisIterator.cs
- ProtocolImporter.cs
- CopyOnWriteList.cs
- SelectedDatesCollection.cs
- _IPv4Address.cs
- ToolStripPanel.cs
- InstancePersistenceContext.cs
- RegisteredArrayDeclaration.cs
- BitVector32.cs
- CharKeyFrameCollection.cs
- VolatileEnlistmentState.cs
- safemediahandle.cs
- ChtmlTextWriter.cs
- ExpressionPrefixAttribute.cs
- MenuItemBinding.cs
- ObjectMemberMapping.cs
- UIAgentAsyncParams.cs
- SessionEndingEventArgs.cs
- Point3DAnimation.cs
- FormViewPageEventArgs.cs
- XmlLinkedNode.cs
- PenThread.cs
- ObjectSecurity.cs
- MLangCodePageEncoding.cs
- OdbcTransaction.cs
- MetafileHeader.cs
- HostSecurityManager.cs
- InlineCollection.cs
- LayoutTableCell.cs
- WindowsIPAddress.cs
- ColumnHeader.cs
- DateTimeUtil.cs
- DoubleAnimationClockResource.cs
- DbgCompiler.cs
- MouseEvent.cs
- SolidColorBrush.cs
- NumberSubstitution.cs
- LayoutEditorPart.cs
- XmlNotation.cs
- ListViewGroup.cs
- HttpCapabilitiesBase.cs
- TypeDescriptionProviderAttribute.cs
- ObjectStateFormatter.cs
- LayoutEditorPart.cs
- DefaultTextStore.cs
- ReceiveParametersContent.cs