diff --git a/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.IsNtlmInstalled.cs b/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.IsNtlmInstalled.cs index b799ef433e8830..3834c80c46fab7 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.IsNtlmInstalled.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.IsNtlmInstalled.cs @@ -22,11 +22,13 @@ static NetSecurityNative() internal static class GssInitializer { + private const string GssApiLibraryName = "libgssapi_krb5.so.2"; + static GssInitializer() { if (EnsureGssInitialized() != 0) { - throw new InvalidOperationException(); + throw new DllNotFoundException(GssApiLibraryName); } } diff --git a/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs b/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs index 475483944f84a3..45b928cf72180c 100644 --- a/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs +++ b/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs @@ -55,6 +55,12 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOpt // GSSAPI shim may not be available on some platforms (Linux Bionic) return new UnsupportedNegotiateAuthenticationPal(clientOptions); } + catch (TypeInitializationException tie) when (tie.InnerException is DllNotFoundException) + { + // GSSAPI native library (e.g. libgssapi_krb5) may not be available on the system + if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, tie.InnerException); + return new UnsupportedNegotiateAuthenticationPal(clientOptions); + } } public static NegotiateAuthenticationPal Create(NegotiateAuthenticationServerOptions serverOptions) @@ -78,6 +84,12 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationServerOpt // GSSAPI shim may not be available on some platforms (Linux Bionic) return new UnsupportedNegotiateAuthenticationPal(serverOptions); } + catch (TypeInitializationException tie) when (tie.InnerException is DllNotFoundException) + { + // GSSAPI native library (e.g. libgssapi_krb5) may not be available on the system + if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, tie.InnerException); + return new UnsupportedNegotiateAuthenticationPal(serverOptions); + } } internal sealed class UnixNegotiateAuthenticationPal : NegotiateAuthenticationPal @@ -774,6 +786,8 @@ public static bool CheckHasSystemNetSecurityNative() } catch (Exception e) when (e is EntryPointNotFoundException || e is DllNotFoundException || e is TypeInitializationException) { + Exception logException = e is TypeInitializationException tie ? tie.InnerException ?? e : e; + if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, logException); // libSystem.Net.Security.Native is not available return false; } diff --git a/src/native/libs/System.Net.Security.Native/pal_gssapi.c b/src/native/libs/System.Net.Security.Native/pal_gssapi.c index 9be66b8a7566c2..e0779820bc1f1a 100644 --- a/src/native/libs/System.Net.Security.Native/pal_gssapi.c +++ b/src/native/libs/System.Net.Security.Native/pal_gssapi.c @@ -122,7 +122,7 @@ static void* volatile s_gssLib = NULL; static int32_t ensure_gss_shim_initialized(void) { void* lib = dlopen(gss_lib_name, RTLD_LAZY); - if (lib == NULL) { fprintf(stderr, "Cannot load library %s \nError: %s\n", gss_lib_name, dlerror()); return -1; } + if (lib == NULL) { return -1; } // check is someone else has opened and published s_gssLib already if (!pal_atomic_cas_ptr(&s_gssLib, lib, NULL))