[dovecot-cvs] dovecot/src/master login-process.c, 1.54, 1.55 mail-process.c, 1.48, 1.49 mail-process.h, 1.4, 1.5 master-login-interface.h, 1.4, 1.5 master-settings.c, 1.51, 1.52 master-settings.h, 1.32, 1.33

cras at procontrol.fi cras at procontrol.fi
Mon May 31 21:04:50 EEST 2004


Update of /home/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv4696/src/master

Modified Files:
	login-process.c mail-process.c mail-process.h 
	master-login-interface.h master-settings.c master-settings.h 
Log Message:
Added %l, %r and %P variables and mail_log_prefix setting.



Index: login-process.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/login-process.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- a/login-process.c	23 May 2004 19:23:57 -0000	1.54
+++ b/login-process.c	31 May 2004 18:04:47 -0000	1.55
@@ -39,7 +39,7 @@
 	unsigned int login_tag;
 	int fd;
 
-	struct ip_addr ip;
+	struct ip_addr local_ip, remote_ip;
 };
 
 static unsigned int auth_id_counter, login_pid_counter;
@@ -82,9 +82,13 @@
 	else {
 		struct login_group *group = request->process->group;
 
+		t_push();
 		master_reply.success =
-			create_mail_process(group, request->fd, &request->ip,
+			create_mail_process(group, request->fd,
+					    &request->local_ip,
+					    &request->remote_ip,
 					    reply, (const char *) data);
+		t_pop();
 	}
 
 	/* reply to login */
@@ -268,7 +272,8 @@
 	authreq->tag = ++auth_id_counter;
 	authreq->login_tag = req.tag;
 	authreq->fd = client_fd;
-	authreq->ip = req.ip;
+	authreq->local_ip = req.local_ip;
+	authreq->remote_ip = req.remote_ip;
 
 	auth_process = auth_process_find(req.auth_pid);
 	if (auth_process == NULL) {

Index: mail-process.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/mail-process.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- a/mail-process.c	29 May 2004 22:35:32 -0000	1.48
+++ b/mail-process.c	31 May 2004 18:04:47 -0000	1.49
@@ -75,8 +75,10 @@
 }
 
 static const struct var_expand_table *
-get_var_expand_table(const char *user, const char *home,
-		     enum process_type process_type)
+get_var_expand_table(enum process_type process_type,
+		     const char *user, const char *home,
+		     const struct ip_addr *local_ip,
+		     const struct ip_addr *remote_ip, pid_t pid)
 {
 	static struct var_expand_table static_tab[] = {
 		{ 'u', NULL },
@@ -84,6 +86,9 @@
 		{ 'd', NULL },
 		{ 'p', NULL },
 		{ 'h', NULL },
+		{ 'l', NULL },
+		{ 'r', NULL },
+		{ 'P', NULL },
 		{ '\0', NULL }
 	};
 	struct var_expand_table *tab;
@@ -97,6 +102,9 @@
 	if (tab[2].value != NULL) tab[2].value++;
 	tab[3].value = t_str_ucase(process_names[process_type]);
 	tab[4].value = home;
+	tab[5].value = net_ip2addr(local_ip);
+	tab[6].value = net_ip2addr(remote_ip);
+	tab[7].value = dec2str(pid);
 
 	return tab;
 }
@@ -173,16 +181,18 @@
 }
 
 int create_mail_process(struct login_group *group, int socket,
-			struct ip_addr *ip,
+			const struct ip_addr *local_ip,
+			const struct ip_addr *remote_ip,
 			struct auth_master_reply *reply, const char *data)
 {
 	struct settings *set = group->set;
 	const struct var_expand_table *var_expand_table;
 	const char *argv[4];
 	const char *addr, *mail, *user, *chroot_dir, *home_dir, *full_home_dir;
-	const char *executable, *p, *prefix;
+	const char *executable, *p;
 	struct log_io *log;
 	char title[1024];
+	string_t *str;
 	pid_t pid;
 	int i, err, ret, log_fd;
 
@@ -196,6 +206,8 @@
 			      data + reply->virtual_user_idx))
 		return FALSE;
 
+	user = data + reply->virtual_user_idx;
+	mail = data + reply->mail_idx;
 	home_dir = data + reply->home_idx;
 	chroot_dir = data + reply->chroot_idx;
 
@@ -217,12 +229,16 @@
 		return FALSE;
 	}
 
