From 970c0f2bfaa2c5088506f6f2f6b07b7e2b4eb481 Mon Sep 17 00:00:00 2001 From: antiduh Date: Tue, 24 Jun 2014 20:21:09 +0000 Subject: [PATCH] Moved the safe handles for credentials and contexts into their own file. --- Contexts/SafeContextHandle.cs | 27 ++++++++++++++++++++++ Credentials/SafeCredentialHandle.cs | 28 ++++++++++++++++++++++ NSspi.csproj | 2 ++ SspiHandle.cs | 36 ----------------------------- 4 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 Contexts/SafeContextHandle.cs create mode 100644 Credentials/SafeCredentialHandle.cs diff --git a/Contexts/SafeContextHandle.cs b/Contexts/SafeContextHandle.cs new file mode 100644 index 0000000..393056e --- /dev/null +++ b/Contexts/SafeContextHandle.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NSspi.Contexts +{ + + public class SafeContextHandle : SafeSspiHandle + { + public SafeContextHandle() + : base() + { } + + protected override bool ReleaseHandle() + { + SecurityStatus status = ContextNativeMethods.DeleteSecurityContext( + ref base.rawHandle + ); + + base.ReleaseHandle(); + + return status == SecurityStatus.OK; + } + } +} diff --git a/Credentials/SafeCredentialHandle.cs b/Credentials/SafeCredentialHandle.cs new file mode 100644 index 0000000..e6dfa93 --- /dev/null +++ b/Credentials/SafeCredentialHandle.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NSspi.Credentials +{ + + public class SafeCredentialHandle : SafeSspiHandle + { + public SafeCredentialHandle() + : base() + { } + + protected override bool ReleaseHandle() + { + SecurityStatus status = CredentialNativeMethods.FreeCredentialsHandle( + ref base.rawHandle + ); + + base.ReleaseHandle(); + + return status == SecurityStatus.OK; + } + } + +} diff --git a/NSspi.csproj b/NSspi.csproj index e0d5087..cb53f2e 100644 --- a/NSspi.csproj +++ b/NSspi.csproj @@ -53,6 +53,7 @@ + @@ -62,6 +63,7 @@ + diff --git a/SspiHandle.cs b/SspiHandle.cs index 99c213c..6a9c14f 100644 --- a/SspiHandle.cs +++ b/SspiHandle.cs @@ -66,40 +66,4 @@ namespace NSspi return true; } } - - public class SafeCredentialHandle : SafeSspiHandle - { - public SafeCredentialHandle() - : base() - { } - - protected override bool ReleaseHandle() - { - SecurityStatus status = CredentialNativeMethods.FreeCredentialsHandle( - ref base.rawHandle - ); - - base.ReleaseHandle(); - - return status == SecurityStatus.OK; - } - } - - public class SafeContextHandle : SafeSspiHandle - { - public SafeContextHandle() - : base() - { } - - protected override bool ReleaseHandle() - { - SecurityStatus status = ContextNativeMethods.DeleteSecurityContext( - ref base.rawHandle - ); - - base.ReleaseHandle(); - - return status == SecurityStatus.OK; - } - } }