bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
b5ab29780f74cf88212a547ebbe3b6bc0cb867c5Stephan Bosch
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi#include "test-auth.h"
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi#include "auth-common.h"
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi#include "passdb.h"
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomistruct auth_penalty *auth_penalty;
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomitime_t process_start_time;
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomibool worker, worker_restart_request;
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic struct passdb_module *mock_passdb_mod = NULL;
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomivoid auth_module_load(const char *names ATTR_UNUSED)
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi{
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi}
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomivoid auth_refresh_proctitle(void) {
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi}
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic void passdb_mock_init(struct passdb_module *module ATTR_UNUSED)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi{
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi}
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic void passdb_mock_deinit(struct passdb_module *module ATTR_UNUSED)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi{
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi}
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic void passdb_mock_verify_plain(struct auth_request *request, const char *password ATTR_UNUSED,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi verify_plain_callback_t *callback)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi{
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi callback(PASSDB_RESULT_OK, request);
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi}
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic struct passdb_module_interface mock_interface = {
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .name = "mock",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .init = passdb_mock_init,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .deinit = passdb_mock_deinit,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .verify_plain = passdb_mock_verify_plain,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi};
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic struct auth_passdb_settings set = {
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .name = "mock",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .driver = "mock",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .args = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .default_fields = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .override_fields = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .mechanisms = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .username_filter = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .skip = "never",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .result_success = "return-ok",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .result_failure = "continue",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .result_internalfail = "continue",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .deny = FALSE,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .pass = FALSE,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .master = FALSE,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .auth_verbose = "default"
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi};
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistatic void passdb_mock_mod_init(void)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi{
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi if (mock_passdb_mod != NULL)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi return;
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi passdb_register_module(&mock_interface);
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi struct auth_passdb_settings set = {
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .name = "mock",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .driver = "mock",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .args = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .default_fields = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .override_fields = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .mechanisms = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .username_filter = "",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .skip = "never",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .result_success = "return-ok",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .result_failure = "continue",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .result_internalfail = "continue",
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .deny = FALSE,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .pass = FALSE,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .master = FALSE,
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi .auth_verbose = "default"
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi };
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi mock_passdb_mod = passdb_preinit(default_pool, &set);
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi}
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomistruct auth_passdb *passdb_mock(void)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi{
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi passdb_mock_mod_init();
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi struct auth_passdb *ret = i_new(struct auth_passdb, 1);
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi ret->set = &set;
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi ret->passdb = mock_passdb_mod;
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi return ret;
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi}