7684972a |
/* Copyright (C) CJ Affiliate
*
* You may use, distribute and modify this code under the
* terms of the GNU General Public License version 2 or
* later.
*
* You should have received a copy of the license with this
* file. If not, you will find a copy in the "LICENSE" file
* at https://github.com/cjdev/dual-control.
*/
|
bcf6f3d1 |
/* PAM native handler entrypoints. Keep these dumb so the logic can
* be tested.
*/
|
4a1812fd |
#include <security/pam_modules.h>
#include <string>
#include <memory>
#include <vector>
|
194e6869 |
#include "conversation.h"
|
4a1812fd |
#include "dual_control.h"
|
194e6869 |
#include "generator.h"
|
da1b9b25 |
#include "logger.h"
|
194e6869 |
#include "request.h"
#include "session.h"
|
da1b9b25 |
#include "sys_fstream.h"
|
d4af7e88 |
#include "sys_pam.h"
|
194e6869 |
#include "sys_pwd.h"
|
da1b9b25 |
#include "sys_syslog.h"
|
194e6869 |
#include "sys_unistd.h"
#include "token.h"
#include "user.h"
#include "validator.h"
|
4a1812fd |
|
a35decfc |
namespace
{
dual_control initialize()
{
dual_control_configuration configuration;
pwd pwd (pwd::create());
unistd unistd (unistd::create());
directory directory (directory::create (unistd, pwd));
fstreams fstreams (fstreams::create());
|
194e6869 |
sys_time time (sys_time::get());
int code_digits = 6;
|
e57144d3 |
totp_generator generator = totp_generator (time, code_digits);
|
6f186fa4 |
random_source rand (random_source::create (fstreams));
tokens tokens (tokens::create (fstreams, generator, rand));
|
21e4960f |
validator validator (validator::create (directory, tokens, unistd));
|
a35decfc |
pam pam (pam::create());
conversation conversation (conversation::create (pam));
sys_syslog sys_syslog (sys_syslog::create());
logger logger (logger::create (sys_syslog));
|
af675d2b |
sessions sessions (sessions::create (pam));
|
a35decfc |
configuration.validator = validator;
configuration.logger = logger;
configuration.conversation = conversation;
|
f30736f9 |
configuration.sessions = sessions;
|
a35decfc |
return dual_control::create (configuration);
}
dual_control dc = initialize();
|
58902985 |
}
|
4a1812fd |
|
b017a4d2 |
PAM_EXTERN int pam_sm_authenticate (pam_handle_t *pamh, int flags, int argc,
const char **argv)
|
cdf7fd74 |
{
|
a4148e9b |
return dc.authenticate (pam_request (pamh, flags, argc, argv));
|
4a1812fd |
}
|
b017a4d2 |
PAM_EXTERN int pam_sm_setcred (pam_handle_t *pamh, int flags, int argc,
const char **argv)
|
cdf7fd74 |
{
|
a4148e9b |
return dc.setcred (pam_request ( pamh, flags, argc, argv));
|
4a1812fd |
}
|
0d8b9a17 |
|