public static unsafe int QueryContextAttributes(SafeDeleteContext phContext, Interop.SspiCli.ContextAttribute contextAttribute, byte *buffer, SafeHandle?refHandle) { int status = (int)Interop.SECURITY_STATUS.InvalidHandle; try { bool ignore = false; phContext.DangerousAddRef(ref ignore); status = Interop.SspiCli.QueryContextAttributesW(ref phContext._handle, contextAttribute, buffer); } finally { phContext.DangerousRelease(); } if (status == 0 && refHandle != null) { if (refHandle is SafeFreeContextBuffer) { ((SafeFreeContextBuffer)refHandle).Set(*(IntPtr *)buffer); } else { ((SafeFreeCertContext)refHandle).Set(*(IntPtr *)buffer); } } if (status != 0) { refHandle?.SetHandleAsInvalid(); } return(status); }
private static void CloseInvalidOutSafeHandleCritical(SafeHandle handle) { if (handle != null) { handle.SetHandleAsInvalid(); } }
internal static void CloseInvalidOutSafeHandle(SafeHandle handle) { if (handle != null) { handle.SetHandleAsInvalid(); } }
public void Reset() { if (_findHandle.IsInvalid) { return; } _findHandle.Close(); _findHandle.SetHandleAsInvalid(); }
public static unsafe int QueryContextAttributes(SafeDeleteContext phContext, ContextAttribute contextAttribute, byte *buffer, SafeHandle refHandle) { int num = -2146893055; bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { phContext.DangerousAddRef(ref success); } catch (Exception exception) { if (success) { phContext.DangerousRelease(); success = false; } if (!(exception is ObjectDisposedException)) { throw; } } finally { if (success) { num = QueryContextAttributesW(ref phContext._handle, contextAttribute, (void *)buffer); phContext.DangerousRelease(); } if ((num == 0) && (refHandle != null)) { if (refHandle is SafeFreeContextBuffer) { if (contextAttribute == ContextAttribute.SessionKey) { IntPtr ptr = Marshal.ReadIntPtr(new IntPtr((void *)buffer), SecPkgContext_SessionKey.SessionkeyOffset); ((SafeFreeContextBuffer)refHandle).Set(ptr); } else { ((SafeFreeContextBuffer)refHandle).Set(*((IntPtr *)buffer)); } } else { ((SafeFreeCertContext)refHandle).Set(*((IntPtr *)buffer)); } } if ((num != 0) && (refHandle != null)) { refHandle.SetHandleAsInvalid(); } } return(num); }
static void CloseInvalidOutSafeHandleCritical(SafeHandle handle) { // Workaround for 64-bit CLR bug VSWhidbey 546830 - sometimes invalid SafeHandles come back null. if (handle != null) { Fx.Assert(handle.IsInvalid, "CloseInvalidOutSafeHandle called with a valid handle!"); // Calls SuppressFinalize. handle.SetHandleAsInvalid(); } }
static void CloseInvalidOutSafeHandleCritical(SafeHandle handle) { // Workaround for 64-bit CLR if (handle != null) { Fx.Assert(handle.IsInvalid, "CloseInvalidOutSafeHandle called with a valid handle!"); // Calls SuppressFinalize. handle.SetHandleAsInvalid(); } }
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.TransparentMethodsMustNotReferenceCriticalCode)] // we got APTCA approval with no requirement to fix this transparency warning internal static void CloseInvalidOutSafeHandle(SafeHandle handle) { // Workaround for 64-bit CLR bug VSWhidbey 546830 - sometimes invalid SafeHandles come back null. if (handle != null) { #pragma warning disable 618 Fx.Assert(handle.IsInvalid, "CloseInvalidOutSafeHandle called with a valid handle!"); #pragma warning restore 618 // Calls SuppressFinalize. handle.SetHandleAsInvalid(); } }
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.TransparentMethodsMustNotReferenceCriticalCode)] // we got APTCA approval with no requirement to fix this transparency warning internal static void CloseInvalidOutSafeHandle(SafeHandle handle) { // Workaround for 64-bit CLR if (handle != null) { #pragma warning disable 618 Fx.Assert(handle.IsInvalid, "CloseInvalidOutSafeHandle called with a valid handle!"); #pragma warning restore 618 // Calls SuppressFinalize. handle.SetHandleAsInvalid(); } }
private static unsafe int QueryContextAttributes_SCHANNEL(SafeDeleteContext phContext, ContextAttribute contextAttribute, byte *buffer, SafeHandle refHandle) { int num = -2146893055; bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { phContext.DangerousAddRef(ref success); } catch (Exception exception) { if (success) { phContext.DangerousRelease(); success = false; } if (!(exception is ObjectDisposedException)) { throw; } } finally { if (success) { num = UnsafeNclNativeMethods.SafeNetHandles_SCHANNEL.QueryContextAttributesA(ref phContext._handle, contextAttribute, (void *)buffer); phContext.DangerousRelease(); } if ((num == 0) && (refHandle != null)) { if (refHandle is SafeFreeContextBuffer) { ((SafeFreeContextBuffer)refHandle).Set(*((IntPtr *)buffer)); } else { ((SafeFreeCertContext)refHandle).Set(*((IntPtr *)buffer)); } } if ((num != 0) && (refHandle != null)) { refHandle.SetHandleAsInvalid(); } } return(num); }
protected override void Dispose(bool disposing) { // Nothing will be done differently based on whether we are disposing vs. finalizing. lock (this) { if (m_handle != null && !m_handle.IsInvalid) { if (disposing) { CancelPendingIO(); } m_handle.Close(); m_handle.SetHandleAsInvalid(); } } base.Dispose(disposing); }
private unsafe static int QueryContextAttributes_SECURITY( SafeDeleteContext phContext, Interop.Secur32.ContextAttribute contextAttribute, byte *buffer, SafeHandle refHandle) { int status = (int)Interop.SecurityStatus.InvalidHandle; try { bool ignore = false; phContext.DangerousAddRef(ref ignore); status = Interop.Secur32.QueryContextAttributesW(ref phContext._handle, contextAttribute, buffer); } finally { phContext.DangerousRelease(); } if (status == 0 && refHandle != null) { if (refHandle is SafeFreeContextBuffer) { ((SafeFreeContextBuffer)refHandle).Set(*(IntPtr *)buffer); } else { ((SafeFreeCertContext)refHandle).Set(*(IntPtr *)buffer); } } if (status != 0 && refHandle != null) { refHandle.SetHandleAsInvalid(); } return(status); }
/// <inheritdoc /> public void SetHandleAsInvalid() { _instance.SetHandleAsInvalid(); }