changeset 596:ab3590c3a7d9 HEAD

Added verbose_proctitle setting: Show more verbose process titles (in ps). Currently shows user name and IP address. Useful for seeing who are actually using the IMAP processes (eg. shared mailboxes or if same uid is used for multiple accounts).
author Timo Sirainen <tss@iki.fi>
date Wed, 06 Nov 2002 16:20:50 +0200
parents 320f59a5a36c
children 99c7e303c92a
files dovecot-example.conf src/imap/main.c src/login/client-authenticate.c src/login/master.c src/login/master.h src/master/common.h src/master/imap-process.c src/master/login-process.c src/master/master-interface.h src/master/settings.c src/master/settings.h
diffstat 11 files changed, 34 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/dovecot-example.conf	Wed Nov 06 15:06:56 2002 +0200
+++ b/dovecot-example.conf	Wed Nov 06 16:20:50 2002 +0200
@@ -75,6 +75,11 @@
 # new users aren't allowed to log in.
 #max_imap_processes = 1024
 
+# Show more verbose process titles (in ps). Currently shows user name and
+# IP address. Useful for seeing who are actually using the IMAP processes
+# (eg. shared mailboxes or if same uid is used for multiple accounts).
+#verbose_proctitle = no
+
 # Valid UID/GID ranges for imap users, defaults to 500 and above.
 # Note that denying root logins is hardcoded to imap-master binary and
 # can't be done even if first_valid_uid is set to 0.
--- a/src/imap/main.c	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/imap/main.c	Wed Nov 06 16:20:50 2002 +0200
@@ -105,7 +105,7 @@
 	lib_init();
 	ioloop = io_loop_create(system_pool);
 
-	main_init(argc == 2 && strcmp(argv[1], "-s") == 0);
+	main_init(argc >= 2 && strcmp(argv[1], "-s") == 0);
         io_loop_run(ioloop);
 	main_deinit();
 
