免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: startdd
打印 上一主题 下一主题

[Mail] 防止垃圾邮件最新补丁(qmail-smtpd.c)! [复制链接]

论坛徽章:
0
11 [报告]
发表于 2003-05-27 00:12 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

老大,没细看您的qmail-smptd.c,您这个qmail-smptd.c没有支持SMPT认证?是否是最好的qmail-smptd.c?
能否跑在Linux上?

论坛徽章:
0
12 [报告]
发表于 2003-05-27 13:32 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

是浏览器的问题
对了,你的注册界面做的挺好的,比vqsignup好多了,还有用户能通国密码提示答案找回密码的功能......怎么做到的?

论坛徽章:
0
13 [报告]
发表于 2003-05-27 19:04 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

原帖由 "akid" 发表:
老大,没细看您的qmail-smptd.c,您这个qmail-smptd.c没有支持SMPT认证?是否是最好的qmail-smptd.c?
能否跑在Linux上?


你看http://www.soocol.com 上面有没有认证!当然是我自己加的呀!

关于认证补丁这个很多,自己就可以下载这里我不多描述!qmail 本身就是裸机,很多东西都要自己加!我加的是防止垃圾功能,认证功能有smtp-auth 补丁!这个不用我多说了!

论坛徽章:
0
14 [报告]
发表于 2003-05-27 20:34 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

這個補丁是你寫的喔!!!

论坛徽章:
0
15 [报告]
发表于 2003-05-27 22:37 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

startdd大侠,如果您的qmail-smptd.c是打好防垃圾邮件和SMTP认证(基于vpopmail)的,就好了!
我们都是很懒的,如果有现成的东西的话。
拜托啦!

论坛徽章:
0
16 [报告]
发表于 2003-05-29 13:30 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

我没搞过C语言,但我加了认证后,编译都没问题,发不了邮件,始终说服务器不响应,我telnet  localhost 25 又没问题!
startadd老大,帮我看看,哪里有问题!先谢谢啦!

#include <stdio.h>;
#include <string.h>;
#include "qmail-qkey.h"
#include "dns.h"
#include "sig.h"
#include "readwrite.h"
#include "stralloc.h"
#include "substdio.h"
#include "alloc.h"
#include "auto_qmail.h"
#include "control.h"
#include "received.h"
#include "constmap.h"
#include "error.h"
#include "ipme.h"
#include "ip.h"
#include "qmail.h"
#include "str.h"
#include "fmt.h"
#include "scan.h"
#include "byte.h"
#include "case.h"
#include "wait.h"
#include "env.h"
#include "now.h"
#include "exit.h"
#include "rcpthosts.h"
#include "timeoutread.h"
#include "timeoutwrite.h"
#include "commands.h"

#define MAXHOPS 100
#define USE_SMTPAUTH
unsigned int databytes = 0;
int timeout = 1200;
unsigned rcptcount;

int safewrite(fd,buf,len) int fd; char *buf; int len;
{
  int r;
  r = timeoutwrite(timeout,fd,buf,len);
  if (r <= 0) _exit(1);
  return r;
}

char ssoutbuf[512];
substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof ssoutbuf);

void flush() { substdio_flush(&ssout); }
void out(s) char *s; { substdio_puts(&ssout,s); }

