-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Shim gss api on Linux to delay loading libgssapi_krb5.so #55037
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
Changes from 1 commit
348e6bb
4a8f960
ef4c398
998e1a9
7f88c8b
3dece8f
b2868bf
97ca749
adeffde
b4e8953
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
gss_indicate_mechs. It may be used for A…
…PI probing.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <assert.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if defined(GSS_SHIM) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if defined(GSS_DYNAMIC_LIB) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <dlfcn.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pal_atomic.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,7 +53,7 @@ static gss_OID_desc gss_mech_ntlm_OID_desc = {.length = ARRAY_SIZE(gss_ntlm_oid_ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| .elements = gss_ntlm_oid_value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if defined(GSS_SHIM) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if defined(GSS_DYNAMIC_LIB) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define FOR_ALL_GSS_FUNCTIONS \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| PER_FUNCTION_BLOCK(gss_accept_sec_context) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -108,8 +108,8 @@ static gss_shim_t* volatile s_gss_shim_ptr = NULL; | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void init_gss_shim() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal static class CryptoInitializer | |
| { | |
| static CryptoInitializer() | |
| { | |
| if (EnsureOpenSslInitialized() != 0) | |
| { | |
| // Ideally this would be a CryptographicException, but we use | |
| // OpenSSL in libraries lower than System.Security.Cryptography. | |
| // It's not a big deal, though: this will already be wrapped in a | |
| // TypeLoadException, and this failing means something is very | |
| // wrong with the system's configuration and any code using | |
| // these libraries will be unable to operate correctly. | |
| throw new InvalidOperationException(); | |
| } | |
| } | |
| internal static void Initialize() | |
| { | |
| // No-op that exists to provide a hook for other static constructors. | |
| } | |
| [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "CryptoNative_EnsureOpenSslInitialized")] | |
| private static extern int EnsureOpenSslInitialized(); | |
| } | |
| } |
So when the System.Security.Cryptography managed assembly is loaded, the native shim is initialized by the static constructor. When the app doesn't use that assembly, the native shim is not initialized and no functions exported by the native library are called.
A benefit of this approach is that instead of abort from the native code when the library is not installed and the app wants to use it, you'll get an unhandled exception with managed stack trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, the static constructor trick. That should be equally non-disruptive to the overall use of the API and have a better failure mode.
Let me see if we can use it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a change that switches to static constructor scheme.
It looks like, while highly improbable, we can have concurrent initialization because IsNtlmInstalled could live in its own class via a file include. I can't rule out the need for atomic things, so I kept them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer defining the name in the actual shim. We do it that way for openssl and I don't see a benefit of having it here.