dovecot-2.0: mail processes now specify user/lip/rip in config r...
dovecot at dovecot.org
dovecot at dovecot.org
Wed May 6 22:53:14 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/4bf901b4c402
changeset: 9244:4bf901b4c402
user: Timo Sirainen <tss at iki.fi>
date: Wed May 06 15:53:07 2009 -0400
description:
mail processes now specify user/lip/rip in config requests.
diffstat:
7 files changed, 92 insertions(+), 43 deletions(-)
src/auth/auth-settings.c | 3 -
src/lib-master/master-service-settings.c | 81 ++++++++++++++++++++----------
src/lib-master/master-service-settings.h | 19 +++++--
src/lib-storage/mail-storage-service.c | 21 +++++--
src/log/main.c | 3 -
src/login-common/login-settings.c | 4 -
src/master/main.c | 4 -
diffs (truncated from 322 to 300 lines):
diff -r 64a7a1a3fe33 -r 4bf901b4c402 src/auth/auth-settings.c
--- a/src/auth/auth-settings.c Wed May 06 15:22:57 2009 -0400
+++ b/src/auth/auth-settings.c Wed May 06 15:53:07 2009 -0400
@@ -186,8 +186,7 @@ auth_settings_read(struct master_service
struct auth_root_settings *set;
unsigned int i, count;
- if (master_service_settings_read(service, set_roots, NULL, FALSE,
- &error) < 0)
+ if (master_service_settings_read_simple(service, set_roots, &error) < 0)
i_fatal("Error reading configuration: %s", error);
sets = master_service_settings_get_others(service);
diff -r 64a7a1a3fe33 -r 4bf901b4c402 src/lib-master/master-service-settings.c
--- a/src/lib-master/master-service-settings.c Wed May 06 15:22:57 2009 -0400
+++ b/src/lib-master/master-service-settings.c Wed May 06 15:53:07 2009 -0400
@@ -4,6 +4,7 @@
#include "array.h"
#include "istream.h"
#include "write-full.h"
+#include "str.h"
#include "settings-parser.h"
#include "master-service-private.h"
#include "master-service-settings.h"
@@ -16,7 +17,6 @@
#define DOVECOT_CONFIG_BIN_PATH BINDIR"/doveconf"
#define CONFIG_HANDSHAKE "VERSION\t1\t0\n"
-#define CONFIG_REQUEST_SERVICE "REQ\tservice=%s\n"
#undef DEF
#define DEF(type, name) \
@@ -97,31 +97,49 @@ master_service_exec_config(struct master
}
static int
-master_service_read_config(struct master_service *service, bool preserve_home,
+master_service_read_config(struct master_service *service,
+ const struct master_service_settings_input *input,
const char **error_r)
{
- const char *path, *str;
- int fd;
+ const char *path;
+ struct stat st;
+ int fd, ret;
path = master_service_get_config_path(service);
fd = net_connect_unix(path);
if (fd < 0) {
- struct stat st;
-
*error_r = t_strdup_printf("net_connect_unix(%s) failed: %m",
path);
if (stat(path, &st) == 0 && !S_ISFIFO(st.st_mode)) {
/* it's a file, not a socket */
- master_service_exec_config(service, preserve_home);
+ master_service_exec_config(service,
+ input->preserve_home);
}
return -1;
}
net_set_nonblock(fd, FALSE);
- str = t_strdup_printf(CONFIG_HANDSHAKE CONFIG_REQUEST_SERVICE,
- service->name);
- if (write_full(fd, str, strlen(str)) < 0) {
+ T_BEGIN {
+ string_t *str;
+
+ str = t_str_new(128);
+ str_append(str, CONFIG_HANDSHAKE);
+ str_printfa(str, "REQ\tservice=%s", service->name);
+ if (input->username != NULL)
+ str_printfa(str, "\tuser=%s", input->username);
+ if (input->local_ip.family != 0) {
+ str_printfa(str, "\tlip=%s",
+ net_ip2addr(&input->local_ip));
+ }
+ if (input->remote_ip.family != 0) {
+ str_printfa(str, "\trip=%s",
+ net_ip2addr(&input->remote_ip));
+ }
+ str_append_c(str, '\n');
+ ret = write_full(fd, str_data(str), str_len(str));
+ } T_END;
+ if (ret < 0) {
*error_r = t_strdup_printf("write_full(%s) failed: %m", path);
return -1;
}
@@ -151,22 +169,20 @@ master_service_apply_config_overrides(st
}
int master_service_settings_read(struct master_service *service,
- const struct setting_parser_info *roots[],
- const struct dynamic_settings_parser *dyn_parsers,
- bool preserve_home, const char **error_r)
+ const struct master_service_settings_input *input,
+ const char **error_r)
{
ARRAY_DEFINE(all_roots, const struct setting_parser_info *);
const struct setting_parser_info *tmp_root;
struct setting_parser_context *parser;
- struct istream *input;
+ struct istream *istream;
const char *error, *env, *const *keys;
void **sets;
unsigned int i;
int ret, fd = -1;
if (getenv("DOVECONF_ENV") == NULL) {
- fd = master_service_read_config(service, preserve_home,
- error_r);
+ fd = master_service_read_config(service, input, error_r);
if (fd == -1)
return -1;
}
@@ -178,15 +194,17 @@ int master_service_settings_read(struct
pool_alloconly_create("master service settings", 4096);
}
- if (dyn_parsers != NULL)
- settings_parser_info_update(service->set_pool, dyn_parsers);
+ if (input->dyn_parsers != NULL) {
+ settings_parser_info_update(service->set_pool,
+ input->dyn_parsers);
+ }
p_array_init(&all_roots, service->set_pool, 8);
tmp_root = &master_service_setting_parser_info;
array_append(&all_roots, &tmp_root, 1);
- if (roots != NULL) {
- for (i = 0; roots[i] != NULL; i++)
- array_append(&all_roots, &roots[i], 1);
+ if (input->roots != NULL) {
+ for (i = 0; input->roots[i] != NULL; i++)
+ array_append(&all_roots, &input->roots[i], 1);
}
parser = settings_parser_init_list(service->set_pool,
@@ -194,9 +212,9 @@ int master_service_settings_read(struct
SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS);
if (fd != -1) {
- input = i_stream_create_fd(fd, (size_t)-1, FALSE);
- ret = settings_parse_stream_read(parser, input);
- i_stream_unref(&input);
+ istream = i_stream_create_fd(fd, (size_t)-1, FALSE);
+ ret = settings_parse_stream_read(parser, istream);
+ i_stream_unref(&istream);
i_assert(ret <= 0);
if (ret < 0) {
*error_r = settings_parser_get_error(parser);
@@ -210,11 +228,11 @@ int master_service_settings_read(struct
return -1;
}
env = getenv("VARS_EXPANDED");
- if (env != NULL) {
+ if (env != NULL) T_BEGIN {
keys = t_strsplit(env, " ");
settings_parse_set_keys_expandeded(parser, service->set_pool,
keys);
- }
+ } T_END;
if (array_is_created(&service->config_overrides)) {
if (master_service_apply_config_overrides(service, parser,
@@ -243,6 +261,17 @@ int master_service_settings_read(struct
return 0;
}
+int master_service_settings_read_simple(struct master_service *service,
+ const struct setting_parser_info **roots,
+ const char **error_r)
+{
+ struct master_service_settings_input input;
+
+ memset(&input, 0, sizeof(input));
+ input.roots = roots;
+ return master_service_settings_read(service, &input, error_r);
+}
+
const struct master_service_settings *
master_service_settings_get(struct master_service *service)
{
diff -r 64a7a1a3fe33 -r 4bf901b4c402 src/lib-master/master-service-settings.h
--- a/src/lib-master/master-service-settings.h Wed May 06 15:22:57 2009 -0400
+++ b/src/lib-master/master-service-settings.h Wed May 06 15:53:07 2009 -0400
@@ -1,5 +1,7 @@
#ifndef MASTER_SERVICE_SETTINGS_H
#define MASTER_SERVICE_SETTINGS_H
+
+#include "network.h"
struct setting_parser_info;
struct dynamic_settings_parser;
@@ -13,12 +15,23 @@ struct master_service_settings {
bool version_ignore;
};
+struct master_service_settings_input {
+ const struct setting_parser_info **roots;
+ const struct dynamic_settings_parser *dyn_parsers;
+ bool preserve_home;
+
+ const char *username;
+ struct ip_addr local_ip, remote_ip;
+};
+
extern struct setting_parser_info master_service_setting_parser_info;
int master_service_settings_read(struct master_service *service,
- const struct setting_parser_info *roots[],
- const struct dynamic_settings_parser *dyn_parsers,
- bool preserve_home, const char **error_r);
+ const struct master_service_settings_input *input,
+ const char **error_r);
+int master_service_settings_read_simple(struct master_service *service,
+ const struct setting_parser_info **roots,
+ const char **error_r);
const struct master_service_settings *
master_service_settings_get(struct master_service *service);
void **master_service_settings_get_others(struct master_service *service);
diff -r 64a7a1a3fe33 -r 4bf901b4c402 src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c Wed May 06 15:22:57 2009 -0400
+++ b/src/lib-storage/mail-storage-service.c Wed May 06 15:53:07 2009 -0400
@@ -303,11 +303,13 @@ service_drop_privileges(const struct mai
static void
mail_storage_service_init_settings(struct master_service *service,
+ const struct mail_storage_service_input *input,
const struct setting_parser_info *set_roots[],
bool preserve_home)
{
ARRAY_DEFINE(all_set_roots, const struct setting_parser_info *);
const struct setting_parser_info *info = &mail_user_setting_parser_info;
+ struct master_service_settings_input set_input;
const char *error;
unsigned int i;
@@ -327,10 +329,16 @@ mail_storage_service_init_settings(struc
/* read settings after registering storages so they can have their
own setting definitions too */
- set_roots = array_idx_modifiable(&all_set_roots, 0);
- if (master_service_settings_read(service, set_roots,
- mail_storage_get_dynamic_parsers(),
- preserve_home, &error) < 0)
+ memset(&set_input, 0, sizeof(set_input));
+ set_input.roots = array_idx_modifiable(&all_set_roots, 0);
+ set_input.dyn_parsers = mail_storage_get_dynamic_parsers();
+ set_input.preserve_home = preserve_home;
+ if (input != NULL) {
+ set_input.username = input->username;
+ set_input.local_ip = input->local_ip;
+ set_input.remote_ip = input->remote_ip;
+ }
+ if (master_service_settings_read(service, &set_input, &error) < 0)
i_fatal("Error reading configuration: %s", error);
}
@@ -472,7 +480,8 @@ mail_storage_service_init_user(struct ma
master_service_init_finish(service);
userdb_lookup = (flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0;
- mail_storage_service_init_settings(service, set_roots, !userdb_lookup);
+ mail_storage_service_init_settings(service, &input, set_roots,
+ !userdb_lookup);
if ((flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0)
set_keyval(service->set_parser, "mail_debug", "yes");
@@ -564,7 +573,7 @@ mail_storage_service_multi_init(struct m
ctx->service = service;
ctx->flags = flags;
- mail_storage_service_init_settings(service, set_roots, FALSE);
+ mail_storage_service_init_settings(service, NULL, set_roots, FALSE);
set = master_service_settings_get(service);
sets = master_service_settings_get_others(service);
diff -r 64a7a1a3fe33 -r 4bf901b4c402 src/log/main.c
--- a/src/log/main.c Wed May 06 15:22:57 2009 -0400
+++ b/src/log/main.c Wed May 06 15:53:07 2009 -0400
@@ -60,8 +60,7 @@ int main(int argc, char *argv[])
exit(FATAL_DEFAULT);
}
- if (master_service_settings_read(service, NULL, NULL, FALSE,
- &error) < 0)
+ if (master_service_settings_read_simple(service, NULL, &error) < 0)
i_fatal("Error reading configuration: %s", error);
master_service_init_log(service, "log: ", 0);
diff -r 64a7a1a3fe33 -r 4bf901b4c402 src/login-common/login-settings.c
--- a/src/login-common/login-settings.c Wed May 06 15:22:57 2009 -0400
+++ b/src/login-common/login-settings.c Wed May 06 15:53:07 2009 -0400
@@ -181,8 +181,8 @@ struct login_settings *login_settings_re
const char *error;
void **sets;
More information about the dovecot-cvs
mailing list