20
20
#include <assert.h>
21
21
#include <string.h>
22
22
23
- #if defined(GSS_SHIM )
23
+ #if defined(GSS_DYNAMIC_LIB )
24
24
#include <dlfcn.h>
25
25
#include "pal_atomic.h"
26
26
#endif
@@ -53,7 +53,7 @@ static gss_OID_desc gss_mech_ntlm_OID_desc = {.length = ARRAY_SIZE(gss_ntlm_oid_
53
53
.elements = gss_ntlm_oid_value };
54
54
#endif
55
55
56
- #if defined(GSS_SHIM )
56
+ #if defined(GSS_DYNAMIC_LIB )
57
57
58
58
#define FOR_ALL_GSS_FUNCTIONS \
59
59
PER_FUNCTION_BLOCK(gss_accept_sec_context) \
@@ -108,8 +108,8 @@ static gss_shim_t* volatile s_gss_shim_ptr = NULL;
108
108
109
109
static void init_gss_shim ()
110
110
{
111
- void * lib = dlopen (gssLibraryName , RTLD_LAZY );
112
- if (lib == NULL ) { fprintf (stderr , "Cannot load library %s \nError: %s\n" , gssLibraryName , dlerror ()); abort (); }
111
+ void * lib = dlopen (GSS_DYNAMIC_LIB , RTLD_LAZY );
112
+ if (lib == NULL ) { fprintf (stderr , "Cannot load library %s \nError: %s\n" , GSS_DYNAMIC_LIB , dlerror ()); abort (); }
113
113
114
114
// check is someone else has opened and published s_gssLib already
115
115
if (!pal_atomic_cas_ptr (& s_gssLib , lib , NULL ))
@@ -119,10 +119,10 @@ static void init_gss_shim()
119
119
120
120
// initialize indirection pointers for all functions, like:
121
121
// s_gss_shim.gss_accept_sec_context_ptr = (TYPEOF(gss_accept_sec_context)*)dlsym(s_gssLib, "gss_accept_sec_context");
122
- // if (s_gss_shim.gss_accept_sec_context_ptr == NULL) { fprintf(stderr, "Cannot get symbol %s from %s \nError: %s\n", "gss_accept_sec_context", gssLibraryName , dlerror()); abort(); }
122
+ // if (s_gss_shim.gss_accept_sec_context_ptr == NULL) { fprintf(stderr, "Cannot get symbol %s from %s \nError: %s\n", "gss_accept_sec_context", GSS_DYNAMIC_LIB , dlerror()); abort(); }
123
123
#define PER_FUNCTION_BLOCK (fn ) \
124
124
s_gss_shim.fn##_ptr = (TYPEOF(fn)*)dlsym(s_gssLib, #fn); \
125
- if (s_gss_shim.fn##_ptr == NULL) { fprintf(stderr, "Cannot get symbol " #fn " from %s \nError: %s\n", gssLibraryName , dlerror()); abort(); }
125
+ if (s_gss_shim.fn##_ptr == NULL) { fprintf(stderr, "Cannot get symbol " #fn " from %s \nError: %s\n", GSS_DYNAMIC_LIB , dlerror()); abort(); }
126
126
127
127
FOR_ALL_GSS_FUNCTIONS
128
128
#undef PER_FUNCTION_BLOCK
@@ -151,7 +151,6 @@ static gss_shim_t* get_gss_shim()
151
151
#define gss_display_name (...) get_gss_shim()->gss_display_name_ptr(__VA_ARGS__)
152
152
#define gss_display_status (...) get_gss_shim()->gss_display_status_ptr(__VA_ARGS__)
153
153
#define gss_import_name (...) get_gss_shim()->gss_import_name_ptr(__VA_ARGS__)
154
- #define gss_indicate_mechs (...) get_gss_shim()->gss_indicate_mechs_ptr(__VA_ARGS__)
155
154
#define gss_init_sec_context (...) get_gss_shim()->gss_init_sec_context_ptr(__VA_ARGS__)
156
155
#define gss_inquire_context (...) get_gss_shim()->gss_inquire_context_ptr(__VA_ARGS__)
157
156
#define gss_oid_equal (...) get_gss_shim()->gss_oid_equal_ptr(__VA_ARGS__)
@@ -171,7 +170,34 @@ static gss_shim_t* get_gss_shim()
171
170
#define GSS_C_NT_HOSTBASED_SERVICE *get_gss_shim()->GSS_C_NT_HOSTBASED_SERVICE_ptr
172
171
#define gss_mech_krb5 *get_gss_shim()->gss_mech_krb5_ptr
173
172
174
- #endif // GSS_SHIM
173
+ // NB: Managed side may call IsNtlmInstalled, which in turn calls `gss_indicate_mechs` to probe for support and
174
+ // treat all all exceptions same as `false`. Our own tests and platform detection do that.
175
+ // So we will not abort if API is not there for `gss_indicate_mechs_ptr`, and return a failure code instead.
176
+ static bool probe_gss_api ()
177
+ {
178
+ if (s_gss_shim_ptr )
179
+ {
180
+ return true;
181
+ }
182
+
183
+ void * lib = dlopen (GSS_DYNAMIC_LIB , RTLD_LAZY );
184
+ if (lib == NULL )
185
+ {
186
+ return false;
187
+ }
188
+
189
+ // check is someone else has opened and published s_gssLib already
190
+ if (!pal_atomic_cas_ptr (& s_gssLib , lib , NULL ))
191
+ {
192
+ dlclose (lib );
193
+ }
194
+
195
+ return true;
196
+ }
197
+
198
+ #define gss_indicate_mechs (...) (probe_gss_api() ? get_gss_shim()->gss_indicate_mechs_ptr(__VA_ARGS__) : GSS_S_UNAVAILABLE)
199
+
200
+ #endif // GSS_DYNAMIC_LIB
175
201
176
202
// transfers ownership of the underlying data from gssBuffer to PAL_GssBuffer
177
203
static void NetSecurityNative_MoveBuffer (gss_buffer_t gssBuffer , PAL_GssBuffer * targetBuffer )
@@ -670,7 +696,7 @@ uint32_t NetSecurityNative_IsNtlmInstalled()
670
696
671
697
uint32_t majorStatus ;
672
698
uint32_t minorStatus ;
673
- gss_OID_set mechSet ;
699
+ gss_OID_set mechSet = NULL ;
674
700
gss_OID_desc oid ;
675
701
uint32_t foundNtlm = 0 ;
676
702
0 commit comments