master-settings.c revision e0cc3414022c0e6538fd7f5e705d1e73649e6931
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "array.h"
#include "str.h"
#include "istream.h"
#include "fd-close-on-exec.h"
#include "safe-mkdir.h"
#include "mkdir-parents.h"
#include "unlink-directory.h"
#include "syslog-util.h"
#include "mail-process.h"
#include "settings.h"
#include <stdio.h>
#include <stddef.h>
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
#include <pwd.h>
enum settings_type {
};
struct settings_parse_ctx {
enum mail_protocol protocol;
struct auth_settings *auth;
struct socket_settings *socket;
struct auth_socket_settings *auth_socket;
struct auth_passdb_settings *auth_passdb;
struct auth_userdb_settings *auth_userdb;
struct namespace_settings *namespace;
int level;
};
static struct setting_def setting_defs[] = {
/* common */
/* general */
/* login */
/* mail */
/* imap */
/* pop3 */
{ 0, NULL, 0 }
};
static struct setting_def auth_setting_defs[] = {
{ 0, NULL, 0 }
};
static struct setting_def socket_setting_defs[] = {
{ 0, NULL, 0 }
};
static struct setting_def auth_socket_setting_defs[] = {
{ 0, NULL, 0 }
};
static struct setting_def auth_passdb_setting_defs[] = {
{ 0, NULL, 0 }
};
static struct setting_def auth_userdb_setting_defs[] = {
{ 0, NULL, 0 }
};
static struct setting_def namespace_setting_defs[] = {
{ 0, NULL, 0 }
};
struct settings default_settings = {
/* common */
/* general */
/* login */
/* mail */
MEMBER(last_valid_uid) 0,
MEMBER(last_valid_gid) 0,
#ifdef MMAP_CONFLICTS_WRITE
#else
#endif
/* imap */
/* pop3 */
/* .. */
};
struct auth_settings default_auth_settings = {
MEMBER(cache_size) 0,
/* .. */
};
struct socket_settings default_socket_settings = {
};
struct namespace_settings default_namespace_settings = {
};
{
}
}
{
return FALSE;
}
i_error("All login process users must belong to same group "
return FALSE;
}
return TRUE;
}
{
return FALSE;
}
i_error("login_user %s (uid %s) must not be same as auth_user",
return FALSE;
}
i_error("Can't use auth executable %s: %m",
return FALSE;
}
i_error("Can't access auth chroot directory %s: %m",
return FALSE;
}
/* if we require valid cert, make sure we also ask for it */
}
return TRUE;
}
{
const char *name;
i_error("Namespace '%s': "
"Hierarchy separator must be only one character long",
name);
return FALSE;
}
return TRUE;
}
static const char *get_directory(const char *path)
{
char *str, *p;
if (p == NULL)
return ".";
else {
*p = '\0';
return str;
}
}
{
/* we're probably using this with --exec-mail */
return TRUE;
}
return FALSE;
} else {
return FALSE;
}
return TRUE;
}
{
struct auth_settings *auth;
struct server_settings *server;
return TRUE;
}
}
return FALSE;
}
static void unlink_auth_sockets(const char *path)
{
return;
}
continue;
str_truncate(str, 0);
}
}
}
#ifdef HAVE_MODULES
{
/* FIXME: pretty ugly code just for getting the capability
automatically */
static const char *generated_capability = NULL;
static const char *args[] = {
"uid=65534",
"gid=65534",
};
char buf[4096];
unsigned int pos;
if (generated_capability != NULL) {
/* Reloading configuration. Don't try to execute the imap
process again. Too risky and the wait() call below will
break it anyway. Just use the previous capability list we
already had generated. */
return TRUE;
}
if (uid != 0) {
/* use the current user */
}
i_error("pipe() failed: %m");
return FALSE;
}
return FALSE;
}
alarm(5);
i_fatal("imap dump-capability process got stuck");
alarm(0);
if (status != 0) {
if (WIFSIGNALED(status)) {
i_error("imap dump-capability process "
} else {
i_error("imap dump-capability process returned %d",
status);
}
return FALSE;
}
pos = 0;
if (ret < 0) {
i_error("read(imap dump-capability process) failed: %m");
return FALSE;
}
i_error("imap dump-capability: Couldn't read capability "
"(got %u bytes)", pos);
return FALSE;
}
return TRUE;
}
#endif
{
const char *dir;
int facility;
if (!get_login_uid(set))
return FALSE;
i_error("Can't use mail executable %s: %m",
return FALSE;
}
return FALSE;
}
}
i_error("Can't write to info log directory %s: %m",
dir);
return FALSE;
}
}
return FALSE;
}
#ifdef HAVE_SSL
if (!set->ssl_disable) {
i_fatal("Can't use SSL CA file %s: %m",
set->ssl_ca_file);
}
i_error("Can't use SSL certificate %s: %m",
set->ssl_cert_file);
return FALSE;
}
i_error("Can't use SSL key file %s: %m",
set->ssl_key_file);
return FALSE;
}
}
#else
if (!set->ssl_disable) {
i_error("SSL support not compiled in but ssl_disable=no");
return FALSE;
}
#endif
deleted. */
return FALSE;
}
/* allow base_dir to be a symlink, so don't use lstat() */
return FALSE;
}
/* FIXME: backwards compatibility: fix permissions so that
login processes can find ssl-parameters file. Group rx is
enough, but change it to world-rx so that we don't have to
start changing groups and causing possibly other problems.
The second check is to fix 1.0beta1's accidental 0777
mode change.. */
i_warning("Fixing permissions of %s to be world-readable",
}
/* Make sure our permanent state directory exists */
return FALSE;
}
if (!settings_have_connect_sockets(set)) {
/* we are not using external authentication, so make sure the
login directory exists with correct permissions and it's
empty. with external auth we wouldn't want to delete
existing sockets or break the permissions required by the
auth server. */
i_warning("Corrected permissions for login directory "
}
}
i_error("max_mail_processes must be at least 1");
return FALSE;
}
if (set->last_valid_uid != 0 &&
i_error("first_valid_uid can't be larger than last_valid_uid");
return FALSE;
}
if (set->last_valid_gid != 0 &&
i_error("first_valid_gid can't be larger than last_valid_gid");
return FALSE;
}
i_error("mail_drop_priv_before_exec=yes and mail_chroot "
"don't work together");
return FALSE;
}
i_error("Can't use login executable %s: %m",
return FALSE;
}
i_error("login_processes_count must be at least 1");
return FALSE;
}
i_error("login_max_connections must be at least 1");
return FALSE;
}
#ifdef HAVE_MODULES
i_error("Can't access mail module directory: %s: %m",
return FALSE;
}
if (!get_imap_capability(set))
return FALSE;
}
#else
i_error("Module support wasn't built into Dovecot, "
return FALSE;
}
#endif
return TRUE;
}
{
/* fix relative paths */
/* keep this for backwards compatibility */
i_error("Both mail_location and default_mail_env set. "
"Use only one of them.");
return FALSE;
}
}
static struct auth_settings *
{
struct auth_settings *auth;
/* copy defaults */
return auth;
}
static struct auth_settings *
const char **errormsg)
{
struct auth_settings *auth;
*errormsg = "Authentication process name must not contain '/'";
return NULL;
}
*errormsg = "Authentication process already exists "
"with the same name";
return NULL;
}
}
}
static struct auth_passdb_settings *
{
return as;
}
static struct auth_userdb_settings *
{
return as;
}
static struct auth_socket_settings *
{
return as;
}
static struct auth_socket_settings *
const char **errormsg)
{
*errormsg = "Unknown auth socket type";
return NULL;
}
*errormsg = "With connect auth socket no other sockets "
"can be used in same auth section";
return NULL;
}
}
static struct namespace_settings *
{
return ns;
}
static struct namespace_settings *
const char **errormsg)
{
*errormsg = "Unknown namespace type";
return NULL;
}
}
void *context)
{
const char *error;
/* backwards compatibility */
}
i_warning("Ignoring deprecated 'login' section handling. "
"Some settings may have been read incorrectly.");
return NULL;
}
case SETTINGS_TYPE_ROOT:
case SETTINGS_TYPE_SERVER:
}
}
return NULL;
return parse_setting_from_defs(settings_pool,
}
return error;
case SETTINGS_TYPE_AUTH:
key += 5;
return parse_setting_from_defs(settings_pool,
return parse_setting_from_defs(settings_pool,
return parse_setting_from_defs(settings_pool,
case SETTINGS_TYPE_NAMESPACE:
return parse_setting_from_defs(settings_pool,
case SETTINGS_TYPE_SOCKET:
return parse_setting_from_defs(settings_pool,
case SETTINGS_TYPE_DICT:
return NULL;
case SETTINGS_TYPE_PLUGIN:
&value, 1);
}
&value, 1);
}
return NULL;
}
i_unreached();
}
static struct server_settings *
create_new_server(const char *name,
struct settings *imap_defaults,
struct settings *pop3_defaults)
{
struct server_settings *server;
return server;
}
const char **errormsg)
{
struct server_settings *server;
/* section closing */
break;
default:
break;
}
} else {
}
return TRUE;
}
*errormsg = "Server section not allowed here";
return FALSE;
}
return TRUE;
}
*errormsg = "Protocol section not allowed here";
return FALSE;
}
else {
*errormsg = "Unknown protocol name";
return FALSE;
}
return TRUE;
}
*errormsg = "Auth section not allowed here";
return FALSE;
}
}
}
return TRUE;
}
return TRUE;
}
return TRUE;
}
return TRUE;
}
}
*errormsg = "Namespace section not allowed here";
return FALSE;
}
errormsg);
}
*errormsg = "Plugin section not allowed here";
return FALSE;
}
return TRUE;
}
*errormsg = "Plugin section not allowed here";
return FALSE;
}
return TRUE;
}
*errormsg = "Unknown section type";
return FALSE;
}
{
struct settings_parse_ctx ctx;
struct auth_settings *auth;
struct namespace_settings *ns;
create_new_server("default",
return FALSE;
i_error("Missing '}'");
return FALSE;
}
/* If server sections were defined, skip the root */
i_error("No protocols given in configuration file");
return FALSE;
}
return FALSE;
}
} else {
return FALSE;
}
else {
return FALSE;
}
else
} else {
i_error("Missing auth section for server %s",
return FALSE;
}
if (!nochecks) {
if (!auth_settings_verify(auth))
return FALSE;
}
if (!namespace_settings_verify(ns))
return FALSE;
}
}
}
}
/* We aren't actually checking them separately, but if it
contains only invalid protocols we'll get here.. */
i_error("Invalid protocols given in configuration file");
return FALSE;
}
/* settings ok, swap them */
return TRUE;
}
bool nondefaults, unsigned int indent)
{
const char **str;
unsigned int i;
t_push();
case SET_STR: {
const char *const *strp;
for (i = 0; i < count; i++) {
}
break;
}
case SET_INT: {
const unsigned int *n;
for (i = 0; i < count; i++) {
}
break;
}
case SET_BOOL: {
const bool *b;
for (i = 0; i < count; i++) {
}
break;
}
}
for (i = 2; i < count; i++) {
}
if (same) {
for (i = 0; i < indent; i++)
}
} else {
for (i = 0; i < indent; i++)
for (i = 1; i < count; i++) {
}
}
t_pop();
}
}
static void
{
const void *sets[2];
printf("namespace:\n");
nondefaults, 2);
}
}
{
const struct auth_passdb_settings *passdb;
const struct auth_userdb_settings *userdb;
const struct auth_socket_settings *socket;
const void *empty_defaults;
sizeof(struct auth_userdb_settings) +
sizeof(struct auth_socket_settings));
sets[0] = &default_auth_settings;
sets2[0] = empty_defaults;
printf(" passdb:\n");
nondefaults, 4);
}
printf(" userdb:\n");
nondefaults, 4);
}
printf(" socket:\n");
nondefaults, 4);
printf(" client:\n");
}
printf(" master:\n");
}
}
}
}
{
const void *sets[4];
const char *set_names[4];
unsigned int count;
sets[0] = &default_settings;
count = 2;
count++;
}
count++;
}
}
void master_settings_init(void)
{
}
void master_settings_deinit(void)
{
}