This is my first attempt at writing an experimental version of mod_smtpd. I don't yet have svn access yet so this code can be downloaded from http://rian.merseine.nu/mod_smtpd-0.1.tar.gz.

Nifty! I had some compilation problems involving regex, so in the attached patch I use ap_regex.h and change some defines. Hope this doesn't break anything.

The other bug I partially fixed was, strstr in smtp_protocol.c only does exact matches so uppercase commands like MAIL FROM would fail. I added support for the upper case, but this needs to be improved still because mixed case doesn't work. Is there an APR function like stristr?

The overall structure and the approach you took is very nice, easy to understand. I would recommend adding a hook immediately upon the client connection, because an external module (maybe for DNSBLs, or some rate limiting control) might not even want us to return a greeting at all -- i.e. close with "554 Service unavailable" right away.

But I like what you have, would be happy to keep working around this design.
*** smtp_protocol.c.orig        2005-07-18 23:07:26.000000000 -0500
--- smtp_protocol.c     2005-07-18 23:39:18.000000000 -0500
***************
*** 26,31 ****
--- 26,32 ----
  #include "http_log.h"
  #include "ap_config.h"
  #include "ap_mmn.h"
+ #include "ap_regex.h"
  #include "apr_lib.h"
  #include "apr_buckets.h"
  #include "scoreboard.h"
***************
*** 151,156 ****
--- 152,160 ----
    smtpd_request_rec *sr = smtpd_get_request_rec(r);
    char *loc = strstr(buffer, "from:");
    int retval;
+   
+   if (loc == NULL)
+     loc = strstr(buffer, "FROM:");
  
  
    if (loc == NULL) {
***************
*** 177,182 ****
--- 181,189 ----
    smtpd_request_rec *sr = smtpd_get_request_rec(r);
    char *loc = strstr(buffer, "to:");
    int retval = 0;
+   
+   if (loc == NULL)
+     loc = strstr(buffer, "TO:");
  
    if (loc == NULL) {
      ap_rprintf(r, "%d %s\r\n", 501, "Syntax: RCPT TO:<address>");
***************
*** 277,283 ****
  }
  
  HANDLER_DECLARE(vrfy) {
!   regex_t *compiled;
    int error;
    int retval = 0;
  
--- 284,290 ----
  }
  
  HANDLER_DECLARE(vrfy) {
!   ap_regex_t *compiled;
    int error;
    int retval = 0;
  
***************
*** 286,292 ****
      "[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?"
      "(\\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?)*$";
   
!   compiled = ap_pregcomp(r->pool, rexp, REG_EXTENDED | REG_NOSUB);
    error = ap_regexec(compiled, buffer, 0, NULL, 0);
    ap_pregfree(r->pool, compiled);
    
--- 293,299 ----
      "[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?"
      "(\\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?)*$";
   
!   compiled = ap_pregcomp(r->pool, rexp, AP_REG_EXTENDED | AP_REG_NOSUB);
    error = ap_regexec(compiled, buffer, 0, NULL, 0);
    ap_pregfree(r->pool, compiled);
    

Reply via email to