This Space for Rent

New Code (part 2)!

Postoffice has been pushed up to version 1.5.2 to fix a few defects found when moving out of the old co-lo.

  1. On FreeBSD 7.1, setreuid() does not work as expected; it doesn’t give up privileges, but was instead writing files AS ROOT. That is bad. So I’m not even going to try to give up and regain privileges inline; instead I’ll just fork off a child process which will give up privileges and THEN attempt to write.
  2. It turns out that my home router drops packets when they’re pushed in too quickly. I discovered that when mail sessions, including ones from gehenna, started timing out during the DATA part of a transaction. But while debugging this feature (which I can’t work around, because a new router would cost >$100; I’m working around it by putting the mail server on gehenna and popping in to check mail) I found a few things that I needed to check.

    • I’m checking for the existance of setlinebuf() in configure.sh, but was not actually bothering to use the resulting #define in my code.
    • if the close-on-exec fcntl exists, use it on the server socket.
  3. Pay attention to the active flag for virtual domains; if that flag is 0, the domain is not active (previously I was just checking to see if the flag existed to see if it was active.)

  4. I was handling MXes improperly; the queue running code was trying to deliver mail to the highest numeric value of MX, instead of the highest priority MX (MX priorities are like D&D armor classes; lower is better.) This was fixed, plus I randomise MXes of the same priority so that they pseudo-round robin.
  5. data() has been reworked to clean up the dot state machine and to make it smaller. Dropping \r’s with prejudice made the handling of EOL.EOL a lot easier, but I still had a lot of stubby nonsense from the old code there.
  6. smtpbugcheck() now uses mfcomplain() to dump out whatever error messages milters give me for rejecting a letter. mfcomplain() strips the extraneous numeric codes off the front of the error message, which cuts down on clutter.
  7. Finally, I was using open()/read()/close() to read the contents of a .forward file into memory. This left me open to fun attacks because I wasn’t bzero()ing the buffer between reads, and a short .forward would just be overlaid on top of a long .forward instead of replacing it.

    I changed that to use FILE*s which do all the trimming and stuff by magic.

I’m sure there are more things that I need to work on (like, um, STARTTLS) but the move out of the co-lo turned out to be traumatic enough so that this New Code! is enough for this month. Try it and see. If your exploding server can achieve low earth orbit, you’ll probably get a prize