--- a/src/login/client-authenticate.c	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/login/client-authenticate.c	Wed Nov 06 16:20:50 2002 +0200
@@ -135,7 +135,8 @@
 		client->auth_request = NULL;
 
 		master_request_imap(client->fd, auth_process, client->tag,
-				    request->cookie, master_callback, client);
+				    request->cookie, &client->ip,
+				    master_callback, client);
 
 		/* disable IO until we're back from master */
 		if (client->io != NULL) {
--- a/src/login/master.c	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/login/master.c	Wed Nov 06 16:20:50 2002 +0200
@@ -61,7 +61,7 @@
 }
 
 void master_request_imap(int fd, int auth_process, const char *login_tag,
-			 unsigned char cookie[AUTH_COOKIE_SIZE],
+			 unsigned char cookie[AUTH_COOKIE_SIZE], IPADDR *ip,
 			 MasterCallback callback, void *context)
 {
 	MasterRequest req;
@@ -71,6 +71,7 @@
 	memset(&req, 0, sizeof(req));
 	req.id = fd;
 	req.auth_process = auth_process;
+	memcpy(&req.ip, ip, sizeof(IPADDR));
 	memcpy(req.cookie, cookie, AUTH_COOKIE_SIZE);
 
 	if (strlen(login_tag) >= sizeof(req.login_tag))
--- a/src/login/master.h	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/login/master.h	Wed Nov 06 16:20:50 2002 +0200
@@ -6,8 +6,8 @@
 typedef void (*MasterCallback)(MasterReplyResult result, void *context);
 
 /* Request IMAP process for given cookie. */
-void master_request_imap(int fd, int auth_process, const char *login_tag,
-			 unsigned char cookie[AUTH_COOKIE_SIZE],
+void master_request_imap(int fd, int auth_process,  const char *login_tag,
+			 unsigned char cookie[AUTH_COOKIE_SIZE], IPADDR *ip,
 			 MasterCallback callback, void *context);
 
 void master_init(void);
--- a/src/master/common.h	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/master/common.h	Wed Nov 06 16:20:50 2002 +0200
@@ -32,9 +32,9 @@
 
 void clean_child_process(void);
 
-MasterReplyResult
-create_imap_process(int socket, const char *user, uid_t uid, gid_t gid,
-		    const char *home, int chroot, const char *env[]);
+MasterReplyResult create_imap_process(int socket, IPADDR *ip, const char *user,
+				      uid_t uid, gid_t gid, const char *home,
+				      int chroot, const char *env[]);
 void imap_process_destroyed(pid_t pid);
 
 /* misc */
--- a/src/master/imap-process.c	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/master/imap-process.c	Wed Nov 06 16:20:50 2002 +0200
@@ -60,11 +60,12 @@
 	return FALSE;
 }
 
-MasterReplyResult
-create_imap_process(int socket, const char *user, uid_t uid, gid_t gid,
-		    const char *home, int chroot, const char *env[])
+MasterReplyResult create_imap_process(int socket, IPADDR *ip, const char *user,
+				      uid_t uid, gid_t gid, const char *home,
+				      int chroot, const char *env[])
 {
-	static char *argv[] = { NULL, "-s", NULL };
+	static char *argv[] = { NULL, "-s", NULL, NULL };
+	char host[MAX_IP_LEN], title[1024];
 	pid_t pid;
 	int i, j, err;
 
@@ -130,6 +131,11 @@
 	if (umask(set_umask) != set_umask)
 		i_fatal("Invalid umask: %o", set_umask);
 
+	if (set_verbose_proctitle && net_ip2host(ip, host) == 0) {
+		i_snprintf(title, sizeof(title), "[%s %s]", user, host);
+		argv[2] = title;
+	}
+
 	/* setup access environment - needs to be done after
 	   clean_child_process() since it clears environment */
 	restrict_access_set_env(user, uid, gid, chroot ? home : NULL);
--- a/src/master/login-process.c	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/master/login-process.c	Wed Nov 06 16:20:50 2002 +0200
@@ -30,6 +30,7 @@
 	int auth_id;
 	int fd;
 
+	IPADDR ip;
 	char login_tag[LOGIN_TAG_SIZE];
 } LoginAuthRequest;
 
@@ -58,6 +59,7 @@
 		reply.result = MASTER_RESULT_FAILURE;
 	else {
 		reply.result = create_imap_process(request->fd,
+						   &request->ip,
 						   cookie_reply->user,
 						   cookie_reply->uid,
 						   cookie_reply->gid,
@@ -116,6 +118,7 @@
 	authreq->login_id = req.id;
 	authreq->auth_id = ++auth_id_counter;
 	authreq->fd = client_fd;
+	memcpy(&authreq->ip, &req.ip, sizeof(IPADDR));
 	strcpy(authreq->login_tag, req.login_tag);
 
 	auth_process = auth_process_find(req.auth_process);
--- a/src/master/master-interface.h	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/master/master-interface.h	Wed Nov 06 16:20:50 2002 +0200
@@ -1,6 +1,7 @@
 #ifndef __MASTER_INTERFACE_H
 #define __MASTER_INTERFACE_H
 
+#include "network.h"
 #include "../auth/auth-interface.h"
 
 #define LOGIN_TAG_SIZE 32
@@ -21,6 +22,7 @@
 	int auth_process;
 	unsigned char cookie[AUTH_COOKIE_SIZE];
 
+	IPADDR ip;
 	char login_tag[LOGIN_TAG_SIZE];
 } MasterRequest;
 
--- a/src/master/settings.c	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/master/settings.c	Wed Nov 06 16:20:50 2002 +0200
@@ -40,11 +40,12 @@
 	{ "login_dir",		SET_STR, &set_login_dir },
 	{ "login_chroot",	SET_BOOL,&set_login_chroot },
 	{ "login_processes_count", SET_INT, &set_login_processes_count },
+	{ "max_logging_users",	SET_INT, &set_max_logging_users },
 
-	{ "max_logging_users",	SET_INT, &set_max_logging_users },
 	{ "imap_executable",	SET_STR, &set_imap_executable },
 	{ "valid_chroot_dirs",	SET_STR, &set_valid_chroot_dirs },
 	{ "max_imap_processes",	SET_INT, &set_max_imap_processes },
+	{ "verbose_proctitle",	SET_BOOL,&set_verbose_proctitle },
 	{ "first_valid_uid",	SET_INT, &set_first_valid_uid },
 	{ "last_valid_uid",	SET_INT, &set_last_valid_uid },
 	{ "first_valid_gid",	SET_INT, &set_first_valid_gid },
@@ -94,6 +95,7 @@
 char *set_imap_executable = PKG_LIBDIR "/imap";
 char *set_valid_chroot_dirs = NULL;
 unsigned int set_max_imap_processes = 1024;
+int set_verbose_proctitle = FALSE;
 
 unsigned int set_first_valid_uid = 500, set_last_valid_uid = 0;
 unsigned int set_first_valid_gid = 1, set_last_valid_gid = 0;
--- a/src/master/settings.h	Wed Nov 06 15:06:56 2002 +0200
+++ b/src/master/settings.h	Wed Nov 06 16:20:50 2002 +0200
@@ -30,6 +30,7 @@
 extern char *set_imap_executable;
 extern char *set_valid_chroot_dirs;
 extern unsigned int set_max_imap_processes;
+extern int set_verbose_proctitle;
 
 extern unsigned int set_first_valid_uid, set_last_valid_uid;
 extern unsigned int set_first_valid_gid, set_last_valid_gid;