Re: Problems with lmtp delivery on 2.2.2-BETA

2004-01-08 Thread Ken Murchison
Matthew Hodgson wrote:


Looking at the process_recipient() code in lmtpengine.c, I'm not sure 
that the
quote-string parsing has been updated fully to reflect virtual domains - so
I've fiddled around and come up with a version based on the existing 
code, and
also a complete rewrite.  I enclose the latter as a patch here; it 
hasn't been
rigorously tested (at all), but has fixed my particular problem.  If anyone
has interest in the other version, just say - any feedback  flames 
appreciated.
I'm looking at your current patch now to make sure it looks sane before 
I commit it.  If you have an alternate patch, I'd like to see it also.

--
Kenneth Murchison Oceana Matrix Ltd.
Software Engineer 21 Princeton Place
716-662-8973 x26  Orchard Park, NY 14127
--PGP Public Key--http://www.oceana.com/~ken/ksm.pgp


RE: Problems with lmtp delivery on 2.2.2-BETA

2004-01-08 Thread Matthew Hodgson
Ken Murhcison wrote:

 Matthew Hodgson wrote:
 
 
  Looking at the process_recipient() code in lmtpengine.c,
 I'm not sure
  that the
  quote-string parsing has been updated fully to reflect
 virtual domains - so
  I've fiddled around and come up with a version based on the
 existing
  code, and
  also a complete rewrite.  I enclose the latter as a patch here; it
  hasn't been
  rigorously tested (at all), but has fixed my particular 
 problem.  If anyone
  has interest in the other version, just say - any feedback  flames
  appreciated.
 
 I'm looking at your current patch now to make sure it looks
 sane before 
 I commit it.  If you have an alternate patch, I'd like to see it also.
 

Hi Ken,

Be sure to look at the 2nd version of the patch I submitted to the list; the
1st one included a few rather embarassing bugs.

I've abandoned the alternative patch (the minimal extension of the existing
code), as ensuring that forcedowncase vaguely works with quoted-strings as
well as virtual domains was becoming too clunky, and I'm now depending on it
for the installation here.  Rather than ending up with a load of unwrapped
states, I suspect the better idea is to chuck a few state flags in as I did
with the submitted patch, I hope.

In other news, the latest CVS doesn't compile from clean when using a
berkeley backend; HAVE_BDB needs to be #defined in config.h at some point to
avoid disturbing fatal errors of the form:
Jan  8 16:51:16 foo imap[11302]: Fatal error: cyrusdb backend
berkeley-nosync not supported

M.
__
Matthew Hodgson   [EMAIL PROTECTED]   Tel: +44 845 6667778
Systems Analyst, MX Telecom Ltd.





Re: Problems with lmtp delivery on 2.2.2-BETA

2004-01-08 Thread Ken Murchison
Matthew Hodgson wrote:

Ken Murhcison wrote:


Matthew Hodgson wrote:



Looking at the process_recipient() code in lmtpengine.c,
I'm not sure

that the
quote-string parsing has been updated fully to reflect
virtual domains - so

I've fiddled around and come up with a version based on the
existing

code, and
also a complete rewrite.  I enclose the latter as a patch here; it
hasn't been
rigorously tested (at all), but has fixed my particular 
problem.  If anyone

has interest in the other version, just say - any feedback  flames
appreciated.
I'm looking at your current patch now to make sure it looks
sane before 
I commit it.  If you have an alternate patch, I'd like to see it also.



Hi Ken,

Be sure to look at the 2nd version of the patch I submitted to the list; the
1st one included a few rather embarassing bugs.
I've abandoned the alternative patch (the minimal extension of the existing
code), as ensuring that forcedowncase vaguely works with quoted-strings as
well as virtual domains was becoming too clunky, and I'm now depending on it
for the installation here.  Rather than ending up with a load of unwrapped
states, I suspect the better idea is to chuck a few state flags in as I did
with the submitted patch, I hope.
One thing you missed in you patch was the downcasing of the domain for 
something like [EMAIL PROTECTED]  I've written my own patch, based on 
yours which I *think* handles all cases (at least it doesn in my test 
harness).  Try the attached patch and let me know how it works before I 
commit it.


