gssapi
gssapi copied to clipboard
Fix dynamic GSSAPI lib path detection on macOS for kerberos
Description
This PR fixes an issue where the GSSAPI library path for kerberos auth was hardcoded to /usr/lib/libgssapi_krb5.dylib on macOS in lib_gssapi_loader.rb.
This caused failures when GSSAPI was installed via Homebrew, as the actual path differs or does not come by default.
Issue
When using the GSSAPI library for Kerberos authentication with WinRM, authentication fails due to the hardcoded libgssapi_krb5.dylib path.
The error occurs because users with Homebrew-installed Kerberos have the library in /opt/homebrew/Cellar/krb5/....
Error Screenshot
Fix
- Instead of a hardcoded path in
lib_gssapi_loader.rb, this PR dynamically detects the correct GSSAPI library location:- Uses
brew --prefixto find the Homebrew installation directory. - Falls back to
/usr/lib/if Homebrew is not installed.
- Uses
- This ensures compatibility across both system-installed and Homebrew-installed Kerberos libraries.
when /darwin/
brew_lib = `brew --prefix krb5 2>/dev/null`.chomp
gssapi_lib = File.exist?("#{brew_lib}/lib/libgssapi_krb5.dylib") ? "#{brew_lib}/lib/libgssapi_krb5.dylib" : '/usr/lib/libgssapi_krb5.dylib'
ffi_lib gssapi_lib, FFI::Library::LIBC
After fixing code
Why This Fix is Needed
- Recent macOS versions do not include
libgssapi_krb5.dylibby default. - Users installing Kerberos via Homebrew (
krb5package) havelibgssapi_krb5.dylibin/opt/homebrew/Cellar/.... - The previous hardcoded path caused
FFI::Library::ffi_libto fail, making GSSAPI unusable. - This fix allows the library to work seamlessly on macOS regardless of installation method.
Notes for Users
📌 If you are on macOS and do not have libgssapi_krb5.dylib, install it using:
brew install krb5