mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-04-29 18:27:48 +02:00
GSS improvements, set context to null after a successfull call to DeleteSecurityContext
This commit is contained in:
parent
900ff25a3c
commit
d742a22756
5 changed files with 24 additions and 10 deletions
|
@ -112,17 +112,23 @@ namespace SMBLibrary.Authentication.GSSAPI
|
||||||
return mechanism.GetContextAttribute(context, attributeName);
|
return mechanism.GetContextAttribute(context, attributeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteSecurityContext(ref object context)
|
public bool DeleteSecurityContext(ref object context)
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (context != null)
|
if (context != null)
|
||||||
{
|
{
|
||||||
IGSSMechanism mechanism;
|
IGSSMechanism mechanism;
|
||||||
if (m_contextToMechanism.TryGetValue(context, out mechanism))
|
if (m_contextToMechanism.TryGetValue(context, out mechanism))
|
||||||
{
|
{
|
||||||
mechanism.DeleteSecurityContext(ref context);
|
object contextReference = context;
|
||||||
m_contextToMechanism.Remove(context);
|
result = mechanism.DeleteSecurityContext(ref context);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
m_contextToMechanism.Remove(contextReference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -18,12 +18,12 @@ namespace SMBLibrary.Authentication.GSSAPI
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Equivalent to GSS_Delete_sec_context
|
/// Equivalent to GSS_Delete_sec_context
|
||||||
/// Obtains information about a given security context (even an incomplete one)
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DeleteSecurityContext(ref object context);
|
bool DeleteSecurityContext(ref object context);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Equivalent to GSS_Inquire_context
|
/// Equivalent to GSS_Inquire_context
|
||||||
|
/// Obtains information about a given security context (even an incomplete one)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object GetContextAttribute(object context, GSSAttributeName attributeName);
|
object GetContextAttribute(object context, GSSAttributeName attributeName);
|
||||||
|
|
||||||
|
|
|
@ -223,8 +223,10 @@ namespace SMBLibrary.Authentication.NTLM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DeleteSecurityContext(ref object context)
|
public override bool DeleteSecurityContext(ref object context)
|
||||||
{
|
{
|
||||||
|
context = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object GetContextAttribute(object context, GSSAttributeName attributeName)
|
public override object GetContextAttribute(object context, GSSAttributeName attributeName)
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace SMBLibrary.Authentication.NTLM
|
||||||
|
|
||||||
public abstract NTStatus Authenticate(object context, AuthenticateMessage authenticateMessage);
|
public abstract NTStatus Authenticate(object context, AuthenticateMessage authenticateMessage);
|
||||||
|
|
||||||
public abstract void DeleteSecurityContext(ref object context);
|
public abstract bool DeleteSecurityContext(ref object context);
|
||||||
|
|
||||||
public abstract object GetContextAttribute(object context, GSSAttributeName attributeName);
|
public abstract object GetContextAttribute(object context, GSSAttributeName attributeName);
|
||||||
|
|
||||||
|
|
|
@ -125,16 +125,22 @@ namespace SMBLibrary.Win32.Security
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DeleteSecurityContext(ref object context)
|
public override bool DeleteSecurityContext(ref object context)
|
||||||
{
|
{
|
||||||
AuthContext authContext = context as AuthContext;
|
AuthContext authContext = context as AuthContext;
|
||||||
if (authContext == null)
|
if (authContext == null)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SecHandle handle = ((AuthContext)context).ServerContext;
|
SecHandle handle = ((AuthContext)context).ServerContext;
|
||||||
SSPIHelper.DeleteSecurityContext(ref handle);
|
uint result = SSPIHelper.DeleteSecurityContext(ref handle);
|
||||||
|
bool success = (result == 0); // SEC_E_OK
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
context = null;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object GetContextAttribute(object context, GSSAttributeName attributeName)
|
public override object GetContextAttribute(object context, GSSAttributeName attributeName)
|
||||||
|
|
Loading…
Add table
Reference in a new issue