login-settings.c revision 0266a571e98246e2e1b9dd7fe0301e21e226929a
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic bool login_settings_check(void *_set, pool_t pool, const char **error_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen { type, #name, offsetof(struct login_settings, name), NULL }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct setting_define login_setting_defines[] = {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstatic struct login_settings login_default_settings = {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MEMBER(login_log_format_elements) "user=<%u> method=%m rip=%r lip=%l %c",
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen MEMBER(ssl_parameters_file) "ssl-parameters.dat",
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainenstruct setting_parser_info login_setting_parser_info = {
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MEMBER(struct_size) sizeof(struct login_settings),
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen/* <settings checks> */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenstatic int ssl_settings_check(void *_set ATTR_UNUSED, const char **error_r)
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen *error_r = t_strdup_printf("SSL support not compiled in but ssl=%s",
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen *error_r = "ssl enabled, but ssl_cert not set";
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen *error_r = "ssl enabled, but ssl_key not set";
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen if (set->ssl_verify_client_cert && *set->ssl_ca_file == '\0') {
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen *error_r = "ssl_verify_client_cert set, but ssl_ca_file not";
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (*set->ssl_ca_file != '\0' && access(set->ssl_ca_file, R_OK) < 0) {
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen *error_r = t_strdup_printf("ssl_ca_file: access(%s) failed: %m",
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainenstatic bool login_settings_check(void *_set, pool_t pool, const char **error_r)
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen p_strsplit(pool, set->login_log_format_elements, " ");
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (set->ssl_require_client_cert || set->ssl_username_from_cert) {
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* if we require valid cert, make sure we also ask for it */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen *error_r = "login_max_connections must be at least 1";
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* disabled */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen } else if (strcmp(set->ssl, "required") == 0) {
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen *error_r = t_strdup_printf("Unknown ssl setting value: %s",
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen/* </settings checks> */
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainenlogin_settings_read(struct master_service *service, pool_t pool,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen static const struct setting_parser_info *set_roots[] = {
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* this function always clears the previous settings pool. since we're
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen doing per-connection lookups, we always need to duplicate the
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen settings using another pool. */
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen if (master_service_settings_read(service, &input, &error) < 0)
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen i_fatal("Error reading configuration: %s", error);
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen sets = master_service_settings_get_others(service);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen set = settings_dup(&login_setting_parser_info, sets[0], pool);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_fatal("login_settings_check() failed: %s", error);