Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bf95f46ee | ||
|
|
5c63105acf | ||
|
|
19716405b8 | ||
|
|
f0820875c3 | ||
|
|
8355a6b821 |
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using NSspi.Buffers;
|
||||
using NSspi.Credentials;
|
||||
|
||||
@@ -14,19 +16,25 @@ namespace NSspi.Contexts
|
||||
private ContextAttrib finalAttribs;
|
||||
|
||||
private bool impersonating;
|
||||
private bool impersonationSetsThreadPrinciple;
|
||||
|
||||
/// <summary>
|
||||
/// Performs basic initialization of a new instance of the ServerContext class. The ServerContext
|
||||
/// is not ready for message manipulation until a security context has been established with a client.
|
||||
/// Performs basic initialization of a new instance of the ServerContext class. The
|
||||
/// ServerContext is not ready for message manipulation until a security context has been
|
||||
/// established with a client.
|
||||
/// </summary>
|
||||
/// <param name="cred"></param>
|
||||
/// <param name="requestedAttribs"></param>
|
||||
public ServerContext( Credential cred, ContextAttrib requestedAttribs ) : base( cred )
|
||||
/// <param name="impersonationSetsThreadPrinciple">
|
||||
/// If true, the `Thread.CurrentPrinciple` property will be modified by successful impersonation.
|
||||
/// </param>
|
||||
public ServerContext( Credential cred, ContextAttrib requestedAttribs, bool impersonationSetsThreadPrinciple = false ) : base( cred )
|
||||
{
|
||||
this.requestedAttribs = requestedAttribs;
|
||||
this.finalAttribs = ContextAttrib.Zero;
|
||||
|
||||
this.impersonating = false;
|
||||
this.impersonationSetsThreadPrinciple = impersonationSetsThreadPrinciple;
|
||||
|
||||
this.SupportsImpersonate = this.Credential.PackageInfo.Capabilities.HasFlag( SecPkgCapability.Impersonation );
|
||||
}
|
||||
@@ -220,7 +228,7 @@ namespace NSspi.Contexts
|
||||
|
||||
this.ContextHandle.DangerousRelease();
|
||||
|
||||
this.impersonating = true;
|
||||
this.impersonating = status == SecurityStatus.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +245,11 @@ namespace NSspi.Contexts
|
||||
throw new SSPIException( "Failed to impersonate the client", status );
|
||||
}
|
||||
|
||||
if( this.impersonating && this.impersonationSetsThreadPrinciple )
|
||||
{
|
||||
SetThreadPrinciple();
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -299,5 +312,15 @@ namespace NSspi.Contexts
|
||||
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the current thread security context to the impersonated identity.
|
||||
/// </summary>
|
||||
private void SetThreadPrinciple()
|
||||
{
|
||||
Thread.CurrentPrincipal = new WindowsPrincipal(
|
||||
WindowsIdentity.GetCurrent( TokenAccessLevels.AllAccess )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,6 @@ namespace NSspi.Credentials
|
||||
{
|
||||
Ansi = 1,
|
||||
|
||||
Unicode = 1
|
||||
Unicode = 2
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>NSspi</id>
|
||||
<version>0.2.0.0</version>
|
||||
<version>0.2.1.0</version>
|
||||
<authors>Kevin Thompson</authors>
|
||||
<owners>Kevin Thompson</owners>
|
||||
<projectUrl>https://github.com/antiduh/nsspi</projectUrl>
|
||||
@@ -13,6 +13,6 @@
|
||||
</description>
|
||||
<language>C#</language>
|
||||
<releaseNotes>Adds support for username/password credentials, but introduces a minor change in the interface that breaks existing code.</releaseNotes>
|
||||
<copyright>Copyright 2017</copyright>
|
||||
<copyright>Copyright 2018</copyright>
|
||||
</metadata>
|
||||
</package>
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration( "" )]
|
||||
[assembly: AssemblyCompany( "Kevin Thompson" )]
|
||||
[assembly: AssemblyProduct( "NSspi" )]
|
||||
[assembly: AssemblyCopyright( "Copyright © Kevin Thompson 2017" )]
|
||||
[assembly: AssemblyCopyright( "Copyright © Kevin Thompson 2018" )]
|
||||
[assembly: AssemblyTrademark( "" )]
|
||||
[assembly: AssemblyCulture( "" )]
|
||||
|
||||
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion( "0.2.0.0" )]
|
||||
[assembly: AssemblyFileVersion( "0.2.0.0" )]
|
||||
[assembly: AssemblyVersion( "0.2.1.0" )]
|
||||
[assembly: AssemblyFileVersion( "0.2.1.0" )]
|
||||
@@ -6,7 +6,7 @@ Version 0.2.0 adds the ability to authenticate using provided username/password
|
||||
**Please note** that v0.2.0 introduces a small change in the design that breaks backwards compatibility with previous verisons.
|
||||
|
||||
* [Source](https://github.com/antiduh/nsspi/archive/0.2.0.zip)
|
||||
* [Binaries](https://github.com/antiduh/nsspi/releases/download/0.1.3/nsspi-0.2.0-bin.zip)
|
||||
* [Binaries](https://github.com/antiduh/nsspi/releases/download/0.2.0/nsspi-0.2.0-bin.zip)
|
||||
* [Nuget package](https://www.nuget.org/packages/NSspi)
|
||||
|
||||
You can also browse the list of [releases](https://github.com/antiduh/nsspi/releases).
|
||||
|
||||
Reference in New Issue
Block a user