64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#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 <rapidjson/rapidjson.h>
|
|
|
|
#include <rublon/init.hpp>
|
|
#include <rublon/pam.hpp>
|
|
#include <rublon/rublon.hpp>
|
|
#include <rublon/utils.hpp>
|
|
|
|
#define DLL_PUBLIC __attribute__((visibility("default")))
|
|
|
|
using namespace std;
|
|
|
|
namespace {
|
|
|
|
template < typename T >
|
|
using Expected = tl::expected< T, rublon::Error >;
|
|
|
|
} // namespace
|
|
|
|
DLL_PUBLIC int pam_sm_setcred([[maybe_unused]] pam_handle_t * pamh,
|
|
[[maybe_unused]] int flags,
|
|
[[maybe_unused]] int argc,
|
|
[[maybe_unused]] const char ** argv) {
|
|
return PAM_SUCCESS;
|
|
}
|
|
|
|
DLL_PUBLIC int pam_sm_acct_mgmt([[maybe_unused]] pam_handle_t * pamh,
|
|
[[maybe_unused]] int flags,
|
|
[[maybe_unused]] int argc,
|
|
[[maybe_unused]] const char ** argv) {
|
|
return PAM_SUCCESS;
|
|
}
|
|
|
|
DLL_PUBLIC int
|
|
pam_sm_authenticate(pam_handle_t * pamh, [[maybe_unused]] int flags, [[maybe_unused]] int argc, [[maybe_unused]] const char ** argv) {
|
|
using namespace rublon;
|
|
|
|
auto rublonConfig = ConfigurationFactory{}.systemConfig();
|
|
|
|
CoreHandler CH{rublonConfig.value()};
|
|
LinuxPam pam{pamh};
|
|
|
|
auto selectMethod = [&](const MethodSelect & selector) { return selector.create(pam); };
|
|
auto confirmMethod = [&](const PostMethod & confirm) { return confirm.fire(CH); };
|
|
auto verifi = [&](const Method & method) { return method.fire(CH, pam); };
|
|
|
|
auto authStatus = Init{rublonConfig.value()}
|
|
.fire(CH, pam) //
|
|
.and_then(selectMethod)
|
|
.and_then(confirmMethod)
|
|
.and_then(verifi);
|
|
|
|
if(authStatus.has_value()) {
|
|
rublon::log(rublon::LogLevel::Info, "Auth OK");
|
|
}
|
|
|
|
return PAM_SUCCESS;
|
|
}
|