Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | Fixes issue in Integrated Security auth on Windows (Managed SNI) #777

Merged
merged 2 commits into from Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -189,7 +189,14 @@ internal static int QueryMaxTokenSize(string package)
// This value is not used on Unix
return 0;
}


internal static SecurityStatusPal CompleteAuthToken(
ref SafeDeleteContext securityContext,
SecurityBuffer[] inSecurityBufferArray)
{
return new SecurityStatusPal(SecurityStatusPalErrorCode.OK);
}

internal static SafeFreeCredentials AcquireDefaultCredential(string package, bool isServer)
{
return AcquireCredentialsHandle(package, isServer, new NetworkCredential(string.Empty, string.Empty, string.Empty));
Expand Down
Expand Up @@ -20,7 +20,6 @@ internal class SNIProxy
private const int DefaultSqlServerPort = 1433;
private const int DefaultSqlServerDacPort = 1434;
private const string SqlServerSpnHeader = "MSSQLSvc";
private const int MaxTokenSize = 0;

internal class SspiClientContextResult
{
Expand Down Expand Up @@ -96,7 +95,8 @@ internal void GenSspiClientContext(SspiClientContextStatus sspiClientContextStat
inSecurityBufferArray = Array.Empty<SecurityBuffer>();
}

int tokenSize = MaxTokenSize;
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
int tokenSize = NegotiateStreamPal.QueryMaxTokenSize(securityPackage);

SecurityBuffer outSecurityBuffer = new SecurityBuffer(tokenSize, SecurityBufferType.SECBUFFER_TOKEN);

ContextFlagsPal requestedContextFlags = ContextFlagsPal.Connection
Expand All @@ -119,7 +119,7 @@ internal void GenSspiClientContext(SspiClientContextStatus sspiClientContextStat
statusCode.ErrorCode == SecurityStatusPalErrorCode.CompAndContinue)
{
inSecurityBufferArray = new SecurityBuffer[] { outSecurityBuffer };
statusCode = new SecurityStatusPal(SecurityStatusPalErrorCode.OK);
statusCode = NegotiateStreamPal.CompleteAuthToken(ref securityContext, inSecurityBufferArray);
outSecurityBuffer.token = null;
}

Expand Down Expand Up @@ -372,7 +372,7 @@ private static byte[] GetSqlServerSPN(string hostNameOrAddress, string portOrIns
/// <returns>SNITCPHandle</returns>
private SNITCPHandle CreateTcpHandle(DataSource details, long timerExpire, object callbackObject, bool parallel, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo)
{
// TCP Format:
// TCP Format:
// tcp:<host name>\<instance name>
// tcp:<host name>,<TCP/IP port number>

Expand Down Expand Up @@ -474,7 +474,7 @@ internal SNIError GetLastError()
}

/// <summary>
/// Gets the Local db Named pipe data source if the input is a localDB server.
/// Gets the Local db Named pipe data source if the input is a localDB server.
/// </summary>
/// <param name="fullServerName">The data source</param>
/// <param name="error">Set true when an error occurred while getting LocalDB up</param>
Expand Down Expand Up @@ -529,7 +529,7 @@ internal enum Protocol { TCP, NP, None, Admin };
internal Protocol _connectionProtocol = Protocol.None;

/// <summary>
/// Provides the HostName of the server to connect to for TCP protocol.
/// Provides the HostName of the server to connect to for TCP protocol.
/// This information is also used for finding the SPN of SqlServer
/// </summary>
internal string ServerName { get; private set; }
Expand Down Expand Up @@ -733,7 +733,7 @@ private bool InferConnectionDetails()
// Instance Name Handling. Only if we found a '\' and we did not find a port in the Data Source
else if (backSlashIndex > -1)
{
// This means that there will not be any part separated by comma.
// This means that there will not be any part separated by comma.
InstanceName = tokensByCommaAndSlash[1].Trim();

if (string.IsNullOrWhiteSpace(InstanceName))
Expand Down Expand Up @@ -781,7 +781,7 @@ private bool InferNamedPipesInformation()
string[] tokensByBackSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashCharacter);

// The datasource is of the format \\host\pipe\sql\query [0]\[1]\[2]\[3]\[4]\[5]
// It would at least have 6 parts.
// It would at least have 6 parts.
// Another valid Sql named pipe for an named instance is \\.\pipe\MSSQL$MYINSTANCE\sql\query
if (tokensByBackSlash.Length < 6)
{
Expand Down