In other news, the latest CVS doesn't compile from clean when using a
berkeley backend; HAVE_BDB needs to be #defined in config.h at some point to
avoid disturbing fatal errors of the form:
Jan  8 16:51:16 foo imap[11302]: Fatal error: cyrusdb backend
Any time that configure.in is updated, you need to re-make the configure 
script:

rm configure
sh SMakefile
./configure ...
Any time that a Makefile.in is updated, you should re-run configure.

--
Kenneth Murchison Oceana Matrix Ltd.
Software Engineer 21 Princeton Place
716-662-8973 x26  Orchard Park, NY 14127
--PGP Public Key--http://www.oceana.com/~ken/ksm.pgp
Index: lmtpengine.c
===
RCS file: /afs/andrew/system/cvs/src/cyrus/imap/lmtpengine.c,v
retrieving revision 1.98
diff -c -r1.98 lmtpengine.c
*** lmtpengine.c2 Jan 2004 20:34:10 -   1.98
--- lmtpengine.c8 Jan 2004 18:25:03 -
***
*** 756,761 
--- 756,762 
  int r, sl;
  address_data_t *ret = (address_data_t *) xmalloc(sizeof(address_data_t));
  int forcedowncase = config_getswitch(IMAPOPT_LMTP_DOWNCASE_RCPT);
+ int quoted, detail;
  
  assert(addr != NULL  msg != NULL);
  
***
*** 781,817 
addr++;
  }
  
! if (*addr == '\') {
!   addr++;
!   while (*addr  *addr != '\') {
!   if (*addr == '\\') addr++;
!   *dest++ = *addr++;
}
! }
! else {
!   if(forcedowncase) {
!   /* We should downcase the localpart up to the first + */
!   while(*addr != '@'  *addr != ''  *addr != '+') {
!   if(*addr == '\\') addr++;
!   *dest++ = TOLOWER(*addr++);
!   }
!   if (*addr == '+') {
! while(*addr != '@'  *addr != '') {
!   if(*addr == '\\') addr++;
!   *dest++ = *addr++;
! }
!   }
!   while ((config_virtdomains || *addr != '@')  *addr != '') {
!   if(*addr == '\\') addr++;
!   *dest++ = TOLOWER(*addr++);
!   }
} else {
! /* Now finish the remainder of the localpart */
! while ((config_virtdomains || *addr != '@')  *addr != '') {
! if (*addr == '\\') addr++;
! *dest++ = *addr++;
! }
!}
  }
  *dest = '\0';

--- 782,815 
addr++;
  }
  
! quoted = detail = 0;
! while (*addr 
!  (quoted ||
!   ((config_virtdomains || *addr != '@')  *addr != ''))) {
!   /* start/end of quoted localpart, skip the quote */
!   if (*addr == '\') {
!   quoted = !quoted;
!   addr++;
!   continue;
}
! 
!   /* escaped char, pass it through */
!   if (*addr == '\\') {
!   addr++;
!   if (!*addr) break;
} else {
!   /* start of detail */
!   if (*addr == '+') detail = 1;
! 
!   /* end of localpart (unless quoted) */
!   if (*addr == '@'  !quoted) detail = 0;
!   }
! 
!   /* downcase everything accept the detail */
!   if (forcedowncase  !detail)
!   *dest++ = TOLOWER(*addr++);
!   else
!   *dest++ = *addr++;
  }
  *dest = '\0';



RE: Problems with lmtp delivery on 2.2.2-BETA

2004-01-08 Thread Matthew Hodgson
Ken Murchison wrote:
 
 One thing you missed in your patch was the downcasing of the 
 domain for 
 something like [EMAIL PROTECTED]

