Skip to content

Commit

Permalink
Update GSS/NTLM-related sources (from .NET Core 3.0 and 2.2) (mono#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored and steveisok committed Oct 23, 2019
1 parent 8e3b279 commit fb41040
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,59 @@ internal sealed class GssApiException : Exception
{
private readonly Status _minorStatus;

public Status MajorStatus
{
get { return (Status)HResult; }
}

public Status MinorStatus
{
get { return _minorStatus;}
get { return _minorStatus; }
}

public GssApiException(string message) : base(message)
{
}

public GssApiException(Status majorStatus, Status minorStatus)
: base(GetGssApiDisplayStatus(majorStatus, minorStatus))
: base(GetGssApiDisplayStatus(majorStatus, minorStatus, null))
{
HResult = (int)majorStatus;
_minorStatus = minorStatus;
}

public GssApiException(Status majorStatus, Status minorStatus, string helpText)
: base(GetGssApiDisplayStatus(majorStatus, minorStatus, helpText))
{
HResult = (int)majorStatus;
_minorStatus = minorStatus;
}

private static string GetGssApiDisplayStatus(Status majorStatus, Status minorStatus)
private static string GetGssApiDisplayStatus(Status majorStatus, Status minorStatus, string helpText)
{
string majorError = GetGssApiDisplayStatus(majorStatus, isMinor: false);
string minorError = GetGssApiDisplayStatus(minorStatus, isMinor: true);
string errorMessage;

if (minorStatus != Status.GSS_S_COMPLETE)
{
string minorError = GetGssApiDisplayStatus(minorStatus, isMinor: true);
errorMessage = (majorError != null && minorError != null) ?
SR.Format(SR.net_gssapi_operation_failed_detailed, majorError, minorError) :
SR.Format(SR.net_gssapi_operation_failed, majorStatus.ToString("x"), minorStatus.ToString("x"));
}
else
{
errorMessage = (majorError != null) ?
SR.Format(SR.net_gssapi_operation_failed_detailed_majoronly, majorError) :
SR.Format(SR.net_gssapi_operation_failed_majoronly, majorStatus.ToString("x"));
}

if (!string.IsNullOrEmpty(helpText))
{
return errorMessage + " " + helpText;
}

return (majorError != null && minorError != null) ?
SR.Format(SR.net_gssapi_operation_failed_detailed, majorError, minorError) :
SR.Format(SR.net_gssapi_operation_failed, majorStatus.ToString("x"), minorStatus.ToString("x"));
return errorMessage;
}

private static string GetGssApiDisplayStatus(Status status, bool isMinor)
Expand All @@ -60,4 +89,4 @@ private static string GetGssApiDisplayStatus(Status status, bool isMinor)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static partial class NetSecurityNative
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct GssBuffer : IDisposable
{
internal UInt64 _length;
internal ulong _length;
internal IntPtr _data;

internal int Copy(byte[] destination, int offset)
Expand Down Expand Up @@ -66,11 +66,11 @@ public void Dispose()
#if DEBUG
static GssBuffer()
{
// Verify managed size on both 32-bit and 64-bit matches the PAL_GssBuffer
// Verify managed size on both 32-bit and 64-bit matches the PAL_GssBuffer
// native struct size, which is also padded on 32-bit.
Debug.Assert(Marshal.SizeOf<GssBuffer>() == 16);
}
#endif
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ internal static void Initialize()
// No-op that exists to provide a hook for other static constructors
}
}
}
}
Loading

0 comments on commit fb41040

Please sign in to comment.