I’ve been usingĀ mod_auth_imap for authenticating against IMAP for several years. When I recently switched to Dovecot from Courier IMAP, mod_auth_imap2 stopped working.
In browsing through the source code for mod_auth_imap2, I came to two realizations:
- mod_auth_imap2 doesn’t expect the IMAP server to send an untagged response in reply to a LOGIN command, and
- there’s a bug in the code that skips untagged responses, so inserting it in the right spot wouldn’t have worked without fixing it first.
The following patch, which I sent to the author and went unanswered, corrects these problems. It’s not very pretty, but hey, neither is the original code.
--- mod_auth_imap.c.orig 2006-05-07 18:22:43.000000000 -0500
+++ mod_auth_imap.c 2011-03-26 00:07:35.000000000 -0500
@@ -170,7 +170,7 @@
tcp_gets(Sock,result,500);
//skip lines that start with "*"
- if (strncmp(result,"* ",2 == 0)) {
+ if (strncmp(result,"* ",2) == 0) {
tcp_gets(Sock,result,500);
}
@@ -188,6 +188,11 @@
tcp_puts(Sock,buf);
tcp_gets(Sock,result,500);
+ //skip lines that start with "*"
+ if (strncmp(result,"* ",2) == 0) {
+ tcp_gets(Sock,result,500);
+ }
+
if (strncmp(result,"A002 OK",7) == 0) {
if (logflag) {
ap_log_rerror(APLOG_MARK,APLOG_WARNING|APLOG_NOERRNO,0,r,"mod_auth_imap: Verified login for user %s.", username);