bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "lib.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "array.h"
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi#include "hash-method.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "settings-parser.h"
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen#include "master-service-private.h"
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include "master-service-settings.h"
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen#include "service-settings.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "auth-settings.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include <stddef.h>
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainenstatic bool auth_settings_check(void *_set, pool_t pool, const char **error_r);
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainenstatic bool auth_passdb_settings_check(void *_set, pool_t pool, const char **error_r);
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainenstatic bool auth_userdb_settings_check(void *_set, pool_t pool, const char **error_r);
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen/* <settings checks> */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstatic struct file_listener_settings auth_unix_listeners_array[] = {
daa7e7459749ae8f82cd3eed9c44522d81c609a3Timo Sirainen { "login/login", 0666, "", "" },
46ec5983bf4519ea42dbfcae3d7c62be0d8ef95fTimo Sirainen { "token-login/tokenlogin", 0666, "", "" },
bbadd5331f534017cf62d5183003b3d9fdad079eTimo Sirainen { "auth-login", 0600, "$default_internal_user", "" },
6523f54d1521edf894880f2d45e75cef5dd31c3dTimo Sirainen { "auth-client", 0600, "$default_internal_user", "" },
72f5f2c5c6905b5d3f389b424313e2c450dfad96Timo Sirainen { "auth-userdb", 0666, "$default_internal_user", "" },
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen { "auth-master", 0600, "", "" }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstatic struct file_listener_settings *auth_unix_listeners[] = {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen &auth_unix_listeners_array[0],
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen &auth_unix_listeners_array[1],
373492be949e159fda651807b3acda2c5c077027Timo Sirainen &auth_unix_listeners_array[2],
bbadd5331f534017cf62d5183003b3d9fdad079eTimo Sirainen &auth_unix_listeners_array[3],
ab90f702ceedb7ba445a9a592be0b213b27cbafaStephan Bosch &auth_unix_listeners_array[4],
ab90f702ceedb7ba445a9a592be0b213b27cbafaStephan Bosch &auth_unix_listeners_array[5]
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstatic buffer_t auth_unix_listeners_buf = {
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody auth_unix_listeners, sizeof(auth_unix_listeners), { NULL, }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen/* </settings checks> */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstruct service_settings auth_service_settings = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .name = "auth",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .protocol = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .type = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .executable = "auth",
635df5b4cbcd7b24c825e01d9dd66d3a4274c4c7Timo Sirainen .user = "$default_internal_user",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .group = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .privileged_group = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .extra_groups = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .chroot = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .drop_priv_before_exec = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .process_min_avail = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .process_limit = 1,
51fb710488efa419a2964335c30451c62b9633b1Timo Sirainen .client_limit = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .service_count = 0,
93a7d1ee4b518b5c85f9721dc6539e4dab6aae00Timo Sirainen .idle_kill = 0,
f7f25f9e1a38678d0e97d2e609beac16285fac6bTimo Sirainen .vsz_limit = (uoff_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .unix_listeners = { { &auth_unix_listeners_buf,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen sizeof(auth_unix_listeners[0]) } },
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .fifo_listeners = ARRAY_INIT,
35fcdde46a71ac151c2518d48c841019f1181bb2Timo Sirainen .inet_listeners = ARRAY_INIT,
35fcdde46a71ac151c2518d48c841019f1181bb2Timo Sirainen
35fcdde46a71ac151c2518d48c841019f1181bb2Timo Sirainen .process_limit_1 = TRUE
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen/* <settings checks> */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstatic struct file_listener_settings auth_worker_unix_listeners_array[] = {
635df5b4cbcd7b24c825e01d9dd66d3a4274c4c7Timo Sirainen { "auth-worker", 0600, "$default_internal_user", "" }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstatic struct file_listener_settings *auth_worker_unix_listeners[] = {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen &auth_worker_unix_listeners_array[0]
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstatic buffer_t auth_worker_unix_listeners_buf = {
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody auth_worker_unix_listeners, sizeof(auth_worker_unix_listeners), { NULL, }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen/* </settings checks> */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenstruct service_settings auth_worker_service_settings = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .name = "auth-worker",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .protocol = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .type = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .executable = "auth -w",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .user = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .group = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .privileged_group = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .extra_groups = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .chroot = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .drop_priv_before_exec = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .process_min_avail = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .process_limit = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .client_limit = 1,
ba8498efbf886ca8b69fdb20c0ba2f5dba9416e3Timo Sirainen .service_count = 1,
93a7d1ee4b518b5c85f9721dc6539e4dab6aae00Timo Sirainen .idle_kill = 0,
f7f25f9e1a38678d0e97d2e609beac16285fac6bTimo Sirainen .vsz_limit = (uoff_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .unix_listeners = { { &auth_worker_unix_listeners_buf,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen sizeof(auth_worker_unix_listeners[0]) } },
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .fifo_listeners = ARRAY_INIT,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .inet_listeners = ARRAY_INIT
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#undef DEF
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#define DEF(type, name) \
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen { type, #name, offsetof(struct auth_passdb_settings, name), NULL }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_define auth_passdb_setting_defines[] = {
544a727de8ab0e6c55cab18a7ee475fffdf5eff3Timo Sirainen DEF(SET_STR, name),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, driver),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, args),
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen DEF(SET_STR, default_fields),
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen DEF(SET_STR, override_fields),
10f6f2224c897fc543973efd2f46b86a3ab1148dAki Tuomi DEF(SET_STR, mechanisms),
268a76700330d159c805c70d1e3eae2e21f1cb9eAki Tuomi DEF(SET_STR, username_filter),
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen DEF(SET_ENUM, skip),
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen DEF(SET_ENUM, result_success),
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen DEF(SET_ENUM, result_failure),
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen DEF(SET_ENUM, result_internalfail),
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, deny),
380dbb60ae291cbe39d1f710284562ca9167150bTimo Sirainen DEF(SET_BOOL, pass),
380dbb60ae291cbe39d1f710284562ca9167150bTimo Sirainen DEF(SET_BOOL, master),
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen DEF(SET_ENUM, auth_verbose),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen SETTING_DEFINE_LIST_END
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
1b823b2b7790a1e1b7974fcf11a4c48a28e70f37Timo Sirainenstatic const struct auth_passdb_settings auth_passdb_default_settings = {
544a727de8ab0e6c55cab18a7ee475fffdf5eff3Timo Sirainen .name = "",
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen .driver = "",
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen .args = "",
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen .default_fields = "",
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen .override_fields = "",
10f6f2224c897fc543973efd2f46b86a3ab1148dAki Tuomi .mechanisms = "",
268a76700330d159c805c70d1e3eae2e21f1cb9eAki Tuomi .username_filter = "",
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen .skip = "never:authenticated:unauthenticated",
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen .result_success = "return-ok:return:return-fail:continue:continue-ok:continue-fail",
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen .result_failure = "continue:return:return-ok:return-fail:continue-ok:continue-fail",
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen .result_internalfail = "continue:return:return-ok:return-fail:continue-ok:continue-fail",
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen .deny = FALSE,
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen .pass = FALSE,
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen .master = FALSE,
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen .auth_verbose = "default:yes:no"
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen};
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenconst struct setting_parser_info auth_passdb_setting_parser_info = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defines = auth_passdb_setting_defines,
1b823b2b7790a1e1b7974fcf11a4c48a28e70f37Timo Sirainen .defaults = &auth_passdb_default_settings,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
544a727de8ab0e6c55cab18a7ee475fffdf5eff3Timo Sirainen .type_offset = offsetof(struct auth_passdb_settings, name),
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .struct_size = sizeof(struct auth_passdb_settings),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .parent_offset = (size_t)-1,
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen .parent = &auth_setting_parser_info,
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen .check_func = auth_passdb_settings_check
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#undef DEF
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#define DEF(type, name) \
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen { type, #name, offsetof(struct auth_userdb_settings, name), NULL }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_define auth_userdb_setting_defines[] = {
544a727de8ab0e6c55cab18a7ee475fffdf5eff3Timo Sirainen DEF(SET_STR, name),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, driver),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, args),
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen DEF(SET_STR, default_fields),
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen DEF(SET_STR, override_fields),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen DEF(SET_ENUM, skip),
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen DEF(SET_ENUM, result_success),
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen DEF(SET_ENUM, result_failure),
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen DEF(SET_ENUM, result_internalfail),
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen DEF(SET_ENUM, auth_verbose),
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen SETTING_DEFINE_LIST_END
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
1b823b2b7790a1e1b7974fcf11a4c48a28e70f37Timo Sirainenstatic const struct auth_userdb_settings auth_userdb_default_settings = {
74fb6b5a156c5a61bb6ec827089bb142a10547ddTimo Sirainen /* NOTE: when adding fields, update also auth.c:userdb_dummy_set */
544a727de8ab0e6c55cab18a7ee475fffdf5eff3Timo Sirainen .name = "",
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen .driver = "",
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen .args = "",
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen .default_fields = "",
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen .override_fields = "",
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen .skip = "never:found:notfound",
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen .result_success = "return-ok:return:return-fail:continue:continue-ok:continue-fail",
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen .result_failure = "continue:return:return-ok:return-fail:continue-ok:continue-fail",
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen .result_internalfail = "continue:return:return-ok:return-fail:continue-ok:continue-fail",
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen
b484ab4b55b0d5341f2f4dd98a655a75f0bf1275Timo Sirainen .auth_verbose = "default:yes:no"
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen};
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenconst struct setting_parser_info auth_userdb_setting_parser_info = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defines = auth_userdb_setting_defines,
1b823b2b7790a1e1b7974fcf11a4c48a28e70f37Timo Sirainen .defaults = &auth_userdb_default_settings,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
544a727de8ab0e6c55cab18a7ee475fffdf5eff3Timo Sirainen .type_offset = offsetof(struct auth_userdb_settings, name),
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .struct_size = sizeof(struct auth_userdb_settings),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .parent_offset = (size_t)-1,
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen .parent = &auth_setting_parser_info,
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen .check_func = auth_userdb_settings_check
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
57d2429fae575e96ca276355af675deb66b76d00Timo Sirainen/* we're kind of kludging here to avoid "auth_" prefix in the struct fields */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#undef DEF
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen#undef DEF_NOPREFIX
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#undef DEFLIST
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#define DEF(type, name) \
57d2429fae575e96ca276355af675deb66b76d00Timo Sirainen { type, "auth_"#name, offsetof(struct auth_settings, name), NULL }
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen#define DEF_NOPREFIX(type, name) \
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen { type, #name, offsetof(struct auth_settings, name), NULL }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#define DEFLIST(field, name, defines) \
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen { SET_DEFLIST, name, offsetof(struct auth_settings, field), defines }
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_define auth_setting_defines[] = {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, mechanisms),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, realms),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, default_realm),
61618d4c58080570f689614fec204ae14e90cef2Timo Sirainen DEF(SET_SIZE, cache_size),
50e20db49f29917fe9adcf1b56b11badf28bd0e4Timo Sirainen DEF(SET_TIME, cache_ttl),
50e20db49f29917fe9adcf1b56b11badf28bd0e4Timo Sirainen DEF(SET_TIME, cache_negative_ttl),
e42b74025f8d02ee7aa476897a3f44e25bb8fc10Aki Tuomi DEF(SET_BOOL, cache_verify_password_with_worker),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, username_chars),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, username_translation),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, username_format),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, master_user_separator),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, anonymous_username),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, krb5_keytab),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, gssapi_hostname),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_STR, winbind_helper_path),
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen DEF(SET_STR, proxy_self),
50e20db49f29917fe9adcf1b56b11badf28bd0e4Timo Sirainen DEF(SET_TIME, failure_delay),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_STR, policy_server_url),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_STR, policy_server_api_header),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_UINT, policy_server_timeout_msecs),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_STR, policy_hash_mech),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_STR, policy_hash_nonce),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_STR, policy_request_attributes),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_BOOL, policy_reject_on_fail),
41ff6e6a4a085786d4c15a58c7c50a28e2110c3fAki Tuomi DEF(SET_BOOL, policy_check_before_auth),
41ff6e6a4a085786d4c15a58c7c50a28e2110c3fAki Tuomi DEF(SET_BOOL, policy_check_after_auth),
41ff6e6a4a085786d4c15a58c7c50a28e2110c3fAki Tuomi DEF(SET_BOOL, policy_report_after_auth),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi DEF(SET_UINT, policy_hash_truncate),
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen DEF(SET_BOOL, stats),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, verbose),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, debug),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, debug_passwords),
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen DEF(SET_STR, verbose_passwords),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, ssl_require_client_cert),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, ssl_username_from_cert),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_BOOL, use_winbind),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEF(SET_UINT, worker_max_count),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEFLIST(passdbs, "passdb", &auth_passdb_setting_parser_info),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen DEFLIST(userdbs, "userdb", &auth_userdb_setting_parser_info),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
1da01eaa962be13cee75771064e2256b1a82d90aTimo Sirainen DEF_NOPREFIX(SET_STR, base_dir),
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen DEF_NOPREFIX(SET_BOOL, verbose_proctitle),
f01eb1f51d618633c0189be9ab60a774f47fb7dfTimo Sirainen DEF_NOPREFIX(SET_UINT, first_valid_uid),
f01eb1f51d618633c0189be9ab60a774f47fb7dfTimo Sirainen DEF_NOPREFIX(SET_UINT, last_valid_uid),
ca5b3ec5331545b46ec1f1c4ecfa1302ddb10653Timo Sirainen DEF_NOPREFIX(SET_UINT, first_valid_gid),
ca5b3ec5331545b46ec1f1c4ecfa1302ddb10653Timo Sirainen DEF_NOPREFIX(SET_UINT, last_valid_gid),
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen
317689976ad393ab9eb78e7d9399fe3d899912adAki Tuomi DEF_NOPREFIX(SET_STR, ssl_client_ca_dir),
317689976ad393ab9eb78e7d9399fe3d899912adAki Tuomi DEF_NOPREFIX(SET_STR, ssl_client_ca_file),
317689976ad393ab9eb78e7d9399fe3d899912adAki Tuomi
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen SETTING_DEFINE_LIST_END
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct auth_settings auth_default_settings = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .mechanisms = "plain",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .realms = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .default_realm = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .cache_size = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .cache_ttl = 60*60,
f2df3069766c747cbf020fea5d3a4261949064b0Timo Sirainen .cache_negative_ttl = 60*60,
e42b74025f8d02ee7aa476897a3f44e25bb8fc10Aki Tuomi .cache_verify_password_with_worker = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .username_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .username_translation = "",
062ea54b7775d0c92ed67b9b1f4d93fa8ec80c84Timo Sirainen .username_format = "%Lu",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .master_user_separator = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .anonymous_username = "anonymous",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .krb5_keytab = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .gssapi_hostname = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .winbind_helper_path = "/usr/bin/ntlm_auth",
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen .proxy_self = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .failure_delay = 2,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_server_url = "",
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_server_api_header = "",
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_server_timeout_msecs = 2000,
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_hash_mech = "sha256",
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_hash_nonce = "",
31cc2948968dd56af45be1571e2e425f58e7e159Aki Tuomi .policy_request_attributes = "login=%{requested_username} pwhash=%{hashed_password} remote=%{rip} device_id=%{client_id} protocol=%s",
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_reject_on_fail = FALSE,
41ff6e6a4a085786d4c15a58c7c50a28e2110c3fAki Tuomi .policy_check_before_auth = TRUE,
41ff6e6a4a085786d4c15a58c7c50a28e2110c3fAki Tuomi .policy_check_after_auth = TRUE,
41ff6e6a4a085786d4c15a58c7c50a28e2110c3fAki Tuomi .policy_report_after_auth = TRUE,
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi .policy_hash_truncate = 12,
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen .stats = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .verbose = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .debug = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .debug_passwords = FALSE,
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen .verbose_passwords = "no",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .ssl_require_client_cert = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .ssl_username_from_cert = FALSE,
317689976ad393ab9eb78e7d9399fe3d899912adAki Tuomi .ssl_client_ca_dir = "",
317689976ad393ab9eb78e7d9399fe3d899912adAki Tuomi .ssl_client_ca_file = "",
317689976ad393ab9eb78e7d9399fe3d899912adAki Tuomi
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .use_winbind = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .worker_max_count = 30,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .passdbs = ARRAY_INIT,
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen .userdbs = ARRAY_INIT,
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen
1da01eaa962be13cee75771064e2256b1a82d90aTimo Sirainen .base_dir = PKG_RUNDIR,
f01eb1f51d618633c0189be9ab60a774f47fb7dfTimo Sirainen .verbose_proctitle = FALSE,
f01eb1f51d618633c0189be9ab60a774f47fb7dfTimo Sirainen .first_valid_uid = 500,
f01eb1f51d618633c0189be9ab60a774f47fb7dfTimo Sirainen .last_valid_uid = 0,
ca5b3ec5331545b46ec1f1c4ecfa1302ddb10653Timo Sirainen .first_valid_gid = 1,
ca5b3ec5331545b46ec1f1c4ecfa1302ddb10653Timo Sirainen .last_valid_gid = 0,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenconst struct setting_parser_info auth_setting_parser_info = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .module_name = "auth",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defines = auth_setting_defines,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defaults = &auth_default_settings,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .type_offset = (size_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .struct_size = sizeof(struct auth_settings),
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .parent_offset = (size_t)-1,
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .check_func = auth_settings_check
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen};
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen/* <settings checks> */
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainenstatic bool
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainenauth_settings_set_self_ips(struct auth_settings *set, pool_t pool,
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen const char **error_r)
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen{
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen const char *const *tmp;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct ip_addr) ips_array;
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen struct ip_addr *ips;
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen unsigned int ips_count;
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen int ret;
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen if (*set->proxy_self == '\0') {
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen set->proxy_self_ips = p_new(pool, struct ip_addr, 1);
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen return TRUE;
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen }
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen p_array_init(&ips_array, pool, 4);
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen tmp = t_strsplit_spaces(set->proxy_self, " ");
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen for (; *tmp != NULL; tmp++) {
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen ret = net_gethostbyname(*tmp, &ips, &ips_count);
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen if (ret != 0) {
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen *error_r = t_strdup_printf("auth_proxy_self_ips: "
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen "gethostbyname(%s) failed: %s",
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen *tmp, net_gethosterror(ret));
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen }
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen array_append(&ips_array, ips, ips_count);
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen }
31a574fda352ef4f71dbff9c30e15e4744e132c0Timo Sirainen array_append_zero(&ips_array);
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen set->proxy_self_ips = array_idx(&ips_array, 0);
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen return TRUE;
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen}
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainenstatic bool
3190f12fb96daf61f7c880390472e18184cbb2d8Timo Sirainenauth_verify_verbose_password(struct auth_settings *set,
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen const char **error_r)
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen{
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen const char *p, *value = set->verbose_passwords;
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen unsigned int num;
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen p = strchr(value, ':');
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen if (p != NULL) {
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen if (str_to_uint(p+1, &num) < 0 || num == 0) {
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen *error_r = t_strdup_printf("auth_verbose_passwords: "
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen "Invalid truncation number: '%s'", p+1);
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen return FALSE;
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen }
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen value = t_strdup_until(value, p);
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen }
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen if (strcmp(value, "no") == 0)
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen return TRUE;
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen else if (strcmp(value, "plain") == 0)
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen return TRUE;
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen else if (strcmp(value, "sha1") == 0)
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen return TRUE;
3190f12fb96daf61f7c880390472e18184cbb2d8Timo Sirainen else if (strcmp(value, "yes") == 0) {
3190f12fb96daf61f7c880390472e18184cbb2d8Timo Sirainen /* just use it as alias for "plain" */
3190f12fb96daf61f7c880390472e18184cbb2d8Timo Sirainen set->verbose_passwords = "plain";
3190f12fb96daf61f7c880390472e18184cbb2d8Timo Sirainen return TRUE;
3190f12fb96daf61f7c880390472e18184cbb2d8Timo Sirainen } else {
a5bcc9f96bf56121a0704433c12137a43cd093beTimo Sirainen *error_r = "auth_verbose_passwords: Invalid value";
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen return FALSE;
a5bcc9f96bf56121a0704433c12137a43cd093beTimo Sirainen }
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen}
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainenstatic bool auth_settings_check(void *_set, pool_t pool,
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen const char **error_r)
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen{
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen struct auth_settings *set = _set;
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen const char *p;
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen if (set->debug_passwords)
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen set->debug = TRUE;
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen if (set->debug)
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen set->verbose = TRUE;
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen if (set->worker_max_count == 0) {
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen *error_r = "auth_worker_max_count must be above zero";
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen return FALSE;
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen }
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen
6bd263caf006edc75205f446fa0283c6f364941bTimo Sirainen if (set->cache_size > 0 && set->cache_size < 1024) {
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen /* probably a configuration error.
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen older versions used megabyte numbers */
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen *error_r = t_strdup_printf("auth_cache_size value is too small "
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen "(%"PRIuUOFF_T" bytes)",
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen set->cache_size);
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen return FALSE;
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen }
4fc74bba3548987b7e8597491cd9fafc1f701be6Timo Sirainen
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen if (!auth_verify_verbose_password(set, error_r))
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen return FALSE;
4addfd26372c6ae32ec93252696d86fd32081327Timo Sirainen
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen if (*set->username_chars == '\0') {
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen /* all chars are allowed */
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen memset(set->username_chars_map, 1,
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen sizeof(set->username_chars_map));
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen } else {
0f62889d833767acf9c2ad010c3269806b4cfae3Timo Sirainen for (p = set->username_chars; *p != '\0'; p++)
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen set->username_chars_map[(int)(uint8_t)*p] = 1;
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen }
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen if (*set->username_translation != '\0') {
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen p = set->username_translation;
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen for (; *p != '\0' && p[1] != '\0'; p += 2)
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen set->username_translation_map[(int)(uint8_t)*p] = p[1];
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen }
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen set->realms_arr =
7289c5600711b45f30fe289ab5b0293b51d87041Timo Sirainen (const char *const *)p_strsplit_spaces(pool, set->realms, " ");
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi if (*set->policy_server_url != '\0') {
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi if (*set->policy_hash_nonce == '\0') {
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi *error_r = "auth_policy_hash_nonce must be set when policy server is used";
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi return FALSE;
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi }
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi const struct hash_method *digest = hash_method_lookup(set->policy_hash_mech);
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi if (digest == NULL) {
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi *error_r = "invalid auth_policy_hash_mech given";
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi return FALSE;
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi }
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi if (set->policy_hash_truncate > 0 && set->policy_hash_truncate >= digest->digest_size*8) {
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi *error_r = t_strdup_printf("policy_hash_truncate is not smaller than digest size (%u >= %u)",
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi set->policy_hash_truncate,
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi digest->digest_size*8);
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi return FALSE;
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi }
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi }
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen if (!auth_settings_set_self_ips(set, pool, error_r))
738cfeb96c4b9cd92aa3c791d77734c2745cdd1aTimo Sirainen return FALSE;
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen return TRUE;
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen}
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainenstatic bool
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainenauth_passdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen const char **error_r)
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen{
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen struct auth_passdb_settings *set = _set;
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen if (set->driver == NULL || *set->driver == '\0') {
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen *error_r = "passdb is missing driver";
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen return FALSE;
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen }
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen if (set->pass && strcmp(set->result_success, "return-ok") != 0) {
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen *error_r = "Obsolete pass=yes setting mixed with non-default result_success";
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen return FALSE;
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen }
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen return TRUE;
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen}
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainenstatic bool
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainenauth_userdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen const char **error_r)
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen{
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen struct auth_userdb_settings *set = _set;
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen if (set->driver == NULL || *set->driver == '\0') {
272aca0a772140d3a45a425a3fd67854ae2ccec2Timo Sirainen *error_r = "userdb is missing driver";
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen return FALSE;
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen }
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen return TRUE;
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen}
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen/* </settings checks> */
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen
1d22eaac93de41319918a1fc6de42bb302e25c1aTimo Sirainenstruct auth_settings *global_auth_settings;
1d22eaac93de41319918a1fc6de42bb302e25c1aTimo Sirainen
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainenstruct auth_settings *
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainenauth_settings_read(const char *service, pool_t pool,
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen struct master_service_settings_output *output_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen{
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen static const struct setting_parser_info *set_roots[] = {
2024157e8de36edd31f5fd72f5ea7364a0955fa7Timo Sirainen &auth_setting_parser_info,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen NULL
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen };
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct master_service_settings_input input;
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen struct setting_parser_context *set_parser;
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen const char *error;
32b78da5dfbbf6a06b3dbdc9278c60b55714f9bcTimo Sirainen void **sets;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&input);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen input.roots = set_roots;
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen input.module = "auth";
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen input.service = service;
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen if (master_service_settings_read(master_service, &input,
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen output_r, &error) < 0)
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen i_fatal("Error reading configuration: %s", error);
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen
e9371f899a3d4207a0ffd3923ea5ec7250cf5e75Timo Sirainen pool_ref(pool);
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen set_parser = settings_parser_dup(master_service->set_parser, pool);
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen if (!settings_parser_check(set_parser, pool, &error))
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen i_unreached();
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen
32b78da5dfbbf6a06b3dbdc9278c60b55714f9bcTimo Sirainen sets = master_service_settings_parser_get_others(master_service,
32b78da5dfbbf6a06b3dbdc9278c60b55714f9bcTimo Sirainen set_parser);
e9371f899a3d4207a0ffd3923ea5ec7250cf5e75Timo Sirainen settings_parser_deinit(&set_parser);
32b78da5dfbbf6a06b3dbdc9278c60b55714f9bcTimo Sirainen return sets[0];
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen}