bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#include "lib.h"
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#include "hostpid.h"
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#include "settings-parser.h"
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#include "smtp-submit-settings.h"
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#include <stddef.h>
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Boschstatic bool smtp_submit_settings_check(void *_set, pool_t pool, const char **error_r);
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#undef DEF
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#undef DEFLIST
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#define DEF(type, name) \
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch { type, #name, offsetof(struct smtp_submit_settings, name), NULL }
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#define DEFLIST(field, name, defines) \
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch { SET_DEFLIST, name, offsetof(struct smtp_submit_settings, field), defines }
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Boschstatic const struct setting_define smtp_submit_setting_defines[] = {
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch DEF(SET_STR, hostname),
eea481b7931f1a31080acfa92209662d2322a576Stephan Bosch DEF(SET_BOOL, mail_debug),
47fa7b222e197f73042e8b36ad688bf5fcbfc6f0Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch DEF(SET_STR_VARS, submission_host),
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch DEF(SET_STR_VARS, sendmail_path),
47fa7b222e197f73042e8b36ad688bf5fcbfc6f0Stephan Bosch DEF(SET_TIME, submission_timeout),
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
ac8f4f30d6c65f391ef4912ab4e87f4f26c891faStephan Bosch DEF(SET_ENUM, submission_ssl),
ac8f4f30d6c65f391ef4912ab4e87f4f26c891faStephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch SETTING_DEFINE_LIST_END
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch};
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Boschstatic const struct smtp_submit_settings smtp_submit_default_settings = {
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .hostname = "",
eea481b7931f1a31080acfa92209662d2322a576Stephan Bosch .mail_debug = FALSE,
47fa7b222e197f73042e8b36ad688bf5fcbfc6f0Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .submission_host = "",
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .sendmail_path = "/usr/sbin/sendmail",
47fa7b222e197f73042e8b36ad688bf5fcbfc6f0Stephan Bosch .submission_timeout = 30,
ac8f4f30d6c65f391ef4912ab4e87f4f26c891faStephan Bosch
ac8f4f30d6c65f391ef4912ab4e87f4f26c891faStephan Bosch .submission_ssl = "no:smtps:submissions:starttls",
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch};
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Boschconst struct setting_parser_info smtp_submit_setting_parser_info = {
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .module_name = "smtp-submit",
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .defines = smtp_submit_setting_defines,
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .defaults = &smtp_submit_default_settings,
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .type_offset = (size_t)-1,
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .struct_size = sizeof(struct smtp_submit_settings),
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .parent_offset = (size_t)-1,
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#ifndef CONFIG_BINARY
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch .check_func = smtp_submit_settings_check,
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch#endif
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch};
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Boschstatic bool
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Boschsmtp_submit_settings_check(void *_set, pool_t pool,
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch const char **error_r ATTR_UNUSED)
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch{
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch struct smtp_submit_settings *set = _set;
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch if (*set->hostname == '\0')
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch set->hostname = p_strdup(pool, my_hostdomain());
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch return TRUE;
5356717c7944a8527b6ea10ac54012887bcc9f75Stephan Bosch}