]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-common: Change process title to show different connection types
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 1 Nov 2017 20:48:55 +0000 (22:48 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 6 Nov 2017 23:09:00 +0000 (01:09 +0200)
Separate pre-login connections, proxy connections and post-login TLS
proxies.

src/login-common/client-common.c
src/login-common/client-common.h
src/login-common/login-proxy.c
src/login-common/login-proxy.h
src/login-common/main.c

index e099d5ce1189f872149d4c5df4d2fa1a70d0b45e..d9f6222815719ea9082eaa6a7e4fdd5c6c274512 100644 (file)
@@ -33,6 +33,7 @@ static struct client *last_client = NULL;
 static unsigned int clients_count = 0;
 
 static struct client *client_fd_proxies = NULL;
+static unsigned int client_fd_proxies_count = 0;
 
 struct login_client_module_hooks {
        struct module *module;
@@ -269,6 +270,7 @@ void client_destroy(struct client *client, const char *reason)
                if (client->iostream_fd_proxy != NULL) {
                        client->fd_proxying = TRUE;
                        DLLIST_PREPEND(&client_fd_proxies, client);
+                       client_fd_proxies_count++;
                }
        }
 
@@ -354,6 +356,8 @@ bool client_unref(struct client **_client)
                iostream_proxy_unref(&client->iostream_fd_proxy);
        if (client->fd_proxying) {
                DLLIST_REMOVE(&client_fd_proxies, client);
+               i_assert(client_fd_proxies_count > 0);
+               client_fd_proxies_count--;
        }
        i_stream_unref(&client->input);
        o_stream_unref(&client->output);
@@ -574,6 +578,16 @@ unsigned int clients_get_count(void)
        return clients_count;
 }
 
+unsigned int clients_get_fd_proxies_count(void)
+{
+       return client_fd_proxies_count;
+}
+
+struct client *clients_get_first_fd_proxy(void)
+{
+       return client_fd_proxies;
+}
+
 void client_add_forward_field(struct client *client, const char *key,
                              const char *value)
 {
@@ -1032,6 +1046,7 @@ void client_destroy_fd_proxies(void)
                struct client *client = client_fd_proxies;
                client_unref(&client);
        }
+       i_assert(client_fd_proxies_count == 0);
 }
 
 void client_common_deinit(void)
index 2467f20f6c75e312810f0bd841775274f268c514..2d644c139bc5b88cded360e54daea44ce31607f7 100644 (file)
@@ -264,6 +264,8 @@ void client_cmd_starttls(struct client *client);
 int client_get_plaintext_fd(struct client *client, int *fd_r, bool *close_fd_r);
 
 unsigned int clients_get_count(void) ATTR_PURE;
+unsigned int clients_get_fd_proxies_count(void);
+struct client *clients_get_first_fd_proxy(void);
 
 void client_add_forward_field(struct client *client, const char *key,
                              const char *value);
index a7ed71b0fa1331aeff8c32a8ef2ae28ddd22be2b..4cce5d7533941d7eff068d0ab0d29c40fe1a258f 100644 (file)
@@ -75,6 +75,7 @@ static struct login_proxy *login_proxies = NULL;
 static struct login_proxy *login_proxies_pending = NULL;
 static struct login_proxy *login_proxies_disconnecting = NULL;
 static struct ipc_server *login_proxy_ipc_server;
+static unsigned int detached_login_proxies_count = 0;
 
 static int login_proxy_connect(struct login_proxy *proxy);
 static void login_proxy_disconnect(struct login_proxy *proxy);
@@ -505,6 +506,9 @@ login_proxy_free_full(struct login_proxy **_proxy, const char *reason,
                        ipstr != NULL ? ipstr : "",
                        reason == NULL ? "" : t_strdup_printf(" (%s)", reason),
                        delay_ms == 0 ? "" : t_strdup_printf(" - disconnecting client in %ums", delay_ms)));
+
+               i_assert(detached_login_proxies_count > 0);
+               detached_login_proxies_count--;
        } else {
                i_assert(proxy->client_input == NULL);
                i_assert(proxy->client_output == NULL);
@@ -669,6 +673,7 @@ void login_proxy_detach(struct login_proxy *proxy)
 
        DLLIST_REMOVE(&login_proxies_pending, proxy);
        DLLIST_PREPEND(&login_proxies, proxy);
+       detached_login_proxies_count++;
 
        client->login_proxy = NULL;
 }
@@ -957,6 +962,16 @@ static void login_proxy_ipc_cmd(struct ipc_cmd *cmd, const char *line)
                ipc_cmd_fail(&cmd, "Unknown command");
 }
 
