as it didn't made it for the latest patch... it's against 20011001, but
should still work.
If you use it, you have to put "5>&1" at the end of your tcpserver
invocation for qmail-pop3d as you most probably already do with 2>&1. To
enable this patch, add -DPOPLOG to ldapflags in Makefile.
It's based on an idea and some code by Maex.
example log entry (timestamps removed, wrapped for readability)
acct: pid 4898: skywalker.i2.ipv6.bsws.de:3ffe:400:890:1:240:f4ff:fe32:1035:
bsws.de-lists login
acct: pid 4898: skywalker.i2.ipv6.bsws.de:3ffe:400:890:1:240:f4ff:fe32:1035:
bsws.de-lists logout 2683 bytes transferred
I'm looking forward to adjust my patches to 20020501 soon.
--- ../mx/qmail-pop3d.c Mon Dec 10 16:02:09 2001
+++ qmail-pop3d.c Fri Apr 19 11:28:59 2002
@@ -27,7 +27,22 @@
int qfd;
/* end qmail-ldap stuff */
-void die() { _exit(0); }
+#ifdef POPLOG
+void log_quit();
+int log_flag = 0;
+#endif /* POPLOG */
+
+void flush();
+void puts();
+
+void die() {
+#ifdef POPLOG
+ if (!log_flag) log_quit();
+#endif /* POPLOG */
+ _exit(0);
+}
+
+
int saferead(fd,buf,len) int fd; char *buf; int len;
{
@@ -88,6 +103,66 @@
void okay() { puts("+OK \r\n"); flush(); }
+#ifdef POPLOG
+stralloc logs_pidhostinfo = {0};
+unsigned long log_bytes = 0;
+
+char sslogbuf[512];
+substdio sslog = SUBSTDIO_FDBUF(safewrite,5,sslogbuf,sizeof(sslogbuf));
+
+void log(s) char *s; { log_flag=1; if(substdio_puts(&sslog,s) == -1) _exit(1);
+log_flag=0;}
+void logf(s) char *s; { log_flag=1; if(substdio_puts(&sslog,s) == -1) _exit(1);
+if(substdio_flush(&sslog) == -1) _exit(1); log_flag=0;}
+void log_pidhostinfo() { log(logs_pidhostinfo.s); }
+
+void log_quit()
+{
+ char strnum[FMT_ULONG];
+
+ log("acct:");
+ log_pidhostinfo();
+ log("logout ");
+ strnum[fmt_ulong(strnum,log_bytes)] = 0;
+ log(strnum); logf(" bytes transferred\n");
+}
+
+void log_init()
+{
+ char strnum[FMT_ULONG];
+ char *remotehost;
+ char *remoteip;
+ char *remoteinfo;
+ char *user;
+
+ remoteip = env_get("TCPREMOTEIP");
+ if (!remoteip) remoteip = "unknown";
+ remotehost = env_get("TCPREMOTEHOST");
+ if (!remotehost) remotehost = "unknown";
+ remoteinfo = env_get("TCPREMOTEINFO");
+ if (!remoteinfo) remoteinfo = "";
+ user = env_get("USER");
+ if (!user) user = "unknown";
+
+ if (!stralloc_copys(&logs_pidhostinfo, " pid ")) die_nomem();
+ strnum[fmt_ulong(strnum,getpid())] = 0;
+ if (!stralloc_cats(&logs_pidhostinfo, strnum)) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, ": ")) die_nomem();
+
+ if (!stralloc_cats(&logs_pidhostinfo, remotehost)) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, ":")) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, remoteip)) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, ":")) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, remoteinfo)) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, " ")) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, user)) die_nomem();
+ if (!stralloc_cats(&logs_pidhostinfo, " ")) die_nomem();
+ if (!stralloc_0(&logs_pidhostinfo)) die_nomem();
+}
+
+
+
+#endif /* POPLOG */
+
+
void printfn(fn) char *fn;
{
fn += 4;
@@ -116,6 +191,10 @@
put(".",1);
put(line.s,line.len);
put("\r\n",2);
+#ifdef POPLOG
+ log_bytes += line.len + 2;
+#endif /* POPLOG */
+
if (!match) break;
}
put("\r\n.\r\n",5);
@@ -387,6 +466,11 @@
}
#endif
/* qmail-ldap stuff */
+
+#ifdef POPLOG
+ log_init();
+ log("acct:"); log_pidhostinfo(); logf("login\n");
+#endif /* POPLOG */
getlist();
--
| Henning Brauer | PGP-Key: http://misc.bsws.de/hb/pubkey.asc
| BS Web Services | Roedingsmarkt 14, 20459 Hamburg, DE | http://bsws.de
Unix is very simple, but it takes a genius to understand the simplicity.
(Dennis Ritchie)