Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4861:a688269c0dd4 HEAD
Added %a=local port and %b=remote port variables for
login_log_format_elements.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 03 Dec 2006 15:50:44 +0200 |
parents | 87ae4d41bc10 |
children | bddfbc560857 |
files | doc/variables.txt src/login-common/client-common.c src/login-common/client-common.h src/login-common/main.c |
diffstat | 4 files changed, 36 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/variables.txt Sun Dec 03 15:35:18 2006 +0200 +++ b/doc/variables.txt Sun Dec 03 15:50:44 2006 +0200 @@ -50,4 +50,6 @@ For login_log_format_elements there are also these variables: %m - authentication method (eg. PLAIN) + %a - Local port + %b - Remote port %c - SSL, TLS or empty
--- a/src/login-common/client-common.c Sun Dec 03 15:35:18 2006 +0200 +++ b/src/login-common/client-common.c Sun Dec 03 15:50:44 2006 +0200 @@ -23,6 +23,8 @@ { 'r', NULL }, { 'p', NULL }, { 'm', NULL }, + { 'a', NULL }, + { 'b', NULL }, { 'c', NULL }, { '\0', NULL } }; @@ -44,10 +46,12 @@ tab[7].value = my_pid; tab[8].value = client->auth_mech_name == NULL ? NULL : str_sanitize(client->auth_mech_name, MAX_MECH_NAME); + tab[9].value = dec2str(client->local_port); + tab[10].value = dec2str(client->remote_port); if (!client->tls) { - tab[9].value = client->secured ? "secured" : NULL; + tab[11].value = client->secured ? "secured" : NULL; } else { - tab[9].value = client->proxy != NULL && + tab[11].value = client->proxy != NULL && ssl_proxy_is_handshaked(client->proxy) ? "TLS" : "TLS handshaking"; }
--- a/src/login-common/client-common.h Sun Dec 03 15:35:18 2006 +0200 +++ b/src/login-common/client-common.h Sun Dec 03 15:50:44 2006 +0200 @@ -8,6 +8,7 @@ struct client { struct ip_addr local_ip; struct ip_addr ip; + unsigned int local_port, remote_port; struct ssl_proxy *proxy; int fd;
--- a/src/login-common/main.c Sun Dec 03 15:35:18 2006 +0200 +++ b/src/login-common/main.c Sun Dec 03 15:50:44 2006 +0200 @@ -61,20 +61,26 @@ static void login_accept(void *context __attr_unused__) { - struct ip_addr ip, local_ip; + struct ip_addr remote_ip, local_ip; + unsigned int remote_port, local_port; + struct client *client; int fd; - fd = net_accept(LOGIN_LISTEN_FD, &ip, NULL); + fd = net_accept(LOGIN_LISTEN_FD, &remote_ip, &remote_port); if (fd < 0) { if (fd < -1) i_fatal("accept() failed: %m"); return; } - if (net_getsockname(fd, &local_ip, NULL) < 0) + if (net_getsockname(fd, &local_ip, &local_port) < 0) { memset(&local_ip, 0, sizeof(local_ip)); + local_port = 0; + } - (void)client_create(fd, FALSE, &local_ip, &ip); + client = client_create(fd, FALSE, &local_ip, &remote_ip); + client->remote_port = remote_port; + client->local_port = local_port; if (process_per_connection) { closing_down = TRUE; @@ -84,27 +90,32 @@ static void login_accept_ssl(void *context __attr_unused__) { - struct ip_addr ip, local_ip; + struct ip_addr remote_ip, local_ip; + unsigned int remote_port, local_port; struct client *client; struct ssl_proxy *proxy; int fd, fd_ssl; - fd = net_accept(LOGIN_SSL_LISTEN_FD, &ip, NULL); + fd = net_accept(LOGIN_SSL_LISTEN_FD, &remote_ip, &remote_port); if (fd < 0) { if (fd < -1) i_fatal("accept() failed: %m"); return; } - if (net_getsockname(fd, &local_ip, NULL) < 0) + if (net_getsockname(fd, &local_ip, &local_port) < 0) { memset(&local_ip, 0, sizeof(local_ip)); + local_port = 0; + } - fd_ssl = ssl_proxy_new(fd, &ip, &proxy); + fd_ssl = ssl_proxy_new(fd, &remote_ip, &proxy); if (fd_ssl == -1) net_disconnect(fd); else { - client = client_create(fd_ssl, TRUE, &local_ip, &ip); + client = client_create(fd_ssl, TRUE, &local_ip, &remote_ip); client->proxy = proxy; + client->remote_port = remote_port; + client->local_port = local_port; } if (process_per_connection) { @@ -336,8 +347,8 @@ int main(int argc __attr_unused__, char *argv[], char *envp[]) { const char *name, *group_name; - struct ip_addr ip, local_ip; - unsigned int local_port; + struct ip_addr remote_ip, local_ip; + unsigned int remote_port, local_port; struct ssl_proxy *proxy = NULL; struct client *client; int i, fd = -1, master_fd = -1; @@ -378,7 +389,7 @@ main_init(); if (is_inetd) { - if (net_getpeername(1, &ip, NULL) < 0) { + if (net_getpeername(1, &remote_ip, &remote_port) < 0) { i_fatal("%s can be started only through dovecot " "master process, inetd or equilevant", argv[0]); } @@ -398,7 +409,7 @@ /* hardcoded imaps and pop3s ports to be SSL by default */ if (local_port == 993 || local_port == 995 || ssl) { ssl = TRUE; - fd = ssl_proxy_new(fd, &ip, &proxy); + fd = ssl_proxy_new(fd, &remote_ip, &proxy); if (fd == -1) return 1; } @@ -407,8 +418,10 @@ closing_down = TRUE; if (fd != -1) { - client = client_create(fd, ssl, &local_ip, &ip); + client = client_create(fd, ssl, &local_ip, &remote_ip); client->proxy = proxy; + client->remote_port = remote_port; + client->local_port = local_port; } }