示例#1
0
        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);
        }
示例#2
0
 private static void CloseInvalidOutSafeHandleCritical(SafeHandle handle)
 {
     if (handle != null)
     {
         handle.SetHandleAsInvalid();
     }
 }
 internal static void CloseInvalidOutSafeHandle(SafeHandle handle)
 {
     if (handle != null)
     {
         handle.SetHandleAsInvalid();
     }
 }
示例#4
0
        public void Reset()
        {
            if (_findHandle.IsInvalid)
            {
                return;
            }

            _findHandle.Close();
            _findHandle.SetHandleAsInvalid();
        }
示例#5
0
        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);
        }
示例#6
0
        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();
            }
        }
示例#8
0
        [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();
            }
        }
示例#9
0
        [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();
            }
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#13
0
 /// <inheritdoc />
 public void SetHandleAsInvalid()
 {
     _instance.SetHandleAsInvalid();
 }