bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#include "lib.h"
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen#include "buffer.h"
4afd50dff16661684ad2acddad7284bcd8c564dbTimo Sirainen#include "var-expand.h"
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#include "settings-parser.h"
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen#include "service-settings.h"
79f416d4000aa4192683207aea58a7b12ce66411Timo Sirainen#include "master-service.h"
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#include "master-service-settings.h"
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen#include "lda-settings.h"
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#include "lmtp-settings.h"
55a14bce15b9f44441b5f56616d73651a294d770Timo Sirainen#include "mail-storage-settings.h"
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#include <stddef.h>
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#include <unistd.h>
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainenstatic bool lmtp_settings_check(void *_set, pool_t pool, const char **error_r);
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen/* <settings checks> */
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainenstatic struct file_listener_settings lmtp_unix_listeners_array[] = {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen { "lmtp", 0666, "", "" }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainenstatic struct file_listener_settings *lmtp_unix_listeners[] = {
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainen &lmtp_unix_listeners_array[0]
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainenstatic buffer_t lmtp_unix_listeners_buf = {
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody lmtp_unix_listeners, sizeof(lmtp_unix_listeners), { NULL, }
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen/* </settings checks> */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainenstruct service_settings lmtp_service_settings = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .name = "lmtp",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .protocol = "lmtp",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .type = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .executable = "lmtp",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .user = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .group = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .privileged_group = "",
d7952621661d9a9102393d27d061dad3d22083fdTimo Sirainen .extra_groups = "$default_internal_group",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .chroot = "",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .drop_priv_before_exec = FALSE,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .process_min_avail = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .process_limit = 0,
1906aead346ac17a33f71b3c82709bac57e5c298Timo Sirainen .client_limit = 1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .service_count = 0,
93a7d1ee4b518b5c85f9721dc6539e4dab6aae00Timo Sirainen .idle_kill = 0,
e960fec8bc7d657026533e6cc4dc09781a1edcbfTimo Sirainen .vsz_limit = (uoff_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainen .unix_listeners = { { &lmtp_unix_listeners_buf,
f98cd3b7ccfb026fb56c580b5c7c2e2ee5468049Timo Sirainen sizeof(lmtp_unix_listeners[0]) } },
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .fifo_listeners = ARRAY_INIT,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .inet_listeners = ARRAY_INIT
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen};
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#undef DEF
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen#define DEF(type, name) \
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen { type, #name, offsetof(struct lmtp_settings, name), NULL }
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_define lmtp_setting_defines[] = {
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen DEF(SET_BOOL, lmtp_proxy),
70af4db1c95a5ea3749213da539359b76abcfcd1Timo Sirainen DEF(SET_BOOL, lmtp_save_to_detail_mailbox),
02e8b5f55210f413853998a0ba5832eb3f9a6dc6Timo Sirainen DEF(SET_BOOL, lmtp_rcpt_check_quota),
42abccd9b2a5a4190bd3c14ec2dcc10d51c0f491Timo Sirainen DEF(SET_UINT, lmtp_user_concurrency_limit),
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen DEF(SET_ENUM, lmtp_hdr_delivery_address),
05c32766dbb5f79372a732acf87f1f02d6c45a7fTimo Sirainen DEF(SET_STR_VARS, login_greeting),
b015d3d3af5b1c0fd526f31d78229bf9f633db56Timo Sirainen DEF(SET_STR, login_trusted_networks),
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen SETTING_DEFINE_LIST_END
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen};
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct lmtp_settings lmtp_default_settings = {
70af4db1c95a5ea3749213da539359b76abcfcd1Timo Sirainen .lmtp_proxy = FALSE,
05c32766dbb5f79372a732acf87f1f02d6c45a7fTimo Sirainen .lmtp_save_to_detail_mailbox = FALSE,
02e8b5f55210f413853998a0ba5832eb3f9a6dc6Timo Sirainen .lmtp_rcpt_check_quota = FALSE,
42abccd9b2a5a4190bd3c14ec2dcc10d51c0f491Timo Sirainen .lmtp_user_concurrency_limit = 0,
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen .lmtp_hdr_delivery_address = "final:none:original",
b015d3d3af5b1c0fd526f31d78229bf9f633db56Timo Sirainen .login_greeting = PACKAGE_NAME" ready.",
b015d3d3af5b1c0fd526f31d78229bf9f633db56Timo Sirainen .login_trusted_networks = ""
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen};
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_parser_info *lmtp_setting_dependencies[] = {
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen &lda_setting_parser_info,
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen NULL
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen};
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenconst struct setting_parser_info lmtp_setting_parser_info = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .module_name = "lmtp",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defines = lmtp_setting_defines,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defaults = &lmtp_default_settings,
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .type_offset = (size_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .struct_size = sizeof(struct lmtp_settings),
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .parent_offset = (size_t)-1,
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen .check_func = lmtp_settings_check,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .dependencies = lmtp_setting_dependencies
458acd7b39c84bae0d18c36ff9ddff9a49b4ae4aTimo Sirainen};
79f416d4000aa4192683207aea58a7b12ce66411Timo Sirainen
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen/* <settings checks> */
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainenstatic bool lmtp_settings_check(void *_set, pool_t pool ATTR_UNUSED,
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen const char **error_r)
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen{
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen struct lmtp_settings *set = _set;
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen if (strcmp(set->lmtp_hdr_delivery_address, "none") == 0) {
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen set->parsed_lmtp_hdr_delivery_address =
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen LMTP_HDR_DELIVERY_ADDRESS_NONE;
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen } else if (strcmp(set->lmtp_hdr_delivery_address, "final") == 0) {
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen set->parsed_lmtp_hdr_delivery_address =
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen LMTP_HDR_DELIVERY_ADDRESS_FINAL;
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen } else if (strcmp(set->lmtp_hdr_delivery_address, "original") == 0) {
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen set->parsed_lmtp_hdr_delivery_address =
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen LMTP_HDR_DELIVERY_ADDRESS_ORIGINAL;
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen } else {
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen *error_r = t_strdup_printf("Unknown lmtp_hdr_delivery_address: %s",
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen set->lmtp_hdr_delivery_address);
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen return FALSE;
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen }
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen return TRUE;
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen}
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen/* </settings checks> */
1ac7b6969120bfdb15497663229f0dd168ae4ab8Timo Sirainen
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainenvoid lmtp_settings_dup(const struct setting_parser_context *set_parser,
55a14bce15b9f44441b5f56616d73651a294d770Timo Sirainen pool_t pool,
1f09437dac19eba1b95842e4850895b9ad2cb57eTimo Sirainen struct lmtp_settings **lmtp_set_r,
1f09437dac19eba1b95842e4850895b9ad2cb57eTimo Sirainen struct lda_settings **lda_set_r)
79f416d4000aa4192683207aea58a7b12ce66411Timo Sirainen{
79f416d4000aa4192683207aea58a7b12ce66411Timo Sirainen void **sets;
79f416d4000aa4192683207aea58a7b12ce66411Timo Sirainen
32b78da5dfbbf6a06b3dbdc9278c60b55714f9bcTimo Sirainen sets = master_service_settings_parser_get_others(master_service,
32b78da5dfbbf6a06b3dbdc9278c60b55714f9bcTimo Sirainen set_parser);
0f72f253d5a117dad2f28b2ce336190a5e6b79c8Stephan Bosch *lda_set_r = settings_dup(&lda_setting_parser_info, sets[2], pool);
0f72f253d5a117dad2f28b2ce336190a5e6b79c8Stephan Bosch *lmtp_set_r = settings_dup(&lmtp_setting_parser_info, sets[3], pool);
79f416d4000aa4192683207aea58a7b12ce66411Timo Sirainen}