[dovecot-cvs] dovecot/src/login-common client-common.c, 1.1, 1.2 client-common.h, 1.7, 1.8 common.h, 1.7, 1.8 main.c, 1.24, 1.25 sasl-server.c, 1.7, 1.8

cras at dovecot.org cras at dovecot.org
Sat May 14 23:32:08 EEST 2005


Update of /var/lib/cvs/dovecot/src/login-common
In directory talvi:/tmp/cvs-serv17364/src/login-common

Modified Files:
	client-common.c client-common.h common.h main.c sasl-server.c 
Log Message:
Added configurable logging for login process. Added configurable pop3 logout
string. Based on a patch by Andrey Panin.



Index: client-common.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/login-common/client-common.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- client-common.c	13 Oct 2004 17:20:43 -0000	1.1
+++ client-common.c	14 May 2005 20:32:06 -0000	1.2
@@ -1,20 +1,108 @@
-/* Copyright (C) 2002 Timo Sirainen */
+/* Copyright (C) 2002-2005 Timo Sirainen */
 
 #include "common.h"
+#include "hostpid.h"
+#include "str.h"
+#include "str-sanitize.h"
+#include "var-expand.h"
 #include "client-common.h"
 
-void client_syslog(struct client *client, const char *format, ...)
+#include <stdlib.h>
+
+static const struct var_expand_table *
+get_var_expand_table(struct client *client)
 {
-	const char *addr;
-	va_list args;
+	static struct var_expand_table static_tab[] = {
+		{ 'u', NULL },
+		{ 'n', NULL },
+		{ 'd', NULL },
+		{ 's', NULL },
+		{ 'h', NULL },
+		{ 'l', NULL },
+		{ 'r', NULL },
+		{ 'p', NULL },
+		{ 'm', NULL },
+		{ 'c', NULL },
+		{ '\0', NULL }
+	};
+	struct var_expand_table *tab;
 
-	addr = net_ip2addr(&client->ip);
-	if (addr == NULL)
-		addr = "??";
+	tab = t_malloc(sizeof(static_tab));
+	memcpy(tab, static_tab, sizeof(static_tab));
+
+	if (client->virtual_user != NULL) {
+		tab[0].value = client->virtual_user;
+		tab[1].value = t_strcut(client->virtual_user, '@');
+		tab[2].value = strchr(client->virtual_user, '@');
+		if (tab[2].value != NULL) tab[2].value++;
+	}
+	tab[3].value = login_protocol;
+	tab[4].value = getenv("HOME");
+	tab[5].value = net_ip2addr(&client->local_ip);
+	tab[6].value = net_ip2addr(&client->ip);
+	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 = client->tls ? "TLS" : client->secured ? "SSL" : NULL;
+
+	return tab;
+}
+
+static int have_key(const struct var_expand_table *table, const char *str)
+{
+	char key;
+	unsigned int i;
+
+	key = var_get_key(str);
+	for (i = 0; table[i].key != '\0'; i++) {
+		if (table[i].key == key) {
+			return table[i].value != NULL &&
+				table[i].value[0] != '\0';
+		}
+	}
+	return FALSE;
+}
+
+void client_syslog(struct client *client, const char *msg)
+{
+	static struct var_expand_table static_tab[3] = {
+		{ 's', NULL },
+		{ '$', NULL },
+		{ '\0', NULL }
+	};
+	const struct var_expand_table *var_expand_table;
+	struct var_expand_table *tab;
+	const char *p, *const *e;
+	string_t *str;
 
 	t_push();
-	va_start(args, format);
-	i_info("%s [%s]", t_strdup_vprintf(format, args), addr);
-	va_end(args);
+	var_expand_table = get_var_expand_table(client);
+
+	tab = t_malloc(sizeof(static_tab));
+	memcpy(tab, static_tab, sizeof(static_tab));
+
+	str = t_str_new(256);
+	for (e = log_format_elements; *e != NULL; e++) {
+		for (p = *e; *p != '\0'; p++) {
+			if (*p != '%' || p[1] == '\0')
+				continue;
+
+			p++;
+			if (have_key(var_expand_table, p)) {
+				if (str_len(str) > 0)
+					str_append(str, ", ");
+				var_expand(str, *e, var_expand_table);
+				break;
+			}
+		}
+	}
+
+	tab[0].value = t_strdup(str_c(str));
+	tab[1].value = msg;
+	str_truncate(str, 0);
+
+	var_expand(str, log_format, tab);
+	i_info("%s", str_c(str));
+
 	t_pop();
 }

