]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-login: If imap_capability is set, use it.
authorTimo Sirainen <tss@iki.fi>
Tue, 20 Oct 2009 22:11:00 +0000 (18:11 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 20 Oct 2009 22:11:00 +0000 (18:11 -0400)
--HG--
branch : HEAD

15 files changed:
src/imap-login/Makefile.am
src/imap-login/client.c
src/imap-login/client.h
src/imap-login/imap-login-settings.c [new file with mode: 0644]
src/imap-login/imap-login-settings.h [new file with mode: 0644]
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 [new file with mode: 0644]
src/pop3-login/pop3-login-settings.h [new file with mode: 0644]

index 5b48406b64d5a8efed0eb5f083c45eba994caac0..435e346da2d1f0e1c1c99ee4164c063dc476d6fa 100644 (file)
@@ -4,6 +4,7 @@ pkglibexec_PROGRAMS = imap-login
 
 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_DEPENDENCIES = \
 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
index dcb16291b0beb3fd876a5d7698b3314247aa34c1..3bcbc2d4442bac32f4d1c1578a46db85819565a3 100644 (file)
@@ -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 @@ bool client_skip_line(struct imap_client *client)
 
 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 @@ static struct client *imap_client_alloc(pool_t pool)
        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 @@ imap_client_send_line(struct client *client, enum client_cmd_reply reply,
 
 void clients_init(void)
 {
-       /* Nothing to initialize for IMAP */
+       login_set_roots = imap_login_setting_roots;
 }
 
 void clients_deinit(void)
index 1339ee39fcf21bbf35d2ac93f049c6d85bed44b9..100fc87d77598c758f1ac384cd30d7bb332d6bf5 100644 (file)
@@ -7,6 +7,7 @@
 struct imap_client {
        struct client common;
 
+       const struct imap_login_settings *set;
        struct imap_parser *parser;
        char *proxy_backend_capability;
 
diff --git a/src/imap-login/imap-login-settings.c b/src/imap-login/imap-login-settings.c
new file mode 100644 (file)
index 0000000..9ca1a5f
--- /dev/null
@@ -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
+};
diff --git a/src/imap-login/imap-login-settings.h b/src/imap-login/imap-login-settings.h
new file mode 100644 (file)
index 0000000..3307c52
--- /dev/null
@@ -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
index 6bc653c549b348378ef22b3f5863279a1afe6d23..3be771aaf15881074248a717f8aa26dea020835a 100644 (file)
@@ -37,10 +37,10 @@ static void client_open_streams(struct client *client)
                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 @@ struct client *client_create(int fd, bool ssl, pool_t pool,
                            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);
index cd3f896e272cae4b3bb2c9004b6fc082dac32e2f..de75c3841da28d726a4c286f638870c846d610e6 100644 (file)
@@ -53,7 +53,7 @@ struct client_auth_reply {
 
 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 @@ struct client {
 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);
index d44cfc0401c775b19eb4338451ef1b0148449c51..613b4a9076f64e509cbc44cf3e9acea3877ef167 100644 (file)
@@ -21,6 +21,7 @@ extern bool closing_down;
 extern int anvil_fd;
 
 extern const struct login_settings *global_login_settings;
+extern void **global_other_settings;
 
 void login_process_preinit(void);
 
index 5bd96fc9789054dd915c996023b51616de2b8336..072cd97e1b1cecbab1eb7a95aec101c23b580039 100644 (file)
@@ -84,11 +84,13 @@ struct setting_parser_info login_setting_parser_info = {
        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 @@ static bool login_settings_check(void *_set, pool_t pool, const char **error_r)
 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 @@ login_settings_read(struct master_service *service, pool_t pool,
                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];
 }
index f63f5cb960484a7616ce90d6a7053ac4f22edb58..7c4b2e92ccd171664114c087d85142023fb55489 100644 (file)
@@ -32,11 +32,13 @@ struct login_settings {
        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
index 25eebddbdae32071e2d98905980aed3930e527c3..a843117d4c6ba934aae554001084213136c7f4ce 100644 (file)
@@ -24,6 +24,7 @@ bool closing_down;
 int anvil_fd = -1;
 
 const struct login_settings *global_login_settings;
+void **global_other_settings;
 
 static bool ssl_connections = FALSE;
 
@@ -36,6 +37,7 @@ static void client_connected(const struct master_service_connection *conn)
        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 @@ static void client_connected(const struct master_service_connection *conn)
 
        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 @@ static void client_connected(const struct master_service_connection *conn)
                        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 @@ int main(int argc, char *argv[], char *envp[])
        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. */
index 6cbf1101a3a4860d84d4a86a20f1a9b68481176e..7eff6858db1c0c920376f859add14242237dcaa3 100644 (file)
@@ -4,6 +4,7 @@ pkglibexec_PROGRAMS = pop3-login
 
 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_DEPENDENCIES = \
 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
index 19d6007d466e7aff1829c60e609e26ec010cc890..ef5de37f7e42a4c4378ad42c07354c3b6ac84d03 100644 (file)
@@ -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 @@ static struct client *pop3_client_alloc(pool_t pool)
        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 @@ pop3_client_send_line(struct client *client, enum client_cmd_reply reply,
 
 void clients_init(void)
 {
-       /* Nothing to initialize for POP3 */
+       login_set_roots = pop3_login_setting_roots;
 }
 
 void clients_deinit(void)
diff --git a/src/pop3-login/pop3-login-settings.c b/src/pop3-login/pop3-login-settings.c
new file mode 100644 (file)
index 0000000..e33f882
--- /dev/null
@@ -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
+};
diff --git a/src/pop3-login/pop3-login-settings.h b/src/pop3-login/pop3-login-settings.h
new file mode 100644 (file)
index 0000000..1c497eb
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef POP3_LOGIN_SETTINGS_H
+#define POP3_LOGIN_SETTINGS_H
+
+extern const struct setting_parser_info *pop3_login_setting_roots[];
+
+#endif