Skip to content

Commit 4def406

Browse files
committed
remove unneeded if/def
1 parent c41dec3 commit 4def406

File tree

3 files changed

+1
-118
lines changed

3 files changed

+1
-118
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@
146146
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ApplicationIntent.cs">
147147
<Link>Microsoft\Data\SqlClient\ApplicationIntent.cs</Link>
148148
</Compile>
149-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ArrayBufferWriter.cs">
150-
<Link>Microsoft\Data\SqlClient\ArrayBufferWriter.cs</Link>
151-
</Compile>
152149
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\AssemblyRef.cs">
153150
<Link>Microsoft\Data\SqlClient\AssemblyRef.cs</Link>
154151
</Compile>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -26,121 +26,7 @@ internal class SNIProxy
2626
private static readonly SNIProxy s_singleton = new SNIProxy();
2727

2828
internal static SNIProxy Instance => s_singleton;
29-
#if !NET8_0_OR_GREATER
30-
/// <summary>
31-
/// Generate SSPI context
32-
/// </summary>
33-
/// <param name="sspiClientContextStatus">SSPI client context status</param>
34-
/// <param name="receivedBuff">Receive buffer</param>
35-
/// <param name="sendWriter">Writer for send buffer</param>
36-
/// <param name="serverName">Service Principal Name buffer</param>
37-
/// <returns>SNI error code</returns>
38-
internal static void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> sendWriter, byte[][] serverName)
39-
{
40-
// TODO: this should use ReadOnlyMemory all the way through
41-
byte[] array = null;
42-
43-
if (!receivedBuff.IsEmpty)
44-
{
45-
array = new byte[receivedBuff.Length];
46-
receivedBuff.CopyTo(array);
47-
}
48-
49-
GenSspiClientContext(sspiClientContextStatus, array, sendWriter, serverName);
50-
}
51-
52-
private static void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, byte[] receivedBuff, IBufferWriter<byte> sendWriter, byte[][] serverName)
53-
{
54-
SafeDeleteContext securityContext = sspiClientContextStatus.SecurityContext;
55-
ContextFlagsPal contextFlags = sspiClientContextStatus.ContextFlags;
56-
SafeFreeCredentials credentialsHandle = sspiClientContextStatus.CredentialsHandle;
57-
58-
string securityPackage = NegotiationInfoClass.Negotiate;
59-
60-
if (securityContext == null)
61-
{
62-
credentialsHandle = NegotiateStreamPal.AcquireDefaultCredential(securityPackage, false);
63-
}
64-
65-
SecurityBuffer[] inSecurityBufferArray;
66-
if (receivedBuff != null)
67-
{
68-
inSecurityBufferArray = new SecurityBuffer[] { new SecurityBuffer(receivedBuff, SecurityBufferType.SECBUFFER_TOKEN) };
69-
}
70-
else
71-
{
72-
inSecurityBufferArray = Array.Empty<SecurityBuffer>();
73-
}
74-
75-
int tokenSize = NegotiateStreamPal.QueryMaxTokenSize(securityPackage);
76-
77-
SecurityBuffer outSecurityBuffer = new SecurityBuffer(tokenSize, SecurityBufferType.SECBUFFER_TOKEN);
7829

79-
ContextFlagsPal requestedContextFlags = ContextFlagsPal.Connection
80-
| ContextFlagsPal.Confidentiality
81-
| ContextFlagsPal.Delegate
82-
| ContextFlagsPal.MutualAuth;
83-
84-
string[] serverSPNs = new string[serverName.Length];
85-
for (int i = 0; i < serverName.Length; i++)
86-
{
87-
serverSPNs[i] = Encoding.Unicode.GetString(serverName[i]);
88-
}
89-
SecurityStatusPal statusCode = NegotiateStreamPal.InitializeSecurityContext(
90-
credentialsHandle,
91-
ref securityContext,
92-
serverSPNs,
93-
requestedContextFlags,
94-
inSecurityBufferArray,
95-
outSecurityBuffer,
96-
ref contextFlags);
97-
98-
if (statusCode.ErrorCode == SecurityStatusPalErrorCode.CompleteNeeded ||
99-
statusCode.ErrorCode == SecurityStatusPalErrorCode.CompAndContinue)
100-
{
101-
inSecurityBufferArray = new SecurityBuffer[] { outSecurityBuffer };
102-
statusCode = NegotiateStreamPal.CompleteAuthToken(ref securityContext, inSecurityBufferArray);
103-
outSecurityBuffer.token = null;
104-
}
105-
106-
if (outSecurityBuffer.token is { } token)
107-
{
108-
sendWriter.Write(token);
109-
}
110-
111-
sspiClientContextStatus.SecurityContext = securityContext;
112-
sspiClientContextStatus.ContextFlags = contextFlags;
113-
sspiClientContextStatus.CredentialsHandle = credentialsHandle;
114-
115-
if (IsErrorStatus(statusCode.ErrorCode))
116-
{
117-
// Could not access Kerberos Ticket.
118-
//
119-
// SecurityStatusPalErrorCode.InternalError only occurs in Unix and always comes with a GssApiException,
120-
// so we don't need to check for a GssApiException here.
121-
if (statusCode.ErrorCode == SecurityStatusPalErrorCode.InternalError)
122-
{
123-
throw new InvalidOperationException(SQLMessage.KerberosTicketMissingError() + Environment.NewLine + statusCode);
124-
}
125-
else
126-
{
127-
throw new InvalidOperationException(SQLMessage.SSPIGenerateError() + Environment.NewLine + statusCode);
128-
}
129-
}
130-
}
131-
132-
private static bool IsErrorStatus(SecurityStatusPalErrorCode errorCode)
133-
{
134-
return errorCode != SecurityStatusPalErrorCode.NotSet &&
135-
errorCode != SecurityStatusPalErrorCode.OK &&
136-
errorCode != SecurityStatusPalErrorCode.ContinueNeeded &&
137-
errorCode != SecurityStatusPalErrorCode.CompleteNeeded &&
138-
errorCode != SecurityStatusPalErrorCode.CompAndContinue &&
139-
errorCode != SecurityStatusPalErrorCode.ContextExpired &&
140-
errorCode != SecurityStatusPalErrorCode.CredentialsNeeded &&
141-
errorCode != SecurityStatusPalErrorCode.Renegotiate;
142-
}
143-
#endif
14430
/// <summary>
14531
/// Create a SNI connection handle
14632
/// </summary>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ArrayBufferWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private void CheckAndResizeBuffer(int sizeHint)
242242

243243
private static void ThrowInvalidOperationException_AdvancedTooFar(int capacity)
244244
{
245-
throw new InvalidOperationException($"Buffer advanced to far: {capacity}");
245+
throw new InvalidOperationException($"Buffer advanced too far: {capacity}");
246246
}
247247

248248
private static void ThrowOutOfMemoryException(uint capacity)

0 commit comments

Comments
 (0)