diff --git a/NSspi/Contexts/ImpersonationHandle.cs b/NSspi/Contexts/ImpersonationHandle.cs index 6c5c530..595e98d 100644 --- a/NSspi/Contexts/ImpersonationHandle.cs +++ b/NSspi/Contexts/ImpersonationHandle.cs @@ -18,8 +18,9 @@ namespace NSspi.Contexts /// public class ImpersonationHandle : IDisposable { + private readonly ServerContext server; + private bool disposed; - private ServerContext server; /// /// Initializes a new instance of the ImpersonationHandle. Does not perform impersonation. diff --git a/NSspi/Contexts/ServerContext.cs b/NSspi/Contexts/ServerContext.cs index 686b4ee..7f197de 100644 --- a/NSspi/Contexts/ServerContext.cs +++ b/NSspi/Contexts/ServerContext.cs @@ -12,11 +12,11 @@ namespace NSspi.Contexts /// public class ServerContext : Context { - private ContextAttrib requestedAttribs; - private ContextAttrib finalAttribs; + private readonly ContextAttrib requestedAttribs; + private readonly bool impersonationSetsThreadPrinciple; + private ContextAttrib finalAttribs; private bool impersonating; - private bool impersonationSetsThreadPrinciple; /// /// Performs basic initialization of a new instance of the ServerContext class. The @@ -31,11 +31,12 @@ namespace NSspi.Contexts public ServerContext( Credential cred, ContextAttrib requestedAttribs, bool impersonationSetsThreadPrinciple = false ) : base( cred ) { this.requestedAttribs = requestedAttribs; + this.impersonationSetsThreadPrinciple = impersonationSetsThreadPrinciple; + this.finalAttribs = ContextAttrib.Zero; this.impersonating = false; - this.impersonationSetsThreadPrinciple = impersonationSetsThreadPrinciple; - + this.SupportsImpersonate = this.Credential.PackageInfo.Capabilities.HasFlag( SecPkgCapability.Impersonation ); } @@ -135,8 +136,6 @@ namespace NSspi.Contexts if( status == SecurityStatus.OK ) { - nextToken = null; - base.Initialize( rawExpiry.ToDateTime() ); if( outBuffer.Length != 0 ) @@ -295,6 +294,10 @@ namespace NSspi.Contexts } } + /// + /// Releases all resources associted with the ServerContext. + /// + /// protected override void Dispose( bool disposing ) { // We were disposed while impersonating. This means that the consumer that is currently holding