+	var_expand_table =
+		get_var_expand_table(group->process_type, user, home_dir,
+				     local_ip, remote_ip,
+				     pid != 0 ? pid : getpid());
+	str = t_str_new(128);
+
 	if (pid != 0) {
 		/* master */
-		prefix = t_strdup_printf("%s(%s): ",
-					 process_names[group->process_type],
-					 data + reply->virtual_user_idx);
-		log_set_prefix(log, prefix);
+		var_expand(str, set->mail_log_prefix, var_expand_table);
+		log_set_prefix(log, str_c(str));
 
 		mail_process_count++;
 		PID_ADD_PROCESS_TYPE(pid, group->process_type);
@@ -230,10 +246,9 @@
 		return TRUE;
 	}
 
-	prefix = t_strdup_printf("master-%s(%s): ",
-				 process_names[group->process_type],
-				 data + reply->virtual_user_idx);
-	log_set_prefix(log, prefix);
+	str_append(str, "master-");
+	var_expand(str, set->mail_log_prefix, var_expand_table);
+	log_set_prefix(log, str_c(str));
 
 	child_process_init_env();
 
@@ -345,12 +360,6 @@
 	/* user given environment - may be malicious. virtual_user comes from
 	   auth process, but don't trust that too much either. Some auth
 	   mechanism might allow leaving extra data there. */
-	mail = data + reply->mail_idx;
-	user = data + reply->virtual_user_idx;
-
-	var_expand_table =
-		get_var_expand_table(user, home_dir, group->process_type);
-
 	if (*mail == '\0' && set->default_mail_env != NULL)
 		mail = expand_mail_env(set->default_mail_env, var_expand_table);
 
@@ -362,7 +371,7 @@
 	env_put(t_strconcat("MAIL=", mail, NULL));
 	env_put(t_strconcat("USER=", data + reply->virtual_user_idx, NULL));
 
-	addr = net_ip2addr(ip);
+	addr = net_ip2addr(remote_ip);
 	env_put(t_strconcat("IP=", addr, NULL));
 
 	if (!set->verbose_proctitle)

Index: mail-process.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/mail-process.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/mail-process.h	10 Jul 2003 03:04:07 -0000	1.4
+++ b/mail-process.h	31 May 2004 18:04:47 -0000	1.5
@@ -5,7 +5,8 @@
 struct auth_master_reply;
 
 int create_mail_process(struct login_group *group, int socket,
-			struct ip_addr *ip,
+			const struct ip_addr *local_ip,
+			const struct ip_addr *remote_ip,
 			struct auth_master_reply *reply, const char *data);
 
 void mail_process_destroyed(pid_t pid);

Index: master-login-interface.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/master-login-interface.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/master-login-interface.h	4 Mar 2003 04:02:56 -0000	1.4
+++ b/master-login-interface.h	31 May 2004 18:04:47 -0000	1.5
@@ -13,7 +13,7 @@
 	unsigned int auth_pid;
 	unsigned int auth_id;
 
-	struct ip_addr ip;
+	struct ip_addr local_ip, remote_ip;
 };
 
 struct master_login_reply {

Index: master-settings.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/master-settings.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- a/master-settings.c	29 May 2004 22:21:39 -0000	1.51
+++ b/master-settings.c	31 May 2004 18:04:47 -0000	1.52
@@ -107,6 +107,7 @@
 	DEF(SET_INT, mail_process_size),
 	DEF(SET_BOOL, mail_use_modules),
 	DEF(SET_STR, mail_modules),
+	DEF(SET_STR, mail_log_prefix),
 
 	/* imap */
 	DEF(SET_INT, imap_max_line_length),
@@ -241,6 +242,7 @@
 	MEMBER(mail_process_size) 256,
 	MEMBER(mail_use_modules) FALSE,
 	MEMBER(mail_modules) MODULEDIR"/imap",
+	MEMBER(mail_log_prefix) "%Up(%u): ",
 
 	/* imap */
 	MEMBER(imap_max_line_length) 65536,

Index: master-settings.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/master-settings.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- a/master-settings.h	29 May 2004 22:21:39 -0000	1.32
+++ b/master-settings.h	31 May 2004 18:04:47 -0000	1.33
@@ -82,6 +82,7 @@
 	unsigned int mail_process_size;
 	int mail_use_modules;
 	const char *mail_modules;
+	const char *mail_log_prefix;
 
 	/* imap */
 	unsigned int imap_max_line_length;



More information about the dovecot-cvs mailing list