Fix build on sun
This commit is contained in:
parent
e13699db43
commit
3c3c4131c6
@ -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)
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,47 @@
|
||||
#pragma once
|
||||
#ifdef __sun
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_modules.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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 <security/pam_appl.h>
|
||||
#include <security/pam_ext.h>
|
||||
#endif
|
||||
|
||||
#include <rublon/non_owning_ptr.hpp>
|
||||
#include <rublon/utils.hpp>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user