5 Commits
0.2.0 ... 0.2.1

Author SHA1 Message Date
Kevin Thompson
6bf95f46ee Updated version information to v0.2.1 2018-09-23 10:44:43 -04:00
Kevin Thompson
5c63105acf Merge pull request #12 from antiduh/pr/11
Pr/11 Integrate @SteveSyfuhs Thread.CurrentPrinciple changes
2018-04-01 18:10:28 -04:00
Kevin Thompson
19716405b8 Moved SetThreadIdentity into the ServerContext
The ImpersonationHandle class should probably stay as bare as possible since it's provided to the caller and we don't want to expose anything more than we need. Since the ServerContext is capable of performing this as a private method, move it there.
Updated the comments and variable names on the constructor to better indicate what exactly the option does, especially since modification of this property seems to be such a touchy subject.
2018-04-01 18:05:00 -04:00
Steve Syfuhs
f0820875c3 Fixed enum value. Any actual unicode strings passed in will only use the first character because the 0 byte after the first character is treated as a terminator.
Added ability to set the current thread principal so it's inline with the actual security context.
2018-03-30 11:40:37 -07:00
Kevin Thompson
8355a6b821 Fixed binaries url 2017-10-20 01:52:33 -04:00
6 changed files with 36 additions and 11 deletions

View File

@@ -1,4 +1,6 @@
using System;
using System.Security.Principal;
using System.Threading;
namespace NSspi.Contexts
{

View File

@@ -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 )
);
}
}
}

View File

@@ -50,6 +50,6 @@ namespace NSspi.Credentials
{
Ansi = 1,
Unicode = 1
Unicode = 2
}
}

View File

@@ -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>

View File

@@ -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" )]

View File

@@ -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).