settings.c revision ad56ed098867ae42af11132577b9ad3f1c5c17df
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainentypedef enum {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainentypedef struct {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "log_timestamp", SET_STR, &set_log_timestamp },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "imaps_listen", SET_STR, &set_imaps_listen },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "ssl_cert_file", SET_STR, &set_ssl_cert_file },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "ssl_key_file", SET_STR, &set_ssl_key_file },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "ssl_parameters_file",SET_STR, &set_ssl_parameters_file },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "ssl_parameters_regenerate",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "disable_plaintext_auth",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "login_executable", SET_STR, &set_login_executable },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "login_chroot", SET_BOOL,&set_login_chroot },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "login_process_per_connection",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "login_processes_count",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "max_logging_users", SET_INT, &set_max_logging_users },
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen { "imap_executable", SET_STR, &set_imap_executable },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "valid_chroot_dirs", SET_STR, &set_valid_chroot_dirs },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "max_imap_processes", SET_INT, &set_max_imap_processes },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "verbose_proctitle", SET_BOOL,&set_verbose_proctitle },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "first_valid_uid", SET_INT, &set_first_valid_uid },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "last_valid_uid", SET_INT, &set_last_valid_uid },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "first_valid_gid", SET_INT, &set_first_valid_gid },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "last_valid_gid", SET_INT, &set_last_valid_gid },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "mail_cache_fields", SET_STR, &set_mail_cache_fields },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "mail_never_cache_fields",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "mailbox_check_interval",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "mail_save_crlf", SET_BOOL,&set_mail_save_crlf },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "maildir_copy_with_hardlinks",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "maildir_check_content_changes",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen SET_BOOL,&set_maildir_check_content_changes },
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen { "overwrite_incompatible_index",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenchar *set_log_timestamp = DEFAULT_FAILURE_STAMP_FORMAT;
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainenchar *set_ssl_cert_file = "/etc/ssl/certs/imapd.pem";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenchar *set_ssl_key_file = "/etc/ssl/private/imapd.pem";
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainenchar *set_ssl_parameters_file = PKG_RUNDIR"/ssl-parameters.dat";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenunsigned int set_ssl_parameters_regenerate = 24;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenchar *set_login_executable = PKG_LIBDIR "/imap-login";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenunsigned int set_login_max_processes_count = 128;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenuid_t set_login_uid; /* generated from set_login_user */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainengid_t set_login_gid; /* generated from set_login_user */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenchar *set_imap_executable = PKG_LIBDIR "/imap";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenunsigned int set_first_valid_uid = 500, set_last_valid_uid = 0;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenunsigned int set_first_valid_gid = 1, set_last_valid_gid = 0;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic void get_login_uid(void)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("Login user doesn't exist: %s", set_login_user);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen for (auth = auth_processes_config; auth != NULL; auth = auth->next) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen if (auth->chroot != NULL && *auth->chroot != '\0' &&
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("Can't access auth chroot directory %s: %m",
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic void settings_verify(void)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* since they're under /var/run by default, they may have been
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen (void)chown(set_login_dir, set_login_uid, set_login_gid);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("Can't access login directory %s: %m", set_login_dir);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("max_imap_processes must be at least 1");
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("login_processes_count must be at least 1");
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("max_logging_users must be at least 1");
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("first_valid_uid can't be larger than last_valid_uid");
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen i_fatal("first_valid_gid can't be larger than last_valid_gid");
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic AuthConfig *auth_config_new(const char *name)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen auth->executable = i_strdup(PKG_LIBDIR "/imap-auth");
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic const char *parse_new_auth(const char *name)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen return "Authentication process name must not contain '/'";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen for (auth = auth_processes_config; auth != NULL; auth = auth->next) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen return "Authentication process already exists "
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen "with the same name";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic const char *parse_auth(const char *key, const char *value)
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen const char *p;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen return "Authentication process name not defined yet";
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* check the easy string values first */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* split it into userinfo + userinfo_args */
return NULL;
return NULL;
case SET_STR:
case SET_INT:
case SET_BOOL:
return NULL;
static void settings_free(void)
const char *errormsg;
if (fd < 0)
linenum = 0;
linenum++;
line++;
line++;
void settings_init(void)