+unsigned int login_proxies_get_detached_count(void)
+{
+       return detached_login_proxies_count;
+}
+
+struct client *login_proxies_get_first_detached_client(void)
+{
+       return login_proxies == NULL ? NULL : login_proxies->client;
+}
+
 void login_proxy_init(const char *proxy_notify_pipe_path)
 {
        proxy_state = login_proxy_state_init(proxy_notify_pipe_path);
@@ -970,6 +985,8 @@ void login_proxy_deinit(void)
                proxy = login_proxies;
                login_proxy_free_reason(&proxy, KILLED_BY_SHUTDOWN_REASON);
        }
+       i_assert(detached_login_proxies_count == 0);
+
        while (login_proxies_disconnecting != NULL)
                login_proxy_free_final(login_proxies_disconnecting);
        if (login_proxy_ipc_server != NULL)
index a5dfb904c0bae0d4be0dccc03f5ac231709fe6d1..7848ae51d1ea48882e0acafdbf014eb096da35f3 100644 (file)
@@ -66,6 +66,9 @@ login_proxy_get_ssl_flags(const struct login_proxy *proxy) ATTR_PURE;
 
 void login_proxy_kill_idle(void);
 
+unsigned int login_proxies_get_detached_count(void);
+struct client *login_proxies_get_first_detached_client(void);
+
 void login_proxy_init(const char *proxy_notify_pipe_path);
 void login_proxy_deinit(void);
 
index 2df7f3b1574ba3aab0d726f108c38b93e0197729..c5e7dffb7026af186da4bc06a2a34a19a4cc7a43 100644 (file)
@@ -3,6 +3,7 @@
 #include "login-common.h"
 #include "ioloop.h"
 #include "array.h"
+#include "str.h"
 #include "randgen.h"
 #include "module-dir.h"
 #include "process-title.h"
@@ -60,28 +61,67 @@ static bool auth_connected_once = FALSE;
 
 static void login_access_lookup_next(struct login_access_lookup *lookup);
 
-void login_refresh_proctitle(void)
+static bool get_first_client(struct client **client_r)
 {
        struct client *client = clients;
+
+       if (client == NULL)
+               client = login_proxies_get_first_detached_client();
+       if (client == NULL)
+               client = clients_get_first_fd_proxy();
+       *client_r = client;
+       return client != NULL;
+}
+
+void login_refresh_proctitle(void)
+{
+       struct client *client;
        const char *addr;
 
        if (!global_login_settings->verbose_proctitle)
                return;
 
+       /* clients_get_count() includes all the clients being served.
+          Inside that there are 3 groups:
+          1. pre-login clients
+          2. post-login clients being proxied to remote hosts
+          3. post-login clients being proxied to post-login processes
+          Currently the post-login proxying is done only for SSL/TLS
+          connections, so we're assuming that they're the same. */
+       string_t *str = t_str_new(64);
        if (clients_get_count() == 0) {
-               process_title_set("");
-       } else if (clients_get_count() > 1 || client == NULL) {
-               process_title_set(t_strdup_printf("[%u connections (%u TLS)]",
-                       clients_get_count(), ssl_proxy_get_count()));
+               /* no clients */
+       } else if (clients_get_count() > 1 || !get_first_client(&client)) {
+               str_printfa(str, "[%u pre-login", clients_get_count() -
+                           login_proxies_get_detached_count() -
+                           clients_get_fd_proxies_count());
+               if (login_proxies_get_detached_count() > 0) {
+                       /* show detached proxies only if they exist, so
+                          non-proxy servers don't unnecessarily show them. */
+                       str_printfa(str, " + %u proxies",
+                                   login_proxies_get_detached_count());
+               }
+               if (clients_get_fd_proxies_count() > 0) {
+                       /* show post-login proxies only if they exist, so
+                          proxy-only servers don't unnecessarily show them. */
+                       str_printfa(str, " + %u TLS proxies",
+                                   clients_get_fd_proxies_count());
+               }
+               str_append_c(str, ']');
        } else {
+               str_append_c(str, '[');
                addr = net_ip2addr(&client->ip);
-               if (addr[0] != '\0') {
-                       process_title_set(t_strdup_printf(client->tls ?
-                               "[%s TLS]" : "[%s]", addr));
-               } else {
-                       process_title_set(client->tls ? "[TLS]" : "");
-               }
+               if (addr[0] != '\0')
+                       str_printfa(str, "%s ", addr);
+               if (client->fd_proxying)
+                       str_append(str, "TLS proxy");
+               else if (client->destroyed)
+                       str_append(str, "proxy");
+               else
+                       str_append(str, "pre-login");
+               str_append_c(str, ']');
        }
+       process_title_set(str_c(str));
 }
 
 static void auth_client_idle_timeout(struct auth_client *auth_client)