Mercurial > dovecot > core-2.2
changeset 10111:9a71228ea41c HEAD
imap-login: If imap_capability is set, use it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Oct 2009 18:11:00 -0400 |
parents | ac674fc9de57 |
children | c80eb856a742 |
files | src/imap-login/Makefile.am src/imap-login/client.c src/imap-login/client.h src/imap-login/imap-login-settings.c src/imap-login/imap-login-settings.h src/login-common/client-common.c src/login-common/client-common.h src/login-common/common.h src/login-common/login-settings.c src/login-common/login-settings.h src/login-common/main.c src/pop3-login/Makefile.am src/pop3-login/client.c src/pop3-login/pop3-login-settings.c src/pop3-login/pop3-login-settings.h |
diffstat | 15 files changed, 164 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap-login/Makefile.am Tue Oct 20 18:04:06 2009 -0400 +++ b/src/imap-login/Makefile.am Tue Oct 20 18:11:00 2009 -0400 @@ -4,6 +4,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ -I$(top_srcdir)/src/lib-auth \ -I$(top_srcdir)/src/lib-imap \ -I$(top_srcdir)/src/lib-master \ @@ -19,9 +20,11 @@ imap_login_SOURCES = \ client.c \ client-authenticate.c \ + imap-login-settings.c \ imap-proxy.c noinst_HEADERS = \ client.h \ client-authenticate.h \ + imap-login-settings.h \ imap-proxy.h
--- a/src/imap-login/client.c Tue Oct 20 18:04:06 2009 -0400 +++ b/src/imap-login/client.c Tue Oct 20 18:11:00 2009 -0400 @@ -19,6 +19,7 @@ #include "auth-client.h" #include "ssl-proxy.h" #include "imap-proxy.h" +#include "imap-login-settings.h" #include <stdlib.h> @@ -57,10 +58,13 @@ static const char *get_capability(struct client *client) { - const char *auths; + struct imap_client *imap_client = (struct imap_client *)client; + const char *auths, *cap_str; + cap_str = *imap_client->set->imap_capability != '\0' ? + imap_client->set->imap_capability : CAPABILITY_BANNER_STRING; auths = client_authenticate_get_capabilities(client); - return t_strconcat(CAPABILITY_BANNER_STRING, + return t_strconcat(cap_str, (ssl_initialized && !client->tls) ? " STARTTLS" : "", client->set->disable_plaintext_auth && !client->secured ? " LOGINDISABLED" : "", @@ -306,10 +310,11 @@ return &imap_client->common; } -static void imap_client_create(struct client *client) +static void imap_client_create(struct client *client, void **other_sets) { struct imap_client *imap_client = (struct imap_client *)client; + imap_client->set = other_sets[0]; imap_client->parser = imap_parser_create(imap_client->common.input, imap_client->common.output, MAX_IMAP_LINE); @@ -419,7 +424,7 @@ void clients_init(void) { - /* Nothing to initialize for IMAP */ + login_set_roots = imap_login_setting_roots; } void clients_deinit(void)
--- a/src/imap-login/client.h Tue Oct 20 18:04:06 2009 -0400 +++ b/src/imap-login/client.h Tue Oct 20 18:11:00 2009 -0400 @@ -7,6 +7,7 @@ struct imap_client { struct client common; + const struct imap_login_settings *set; struct imap_parser *parser; char *proxy_backend_capability;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/imap-login/imap-login-settings.c Tue Oct 20 18:11:00 2009 -0400 @@ -0,0 +1,48 @@ +/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "settings-parser.h" +#include "login-settings.h" +#include "imap-login-settings.h" + +#include <stddef.h> + +#undef DEF +#define DEF(type, name) \ + { type, #name, offsetof(struct imap_login_settings, name), NULL } + +static struct setting_define imap_login_setting_defines[] = { + DEF(SET_STR, imap_capability), + + SETTING_DEFINE_LIST_END +}; + +static struct imap_login_settings imap_login_default_settings = { + MEMBER(imap_capability) "" +}; + +static struct setting_parser_info *imap_login_setting_dependencies[] = { + &login_setting_parser_info, + NULL +}; + +static struct setting_parser_info imap_login_setting_parser_info = { + MEMBER(module_name) "imap-login", + MEMBER(defines) imap_login_setting_defines, + MEMBER(defaults) &imap_login_default_settings, + + MEMBER(type_offset) (size_t)-1, + MEMBER(struct_size) sizeof(struct imap_login_settings), + + MEMBER(parent_offset) (size_t)-1, + MEMBER(parent) NULL, + + MEMBER(check_func) NULL, + MEMBER(dependencies) imap_login_setting_dependencies +}; + +const struct setting_parser_info *imap_login_setting_roots[] = { + &login_setting_parser_info, + &imap_login_setting_parser_info, + NULL +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/imap-login/imap-login-settings.h Tue Oct 20 18:11:00 2009 -0400 @@ -0,0 +1,10 @@ +#ifndef IMAP_LOGIN_SETTINGS_H +#define IMAP_LOGIN_SETTINGS_H + +struct imap_login_settings { + const char *imap_capability; +}; + +extern const struct setting_parser_info *imap_login_setting_roots[]; + +#endif
--- a/src/login-common/client-common.c Tue Oct 20 18:04:06 2009 -0400 +++ b/src/login-common/client-common.c Tue Oct 20 18:11:00 2009 -0400 @@ -37,10 +37,10 @@ o_stream_create_fd(client->fd, LOGIN_MAX_OUTBUF_SIZE, FALSE); } -struct client *client_create(int fd, bool ssl, pool_t pool, - const struct login_settings *set, - const struct ip_addr *local_ip, - const struct ip_addr *remote_ip) +struct client * +client_create(int fd, bool ssl, pool_t pool, + const struct login_settings *set, void **other_sets, + const struct ip_addr *local_ip, const struct ip_addr *remote_ip) { struct client *client; @@ -78,7 +78,7 @@ client_idle_disconnect_timeout, client); client_open_streams(client); - client->v.create(client); + client->v.create(client, other_sets); if (auth_client_is_connected(auth_client)) client->v.send_greeting(client);
--- a/src/login-common/client-common.h Tue Oct 20 18:04:06 2009 -0400 +++ b/src/login-common/client-common.h Tue Oct 20 18:11:00 2009 -0400 @@ -53,7 +53,7 @@ struct client_vfuncs { struct client *(*alloc)(pool_t pool); - void (*create)(struct client *client); + void (*create)(struct client *client, void **other_sets); void (*destroy)(struct client *client); void (*send_greeting)(struct client *client); void (*starttls)(struct client *client); @@ -126,10 +126,10 @@ extern struct client *clients; extern struct client_vfuncs client_vfuncs; -struct client *client_create(int fd, bool ssl, pool_t pool, - const struct login_settings *set, - const struct ip_addr *local_ip, - const struct ip_addr *remote_ip); +struct client * +client_create(int fd, bool ssl, pool_t pool, + const struct login_settings *set, void **other_sets, + const struct ip_addr *local_ip, const struct ip_addr *remote_ip); void client_destroy(struct client *client, const char *reason); void client_destroy_success(struct client *client, const char *reason); void client_destroy_internal_failure(struct client *client);
--- a/src/login-common/common.h Tue Oct 20 18:04:06 2009 -0400 +++ b/src/login-common/common.h Tue Oct 20 18:11:00 2009 -0400 @@ -21,6 +21,7 @@ extern int anvil_fd; extern const struct login_settings *global_login_settings; +extern void **global_other_settings; void login_process_preinit(void);
--- a/src/login-common/login-settings.c Tue Oct 20 18:04:06 2009 -0400 +++ b/src/login-common/login-settings.c Tue Oct 20 18:11:00 2009 -0400 @@ -84,11 +84,13 @@ MEMBER(check_func) login_settings_check }; -const struct setting_parser_info *login_set_roots[] = { +static const struct setting_parser_info *default_login_set_roots[] = { &login_setting_parser_info, NULL }; +const struct setting_parser_info **login_set_roots = default_login_set_roots; + /* <settings checks> */ static int ssl_settings_check(void *_set ATTR_UNUSED, const char **error_r) { @@ -156,16 +158,17 @@ struct login_settings * login_settings_read(struct master_service *service, pool_t pool, const struct ip_addr *local_ip, - const struct ip_addr *remote_ip) + const struct ip_addr *remote_ip, + void ***other_settings_r) { struct master_service_settings_input input; const char *error; void **sets; - struct login_settings *set; + unsigned int i; memset(&input, 0, sizeof(input)); input.roots = login_set_roots; - input.module = "login"; + input.module = login_process_name; input.service = login_protocol; if (local_ip != NULL) @@ -180,8 +183,15 @@ i_fatal("Error reading configuration: %s", error); sets = master_service_settings_get_others(service); - set = settings_dup(&login_setting_parser_info, sets[0], pool); - if (!login_settings_check(set, pool, &error)) - i_fatal("login_settings_check() failed: %s", error); - return set; + for (i = 0; sets[i] != NULL; i++) { + sets[i] = settings_dup(input.roots[i], sets[i], pool); + if (!settings_check(input.roots[i], pool, sets[i], &error)) { + const char *name = input.roots[i]->module_name; + i_fatal("settings_check(%s) failed: %s", + name != NULL ? name : "unknown", error); + } + } + + *other_settings_r = sets + 1; + return sets[0]; }
--- a/src/login-common/login-settings.h Tue Oct 20 18:04:06 2009 -0400 +++ b/src/login-common/login-settings.h Tue Oct 20 18:11:00 2009 -0400 @@ -32,11 +32,13 @@ char *const *log_format_elements_split; }; -extern const struct setting_parser_info *login_set_roots[]; +extern const struct setting_parser_info **login_set_roots; +extern struct setting_parser_info login_setting_parser_info; struct login_settings * login_settings_read(struct master_service *service, pool_t pool, const struct ip_addr *local_ip, - const struct ip_addr *remote_ip); + const struct ip_addr *remote_ip, + void ***other_settings_r); #endif
--- a/src/login-common/main.c Tue Oct 20 18:04:06 2009 -0400 +++ b/src/login-common/main.c Tue Oct 20 18:11:00 2009 -0400 @@ -24,6 +24,7 @@ int anvil_fd = -1; const struct login_settings *global_login_settings; +void **global_other_settings; static bool ssl_connections = FALSE; @@ -36,6 +37,7 @@ unsigned int local_port; pool_t pool; int fd_ssl; + void **other_sets; if (net_getsockname(conn->fd, &local_ip, &local_port) < 0) { memset(&local_ip, 0, sizeof(local_ip)); @@ -44,11 +46,11 @@ pool = pool_alloconly_create("login client", 3*1024); set = login_settings_read(master_service, pool, &local_ip, - &conn->remote_ip); + &conn->remote_ip, &other_sets); if (!ssl_connections && !conn->ssl) { - client = client_create(conn->fd, FALSE, pool, set, &local_ip, - &conn->remote_ip); + client = client_create(conn->fd, FALSE, pool, set, other_sets, + &local_ip, &conn->remote_ip); } else { fd_ssl = ssl_proxy_new(conn->fd, &conn->remote_ip, set, &proxy); if (fd_ssl == -1) { @@ -57,7 +59,7 @@ return; } - client = client_create(fd_ssl, TRUE, pool, set, + client = client_create(fd_ssl, TRUE, pool, set, other_sets, &local_ip, &conn->remote_ip); client->ssl_proxy = proxy; ssl_proxy_set_client(proxy, client); @@ -198,7 +200,8 @@ process_title_init(argv, envp); set_pool = pool_alloconly_create("global login settings", 4096); global_login_settings = - login_settings_read(master_service, set_pool, NULL, NULL); + login_settings_read(master_service, set_pool, NULL, NULL, + &global_other_settings); /* main_preinit() needs to know the client limit, which is set by this. so call it first. */
--- a/src/pop3-login/Makefile.am Tue Oct 20 18:04:06 2009 -0400 +++ b/src/pop3-login/Makefile.am Tue Oct 20 18:11:00 2009 -0400 @@ -4,6 +4,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ -I$(top_srcdir)/src/lib-auth \ -I$(top_srcdir)/src/lib-master \ -I$(top_srcdir)/src/login-common @@ -18,9 +19,11 @@ pop3_login_SOURCES = \ client.c \ client-authenticate.c \ + pop3-login-settings.c \ pop3-proxy.c noinst_HEADERS = \ client.h \ client-authenticate.h \ + pop3-login-settings.h \ pop3-proxy.h
--- a/src/pop3-login/client.c Tue Oct 20 18:04:06 2009 -0400 +++ b/src/pop3-login/client.c Tue Oct 20 18:11:00 2009 -0400 @@ -7,6 +7,7 @@ #include "istream.h" #include "ostream.h" #include "randgen.h" +#include "hostpid.h" #include "safe-memset.h" #include "str.h" #include "strescape.h" @@ -15,7 +16,7 @@ #include "auth-client.h" #include "ssl-proxy.h" #include "pop3-proxy.h" -#include "hostpid.h" +#include "pop3-login-settings.h" /* Disconnect client when it sends too many bad commands */ #define CLIENT_MAX_BAD_COMMANDS 10 @@ -109,7 +110,8 @@ return &pop3_client->common; } -static void pop3_client_create(struct client *client ATTR_UNUSED) +static void pop3_client_create(struct client *client ATTR_UNUSED, + void **other_sets ATTR_UNUSED) { } @@ -206,7 +208,7 @@ void clients_init(void) { - /* Nothing to initialize for POP3 */ + login_set_roots = pop3_login_setting_roots; } void clients_deinit(void)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pop3-login/pop3-login-settings.c Tue Oct 20 18:11:00 2009 -0400 @@ -0,0 +1,38 @@ +/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "settings-parser.h" +#include "login-settings.h" +#include "pop3-login-settings.h" + +#include <stddef.h> + +static struct setting_define pop3_login_setting_defines[] = { + SETTING_DEFINE_LIST_END +}; + +static struct setting_parser_info *pop3_login_setting_dependencies[] = { + &login_setting_parser_info, + NULL +}; + +struct setting_parser_info pop3_login_setting_parser_info = { + MEMBER(module_name) "pop3-login", + MEMBER(defines) pop3_login_setting_defines, + MEMBER(defaults) NULL, + + MEMBER(type_offset) (size_t)-1, + MEMBER(struct_size) 0, + + MEMBER(parent_offset) (size_t)-1, + MEMBER(parent) NULL, + + MEMBER(check_func) NULL, + MEMBER(dependencies) pop3_login_setting_dependencies +}; + +const struct setting_parser_info *pop3_login_setting_roots[] = { + &login_setting_parser_info, + &pop3_login_setting_parser_info, + NULL +};