imap-settings.c revision c606578cc0390611803b50f2c8c448541f9755e2
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "lib.h"
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen#include "buffer.h"
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen#include "settings-parser.h"
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen#include "service-settings.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "mail-storage-settings.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "imap-settings.h"
6cc0546c058f3e6253c6f99727b28dd602712974Timo Sirainen
6cc0546c058f3e6253c6f99727b28dd602712974Timo Sirainen#include <stddef.h>
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include <stdlib.h>
6cc0546c058f3e6253c6f99727b28dd602712974Timo Sirainen#include <unistd.h>
6cc0546c058f3e6253c6f99727b28dd602712974Timo Sirainen
6cc0546c058f3e6253c6f99727b28dd602712974Timo Sirainenstatic bool imap_settings_verify(void *_set, pool_t pool,
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainen const char **error_r);
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainen
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainen/* <settings checks> */
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainenstatic struct file_listener_settings imap_unix_listeners_array[] = {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen { "login/imap", 0666, "", "" }
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen};
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainenstatic struct file_listener_settings *imap_unix_listeners[] = {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen &imap_unix_listeners_array[0]
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen};
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainenstatic buffer_t imap_unix_listeners_buf = {
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen imap_unix_listeners, sizeof(imap_unix_listeners), { 0, }
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen};
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen/* </settings checks> */
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen
9b7eeffb5752b500ac62ba1fd01c4a8c4ada14e9Timo Sirainenstruct service_settings imap_service_settings = {
9b7eeffb5752b500ac62ba1fd01c4a8c4ada14e9Timo Sirainen .name = "imap",
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen .protocol = "imap",
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen .type = "",
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen .executable = "imap",
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen .user = "",
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen .group = "",
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen .privileged_group = "",
b565a6a7a66fb9f224d00c06a950e3c1c585c18eTimo Sirainen .extra_groups = "",
b565a6a7a66fb9f224d00c06a950e3c1c585c18eTimo Sirainen .chroot = "",
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen .drop_priv_before_exec = FALSE,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen .process_min_avail = 0,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen .process_limit = 1024,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen .client_limit = 1,
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen .service_count = 1,
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen .vsz_limit = -1U,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen .unix_listeners = { { &imap_unix_listeners_buf,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen sizeof(imap_unix_listeners[0]) } },
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen .fifo_listeners = ARRAY_INIT,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen .inet_listeners = ARRAY_INIT
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen};
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen#undef DEF
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#undef DEFLIST
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen#define DEF(type, name) \
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen { type, #name, offsetof(struct imap_settings, name), NULL }
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen#define DEFLIST(field, name, defines) \
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen { SET_DEFLIST, name, offsetof(struct imap_settings, field), defines }
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainenstatic const struct setting_define imap_setting_defines[] = {
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainen DEF(SET_BOOL, mail_debug),
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainen DEF(SET_BOOL, verbose_proctitle),
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen DEF(SET_SIZE, imap_max_line_length),
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen DEF(SET_TIME, imap_idle_notify_interval),
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen DEF(SET_STR, imap_capability),
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen DEF(SET_STR, imap_client_workarounds),
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen DEF(SET_STR, imap_logout_format),
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen DEF(SET_STR, imap_id_send),
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen DEF(SET_STR, imap_id_log),
683eebe490bbe5caec246c535a10ea9f93f5c330Timo Sirainen
683eebe490bbe5caec246c535a10ea9f93f5c330Timo Sirainen SETTING_DEFINE_LIST_END
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen};
5238111c460098d9cc8cc22527026138a278b9a4Timo Sirainen
5238111c460098d9cc8cc22527026138a278b9a4Timo Sirainenstatic const struct imap_settings imap_default_settings = {
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen .mail_debug = FALSE,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen .verbose_proctitle = FALSE,
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen
de954ff15b495be13007a8aca2c09fd1d356a283Timo Sirainen /* RFC-2683 recommends at least 8000 bytes. Some clients however don't
de954ff15b495be13007a8aca2c09fd1d356a283Timo Sirainen break large message sets to multiple commands, so we're pretty
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen liberal by default. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen .imap_max_line_length = 64*1024,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen .imap_idle_notify_interval = 2*60,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen .imap_capability = "",
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen .imap_client_workarounds = "",
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen .imap_logout_format = "bytes=%i/%o",
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen .imap_id_send = "",
0ce5f96804e81cb0f857e7df32c0272f1eed9377Timo Sirainen .imap_id_log = ""
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen};
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic const struct setting_parser_info *imap_setting_dependencies[] = {
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen &mail_user_setting_parser_info,
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen NULL
d7e72877b7a5085c3addf9729d0bfbe1b5357853Timo Sirainen};
d7e72877b7a5085c3addf9729d0bfbe1b5357853Timo Sirainen
d7e72877b7a5085c3addf9729d0bfbe1b5357853Timo Sirainenconst struct setting_parser_info imap_setting_parser_info = {
d7e72877b7a5085c3addf9729d0bfbe1b5357853Timo Sirainen .module_name = "imap",
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen .defines = imap_setting_defines,
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen .defaults = &imap_default_settings,
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen .type_offset = (size_t)-1,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen .struct_size = sizeof(struct imap_settings),
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
8cdb3234fe3c77e477c7a0e6934678f58fc54d4dTimo Sirainen .parent_offset = (size_t)-1,
8cdb3234fe3c77e477c7a0e6934678f58fc54d4dTimo Sirainen
8cdb3234fe3c77e477c7a0e6934678f58fc54d4dTimo Sirainen .check_func = imap_settings_verify,
8cdb3234fe3c77e477c7a0e6934678f58fc54d4dTimo Sirainen .dependencies = imap_setting_dependencies
71da447014454c84828d9dface77219875554d7dTimo Sirainen};
71da447014454c84828d9dface77219875554d7dTimo Sirainen
71da447014454c84828d9dface77219875554d7dTimo Sirainen/* <settings checks> */
71da447014454c84828d9dface77219875554d7dTimo Sirainenstruct imap_client_workaround_list {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const char *name;
enum imap_client_workarounds num;
};
static const struct imap_client_workaround_list imap_client_workaround_list[] = {
{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
{ "outlook-idle", 0 }, /* only for backwards compatibility */
{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
{ NULL, 0 }
};
static int
imap_settings_parse_workarounds(struct imap_settings *set,
const char **error_r)
{
enum imap_client_workarounds client_workarounds = 0;
const struct imap_client_workaround_list *list;
const char *const *str;
str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
for (; *str != NULL; str++) {
list = imap_client_workaround_list;
for (; list->name != NULL; list++) {
if (strcasecmp(*str, list->name) == 0) {
client_workarounds |= list->num;
break;
}
}
if (list->name == NULL) {
*error_r = t_strdup_printf("imap_client_workarounds: "
"Unknown workaround: %s", *str);
return -1;
}
}
set->parsed_workarounds = client_workarounds;
return 0;
}
static bool
imap_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
{
struct imap_settings *set = _set;
if (imap_settings_parse_workarounds(set, error_r) < 0)
return FALSE;
return TRUE;
}
/* </settings checks> */