rublon-ssh/PAM/ssh/include/rublon/pam.hpp
rublon-bwi af64f8e9e3
Bwi/v2.2.0 (#16)
* Remove dynamic memory usage from core

* Refacor status check to use json pointers

* Move access token to session

* Remove code duplication

* Fix compile warnings from rapidjson sources

* Add 'interactive mode option to session configuration

* Implement non interactive mode connector

* Add 'non interactove' implementation

* Apply rapidjson patch

* Build on all cores

* Rename build script

* Split configure and build steps

* Add scripts for building all images

* Change bash to python for build scripts

* Stop printing methods name in non interactive mode

* Add trace log level, adn more params to init message

* Fix build

* Fix non interactive method selection and refactor vagrant files for debian like systems

* Refactor log messages

* Remove exces dependencies from vagrant configuration files

* Fixed vagrantfiles

* Added repo for rhel

* Add nonInteractiveMode option

* Added instalation script for pubkey

* Fixed pubkey install script and postrm for rhel
2025-03-07 11:41:12 +01:00

62 lines
1.8 KiB
C++

#pragma once
#include <security/_pam_types.h>
#include <security/pam_appl.h>
#include <security/pam_client.h>
#include <security/pam_ext.h>
#include <security/pam_misc.h>
#include <security/pam_modules.h>
#include <rublon/non_owning_ptr.hpp>
#include <rublon/utils.hpp>
namespace rublon {
class LinuxPam {
pam_handle_t * pamh;
public:
LinuxPam(pam_handle_t * handler) : pamh{handler} {}
rublon::NonOwningPtr< const char > ip() const {
const void * ip = NULL;
pam_get_item(pamh, PAM_RHOST, &ip);
if(ip == NULL) {
rublon::log(rublon::LogLevel::Warning, "Cant read ip from linux PAM");
ip = "";
}
return ( const char * ) ip;
}
rublon::NonOwningPtr< const char > username() const {
const char * user = NULL;
pam_get_user(pamh, &user, nullptr);
if(user == NULL) {
rublon::log(rublon::LogLevel::Warning, "Cant read user from linux PAM");
user = "";
}
return user;
}
template < typename... Ti >
void print(const char * fmt, Ti... ti) const noexcept {
char buf[256] = {};
sprintf(buf, fmt, std::forward< Ti >(ti)...);
if(auto r = pam_prompt(pamh, PAM_TEXT_INFO, nullptr, fmt, std::forward< Ti >(ti)...); r != PAM_SUCCESS) {
log(LogLevel::Error, "pam_print returned with error code %d", r);
}
}
template < typename Fun, typename... Ti >
auto scan(Fun && f, const char * fmt, Ti... ti) const noexcept {
char * response = nullptr;
pam_prompt(pamh, PAM_PROMPT_ECHO_ON, &response, fmt, std::forward< Ti >(ti)...);
if(response) {
auto ret = f(response);
free(response);
return ret;
}
return std::result_of_t< Fun(char *) >();
}
};
} // namespace rublon