Hm, I didn't know whether forcedowncase was actually meant to affect the
domain or not.  Moreover, the domain seemed to be being downcased elsewhere
anyway, so I left it be.  Making it explicit in process_recipient like this
seems cleaner, though.

 I've written my own 
 patch, based on 
 yours which I *think* handles all cases (at least it doesn in my test 
 harness).  Try the attached patch and let me know how it 
 works before I 
 commit it.

Applied it, appears to work like a charm :)
 
  In other news, the latest CVS doesn't compile from clean 
...
 Any time that configure.in is updated, you need to re-make 
 the configure 
 script:

ooops, I was trying to re-make with a simple make distclean  autogen. Mea
culpa.

thanks,

Matthew.

--
__
Matthew Hodgson   [EMAIL PROTECTED]   Tel: +44 845 6667778
Systems Analyst, MX Telecom Ltd.



Re: Problems with lmtp delivery on 2.2.2-BETA

2004-01-07 Thread Matthew Hodgson
Matthew Hodgson wrote:

Looking at the process_recipient() code in lmtpengine.c, I'm not sure 
that the quote-string parsing has been updated fully to reflect
 virtual domains - so I've fiddled around and come up with a version
 based on the existing code, and also a complete rewrite.
 I enclose the latter as a patch here; it hasn't been rigorously
 tested (at all), but has fixed my particular problem.
Hm, a bit of peer review  common sense later, i enclose a copy of said patch 
which hopefully takes terminal cases better into account and avoids buffer 
overruns...

M.

__
Matthew Hodgson   [EMAIL PROTECTED]   Tel: +44 845 6667778
  Systems Analyst, MX Telecom Ltd.
Index: lmtpengine.c
===
RCS file: /cvs/src/cyrus/imap/lmtpengine.c,v
retrieving revision 1.96
diff -u -r1.96 lmtpengine.c
--- lmtpengine.c10 Nov 2003 16:42:14 -  1.96
+++ lmtpengine.c7 Jan 2004 20:15:40 -
@@ -754,6 +754,7 @@
 char *dest;
 char *user;
 int r, sl;
+int inusername, inquoted;
 address_data_t *ret = (address_data_t *) xmalloc(sizeof(address_data_t));
 int forcedowncase = config_getswitch(IMAPOPT_LMTP_DOWNCASE_RCPT);
 
@@ -781,40 +782,34 @@
addr++;
 }
 
-if (*addr == '\') {
-   addr++;
-   while (*addr  *addr != '\') {
-   if (*addr == '\\') addr++;
-   *dest++ = *addr++;
-   }
-}
-else {
-   if(forcedowncase) {
-   /* We should downcase the localpart up to the first + */
-   while(*addr != '@'  *addr != ''  *addr != '+') {
-   if(*addr == '\\') addr++;
-   *dest++ = TOLOWER(*addr++);
-   }
-   if (*addr == '+') {
- while(*addr != '@'  *addr != '') {
-   if(*addr == '\\') addr++;
-   *dest++ = *addr++;
- }
-   }
-   while ((config_virtdomains || *addr != '@')  *addr != '') {
-   if(*addr == '\\') addr++;
-   *dest++ = TOLOWER(*addr++);
-   }
-   } else {
- /* Now finish the remainder of the localpart */
- while ((config_virtdomains || *addr != '@')  *addr != '') {
- if (*addr == '\\') addr++;
- *dest++ = *addr++;
- }
-   }
+inusername = 1;
+inquoted = 0;
+
+while(*addr  (inquoted || ((config_virtdomains || *addr != '@')  *addr != 
''))) {
+if (*addr == '\\'  inquoted) {
+ addr++;
+ if (!*addr) { break; }
+}
+
+if (*addr == '\') {
+inquoted = inquoted ? 0 : 1;
+addr++;
+continue;
+}
+if (*addr == '+'  inusername) {
+inusername = 0;
+}
+
+if (forcedowncase  inusername) {
+*dest++ = TOLOWER(*addr++);
+}
+else {
+*dest++ = *addr++;
+}
 }
+
 *dest = '\0';
-   
+
 r = verify_user(user, ignorequota ? -1 : msg-size, msg-authstate);
 if (r) {
/* we lost */