auth-settings.c revision 31a574fda352ef4f71dbff9c30e15e4744e132c0
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#include "lib.h"
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#include "array.h"
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#include "settings-parser.h"
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#include "master-service-private.h"
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#include "master-service-settings.h"
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#include "service-settings.h"
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#include "auth-settings.h"
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen#include <stddef.h>
a1607f6001a9949e1cf9d49eb0aa936dbb4c77ffTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic bool auth_settings_check(void *_set, pool_t pool, const char **error_r);
00d58fcfe8191d6ce7efa801d289a5c0fe88d1aeTimo Sirainenstatic bool auth_passdb_settings_check(void *_set, pool_t pool, const char **error_r);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic bool auth_userdb_settings_check(void *_set, pool_t pool, const char **error_r);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen/* <settings checks> */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic struct file_listener_settings auth_unix_listeners_array[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { "login/login", 0666, "", "" },
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { "auth-login", 0600, "$default_internal_user", "" },
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { "auth-client", 0600, "", "" },
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen { "auth-userdb", 0666, "$default_internal_user", "" },
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen { "auth-master", 0600, "", "" }
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstatic struct file_listener_settings *auth_unix_listeners[] = {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen &auth_unix_listeners_array[0],
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen &auth_unix_listeners_array[1],
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen &auth_unix_listeners_array[2],
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen &auth_unix_listeners_array[3],
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen &auth_unix_listeners_array[4]
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstatic buffer_t auth_unix_listeners_buf = {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen auth_unix_listeners, sizeof(auth_unix_listeners), { 0, }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* </settings checks> */
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstruct service_settings auth_service_settings = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .name = "auth",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .protocol = "",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .type = "",
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen .executable = "auth",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .user = "$default_internal_user",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .group = "",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .privileged_group = "",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .extra_groups = "",
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen .chroot = "",
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen .drop_priv_before_exec = FALSE,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .process_min_avail = 0,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .process_limit = 1,
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainen .client_limit = 0,
f6c1297c26b355c4aec2a08978f51ec3efecb351Timo Sirainen .service_count = 0,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen .idle_kill = 0,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen .vsz_limit = (uoff_t)-1,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen .unix_listeners = { { &auth_unix_listeners_buf,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen sizeof(auth_unix_listeners[0]) } },
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .fifo_listeners = ARRAY_INIT,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .inet_listeners = ARRAY_INIT,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .process_limit_1 = TRUE
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* <settings checks> */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic struct file_listener_settings auth_worker_unix_listeners_array[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { "auth-worker", 0600, "$default_internal_user", "" }
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic struct file_listener_settings *auth_worker_unix_listeners[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen &auth_worker_unix_listeners_array[0]
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic buffer_t auth_worker_unix_listeners_buf = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen auth_worker_unix_listeners, sizeof(auth_worker_unix_listeners), { 0, }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* </settings checks> */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstruct service_settings auth_worker_service_settings = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .name = "auth-worker",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .protocol = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .type = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .executable = "auth -w",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .user = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .group = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .privileged_group = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .extra_groups = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .chroot = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .drop_priv_before_exec = FALSE,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .process_min_avail = 0,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .process_limit = 0,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .client_limit = 1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .service_count = 1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .idle_kill = 0,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .vsz_limit = (uoff_t)-1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .unix_listeners = { { &auth_worker_unix_listeners_buf,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen sizeof(auth_worker_unix_listeners[0]) } },
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .fifo_listeners = ARRAY_INIT,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .inet_listeners = ARRAY_INIT
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#undef DEF
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#define DEF(type, name) \
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen { type, #name, offsetof(struct auth_passdb_settings, name), NULL }
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct setting_define auth_passdb_setting_defines[] = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, driver),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, args),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, default_fields),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, override_fields),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_BOOL, deny),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_BOOL, pass),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_BOOL, master),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen SETTING_DEFINE_LIST_END
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct auth_passdb_settings auth_passdb_default_settings = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .driver = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .args = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .default_fields = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .override_fields = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .deny = FALSE,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .pass = FALSE,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .master = FALSE
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenconst struct setting_parser_info auth_passdb_setting_parser_info = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .defines = auth_passdb_setting_defines,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .defaults = &auth_passdb_default_settings,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .type_offset = (size_t)-1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .struct_size = sizeof(struct auth_passdb_settings),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .parent_offset = (size_t)-1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .parent = &auth_setting_parser_info,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .check_func = auth_passdb_settings_check
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#undef DEF
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#define DEF(type, name) \
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen { type, #name, offsetof(struct auth_userdb_settings, name), NULL }
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct setting_define auth_userdb_setting_defines[] = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, driver),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, args),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, default_fields),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen DEF(SET_STR, override_fields),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen SETTING_DEFINE_LIST_END
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct auth_userdb_settings auth_userdb_default_settings = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .driver = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .args = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .default_fields = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .override_fields = ""
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenconst struct setting_parser_info auth_userdb_setting_parser_info = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .defines = auth_userdb_setting_defines,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .defaults = &auth_userdb_default_settings,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .type_offset = (size_t)-1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .struct_size = sizeof(struct auth_userdb_settings),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .parent_offset = (size_t)-1,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .parent = &auth_setting_parser_info,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .check_func = auth_userdb_settings_check
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* we're kind of kludging here to avoid "auth_" prefix in the struct fields */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#undef DEF
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen#undef DEF_NOPREFIX
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen#undef DEFLIST
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#define DEF(type, name) \
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen { type, "auth_"#name, offsetof(struct auth_settings, name), NULL }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#define DEF_NOPREFIX(type, name) \
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen { type, #name, offsetof(struct auth_settings, name), NULL }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#define DEFLIST(field, name, defines) \
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { SET_DEFLIST, name, offsetof(struct auth_settings, field), defines }
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenstatic const struct setting_define auth_setting_defines[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_STR, mechanisms),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_STR, realms),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_STR, default_realm),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_SIZE, cache_size),
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen DEF(SET_TIME, cache_ttl),
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen DEF(SET_TIME, cache_negative_ttl),
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen DEF(SET_STR, username_chars),
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen DEF(SET_STR, username_translation),
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen DEF(SET_STR, username_format),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_STR, master_user_separator),
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen DEF(SET_STR, anonymous_username),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_STR, krb5_keytab),
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen DEF(SET_STR, gssapi_hostname),
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen DEF(SET_STR, winbind_helper_path),
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen DEF(SET_STR, proxy_self),
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen DEF(SET_TIME, failure_delay),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_UINT, first_valid_uid),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_UINT, last_valid_uid),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_BOOL, verbose),
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen DEF(SET_BOOL, debug),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_BOOL, debug_passwords),
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen DEF(SET_ENUM, verbose_passwords),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_BOOL, ssl_require_client_cert),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEF(SET_BOOL, ssl_username_from_cert),
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen DEF(SET_BOOL, use_winbind),
e376e08040b5f21ff79a15ae728d2532a34207f6Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen DEF(SET_UINT, worker_max_count),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEFLIST(passdbs, "passdb", &auth_passdb_setting_parser_info),
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen DEFLIST(userdbs, "userdb", &auth_userdb_setting_parser_info),
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen DEF_NOPREFIX(SET_STR, base_dir),
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen DEF_NOPREFIX(SET_BOOL, verbose_proctitle),
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen SETTING_DEFINE_LIST_END
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen};
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenstatic const struct auth_settings auth_default_settings = {
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .mechanisms = "plain",
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .realms = "",
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .default_realm = "",
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .cache_size = 0,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen .cache_ttl = 60*60,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .cache_negative_ttl = 60*60,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .username_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@",
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen .username_translation = "",
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen .username_format = "%Lu",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .master_user_separator = "",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .anonymous_username = "anonymous",
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen .krb5_keytab = "",
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen .gssapi_hostname = "",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .winbind_helper_path = "/usr/bin/ntlm_auth",
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen .proxy_self = "",
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .failure_delay = 2,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen .first_valid_uid = 500,
783278c012551bc2f25f065a8d3ec1a3cfc0d296Timo Sirainen .last_valid_uid = 0,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen
5d49cbcf87354f0ddf3b71bc5f0cefdc02b14f68Timo Sirainen .verbose = FALSE,
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainen .debug = FALSE,
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen .debug_passwords = FALSE,
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainen .verbose_passwords = "no:plain:sha1",
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainen .ssl_require_client_cert = FALSE,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen .ssl_username_from_cert = FALSE,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen .use_winbind = FALSE,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen .worker_max_count = 30,
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen .passdbs = ARRAY_INIT,
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen .userdbs = ARRAY_INIT,
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen .base_dir = PKG_RUNDIR,
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen .verbose_proctitle = FALSE
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen};
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainenconst struct setting_parser_info auth_setting_parser_info = {
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen .module_name = "auth",
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen .defines = auth_setting_defines,
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .defaults = &auth_default_settings,
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .type_offset = (size_t)-1,
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen .struct_size = sizeof(struct auth_settings),
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen .parent_offset = (size_t)-1,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .check_func = auth_settings_check
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* <settings checks> */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic bool
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenauth_settings_set_self_ips(struct auth_settings *set, pool_t pool,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char **error_r)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen{
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *const *tmp;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen ARRAY_DEFINE(ips_array, struct ip_addr);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct ip_addr *ips;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen unsigned int ips_count;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen int ret;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (*set->proxy_self == '\0') {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen set->proxy_self_ips = p_new(pool, struct ip_addr, 1);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen return TRUE;
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen p_array_init(&ips_array, pool, 4);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen tmp = t_strsplit_spaces(set->proxy_self, " ");
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen for (; *tmp != NULL; tmp++) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen ret = net_gethostbyname(*tmp, &ips, &ips_count);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (ret != 0) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *error_r = t_strdup_printf("auth_proxy_self_ips: "
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen "gethostbyname(%s) failed: %s",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *tmp, net_gethosterror(ret));
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen }
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen array_append(&ips_array, ips, ips_count);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen array_append_zero(&ips_array);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen set->proxy_self_ips = array_idx(&ips_array, 0);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen return TRUE;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen}
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenstatic bool auth_settings_check(void *_set, pool_t pool,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen const char **error_r)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen{
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct auth_settings *set = _set;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen const char *p;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen if (set->debug_passwords)
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen set->debug = TRUE;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen if (set->debug)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen set->verbose = TRUE;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen if (set->worker_max_count == 0) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *error_r = "auth_worker_max_count must be above zero";
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen return FALSE;
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen if (set->cache_size > 0 && set->cache_size < 1024) {
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen /* probably a configuration error.
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen older versions used megabyte numbers */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *error_r = t_strdup_printf("auth_cache_size value is too small "
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen "(%"PRIuUOFF_T" bytes)",
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen set->cache_size);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen return FALSE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen if (*set->username_chars == '\0') {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* all chars are allowed */
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen memset(set->username_chars_map, 1,
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen sizeof(set->username_chars_map));
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen } else {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen for (p = set->username_chars; *p != '\0'; p++)
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen set->username_chars_map[(int)(uint8_t)*p] = 1;
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (*set->username_translation != '\0') {
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen p = set->username_translation;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen for (; *p != '\0' && p[1] != '\0'; p += 2)
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen set->username_translation_map[(int)(uint8_t)*p] = p[1];
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen set->realms_arr =
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen (const char *const *)p_strsplit_spaces(pool, set->realms, " ");
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen if (!auth_settings_set_self_ips(set, pool, error_r))
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen return FALSE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen return TRUE;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen}
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenstatic bool
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenauth_passdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen const char **error_r)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen{
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct auth_passdb_settings *set = _set;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (set->driver == NULL || *set->driver == '\0') {
56963ffad65b860c827553dfaf09fb766cb7e20eTimo Sirainen *error_r = "passdb is missing driver";
56963ffad65b860c827553dfaf09fb766cb7e20eTimo Sirainen return FALSE;
56963ffad65b860c827553dfaf09fb766cb7e20eTimo Sirainen }
56963ffad65b860c827553dfaf09fb766cb7e20eTimo Sirainen return TRUE;
56963ffad65b860c827553dfaf09fb766cb7e20eTimo Sirainen}
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainenstatic bool
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenauth_userdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char **error_r)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen{
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct auth_userdb_settings *set = _set;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen if (set->driver == NULL || *set->driver == '\0') {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen *error_r = "userdb is missing driver";
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen return FALSE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen }
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen return TRUE;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen}
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen/* </settings checks> */
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainenstruct auth_settings *global_auth_settings;
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainenstruct auth_settings *
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenauth_settings_read(const char *service, pool_t pool,
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen struct master_service_settings_output *output_r)
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen{
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen static const struct setting_parser_info *set_roots[] = {
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen &auth_setting_parser_info,
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen NULL
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen };
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen struct master_service_settings_input input;
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen struct setting_parser_context *set_parser;
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen struct auth_settings *set;
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen const char *error;
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen
31a574fda352ef4f71dbff9c30e15e4744e132c0Timo Sirainen memset(&input, 0, sizeof(input));
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen input.roots = set_roots;
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen input.module = "auth";
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen input.service = service;
9514dbd41faad453406fc3a10aca791417a9ce75Timo Sirainen if (master_service_settings_read(master_service, &input,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen output_r, &error) < 0)
9514dbd41faad453406fc3a10aca791417a9ce75Timo Sirainen i_fatal("Error reading configuration: %s", error);
877912710a33c5645c85d6902a0ec6c79fcd0649Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen pool_ref(pool);
20e04227229970d148801c507946666e2a9bd838Timo Sirainen set_parser = settings_parser_dup(master_service->set_parser, pool);
877912710a33c5645c85d6902a0ec6c79fcd0649Timo Sirainen if (!settings_parser_check(set_parser, pool, &error))
eca38954bcf972618f6b85932a3690acbd2b673aTimo Sirainen i_unreached();
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
71748cca1bacd74451fd228db5536828bdfeb190Baofeng Wang set = settings_parser_get_list(set_parser)[1];
b87daa509bf5b306189282a9df795d094a6d7150Timo Sirainen settings_parser_deinit(&set_parser);
b87daa509bf5b306189282a9df795d094a6d7150Timo Sirainen return set;
877912710a33c5645c85d6902a0ec6c79fcd0649Timo Sirainen}
877912710a33c5645c85d6902a0ec6c79fcd0649Timo Sirainen