bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen#include "lib.h"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen#include "str.h"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen#include "settings-parser.h"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen#include "config-parser-private.h"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen#include "old-set-parser.h"
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi#include "istream.h"
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi#include "base64.h"
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomistatic bool seen_ssl_parameters_dat;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomistatic const char *ssl_dh_parameters;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen#define config_apply_line (void)config_apply_line
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstruct socket_set {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *path, *mode, *user, *group;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool master;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen};
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstruct old_set_parser {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *base_dir;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* 1 when in auth {} section, >1 when inside auth { .. { .. } } */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen unsigned int auth_section;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* 1 when in socket listen {}, >1 when inside more of its sections */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen unsigned int socket_listen_section;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool seen_auth_section;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen struct socket_set socket_set;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen};
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic const struct config_filter any_filter = {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen .service = NULL
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen};
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic const struct config_filter imap_filter = {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen .service = "imap"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen};
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic const struct config_filter pop3_filter = {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen .service = "pop3"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen};
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic const struct config_filter managesieve_filter = {
45dda77a1e51970a06c82dd1b4c1ee5b0368cfe1Timo Sirainen .service = "sieve"
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen};
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic void ATTR_FORMAT(2, 3)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenobsolete(struct config_parser_context *ctx, const char *str, ...)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen static bool seen_obsoletes = FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen va_list args;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen if (!seen_obsoletes) {
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen i_warning("NOTE: You can get a new clean config file with: "
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen "doveconf -n > dovecot-new.conf");
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen seen_obsoletes = TRUE;
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen }
66fbbac231b0385273b11f9b4c43ad252330dea5Timo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen va_start(args, str);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen i_warning("Obsolete setting in %s:%u: %s",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->cur_input->path, ctx->cur_input->linenum,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_vprintf(str, args));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen va_end(args);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic void set_rename(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *old_key, const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s has been renamed to %s", old_key, key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE, key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomibool old_settings_ssl_dh_load(const char **value, const char **error_r)
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi{
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (ssl_dh_parameters != NULL) *value = ssl_dh_parameters;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi const char *fn = t_strconcat(PKG_STATEDIR, "/ssl-parameters.dat", NULL);
c147bff818798a979d93537f72f5c1f68f5d5ba8Aki Tuomi buffer_t *data = t_buffer_create(300);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi string_t *b64_data = t_str_new(500);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi size_t siz;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi unsigned short keysize;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi unsigned int off=0;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi /* try read it */
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi struct istream *is = i_stream_create_file(fn, IO_BLOCK_SIZE);
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (is->stream_errno == ENOENT) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi /* this is given because the ssl-parameters.dat file is no more there
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi and we don't want to to make go searching for the file
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi this code is only ever reached if ssl_dh_parameters is empty anyways
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi */
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi /* check moved to correct place from here */
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi *value = NULL;
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi return TRUE;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi } else if (is->stream_errno != 0) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi *error_r = t_strdup(i_stream_get_error(is));
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi return FALSE;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi }
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi /* then try to read the rest of the data */
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi while(i_stream_read(is) > 0) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi const unsigned char *buf = i_stream_get_data(is, &siz);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (siz < 88) break;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi memcpy(&keysize, buf, 2);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (keysize == 512) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi memcpy(&off, buf+4, 4);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi off += 16; // skip headers
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi } else {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi off = 8; // skip header
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi }
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (off > siz) break;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi buffer_append(data, buf+off, siz);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi break;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi }
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi const void *tmp = buffer_get_data(data, &siz);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (siz > 4) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi str_append(b64_data, "-----BEGIN DH PARAMETERS-----\n");
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi base64_encode(tmp, siz-4, b64_data);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi /* need to wrap the string nicely */
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi for(size_t i = 29+65; i < str_len(b64_data); i+=64) /* start at header + first 64 */
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi str_insert(b64_data, i++, "\n");
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi }
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi str_append_c(b64_data,'\n');
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi str_append(b64_data, "-----END DH PARAMETERS-----");
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi ssl_dh_parameters = i_strdup(str_c(b64_data));
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi *value = ssl_dh_parameters;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (!seen_ssl_parameters_dat) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi i_warning("please set ssl_dh=<%s", SYSCONFDIR"/dh.pem");
392616c228f821e81342c5ac24d8a4901b0b582fAki Tuomi i_warning("You can generate it with: dd if=%s bs=1 skip=%u | openssl dhparam -inform der > %s", fn, off, SYSCONFDIR"/dh.pem");
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi seen_ssl_parameters_dat = TRUE;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi }
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi } else if (is->stream_errno == ENOENT) {
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi /* check for empty ssl_dh elsewhere */
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi *value = NULL;
551f3b2ebd588ca125c01f49b54c4103fbd5b2c5Aki Tuomi return TRUE;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi } else {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi *error_r = "ssl enabled, but ssl_dh not set";
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi return FALSE;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi }
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi i_stream_unref(&is);
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi return TRUE;
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi}
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi/* FIXME: Remove ssl_protocols_to_min_protocol() in v2.4 */
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvistatic int ssl_protocols_to_min_protocol(const char *ssl_protocols,
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi const char **min_protocol_r,
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi const char **error_r)
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi{
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi static const char *protocol_versions[] = {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2",
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi };
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi /* Array where -1 = disable, 0 = not found, 1 = enable */
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi int protos[N_ELEMENTS(protocol_versions)];
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi memset(protos, 0, sizeof(protos));
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi bool explicit_enable = FALSE;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi const char *const *tmp = t_strsplit_spaces(ssl_protocols, ", ");
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi for (; *tmp != NULL; tmp++) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi const char *p = *tmp;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi bool enable = TRUE;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (p[0] == '!') {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi enable = FALSE;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi ++p;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi for (unsigned i = 0; i < N_ELEMENTS(protocol_versions); i++) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (strcmp(p, protocol_versions[i]) == 0) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (enable) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi protos[i] = 1;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi explicit_enable = TRUE;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi } else {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi protos[i] = -1;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi goto found;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi *error_r = t_strdup_printf("Unrecognized protocol '%s'", p);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi return -1;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi found:;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi unsigned min = N_ELEMENTS(protocol_versions);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi for (unsigned i = 0; i < N_ELEMENTS(protocol_versions); i++) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (explicit_enable) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (protos[i] > 0)
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi min = I_MIN(min, i);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi } else if (protos[i] == 0)
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi min = I_MIN(min, i);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (min == N_ELEMENTS(protocol_versions)) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi *error_r = "All protocols disabled";
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi return -1;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi *min_protocol_r = protocol_versions[min];
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi return 0;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi}
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic bool
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenold_settings_handle_root(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *p;
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen size_t len;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
a545bcd54312b543ddc46a872ec79d0416032b0fTimo Sirainen if (strcmp(key, "base_dir") == 0) {
a545bcd54312b543ddc46a872ec79d0416032b0fTimo Sirainen len = strlen(value);
a545bcd54312b543ddc46a872ec79d0416032b0fTimo Sirainen if (len > 0 && value[len-1] == '/')
a545bcd54312b543ddc46a872ec79d0416032b0fTimo Sirainen value = t_strndup(value, len-1);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->base_dir = p_strdup(ctx->pool, value);
a545bcd54312b543ddc46a872ec79d0416032b0fTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "protocols") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen char **protos, **s;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool have_imap = FALSE, have_imaps = FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool have_pop3 = FALSE, have_pop3s = FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen protos = p_strsplit_spaces(pool_datastack_create(), value, " ");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen for (s = protos; *s != NULL; s++) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(*s, "imap") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen have_imap = TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else if (strcmp(*s, "imaps") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen *s = "";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen have_imaps = TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen } else if (strcmp(*s, "pop3") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen have_pop3 = TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else if (strcmp(*s, "pop3s") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen *s = "";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen have_pop3s = TRUE;
bc85ab91357eaf47c789179362ee36f4f4f4abd7Timo Sirainen } else if (strcmp(*s, "managesieve") == 0) {
bc85ab91357eaf47c789179362ee36f4f4f4abd7Timo Sirainen *s = "sieve";
bc85ab91357eaf47c789179362ee36f4f4f4abd7Timo Sirainen obsolete(ctx, "protocols=managesieve has been renamed to protocols=sieve");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = t_strarray_join((const char *const *)protos, " ");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* ugly way to drop extra spaces.. */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen protos = p_strsplit_spaces(pool_datastack_create(), value, " ");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = t_strarray_join((const char *const *)protos, " ");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (have_imaps && !have_imap) {
bc4cb06efd149ff759ad5462c6cd1a352f735034Timo Sirainen obsolete(ctx, "'imaps' protocol can no longer be specified (use protocols=imap). to disable non-ssl imap, use service imap-login { inet_listener imap { port=0 } }");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = t_strconcat(value, " imap", NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "port",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen "service/imap-login/inet_listener/imap/port=0", NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen } else if (have_imaps)
e4ff3c71af029c7e63852cffc59c2352610d73a9Timo Sirainen obsolete(ctx, "'imaps' protocol is no longer necessary, remove it");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (have_pop3s && !have_pop3) {
bc4cb06efd149ff759ad5462c6cd1a352f735034Timo Sirainen obsolete(ctx, "'pop3s' protocol can no longer be specified (use protocols=pop3). to disable non-ssl pop3, use service pop3-login { inet_listener pop3 { port=0 } }");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = t_strconcat(value, " pop3", NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "port",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen "service/pop3-login/inet_listener/pop3/port=0", NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen } else if (have_pop3s)
e4ff3c71af029c7e63852cffc59c2352610d73a9Timo Sirainen obsolete(ctx, "'pop3s' protocol is no longer necessary, remove it");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (*value == ' ') value++;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "ssl_cert_file") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(key, "ssl_key_file") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(key, "ssl_ca_file") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (*value == '\0')
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen p = t_strdup_until(key, strrchr(key, '_'));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s has been replaced by %s = <file", key, p);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYFILE,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen p, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen if (strcmp(key, "ssl_disable") == 0) {
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen if (strcasecmp(value, "yes") == 0)
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen value = "no";
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen else if (strcasecmp(value, "no") == 0)
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen value = "yes";
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen set_rename(ctx, key, "ssl", value);
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen return TRUE;
e5c28185478ecab60d0dbd78f9daaab113d5c060Timo Sirainen }
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi if (strcmp(key, "ssl_parameters_regenerate") == 0 ||
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi strcmp(key, "ssl_dh_parameters_length") == 0) {
42cb779853b1814d7ab052436b0b6d1f507c742bAki Tuomi obsolete(ctx, "%s is no longer needed", key);
de84f428e20b57f98d2de9a3793e46e0e1560fb4Timo Sirainen return TRUE;
de84f428e20b57f98d2de9a3793e46e0e1560fb4Timo Sirainen }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (strcmp(key, "ssl_protocols") == 0) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi obsolete(ctx, "%s has been replaced by ssl_min_protocol", key);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi const char *min_protocol, *error;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi if (ssl_protocols_to_min_protocol(value, &min_protocol, &error) < 0) {
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi i_error("Could not find a minimum ssl_min_protocol "
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi "setting from ssl_protocols = %s: %s",
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi value, error);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi return TRUE;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi "ssl_min_protocol", min_protocol);
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi return TRUE;
976dee5384c4827dc648c9bc53825390521c388eMartti Rannanjärvi }
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen if (strcmp(key, "sieve") == 0 ||
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen strcmp(key, "sieve_storage") == 0) {
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen if (strcmp(key, "sieve_storage") == 0)
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen obsolete(ctx, "sieve_storage has been moved into plugin { sieve_dir }");
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen else
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen obsolete(ctx, "%s has been moved into plugin {} section", key);
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen config_apply_line(ctx, "", "plugin=", NULL);
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen config_apply_line(ctx, key,
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen t_strdup_printf("plugin/%s=%s", key, value), NULL);
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen return TRUE;
ba8a3fbee3f8fca8e481ba929bce6b78296a7820Timo Sirainen }
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen if (strcmp(key, "fsync_disable") == 0) {
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen if (strcasecmp(value, "yes") == 0)
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen value = "never";
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen else if (strcasecmp(value, "no") == 0)
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen value = "optimized";
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen set_rename(ctx, key, "mail_fsync", value);
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen return TRUE;
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "dbox_rotate_size") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen set_rename(ctx, key, "mdbox_rotate_size", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen if (strcmp(key, "imap_client_workarounds") == 0) {
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen char **args, **arg;
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen args = p_strsplit_spaces(pool_datastack_create(), value, " ,");
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen for (arg = args; *arg != NULL; arg++) {
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen if (strcmp(*arg, "outlook-idle") == 0) {
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen *arg = "";
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen obsolete(ctx, "imap_client_workarounds=outlook-idle is no longer necessary");
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen } else if (strcmp(*arg, "netscape-eoh") == 0) {
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen *arg = "";
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen obsolete(ctx, "imap_client_workarounds=netscape-eoh is no longer supported");
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen }
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen }
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen value = t_strarray_join((void *)args, " ");
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen key, value);
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen return TRUE;
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_dir") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(key, "dbox_rotate_min_size") == 0 ||
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen strcmp(key, "dbox_rotate_days") == 0 ||
a934b65e8ba7aaa1f972c8c5062c4608397135c1Martti Rannanjärvi strcmp(key, "director_consistent_hashing") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(key, "mail_log_max_lines_per_sec") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(key, "maildir_copy_preserve_filename") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s has been removed", key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->auth_section == 1) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strncmp(key, "auth_", 5) != 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen key = t_strconcat("auth_", key, NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic void
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_apply_login_set(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen struct config_section_stack *old_section,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *old_key, const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s has been replaced by service { %s }", old_key, key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &imap_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/imap-login/%s=%s", key, value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &pop3_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/pop3-login/%s=%s", key, value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &managesieve_filter)) {
358f356749078ed2ae69fc48ced375761c877b61Timo Sirainen /* if pigeonhole isn't installed, this fails.
358f356749078ed2ae69fc48ced375761c877b61Timo Sirainen just ignore it then.. */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/managesieve-login/%s=%s", key, value), NULL);
358f356749078ed2ae69fc48ced375761c877b61Timo Sirainen ctx->error = NULL;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic void
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_apply_mail_set(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen struct config_section_stack *old_section,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *old_key, const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s has been replaced by service { %s }", old_key, key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &imap_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/imap/%s=%s", key,value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &pop3_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/pop3/%s=%s", key,value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &managesieve_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/managesieve/%s=%s", key,value), NULL);
358f356749078ed2ae69fc48ced375761c877b61Timo Sirainen ctx->error = NULL;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic void
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_apply_auth_set(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *old_key, const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s has been replaced by service auth { %s }", old_key, key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, key,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/auth/%s=%s", key,value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainenstatic bool listen_has_port(const char *str)
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen{
8bb360f9e5de1c25e4f875205bb06e8bf15dae14Timo Sirainen const char *const *addrs;
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen
8bb360f9e5de1c25e4f875205bb06e8bf15dae14Timo Sirainen if (strchr(str, ':') == NULL)
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen return FALSE;
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen
3402c71658e8c440941d50a66aba777849b3b89fTimo Sirainen addrs = t_strsplit_spaces(str, ", ");
3402c71658e8c440941d50a66aba777849b3b89fTimo Sirainen for (; *addrs != NULL; addrs++) {
e7a81e78fb5d8078d32ec05257f75095b28eb9e8Timo Sirainen if (strcmp(*addrs, "*") != 0 &&
e7a81e78fb5d8078d32ec05257f75095b28eb9e8Timo Sirainen strcmp(*addrs, "::") != 0 &&
8eeced2d681741d4071e6b145fe26232186af34aTimo Sirainen strcmp(*addrs, "[::]") != 0 &&
e7a81e78fb5d8078d32ec05257f75095b28eb9e8Timo Sirainen !is_ipv4_address(*addrs) &&
e7a81e78fb5d8078d32ec05257f75095b28eb9e8Timo Sirainen !is_ipv6_address(*addrs))
3402c71658e8c440941d50a66aba777849b3b89fTimo Sirainen return TRUE;
3402c71658e8c440941d50a66aba777849b3b89fTimo Sirainen }
3402c71658e8c440941d50a66aba777849b3b89fTimo Sirainen return FALSE;
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen}
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic bool
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenold_settings_handle_proto(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen struct config_section_stack *old_section = ctx->cur_section;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *p;
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen uoff_t size;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool root;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen while (ctx->cur_section->prev != NULL)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->cur_section = ctx->cur_section->prev;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen root = config_filter_match(&old_section->filter, &any_filter);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "ssl_listen") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen (strcmp(key, "listen") == 0 &&
417d2a64eba7d8c395b6c8a18d845f7ff2471637Timo Sirainen (listen_has_port(value) || !root))) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *ssl = strcmp(key, "ssl_listen") == 0 ? "s" : "";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (*value == '\0') {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* default */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
9accc087160a4a485df40276daf7f6d1aa23d9b6Timo Sirainen p = strrchr(value, ':');
3f780bf67ec3047194ab89e2ec1ffc8da8698775Timo Sirainen if (p != NULL && listen_has_port(value)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s=..:port has been replaced by service { inet_listener { port } }", key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = t_strdup_until(value, p++);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &imap_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "port",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/imap-login/inet_listener/imap%s/port=%s", ssl, p), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &pop3_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "port",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/pop3-login/inet_listener/pop3%s/port=%s", ssl, p), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (*ssl == '\0' &&
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_filter_match(&old_section->filter, &managesieve_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "port",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/managesieve-login/inet_listener/managesieve/port=%s", p), NULL);
358f356749078ed2ae69fc48ced375761c877b61Timo Sirainen ctx->error = NULL;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (root && *ssl == '\0') {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen } else {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "protocol { %s } has been replaced by service { inet_listener { address } }", key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &imap_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "address",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/imap-login/inet_listener/imap%s/address=%s", ssl, value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_match(&old_section->filter, &pop3_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "address",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/pop3-login/inet_listener/pop3%s/address=%s", ssl, value), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (*ssl == '\0' &&
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_filter_match(&old_section->filter, &managesieve_filter)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "address",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/managesieve-login/inet_listener/managesieve/address=%s", value), NULL);
358f356749078ed2ae69fc48ced375761c877b61Timo Sirainen ctx->error = NULL;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_chroot") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(value, "no") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = "";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen value = "login";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "chroot", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_user") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "user", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_executable") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "executable", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_process_size") == 0) {
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen config_apply_login_set(ctx, old_section, key, "vsz_limit",
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen t_strconcat(value, " M", NULL));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_process_per_connection") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "service_count",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(value, "no") == 0 ? "0" : "1");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_processes_count") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "process_min_avail", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_max_processes_count") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "process_limit", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_max_connections") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_login_set(ctx, old_section, key, "client_limit", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "login_process_size") == 0) {
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen config_apply_login_set(ctx, old_section, key, "vsz_limit",
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen t_strconcat(value, " M", NULL));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "max_mail_processes") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_mail_set(ctx, old_section, key, "process_limit", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "mail_executable") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_mail_set(ctx, old_section, key, "executable", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "mail_process_size") == 0) {
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen config_apply_mail_set(ctx, old_section, key, "vsz_limit",
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen t_strconcat(value, " M", NULL));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "mail_drop_priv_before_exec") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_mail_set(ctx, old_section, key, "drop_priv_before_exec", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->auth_section == 1) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strncmp(key, "auth_", 5) != 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen key = t_strconcat("auth_", key, NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "auth_executable") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_auth_set(ctx, key, "executable", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "auth_process_size") == 0) {
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen config_apply_auth_set(ctx, key, "vsz_limit",
a37c2c1ad645b6d8ea73e6d38695efdde4f3f928Timo Sirainen t_strconcat(value, " M", NULL));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "auth_user") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_auth_set(ctx, key, "user", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "auth_chroot") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_auth_set(ctx, key, "chroot", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen if (strcmp(key, "auth_cache_size") == 0 &&
6bd263caf006edc75205f446fa0283c6f364941bTimo Sirainen str_to_uoff(value, &size) == 0 && size > 0 && size < 1024) {
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen obsolete(ctx, "auth_cache_size value no longer defaults to "
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen "megabytes. Use %sM", value);
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen config_apply_line(ctx, key,
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen t_strdup_printf("%s=%sM", key, value), NULL);
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen return TRUE;
5ce40a7370a19a98caeca5d2e27b3d6c77c90ea9Timo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "auth_count") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(value, "count") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "auth_count has been removed");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "auth_count has been removed, and its value must be 1");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->socket_listen_section == 2) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char **p = NULL;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "path") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen p = &ctx->old->socket_set.path;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else if (strcmp(key, "mode") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen p = &ctx->old->socket_set.mode;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else if (strcmp(key, "user") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen p = &ctx->old->socket_set.user;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else if (strcmp(key, "group") == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen p = &ctx->old->socket_set.group;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (p != NULL) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen *p = p_strdup(ctx->pool, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic bool old_auth_section(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->auth_section == 0 && ctx->old->seen_auth_section) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "Multiple auth sections are no longer supported");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->seen_auth_section = TRUE;
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&ctx->old->socket_set);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->auth_section++;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if ((strcmp(key, "passdb") == 0 || strcmp(key, "userdb") == 0) &&
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->auth_section == 2) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "%s %s {} has been replaced by %s { driver=%s }",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen key, value, key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_SECTION_BEGIN, key, "");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen "driver", value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(key, "socket") == 0 && ctx->old->auth_section == 2) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(value, "connect") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "socket connect {} is no longer supported, configure external auth server separately");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strcmp(value, "listen") != 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* socket listen { .. } */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->socket_listen_section++;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->socket_listen_section > 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->socket_listen_section++;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if ((strcmp(key, "master") == 0 || strcmp(key, "client") == 0) &&
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->socket_listen_section == 2) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->socket_set.master = strcmp(key, "master") == 0;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic void socket_apply(struct config_parser_context *ctx)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const struct socket_set *set = &ctx->old->socket_set;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *path, *prefix;
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen size_t len;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool master_suffix;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (set->path == NULL) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->error = "socket listen {} is missing path";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen path = set->path;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen len = strlen(ctx->old->base_dir);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (strncmp(path, ctx->old->base_dir, len) == 0 &&
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen path[len] == '/')
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen path += len + 1;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen len = strlen(path);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen master_suffix = len >= 7 &&
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen (strcmp(path + len - 7, "-master") == 0 ||
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen strcmp(path + len - 7, "-userdb") == 0);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (set->master && !master_suffix) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->error = "socket listen { master { path=.. } } must end with -master (or -userdb) suffix";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen } else if (!set->master && master_suffix) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->error = "socket listen { client { path=.. } } must end not with -master or -userdb suffix";
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "unix_listener",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("service/auth/unix_listener=%s", settings_section_escape(path)), path);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen prefix = t_strdup_printf("service/auth/unix_listener/%s", settings_section_escape(path));
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (set->mode != NULL) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "mode",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("%s/mode=%s", prefix, set->mode), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (set->user != NULL) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "user",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("%s/user=%s", prefix, set->user), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (set->group != NULL) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen config_apply_line(ctx, "group",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen t_strdup_printf("%s/group=%s", prefix, set->group), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&ctx->old->socket_set);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenbool old_settings_handle(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen enum config_line_type type,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen const char *key, const char *value)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen switch (type) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_SKIP:
0fa40bfd73cedc311ff2e0ae90707836382bfc8cTimo Sirainen case CONFIG_LINE_TYPE_CONTINUE:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_ERROR:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_INCLUDE:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_INCLUDE_TRY:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_KEYFILE:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_KEYVARIABLE:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen break;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_KEYVALUE:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->pathlen == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen struct config_section_stack *old_section =
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->cur_section;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen bool ret;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ret = old_settings_handle_proto(ctx, key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->cur_section = old_section;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ret)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return old_settings_handle_root(ctx, key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen break;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_SECTION_BEGIN:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->auth_section > 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return old_auth_section(ctx, key, value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen else if (ctx->pathlen == 0 && strcmp(key, "auth") == 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen obsolete(ctx, "add auth_ prefix to all settings inside auth {} and remove the auth {} section completely");
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->auth_section = 1;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
cb06054f863550b766950fe2949b69b7047bcd81Timo Sirainen } else if (ctx->pathlen == 0 && strcmp(key, "protocol") == 0 &&
ec1823d289727d53fc74073e6cdda61d64fc0761Timo Sirainen strcmp(value, "managesieve") == 0) {
ec1823d289727d53fc74073e6cdda61d64fc0761Timo Sirainen obsolete(ctx, "protocol managesieve {} has been replaced by protocol sieve { }");
ec1823d289727d53fc74073e6cdda61d64fc0761Timo Sirainen config_parser_apply_line(ctx, CONFIG_LINE_TYPE_SECTION_BEGIN,
ec1823d289727d53fc74073e6cdda61d64fc0761Timo Sirainen "protocol", "sieve");
ec1823d289727d53fc74073e6cdda61d64fc0761Timo Sirainen return TRUE;
ec1823d289727d53fc74073e6cdda61d64fc0761Timo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen break;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen case CONFIG_LINE_TYPE_SECTION_END:
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->auth_section > 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (--ctx->old->auth_section == 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->socket_listen_section > 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (ctx->old->socket_listen_section == 2)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen socket_apply(ctx);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->socket_listen_section--;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return TRUE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen break;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen }
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen return FALSE;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenvoid old_settings_init(struct config_parser_context *ctx)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen{
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old = p_new(ctx->pool, struct old_set_parser, 1);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->old->base_dir = PKG_RUNDIR;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen}