Skip to content

Commit 97ca749

Browse files
committed
move the lib name definition to the shim
1 parent b2868bf commit 97ca749

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro(append_extra_security_libs NativeLibsExtra)
2222
if(CLR_CMAKE_TARGET_LINUX)
2323
# On Linux libgssapi_krb5.so is loaded on demand to tolerate its absense in singlefile apps that do not use it
2424
list(APPEND ${NativeLibsExtra} dl)
25-
add_definitions(-DGSS_DYNAMIC_LIB="libgssapi_krb5.so")
25+
add_definitions(-DGSS_SHIM)
2626
else()
2727
list(APPEND ${NativeLibsExtra} ${LIBGSS})
2828
endif()

src/libraries/Native/Unix/System.Net.Security.Native/pal_gssapi.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <assert.h>
2121
#include <string.h>
2222

23-
#if defined(GSS_DYNAMIC_LIB)
23+
#if defined(GSS_SHIM)
2424
#include <dlfcn.h>
2525
#include "pal_atomic.h"
2626
#endif
@@ -53,7 +53,7 @@ static gss_OID_desc gss_mech_ntlm_OID_desc = {.length = ARRAY_SIZE(gss_ntlm_oid_
5353
.elements = gss_ntlm_oid_value};
5454
#endif
5555

56-
#if defined(GSS_DYNAMIC_LIB)
56+
#if defined(GSS_SHIM)
5757

5858
#define FOR_ALL_GSS_FUNCTIONS \
5959
PER_FUNCTION_BLOCK(gss_accept_sec_context) \
@@ -131,15 +131,17 @@ static gss_shim_t* volatile s_gss_shim_ptr = NULL;
131131
#define GSS_C_NT_HOSTBASED_SERVICE *s_gss_shim_ptr->GSS_C_NT_HOSTBASED_SERVICE_ptr
132132
#define gss_mech_krb5 *s_gss_shim_ptr->gss_mech_krb5_ptr
133133

134+
#define gss_lib_name "libgssapi_krb5.so"
135+
134136
static int32_t ensure_gss_shim_initialized()
135137
{
136138
if (s_gss_shim_ptr != NULL)
137139
{
138140
return 0;
139141
}
140142

141-
void* lib = dlopen(GSS_DYNAMIC_LIB, RTLD_LAZY);
142-
if (lib == NULL) { fprintf(stderr, "Cannot load library %s \nError: %s\n", GSS_DYNAMIC_LIB, dlerror()); return -1; }
143+
void* lib = dlopen(gss_lib_name, RTLD_LAZY);
144+
if (lib == NULL) { fprintf(stderr, "Cannot load library %s \nError: %s\n", gss_lib_name, dlerror()); return -1; }
143145

144146
// check is someone else has opened and published s_gssLib already
145147
if (!pal_atomic_cas_ptr(&s_gssLib, lib, NULL))
@@ -149,10 +151,10 @@ static int32_t ensure_gss_shim_initialized()
149151

150152
// initialize indirection pointers for all functions, like:
151153
// s_gss_shim.gss_accept_sec_context_ptr = (TYPEOF(gss_accept_sec_context)*)dlsym(s_gssLib, "gss_accept_sec_context");
152-
// 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()); return -1; }
154+
// 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_lib_name, dlerror()); return -1; }
153155
#define PER_FUNCTION_BLOCK(fn) \
154156
s_gss_shim.fn##_ptr = (TYPEOF(fn)*)dlsym(s_gssLib, #fn); \
155-
if (s_gss_shim.fn##_ptr == NULL) { fprintf(stderr, "Cannot get symbol " #fn " from %s \nError: %s\n", GSS_DYNAMIC_LIB, dlerror()); return -1; }
157+
if (s_gss_shim.fn##_ptr == NULL) { fprintf(stderr, "Cannot get symbol " #fn " from %s \nError: %s\n", gss_lib_name, dlerror()); return -1; }
156158

157159
FOR_ALL_GSS_FUNCTIONS
158160
#undef PER_FUNCTION_BLOCK
@@ -163,7 +165,7 @@ static int32_t ensure_gss_shim_initialized()
163165
return 0;
164166
}
165167

166-
#endif // GSS_DYNAMIC_LIB
168+
#endif // GSS_SHIM
167169

168170
// transfers ownership of the underlying data from gssBuffer to PAL_GssBuffer
169171
static void NetSecurityNative_MoveBuffer(gss_buffer_t gssBuffer, PAL_GssBuffer* targetBuffer)
@@ -687,7 +689,7 @@ uint32_t NetSecurityNative_IsNtlmInstalled()
687689

688690
int32_t NetSecurityNative_EnsureGssInitialized()
689691
{
690-
#if defined(GSS_DYNAMIC_LIB)
692+
#if defined(GSS_SHIM)
691693
return ensure_gss_shim_initialized();
692694
#else
693695
return 0;

0 commit comments

Comments
 (0)