Hi!

I have two specific problems:
1. need to do pop-before-smtp, BUT on proxy server,
2. need to do pop-before-smtp, BUT based on "service" on which is user 
connected.

As you know, when in "proxy" mode, in logs will only be "Connection," and 
error authenticating. But for pop-before-smtp to work, i need something like 
"LOGIN <user> <ip>".

The fastest way seems to by modifing source. That is, to add few log lines in 
proxy part of courier. In attach is suggested diff.

In short, the following changes are made:
- put in enviroment service, when there isn't one
- in callback function, use service name from enviroment, and ip, and print 
some line when authentication succesuful.
- event when not in "proxy" mode, print service in LOGIN line

I didn't test it yet (it compiles), but it simple enough so there should be 
problems. :-)

Any feedback is welcomed.

H.

Index: imap/pop3login.c
===================================================================
--- imap/pop3login.c	(revision 3284)
+++ imap/pop3login.c	(working copy)
@@ -368,7 +368,11 @@
 						strcat(strcpy(authservice, "AUTHSERVICE"),getenv("TCPLOCALPORT"));
 						q=getenv(authservice);
 						if (!q || !*q)
-							q="pop3";
+						{
+							q="pop3-auth";
+							strcat(strcat(authservice,"="),q);
+							putenv(authservice);
+						}
 
 						rc=auth_generic(q,
 							     authtype,
@@ -416,7 +420,11 @@
 				strcat(strcpy(authservice, "AUTHSERVICE"),getenv("TCPLOCALPORT"));
 				q=getenv(authservice);
 				if (!q || !*q)
+				{
 					q="pop3";
+					strcat(strcat(authservice,"="),q);
+					putenv(authservice);
+				}
 
 				rc=auth_login(q, user, p, login_callback, NULL);
 				courier_safe_printf("INFO: LOGIN "
@@ -448,7 +456,7 @@
 	struct pop3proxyinfo *ppi=(struct pop3proxyinfo *)void_arg;
 	struct proxybuf pb;
 	char linebuf[256];
-	char *cmd;
+	char *cmd,*ip=getenv("TCPREMOTEIP");
 
 	DPRINTF("Proxy connected to %s", hostname);
 
@@ -525,5 +533,14 @@
 	    (printf("+OK Connected to proxy server.\r\n"), fflush(stdout)) < 0)
 		return -1;
 
+	strcat(strcpy(linebuf, "AUTHSERVICE"),getenv("TCPLOCALPORT"));
+	cmd=getenv(linebuf);
+
+	fprintf(stderr, "INFO: PROXY LOGIN, user=%s, service=%s, ip=[%s]\n",
+			ppi->uid,
+			cmd?cmd:"(unknown)",
+			ip?ip:"127.0.0.1");
+	fflush(stderr);
+
 	return 0;
 }
Index: imap/imaplogin.c
===================================================================
--- imap/imaplogin.c	(revision 3284)
+++ imap/imaplogin.c	(working copy)
@@ -370,7 +370,11 @@
 		p=getenv(authservice);
 
 		if (!p || !*p)
+		{
 			p="imap";
+			strcat(strcat(authservice,"="),p);
+			putenv(authservice);
+		}
 
 		rc=auth_login(p, userid, passwd, login_callback, (void *)tag);
 		courier_safe_printf("INFO: LOGIN FAILED, user=%s, ip=[%s]",
Index: imap/pop3dserver.c
===================================================================
--- imap/pop3dserver.c	(revision 3284)
+++ imap/pop3dserver.c	(working copy)
@@ -1004,7 +1004,7 @@
 
 int main(int argc, char **argv)
 {
-char	*p;
+char	*p,service[40];
 
 	time(&start_time);
 
@@ -1056,8 +1056,12 @@
 		exit(1);
 	}
 
-	fprintf(stderr, "INFO: LOGIN, user=%s, ip=[%s]\n",
+	strcat(strcpy(service, "AUTHSERVICE"),getenv("TCPLOCALPORT"));
+	p=getenv(service);
+
+	fprintf(stderr, "INFO: LOGIN, user=%s, service=%s, ip=[%s]\n",
 			authaddr,
+			p?p:"(unknown)",
 			remoteip);
 	fflush(stderr);
 

Reply via email to