pop3c-settings.c revision 83e6a1162fe1cf262ec679f30f43e12dfee750c0
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "lib.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "settings-parser.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "mail-storage-settings.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "pop3c-settings.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include <stddef.h>
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#undef DEF
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#define DEF(type, name) \
551fef69c0633ae3c7738038e047a7c0762d9599Timo Sirainen { type, #name, offsetof(struct pop3c_settings, name), NULL }
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic bool pop3c_settings_check(void *_set, pool_t pool, const char **error_r);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic const struct setting_define pop3c_setting_defines[] = {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_STR, pop3c_host),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_UINT, pop3c_port),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_STR_VARS, pop3c_user),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_STR, pop3c_password),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_ENUM, pop3c_ssl),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_STR, pop3c_ssl_ca_dir),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_BOOL, pop3c_ssl_verify),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_STR, pop3c_rawlog_dir),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen DEF(SET_STR, ssl_crypto_device),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen SETTING_DEFINE_LIST_END
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen};
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic const struct pop3c_settings pop3c_default_settings = {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_host = "",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_port = 110,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_user = "%u",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_password = "",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_ssl = "no:pop3s:starttls",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_ssl_ca_dir = "",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_ssl_verify = TRUE,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .pop3c_rawlog_dir = "",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .ssl_crypto_device = ""
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen};
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic const struct setting_parser_info pop3c_setting_parser_info = {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .module_name = "pop3c",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .defines = pop3c_setting_defines,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .defaults = &pop3c_default_settings,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .type_offset = (size_t)-1,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .struct_size = sizeof(struct pop3c_settings),
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .parent_offset = (size_t)-1,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .parent = &mail_user_setting_parser_info,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen .check_func = pop3c_settings_check
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen};
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenconst struct setting_parser_info *pop3c_get_setting_parser_info(void)
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen{
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen return &pop3c_setting_parser_info;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen}
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen/* <settings checks> */
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic bool pop3c_settings_check(void *_set, pool_t pool ATTR_UNUSED,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen const char **error_r)
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen{
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen struct pop3c_settings *set = _set;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen if (set->pop3c_port == 0 || set->pop3c_port > 65535) {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen *error_r = "invalid pop3c_port";
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen return FALSE;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen }
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#ifndef CONFIG_BINARY
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen if (*set->pop3c_ssl_ca_dir != '\0' &&
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen access(set->pop3c_ssl_ca_dir, X_OK) < 0) {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen *error_r = t_strdup_printf(
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen "pop3c_ssl_ca_dir: access(%s) failed: %m",
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen set->pop3c_ssl_ca_dir);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen return FALSE;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen }
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#endif
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen return TRUE;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen}
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen