imap-settings.c revision 13eb655174f3857b38f4e3ac8658c82184715fd4
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include "lib.h"
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include "buffer.h"
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include "settings-parser.h"
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include "service-settings.h"
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include "mail-storage-settings.h"
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include "imap-settings.h"
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include <stddef.h>
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include <stdlib.h>
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#include <unistd.h>
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekstatic bool imap_settings_verify(void *_set, pool_t pool,
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek const char **error_r);
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek/* <settings checks> */
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekstatic struct file_listener_settings imap_unix_listeners_array[] = {
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek { "login/imap", 0666, "", "" }
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek};
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekstatic struct file_listener_settings *imap_unix_listeners[] = {
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek &imap_unix_listeners_array[0]
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek};
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekstatic buffer_t imap_unix_listeners_buf = {
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek imap_unix_listeners, sizeof(imap_unix_listeners), { 0, }
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek};
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek/* </settings checks> */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastruct service_settings imap_service_settings = {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .name = "imap",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .protocol = "imap",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .type = "",
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek .executable = "imap",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .user = "",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .group = "",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .privileged_group = "",
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek .extra_groups = "",
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek .chroot = "",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .drop_priv_before_exec = FALSE,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .process_min_avail = 0,
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek .process_limit = 1024,
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek .client_limit = 1,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .service_count = 1,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .idle_kill = 0,
919cfb623e9b725eaa654c6e1b513d1305057314Jakub Hrozek .vsz_limit = (uoff_t)-1,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .unix_listeners = { { &imap_unix_listeners_buf,
919cfb623e9b725eaa654c6e1b513d1305057314Jakub Hrozek sizeof(imap_unix_listeners[0]) } },
919cfb623e9b725eaa654c6e1b513d1305057314Jakub Hrozek .fifo_listeners = ARRAY_INIT,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .inet_listeners = ARRAY_INIT
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov#undef DEF
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina#undef DEFLIST
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek#define DEF(type, name) \
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek { type, #name, offsetof(struct imap_settings, name), NULL }
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina#define DEFLIST(field, name, defines) \
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina { SET_DEFLIST, name, offsetof(struct imap_settings, field), defines }
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastatic const struct setting_define imap_setting_defines[] = {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_BOOL, verbose_proctitle),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_SIZE, imap_max_line_length),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_TIME, imap_idle_notify_interval),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_STR, imap_capability),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_STR, imap_client_workarounds),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_STR, imap_logout_format),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_STR, imap_id_send),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_STR, imap_id_log),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_STR, imap_urlauth_host),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEF(SET_UINT, imap_urlauth_port),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina SETTING_DEFINE_LIST_END
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastatic const struct imap_settings imap_default_settings = {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .verbose_proctitle = FALSE,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* RFC-2683 recommends at least 8000 bytes. Some clients however don't
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina break large message sets to multiple commands, so we're pretty
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina liberal by default. */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_max_line_length = 64*1024,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_idle_notify_interval = 2*60,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_capability = "",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_client_workarounds = "",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_logout_format = "in=%i out=%o",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_id_send = "name *",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_id_log = "",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .imap_urlauth_host = "",
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek .imap_urlauth_port = 143
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekstatic const struct setting_parser_info *imap_setting_dependencies[] = {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina &mail_user_setting_parser_info,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina NULL
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinaconst struct setting_parser_info imap_setting_parser_info = {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .module_name = "imap",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .defines = imap_setting_defines,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .defaults = &imap_default_settings,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .type_offset = (size_t)-1,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .struct_size = sizeof(struct imap_settings),
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .parent_offset = (size_t)-1,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .check_func = imap_settings_verify,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina .dependencies = imap_setting_dependencies
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina/* <settings checks> */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastruct imap_client_workaround_list {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina const char *name;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina enum imap_client_workarounds num;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastatic const struct imap_client_workaround_list imap_client_workaround_list[] = {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina { "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina { "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina { "tb-lsub-flags", WORKAROUND_TB_LSUB_FLAGS },
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina { NULL, 0 }
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina};
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastatic int
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinaimap_settings_parse_workarounds(struct imap_settings *set,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina const char **error_r)
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina{
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina enum imap_client_workarounds client_workarounds = 0;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina const struct imap_client_workaround_list *list;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina const char *const *str;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina for (; *str != NULL; str++) {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina list = imap_client_workaround_list;
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek for (; list->name != NULL; list++) {
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek if (strcasecmp(*str, list->name) == 0) {
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek client_workarounds |= list->num;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina break;
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek }
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina }
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina if (list->name == NULL) {
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina *error_r = t_strdup_printf("imap_client_workarounds: "
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek "Unknown workaround: %s", *str);
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek return -1;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina }
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina }
8164714c5c1ca06ed0435db281e0dbe1db80850cJakub Hrozek set->parsed_workarounds = client_workarounds;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina return 0;
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek}
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březinastatic bool
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekimap_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek{
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek struct imap_settings *set = _set;
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina if (imap_settings_parse_workarounds(set, error_r) < 0)
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina return FALSE;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina return TRUE;
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina}
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina/* </settings checks> */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina