auth-settings.c revision 31a574fda352ef4f71dbff9c30e15e4744e132c0
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
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);
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen/* <settings checks> */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic struct file_listener_settings auth_unix_listeners_array[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { "auth-login", 0600, "$default_internal_user", "" },
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen { "auth-userdb", 0666, "$default_internal_user", "" },
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstatic struct file_listener_settings *auth_unix_listeners[] = {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen auth_unix_listeners, sizeof(auth_unix_listeners), { 0, }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* </settings checks> */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstruct service_settings auth_service_settings = {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen .unix_listeners = { { &auth_unix_listeners_buf,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* <settings checks> */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic struct file_listener_settings auth_worker_unix_listeners_array[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { "auth-worker", 0600, "$default_internal_user", "" }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic struct file_listener_settings *auth_worker_unix_listeners[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic buffer_t auth_worker_unix_listeners_buf = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen auth_worker_unix_listeners, sizeof(auth_worker_unix_listeners), { 0, }
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* </settings checks> */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstruct service_settings auth_worker_service_settings = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .unix_listeners = { { &auth_worker_unix_listeners_buf,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen { type, #name, offsetof(struct auth_passdb_settings, name), NULL }
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct setting_define auth_passdb_setting_defines[] = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct auth_passdb_settings auth_passdb_default_settings = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenconst struct setting_parser_info auth_passdb_setting_parser_info = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .struct_size = sizeof(struct auth_passdb_settings),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen { type, #name, offsetof(struct auth_userdb_settings, name), NULL }
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct setting_define auth_userdb_setting_defines[] = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstatic const struct auth_userdb_settings auth_userdb_default_settings = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenconst struct setting_parser_info auth_userdb_setting_parser_info = {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen .struct_size = sizeof(struct auth_userdb_settings),
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* we're kind of kludging here to avoid "auth_" prefix in the struct fields */
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen { type, "auth_"#name, offsetof(struct auth_settings, name), NULL }
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen { type, #name, offsetof(struct auth_settings, name), NULL }
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen { SET_DEFLIST, name, offsetof(struct auth_settings, field), defines }
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenstatic const struct setting_define auth_setting_defines[] = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen DEFLIST(passdbs, "passdb", &auth_passdb_setting_parser_info),
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen DEFLIST(userdbs, "userdb", &auth_userdb_setting_parser_info),
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenstatic const struct auth_settings auth_default_settings = {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen .username_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@",
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainenconst struct setting_parser_info auth_setting_parser_info = {
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* <settings checks> */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenauth_settings_set_self_ips(struct auth_settings *set, pool_t pool,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char **error_r)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *const *tmp;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen set->proxy_self_ips = p_new(pool, struct ip_addr, 1);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen tmp = t_strsplit_spaces(set->proxy_self, " ");
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen ret = net_gethostbyname(*tmp, &ips, &ips_count);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *error_r = t_strdup_printf("auth_proxy_self_ips: "
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen "gethostbyname(%s) failed: %s",
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen set->proxy_self_ips = array_idx(&ips_array, 0);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenstatic bool auth_settings_check(void *_set, pool_t pool,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen const char **error_r)
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen const char *p;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen *error_r = "auth_worker_max_count must be above zero";
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 "
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* all chars are allowed */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen for (p = set->username_chars; *p != '\0'; p++)
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen set->username_chars_map[(int)(uint8_t)*p] = 1;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen set->username_translation_map[(int)(uint8_t)*p] = p[1];
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen (const char *const *)p_strsplit_spaces(pool, set->realms, " ");
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen if (!auth_settings_set_self_ips(set, pool, error_r))
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenauth_passdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen const char **error_r)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (set->driver == NULL || *set->driver == '\0') {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenauth_userdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char **error_r)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen if (set->driver == NULL || *set->driver == '\0') {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen/* </settings checks> */
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenauth_settings_read(const char *service, pool_t pool,
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen struct master_service_settings_output *output_r)
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen static const struct setting_parser_info *set_roots[] = {
9514dbd41faad453406fc3a10aca791417a9ce75Timo Sirainen if (master_service_settings_read(master_service, &input,
9514dbd41faad453406fc3a10aca791417a9ce75Timo Sirainen i_fatal("Error reading configuration: %s", error);
20e04227229970d148801c507946666e2a9bd838Timo Sirainen set_parser = settings_parser_dup(master_service->set_parser, pool);