void die_read() { _exit(1); }
void die_alarm() { out("451 timeout (#4.4.2)\r\n"; flush(); _exit(1); }
void die_nomem() { out("421 out of memory (#4.3.0)\r\n"; flush(); _exit(1); }
void die_control() { out("421 unable to read controls (#4.3.0)\r\n"; flush(); _exit(1); }
void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"; flush(); _exit(1); }
void straynewline() { out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"; flush(); _exit(1); }

void err_bmf() { out("553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n"; }
void err_nogateway() { out("553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)\r\n"; }
void err_unimpl() { out("502 unimplemented (#5.5.1)\r\n"; }
void err_syntax() { out("555 syntax error (#5.5.4)\r\n"; }
void err_wantmail() { out("503 MAIL first (#5.5.1)\r\n"; }
void err_wantrcpt() { out("503 RCPT first (#5.5.1)\r\n"); }
void err_noop() { out("250 ok\r\n"); }
void err_vrfy() { out("252 send some mail, i'll try my best\r\n"); }
void err_qqt() { out("451 qqt failure (#4.3.0)\r\n"); }


stralloc greeting = {0};

void smtp_greet(code) char *code;
{
  substdio_puts(&ssout,code);
  substdio_put(&ssout,greeting.s,greeting.len);
}
void smtp_help()
{
  out("214 qmail home page: http://pobox.com/~djb/qmail.html\r\n");
}
void smtp_quit()
{
  smtp_greet("221 "); out("\r\n"); flush(); _exit(0);
}

char *remoteip;
char *remotehost;
char *remoteinfo;
char *local;
char *relayclient;

stralloc helohost = {0};
char *fakehelo; /* pointer into helohost, or 0 */

void dohelo(arg) char *arg; {
  if (!stralloc_copys(&helohost,arg)) die_nomem();
  if (!stralloc_0(&helohost)) die_nomem();
  fakehelo = case_diffs(remotehost,helohost.s) ? helohost.s : 0;
}

int liphostok = 0;
stralloc liphost = {0};
int bmfok = 0;
stralloc bmf = {0};
struct constmap mapbmf;

int gmfok = 0;
stralloc gmf = {0};
struct constmap mapgmf;

int amfok = 0;
stralloc amf = {0};
struct constmap mapamf;

int grtok = 0;
stralloc grt = {0};
struct constmap mapgrt;

void setup()
{
  char *x;
  unsigned long u;

  if (control_init() == -1) die_control();
  if (control_rldef(&greeting,"control/smtpgreeting",1,(char *) 0) != 1)
    die_control();
  liphostok = control_rldef(&liphost,"control/localiphost",1,(char *) 0);
  if (liphostok == -1) die_control();
  if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control();
  if (timeout <= 0) timeout = 1;

  if (rcpthosts_init() == -1) die_control();

  bmfok = control_readfile(&bmf,"control/badmailfrom",0);
  if (bmfok == -1) die_control();
  if (bmfok)
    if (!constmap_init(&mapbmf,bmf.s,bmf.len,0)) die_nomem();

  gmfok = control_readfile(&gmf,"control/goodmailfrom",0);
  if (gmfok == -1) die_control();
  if (gmfok)
    if (!constmap_init(&mapgmf,gmf.s,gmf.len,0)) die_nomem();

  amfok = control_readfile(&amf,"control/allowmailfrom",0);
  if (amfok == -1) die_control();
  if (amfok)
    if (!constmap_init(&mapamf,amf.s,amf.len,0)) die_nomem();

  grtok = control_readfile(&grt,"control/goodrcptto",0);
  if (grtok == -1) die_control();
  if (grtok)
    if (!constmap_init(&mapgrt,grt.s,grt.len,0)) die_nomem();

  if (control_readint(&databytes,"control/databytes") == -1) die_control();
  x = env_get("DATABYTES");
  if (x) { scan_ulong(x,&u); databytes = u; }
  if (!(databytes + 1)) --databytes;

  remoteip = env_get("TCPREMOTEIP");
  if (!remoteip) remoteip = "unknown";
  local = env_get("TCPLOCALHOST");
  if (!local) local = env_get("TCPLOCALIP");
  if (!local) local = "unknown";
  remotehost = env_get("TCPREMOTEHOST");
  if (!remotehost) remotehost = "unknown";
  remoteinfo = env_get("TCPREMOTEINFO");
  if (!remoteinfo)
     remoteinfo = "(null)";
  relayclient = env_get("RELAYCLIENT");
  dohelo(remotehost);
}


stralloc addr = {0}; /* will be 0-terminated, if addrparse returns 1 */

int addrparse(arg)
char *arg;
{
  int i;
  char ch;
  char terminator;
  struct ip_address ip;
  int flagesc;
  int flagquoted;

  terminator = '>;';
  i = str_chr(arg,'<');
  if (arg)
    arg += i + 1;
  else { /* partner should go read rfc 821 */
    terminator = ' ';
    arg += str_chr(arg,':');
    if (*arg == ':') ++arg;
    while (*arg == ' ') ++arg;
  }

  /* strip source route */
  if (*arg == '@') while (*arg) if (*arg++ == ':') break;

  if (!stralloc_copys(&addr,"")) die_nomem();
  flagesc = 0;
  flagquoted = 0;
  for (i = 0;ch = arg;++i) { /* copy arg to addr, stripping quotes */
    if (flagesc) {
      if (!stralloc_append(&addr,&ch)) die_nomem();
      flagesc = 0;
    }
    else {
      if (!flagquoted && (ch == terminator)) break;
      switch(ch) {
        case '\\': flagesc = 1; break;
        case '"': flagquoted = !flagquoted; break;
        default: if (!stralloc_append(&addr,&ch)) die_nomem();
      }
    }
  }
  /* could check for termination failure here, but why bother? */
  if (!stralloc_append(&addr,"")) die_nomem();

  if (liphostok) {
    i = byte_rchr(addr.s,addr.len,'@');
    if (i < addr.len) /* if not, partner should go read rfc 821 */
      if (addr.s[i + 1] == '[')
        if (!addr.s[i + 1 + ip_scanbracket(addr.s + i + 1,&ip)])
          if (ipme_is(&ip)) {
            addr.len = i + 1;
            if (!stralloc_cat(&addr,&liphost)) die_nomem();
            if (!stralloc_0(&addr)) die_nomem();
          }
  }

  if (addr.len >; 900) return 0;
  return 1;
}

int bmfcheck()
{
  int i, j;
  char buf[200], *s;

  if (!bmfok) return 0;
  if (constmap(&mapbmf,addr.s,addr.len - 1)) return 1;
  j = byte_rchr(addr.s,addr.len,'@');
  i = j = byte_rchr(addr.s,addr.len,'@');
  if (j < addr.len)
    if (constmap(&mapbmf,addr.s + j,addr.len - j - 1)) return 1;
  for (;j < addr.len;++j)
    if (addr.s[j] == '.')
      if (constmap(&mapbmf,addr.s + j,addr.len - j - 1)) return 1;
  if (i >; 80 || addr.s != '@')
     return 1;
  j = i;
  strncpy(buf, addr.s, ++j);
  for (s = buf + j; j < addr.len; ++j)
     if (addr.s[j] == '.') {
        sprintf(s, "%.100s", addr.s + j);
        if (constmap(&mapbmf, buf, strlen(buf))) return 1;
     }
  return 0;
}

int gmfcheck()
{
  int i, j;
  char buf[200], *s;

  if (!gmfok) return 0;
  if (constmap(&mapgmf,addr.s,addr.len - 1)) return 1;
  i = j = byte_rchr(addr.s,addr.len,'@');
  if (j < addr.len)
    if (constmap(&mapgmf,addr.s + j,addr.len - j - 1)) return 1;
  for (;j < addr.len;++j)
    if (addr.s[j] == '.')
      if (constmap(&mapgmf,addr.s + j,addr.len - j - 1)) return 1;
  if (i >; 80 || addr.s != '@')
     return 0;
  j = i;
  strncpy(buf, addr.s, ++j);
  for (s = buf + j; j < addr.len; ++j)
     if (addr.s[j] == '.') {
        sprintf(s, "%.100s", addr.s + j);
        if (constmap(&mapgmf, buf, strlen(buf))) return 1;
     }
  return 0;
}


int amfcheck()
{
  int i, j;
  char buf[200], *s;

  if (!amfok) return 0;
  if (constmap(&mapamf,addr.s,addr.len - 1)) return 1;
  i = j = byte_rchr(addr.s,addr.len,'@');
  if (j < addr.len)
    if (constmap(&mapamf,addr.s + j,addr.len - j - 1)) return 1;
  for (;j < addr.len;++j)
    if (addr.s[j] == '.')
      if (constmap(&mapamf,addr.s + j,addr.len - j - 1)) return 1;
  if (i >; 80 || addr.s != '@')
     return 1;
  j = i;
  strncpy(buf, addr.s, ++j);
  for (s = buf + j; j < addr.len; ++j)
     if (addr.s[j] == '.') {
        sprintf(s, "%.100s", addr.s + j);
        if (constmap(&mapamf, buf, strlen(buf))) return 1;
     }
  return 0;
}


int addrallowed()
{
  int r;
  r = rcpthosts(addr.s,str_len(addr.s));
  if (r == -1) die_control();
  return r;
}


int seenmail = 0;
int flagbarf; /* defined if seenmail, badmailfrom */
int flaggarf; /* goodmailfrom */
int flagaarf; /* allowmailfrom */
stralloc mailfrom = {0};
stralloc rcptto = {0};

void smtp_helo(arg) char *arg;
{
  smtp_greet("250 "); out("\r\n");
  seenmail = 0; dohelo(arg);
}
void smtp_ehlo(arg) char *arg;
{
#ifdef USE_SMTPAUTH
  out("\r\n250-AUTH=LOGIN");
#endif       
  smtp_greet("250-"); out("\r\n250-PIPELINING\r\n250 8BITMIME\r\n");
  seenmail = 0; dohelo(arg);
}
void smtp_rset()
{
  seenmail = 0;
  out("250 flushed\r\n");
}
void smtp_mail(arg) char *arg;
{
  if (!addrparse(arg)) { err_syntax(); return; }
  if (!(flaggarf = gmfcheck()))
     if (!(flagbarf = bmfcheck()))
        flagaarf = amfcheck();
  seenmail = 1;
  if (!stralloc_copys(&rcptto,"")) die_nomem();
  if (!stralloc_copys(&mailfrom,addr.s)) die_nomem();
  if (!stralloc_0(&mailfrom)) die_nomem();
  out("250 ok\r\n");
}

/*
is good rcptto
byte_rchr return strlen(s) + 1 if faild
addr.len == strlen(addr.s) + 1
*/
isgrt()
{
#define BUFSIZ1 200
   int j, ans;
   char buf[BUFSIZ1];

   if (!grtok)
      return 0;
   if ((j = byte_rchr(addr.s,addr.len,'@')) >;= BUFSIZ1)
      return 0;

   if (addr.len && j == addr.len)
      --j;
   strncpy(buf, addr.s, j);
   buf[j] = 0;
   if (ans = constmap(&mapgrt, buf, j) != 0) {
      char buf2[BUFSIZ1 + 30];

      sprintf(buf2, "control/databytes.%s", buf);
      if (control_readint(&databytes, buf2) == -1) die_control();
      if (!(databytes + 1)) --databytes;
      flaggarf = 1;
   }
   return ans;
}

void smtp_rcpt(arg) char *arg; {
   char *denymsg, *allowfrom, *fromhost;
   static ipalloc ip;
   static stralloc host;
   int j, ans, random;

  if (!seenmail) { err_wantmail(); return; }
  if (!addrparse(arg)) { err_syntax(); return; }

/*
   fprintf(stderr, "TRY haha: %s\n", remotehost);
   fflush(stderr);

  out("haha2\r\n");
  return;
*/

   fprintf(stderr, "TRY %s@%s:%s:%s:%s\n",
      remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
   fflush(stderr);

   if (flaggarf || isgrt())
      goto rcpt_gmf;

   if (denymsg = env_get("DENYMSG")) {
      out("553 ");
      out(denymsg);
      out("\r\n");
      fprintf(stderr, "DENY(badmailhost) %s@%s:%s:%s:%s\n",
         remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
      fflush(stderr);
      return;
   }
   else if (!relayclient && !strcmp(remotehost, "unknown")) {
      out("553 sorry, your mailhost can't be resolved\r\n");
      fprintf(stderr, "DENY(resolvmailhost) %s@%s:%s:%s:%s\n",
         remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
      fflush(stderr);
      return;
   }

/*
   if (!*mailfrom.s)
      goto rcpt_gmf;
*/

   j  = byte_rchr(mailfrom.s,mailfrom.len,'@') + 1;
   fromhost = mailfrom.s + j;
   if (!stralloc_copys(&host, fromhost)) die_nomem();
   random = now() + (getpid() << 16);
   ans = dns_mxip(&ip, &host, random);

   if (ans) {
      out("553 sorry, your envelope sender can't be resolved\r\n");
      fprintf(stderr, "DENY(resolvmailfrom) %s@%s:%s:%s:%s\n",
         remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
      fflush(stderr);
      return;
   }

   if ((allowfrom = env_get("ALLOWFROM")) &&
       strcasecmp(fromhost, remotehost)) {
      int match = 0;
      int i, c;

      for (allowfrom = strtok(allowfrom, ":"); allowfrom;
           allowfrom = strtok(0, ":")) {
         if (!strcasecmp(fromhost, allowfrom)) {
            match = 1;
            break;
         }
         for (i = 0; c = fromhost; i++)
            if (c == '.' && !strcasecmp(fromhost + i, allowfrom)) {
               match = 1;
               break;
            }
      }
      if (!match) {
         out("553 sorry, we do not accept relay from this mailhost\r\n");
         fprintf(stderr, "DENY(allowfrom) %s@%s:%s:%s:%s\n",
            remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
         fflush(stderr);
         return;
      }
   }

   if (flagbarf) {
      err_bmf();
      fprintf(stderr, "DENY(badmailfrom) %s@%s:%s:%s:%s\n",
         remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
      fflush(stderr);
      return;
   }

   if (flagaarf && !allowfrom
      && strcasecmp(fromhost, remotehost)) {
      out("553 sorry, we do not accept relay for this mailfrom\r\n");
      fprintf(stderr, "DENY(allowmailfrom) %s@%s:%s:%s:%s\n",
         remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
      fflush(stderr);
      return;
   }


rcpt_gmf:
  if (relayclient) {
    --addr.len;
    if (!stralloc_cats(&addr,relayclient)) die_nomem();
    if (!stralloc_0(&addr)) die_nomem();
  }
  else
    if (!addrallowed()) { err_nogateway(); return; }
  if (!stralloc_cats(&rcptto,"T")) die_nomem();
  if (!stralloc_cats(&rcptto,addr.s)) die_nomem();
  if (!stralloc_0(&rcptto)) die_nomem();
  out("250 ok\r\n");
  rcptcount++;
}



int saferead(fd,buf,len) int fd; char *buf; int len;
{
  int r;
  flush();
  r = timeoutread(timeout,fd,buf,len);
  if (r == -1) if (errno == error_timeout) die_alarm();
  if (r <= 0) die_read();
  return r;
}

char ssinbuf[1024];
substdio ssin = SUBSTDIO_FDBUF(saferead,0,ssinbuf,sizeof ssinbuf);

struct qmail qqt;
unsigned int bytestooverflow = 0;
int keymatched = 0;

addkey(int checksum, int bodysize, int bodyline)
{
   int match, i, j;

   for (match = 0, i = 1; i < KEYQUEUESIZE; i++) {
      j = (keyshm->;pos - i + KEYQUEUESIZE) % KEYQUEUESIZE;
      #define matchkey(x) x == keyshm->;x[j]
      if (matchkey(checksum) && matchkey(bodysize) && matchkey(bodyline))
         if (++match >; KEYLIMIT)
            return 0;
   }

   j = keyshm->;pos;
   #define fillkey(x) keyshm->;x[j] = x
   fillkey(checksum);
   fillkey(bodysize);
   fillkey(bodyline);

   if (++keyshm->;pos == KEYQUEUESIZE)
      keyshm->;pos = 0;
   return 1;
}

void put(ch)
char *ch;
{
  if (bytestooverflow)
    if (!--bytestooverflow)
      qmail_fail(&qqt);
  qmail_put(&qqt,ch,1);
}


void blast(hops)
int *hops;
{
  char ch;
  int state;
  int flaginheader;
  int pos; /* number of bytes since most recent \n, if fih */
  int flagmaybex; /* 1 if this line might match RECEIVED, if fih */
  int flagmaybey; /* 1 if this line might match \r\n, if fih */
  int flagmaybez; /* 1 if this line might match DELIVERED, if fih */
  int checksum, bodysize, bodyline;

  checksum = bodysize = bodyline = 0;
  state = 1;
  *hops = 0;
  flaginheader = 1;
  pos = 0; flagmaybex = flagmaybey = flagmaybez = 1;
  for (;;) {
    substdio_get(&ssin,&ch,1);
    if (flaginheader) {
      if (pos < 9) {
        if (ch != "delivered"[pos]) if (ch != "DELIVERED"[pos]) flagmaybez = 0;
        if (flagmaybez) if (pos == ++*hops;
        if (pos <
          if (ch != "received"[pos]) if (ch != "RECEIVED"[pos]) flagmaybex = 0;
        if (flagmaybex) if (pos == 7) ++*hops;
        if (pos < 2) if (ch != "\r\n"[pos]) flagmaybey = 0;
        if (flagmaybey) if (pos == 1) flaginheader = 0;
      }
      ++pos;
      if (ch == '\n') { pos = 0; flagmaybex = flagmaybey = flagmaybez = 1; }
    }
    else {
       checksum += ch;
       bodysize++;
       if (ch == '\n')
          bodyline++;
    }
    switch(state) {
      case 0:
        if (ch == '\n') straynewline();
        if (ch == '\r') { state = 4; continue; }
        break;
      case 1: /* \r\n */
        if (ch == '\n') straynewline();
        if (ch == '.') { state = 2; continue; }
        if (ch == '\r') { state = 4; continue; }
        state = 0;
        break;
      case 2: /* \r\n + . */
        if (ch == '\n') straynewline();
        if (ch == '\r') { state = 3; continue; }
        state = 0;
        break;
      case 3: /* \r\n + .\r */
        if (ch == '\n') goto blast_return;
        put(".");
        put("\r");
        if (ch == '\r') { state = 4; continue; }
        state = 0;
        break;
      case 4: /* + \r */
        if (ch == '\n') { state = 1; break; }
        if (ch != '\r') { put("\r"); state = 0; }
    }
    put(&ch);
  }
blast_return:
  fprintf(stderr, "KEY %s@%s:%s:%s:%s:%08x:%d:%d\n",
     remoteinfo, remotehost, remoteip, mailfrom.s, addr.s,
     checksum, bodysize, bodyline);
  if (flaggarf) {
     fflush(stderr);
     return;
  }
  if (keyshm && !addkey(checksum, bodysize, bodyline) ||
      rcptcount >; KEYLIMIT) {
     fprintf(stderr, "DENY(key) %s@%s:%s:%s:%s\n",
        remoteinfo, remotehost, remoteip, mailfrom.s, addr.s);
     qmail_fail(&qqt);
     keymatched = 1;
  }
  rcptcount = 0;
  fflush(stderr);
}

char accept_buf[FMT_ULONG];
void acceptmessage(qp) unsigned long qp;
{
  datetime_sec when;
  when = now();
  out("250 ok ");
  accept_buf[fmt_ulong(accept_buf,(unsigned long) when)] = 0;
  out(accept_buf);
  out(" qp ");
  accept_buf[fmt_ulong(accept_buf,qp)] = 0;
  out(accept_buf);
  out("\r\n");
}

void smtp_data() {
  int hops;
  unsigned long qp;
  char *qqx;

  if (!seenmail) { err_wantmail(); return; }
  if (!rcptto.len) { err_wantrcpt(); return; }
  seenmail = 0;
  if (databytes) bytestooverflow = databytes + 1;
  if (qmail_open(&qqt) == -1) { err_qqt(); return; }
  qp = qmail_qp(&qqt);
  out("354 go ahead\r\n");

  received(&qqt,"SMTP",local,remoteip,remotehost,remoteinfo,fakehelo);
  blast(&hops);
  hops = (hops >;= MAXHOPS);
  if (hops) qmail_fail(&qqt);
  qmail_from(&qqt,mailfrom.s);
  qmail_put(&qqt,rcptto.s,rcptto.len);

  qqx = qmail_close(&qqt);
  if (!*qqx) { acceptmessage(qp); return; }
  if (hops) { out("554 too many hops, this message is looping (#5.4.6)\r\n"); return; }
  if (databytes) if (!bytestooverflow) { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n"); return; }
  if (keymatched) { out("552 sorry, spawm mail ! die your ip (#5.3.4)\r\n"); return; }
  if (*qqx == 'D') out("554 "); else out("451 ");
  out(qqx + 1);
  out("\r\n");
}


#ifdef USE_SMTPAUTH
static unsigned char *base64_alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
static int unbase64(ch) int ch; {
  int i;
  if (ch == '=') return 0;
  for (i = 0; i < 64; i++)
    if (ch == base64_alphabet)
      return i;
  return 0;
}
static int base64_dec_buffer(str,dst,len) const char *str;void *dst;int len;
{
  int i, j, l;
  unsigned char input[4], output[3], *result = (char *)dst;
  if (str == 0)
    return 0;
  l = str_len(str);
  if (dst == 0 || l >; len)
    return (l / 4) * 3;
  memset(dst,0,len);
  for (i=j=0; i<l; i +=4) {
    input[0] = unbase64(str);
    input[1] = unbase64(str[i+1]);
    input[2] = unbase64(str[i+2]);
    input[3] = unbase64(str[i+3]);
    output[0] = (input[0] << 2) | (input[1] >;>; 4);
    output[1] = (input[1] << 4) | (input[2] >;>; 2);
    output[2] = (input[2] << 6) | (input[3]);
    result[j] = output[0];
    if (str[i+1] == '=') return j+1;
    result[j+1]=output[1];
    if (str[i+2] == '=') return j+2;
    result[j+2]=output[2];
    j += 3;
  }
  return j;
}
static stralloc smtpauth = {0};
static char smtpauthlogin[65];
static char smtpauthpass[65];
static int smtpauth_getl(void) {
  int i;
  if (!stralloc_copys(&smtpauth, "")) return -1;
  for (;;) {
    if (!stralloc_readyplus(&smtpauth,1)) return -1;
    i = substdio_get(&ssin, smtpauth.s + smtpauth.len, 1);
    if (i != 1) return i;
    if (smtpauth.s[smtpauth.len] == '\n') break;
    ++smtpauth.len;
  }
  if (smtpauth.len >; 0) if (smtpauth.s[smtpauth.len-1] == '\r') --smtpauth.len;
  smtpauth.s[smtpauth.len] = 0;
  return smtpauth.len;
}
static char **smtpauth_argv;
void smtp_auth(arg) char *arg; {
  int st, pid, fds[2];
  /* netscape 4.5 sends AUTH LOGIN <base64encodedusername>;
     microsoft outlook express sends AUTH LOGIN

     idea is simple

     use an external program to test authority
     if success, set 'RELAYCLIENT'
     otherwise, let them know nicely (hangup)

     note, i really don't like djb's coding style even though i'm using it here.
     i think using spaces for tabs is bad.
                                                -mrs.brisby@nimh.org
  */
  while (arg && *arg && *arg != ' ') arg++;

  /* pass over the space */
  while (arg && *arg && *arg == ' ') arg++;

  if (arg && *arg) {
    /* here's the base64 encoded login */
    base64_dec_buffer(arg, smtpauthlogin, sizeof(smtpauthlogin));
  } else {
    out("334 VXNlcm5hbWU6\r\n"); /* b64 <- 'Username:' */
    flush();
    if (smtpauth_getl() >; 0)
      base64_dec_buffer(smtpauth.s, smtpauthlogin, sizeof(smtpauthlogin));
    else
      die_read();
  }
  out("334 UGFzc3dvcmQ6\r\n"); /* b64 <- 'Password:' */
  flush();
  if (smtpauth_getl() >; 0)
    base64_dec_buffer(smtpauth.s, smtpauthpass, sizeof(smtpauthpass));
  else
    die_read();
  if (pipe(fds)) {
    out("535 pipe failure\r\n");
    flush();
    _exit(0);
  }
  /* spawn external program

  external program should return '0' if it was successful,

  submit: /bin/checkpassword /bin/true
  
  */
  switch ((pid=fork())) {
    case -1: die_nomem();
    case 0: close(fds[1]);
      fd_copy(3,fds[0]);
      execvp(smtpauth_argv[1], smtpauth_argv+1);
      die_nomem();
  };
  close(fds[0]);
  write(fds[1], smtpauthlogin, str_len(smtpauthlogin)+1);
  write(fds[1], smtpauthpass, str_len(smtpauthpass)+1);
  close(fds[1]);
  wait_pid(&st, pid);
  if (wait_exitcode(st) == 0) {
    out("235 go ahead\r\n");
    flush();
    relayclient="";
    return;
  }
  sleep(2);
  out("535 auth failure\r\n"); flush(); _exit(0);
  /* done */
}
#endif



struct commands smtpcommands[] = {
  { "rcpt", smtp_rcpt, 0 }
, { "mail", smtp_mail, 0 }
, { "data", smtp_data, flush }
#ifdef USE_SMTPAUTH
, { "auth", smtp_auth, flush }
#endif
, { "quit", smtp_quit, flush }
, { "helo", smtp_helo, flush }
, { "ehlo", smtp_ehlo, flush }
, { "rset", smtp_rset, 0 }
, { "help", smtp_help, flush }
, { "noop", err_noop, flush }
, { "vrfy", err_vrfy, flush }
, { 0, err_unimpl, flush }
} ;

void*
attach_shm(int shmkey, int shmsize)
{
   void *shmptr;
   int shmid;

   shmid = shmget(shmkey, shmsize, 0);
   if (shmid < 0) {
      shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600);
      if (shmid < 0)
         return 0;
      shmptr = (void *) shmat(shmid, NULL, 0);
      if (shmptr == (void *) -1)
         return 0;
      memset(shmptr, 0, shmsize);
   }
   else {
      shmptr = (void *) shmat(shmid, NULL, 0);
      if (shmptr == (void *) -1)
         return 0;
   }
   return shmptr;
}

#ifdef USE_SMTPAUTH
void main(argc,argv)
int argc;
char **argv;
{
   smtpauth_argv = argv + 1;
#else
void main()
{
#endif
  sig_pipeignore();
  if (chdir(auto_qmail) == -1) die_control();
  setup();
  if (ipme_init() != 1) die_ipme();
  smtp_greet("220 ");
  out(" ESMTP\r\n");
  keyshm = attach_shm(KEYSHM_KEY, sizeof(*keyshm));
  if (commands(&ssin,&smtpcommands) == 0) die_read();
  die_nomem();
}

论坛徽章:
0
17 [报告]
发表于 2003-05-30 10:18 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

把你的日志贴出来!还有把qmail 的错误信息贴出来!

论坛徽章:
0
18 [报告]
发表于 2003-05-30 12:36 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

startdd兄
不好意思這個qmail-spawm.rar補丁
是你寫的嗎???
可以把補丁與qmail修改的部份列出來嗎???
或者可以像gadfly兄一樣
用patch的方式把補丁打上去
這樣不管加認證或加其它的補丁都比較簡單

论坛徽章:
0
19 [报告]
发表于 2003-05-30 13:18 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

打补丁过程出错make: *** [qmail-smtpd] Error 1
有没有人打好过,
我把你包里的几个文件复制到qmail-1.03的源码包里(有两个文件同名覆盖掉),然后用make,就出错了

论坛徽章:
0
20 [报告]
发表于 2003-05-30 13:56 |只看该作者

防止垃圾邮件最新补丁(qmail-smtpd.c)!

原帖由 "haohaoo"]tpd 发表:
Error 1
有没有人打好过,
我把你包里的几个文件复制到qmail-1.03的源码包里(有两个文件同名覆盖掉),然后用make,就出错了
   

你没有把 dns.o 加入 Makefile 所以不能编译通过!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP