From 3c3c4131c6494cd50be31f33a071a9cd698b0645 Mon Sep 17 00:00:00 2001 From: Bartosz Wieczorek Date: Mon, 6 Oct 2025 15:57:55 +0000 Subject: [PATCH] Fix build on sun --- CMakeLists.txt | 2 +- PAM/ssh/include/rublon/curl.hpp | 2 +- .../rublon/method/passcode_based_auth.hpp | 2 +- PAM/ssh/include/rublon/pam.hpp | 52 ++++++++++++++++++- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3616ecc..b998988 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_CXX_EXTENSIONS NO) set(CMAKE_POSITION_INDEPENDENT_CODE YES) add_compile_options(-Wall -Wextra -Wno-format-security) - +add_compile_options(-fpermissive) # add_compile_options(-g -fsanitize=address,undefined,float-divide-by-zero,float-cast-overflow,null -fsanitize-address-use-after-scope -fno-sanitize-recover=all -fno-sanitize=alignment -fno-omit-frame-pointer) # add_link_options(-g -fsanitize=address,undefined,float-divide-by-zero,float-cast-overflow,null -fsanitize-address-use-after-scope -fno-sanitize-recover=all -fno-sanitize=alignment -fno-omit-frame-pointer) diff --git a/PAM/ssh/include/rublon/curl.hpp b/PAM/ssh/include/rublon/curl.hpp index 4e7b7fc..1dc31ab 100644 --- a/PAM/ssh/include/rublon/curl.hpp +++ b/PAM/ssh/include/rublon/curl.hpp @@ -136,7 +136,7 @@ class CURL { curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, curl_headers.get()); curl_easy_setopt(curl.get(), CURLOPT_POST, 1); curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, request.body.data()); - curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, static_cast< u_int32_t >(request.body.size())); + curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, static_cast< uint32_t >(request.body.size())); curl_easy_setopt(curl.get(), CURLOPT_HEADER, 1); curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response_data); diff --git a/PAM/ssh/include/rublon/method/passcode_based_auth.hpp b/PAM/ssh/include/rublon/method/passcode_based_auth.hpp index ce1c7a5..1d04c40 100644 --- a/PAM/ssh/include/rublon/method/passcode_based_auth.hpp +++ b/PAM/ssh/include/rublon/method/passcode_based_auth.hpp @@ -30,7 +30,7 @@ class PasscodeBasedAuth : public AuthenticationStep { const bool _onlyDigits; int _prompts; - constexpr static bool isdigit(char ch) { + static bool isdigit(char ch) { return std::isdigit(static_cast< unsigned char >(ch)); } diff --git a/PAM/ssh/include/rublon/pam.hpp b/PAM/ssh/include/rublon/pam.hpp index e53dbbd..9ca0d6e 100644 --- a/PAM/ssh/include/rublon/pam.hpp +++ b/PAM/ssh/include/rublon/pam.hpp @@ -1,7 +1,47 @@ #pragma once +#ifdef __sun +#include +#include +#include +#include +#include +static int pam_vprompt_compat(pam_handle_t *pamh, int style, char **out, + const char *fmt, va_list ap) { + const struct pam_conv *conv = NULL; + if (pam_get_item(pamh, PAM_CONV, (void **)&conv) != PAM_SUCCESS || !conv || !conv->conv) + return PAM_SYSTEM_ERR; + + char buf[1024]; + vsnprintf(buf, sizeof(buf), fmt, ap); + + struct pam_message msg = { .msg_style = style, .msg = buf }; + struct pam_message *pmsg[1] = { &msg }; + struct pam_response *resp = NULL; + + int r = conv->conv(1, pmsg, &resp, conv->appdata_ptr); + if (r != PAM_SUCCESS) return r; + + if (out) { + if (resp && resp[0].resp) *out = resp[0].resp; else *out = NULL; + } + if (resp) free(resp); // NIE zwalniaj *out; zwolni to wywołujący + return PAM_SUCCESS; +} + +static int pam_prompt_compat(pam_handle_t *pamh, int style, char **out, const char *fmt, ...) { + va_list ap; va_start(ap, fmt); + int r = pam_vprompt_compat(pamh, style, out, fmt, ap); + va_end(ap); + return r; +} + +#define pam_prompt pam_prompt_compat + +#else #include #include +#endif #include #include @@ -20,21 +60,29 @@ class LinuxPam { } rublon::NonOwningPtr< const char > ip() const { +#ifdef __sun + void * ip = NULL; +#else const void * ip = NULL; +#endif pam_get_item(pamh, PAM_RHOST, &ip); if(ip == NULL) { rublon::log(rublon::LogLevel::Warning, "Cant read ip from linux PAM"); - ip = ""; + return ""; } return ( const char * ) ip; } rublon::NonOwningPtr< const char > username() const { +#ifdef __sun + char * user = NULL; +#else const char * user = NULL; +#endif pam_get_user(pamh, &user, nullptr); if(user == NULL) { rublon::log(rublon::LogLevel::Warning, "Cant read user from linux PAM"); - user = ""; + return ""; } return user; }