Index: client-common.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/login-common/client-common.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- client-common.h	11 Oct 2004 17:14:28 -0000	1.7
+++ client-common.h	14 May 2005 20:32:06 -0000	1.8
@@ -29,8 +29,7 @@
 struct client *client_create(int fd, int ssl, const struct ip_addr *local_ip,
 			     const struct ip_addr *ip);
 
-void client_syslog(struct client *client, const char *format, ...)
-	__attr_format__(2, 3);
+void client_syslog(struct client *client, const char *msg);
 
 unsigned int clients_get_count(void);
 void clients_notify_auth_connected(void);

Index: common.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/login-common/common.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- common.h	7 Jan 2005 17:29:25 -0000	1.7
+++ common.h	14 May 2005 20:32:06 -0000	1.8
@@ -3,12 +3,18 @@
 
 #include "lib.h"
 
+/* Used only for string sanitization */
+#define MAX_MECH_NAME 64
+
 #define AUTH_FAILED_MSG "Authentication failed."
 #define AUTH_TEMP_FAILED_MSG "Temporary authentication failure."
 
+extern const char *login_protocol;
+
 extern int disable_plaintext_auth, process_per_connection, greeting_capability;
 extern int verbose_proctitle, verbose_ssl, verbose_auth;
-char *greeting;
+extern const char *greeting, *log_format;
+extern const char *const *log_format_elements;
 extern unsigned int max_logging_users;
 extern unsigned int login_process_uid;
 extern struct auth_client *auth_client;

Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/login-common/main.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- main.c	30 Jan 2005 08:58:19 -0000	1.24
+++ main.c	14 May 2005 20:32:06 -0000	1.25
@@ -20,7 +20,8 @@
 
 int disable_plaintext_auth, process_per_connection, greeting_capability;
 int verbose_proctitle, verbose_ssl, verbose_auth;
-char *greeting;
+const char *greeting, *log_format;
+const char *const *log_format_elements;
 unsigned int max_logging_users;
 unsigned int login_process_uid;
 struct auth_client *auth_client;
@@ -170,6 +171,15 @@
 		greeting = PACKAGE" ready.";
 	greeting_capability = getenv("GREETING_CAPABILITY") != NULL;
 
+	value = getenv("LOG_FORMAT_ELEMENTS");
+	if (value == NULL)
+		value = "user=<%u> method=%m rip=%r lip=%l %c : %$";
+	log_format_elements = t_strsplit(value, " ");
+
+	log_format = getenv("LOG_FORMAT");
+	if (log_format == NULL)
+		log_format = "%$: %s";
+
 	value = getenv("PROCESS_UID");
 	if (value == NULL)
 		i_fatal("BUG: PROCESS_UID environment not given");

Index: sasl-server.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/login-common/sasl-server.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- sasl-server.c	7 Jan 2005 17:24:00 -0000	1.7
+++ sasl-server.c	14 May 2005 20:32:06 -0000	1.8
@@ -9,9 +9,6 @@
 #include "client-common.h"
 #include "master.h"
 
-/* Used only for string sanitization while verbose_auth is set. */
-#define MAX_MECH_NAME 64
-
 static enum auth_request_flags
 client_get_auth_flags(struct client *client)
 {
@@ -154,9 +151,11 @@
 void sasl_server_auth_cancel(struct client *client, const char *reason)
 {
 	if (verbose_auth && reason != NULL) {
-		client_syslog(client, "Authenticate %s failed: %s",
-			      str_sanitize(client->auth_mech_name,
-					   MAX_MECH_NAME), reason);
+		const char *auth_name =
+			str_sanitize(client->auth_mech_name, MAX_MECH_NAME);
+		client_syslog(client,
+			t_strdup_printf("Authenticate %s failed: %s",
+					auth_name, reason));
 	}
 
 	client->authenticating = FALSE;



More information about the dovecot-cvs mailing list