diff options
Diffstat (limited to 'qmail-smtpd.c')
| -rw-r--r-- | qmail-smtpd.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/qmail-smtpd.c b/qmail-smtpd.c index 25f821c..4553b42 100644 --- a/qmail-smtpd.c +++ b/qmail-smtpd.c | |||
| @@ -27,6 +27,9 @@ | |||
| 27 | #include "qregex.h" | 27 | #include "qregex.h" |
| 28 | #include "strerr.h" | 28 | #include "strerr.h" |
| 29 | #include "cdb.h" | 29 | #include "cdb.h" |
| 30 | #include "qmail-spp.h" | ||
| 31 | |||
| 32 | int spp_val; | ||
| 30 | 33 | ||
| 31 | #define BMCHECK_BMF 0 | 34 | #define BMCHECK_BMF 0 |
| 32 | #define BMCHECK_BMFNR 1 | 35 | #define BMCHECK_BMFNR 1 |
| @@ -219,6 +222,7 @@ void setup() | |||
| 219 | if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control(); | 222 | if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control(); |
| 220 | if (timeout <= 0) timeout = 1; | 223 | if (timeout <= 0) timeout = 1; |
| 221 | if (rcpthosts_init() == -1) die_control(); | 224 | if (rcpthosts_init() == -1) die_control(); |
| 225 | if (spp_init() == -1) die_control(); | ||
| 222 | 226 | ||
| 223 | bmfok = control_readfile(&bmf,"control/badmailfrom",0); | 227 | bmfok = control_readfile(&bmf,"control/badmailfrom",0); |
| 224 | if (bmfok == -1) die_control(); | 228 | if (bmfok == -1) die_control(); |
| @@ -439,6 +443,7 @@ int flagbarfbmf; /* defined if seenmail */ | |||
| 439 | int flagbarfbmt; | 443 | int flagbarfbmt; |
| 440 | int flagbrt; /* defined if any bad rcpts */ | 444 | int flagbrt; /* defined if any bad rcpts */ |
| 441 | int flagbarfbhelo; | 445 | int flagbarfbhelo; |
| 446 | int allowed; | ||
| 442 | int flagsize; | 447 | int flagsize; |
| 443 | stralloc mailfrom = {0}; | 448 | stralloc mailfrom = {0}; |
| 444 | stralloc rcptto = {0}; | 449 | stralloc rcptto = {0}; |
| @@ -507,6 +512,7 @@ void mailfrom_parms(arg) char *arg; | |||
| 507 | 512 | ||
| 508 | void smtp_helo(arg) char *arg; | 513 | void smtp_helo(arg) char *arg; |
| 509 | { | 514 | { |
| 515 | if(!spp_helo(arg)) return; | ||
| 510 | smtp_greet("250 "); out("\r\n"); | 516 | smtp_greet("250 "); out("\r\n"); |
| 511 | seenmail = 0; dohelo(arg); | 517 | seenmail = 0; dohelo(arg); |
| 512 | if (bhelook) flagbarfbhelo = bmcheck(BMCHECK_BHELO); | 518 | if (bhelook) flagbarfbhelo = bmcheck(BMCHECK_BHELO); |
| @@ -526,6 +532,7 @@ void smtp_ehlo(arg) char *arg; | |||
| 526 | #endif | 532 | #endif |
| 527 | char size[FMT_ULONG]; | 533 | char size[FMT_ULONG]; |
| 528 | size[fmt_ulong(size,(unsigned int) databytes)] = 0; | 534 | size[fmt_ulong(size,(unsigned int) databytes)] = 0; |
| 535 | if(!spp_helo(arg)) return; | ||
| 529 | smtp_greet("250-"); | 536 | smtp_greet("250-"); |
| 530 | #ifdef TLS | 537 | #ifdef TLS |
| 531 | if (!ssl && (stat("control/servercert.pem",&st) == 0)) | 538 | if (!ssl && (stat("control/servercert.pem",&st) == 0)) |
| @@ -543,6 +550,7 @@ void smtp_ehlo(arg) char *arg; | |||
| 543 | } | 550 | } |
| 544 | void smtp_rset() | 551 | void smtp_rset() |
| 545 | { | 552 | { |
| 553 | spp_rset(); | ||
| 546 | seenmail = 0; | 554 | seenmail = 0; |
| 547 | out("250 flushed\r\n"); | 555 | out("250 flushed\r\n"); |
| 548 | } | 556 | } |
| @@ -557,6 +565,7 @@ void smtp_mail(arg) char *arg; | |||
| 557 | if ((!flagbarfbmf) && (bmfnrok) && (addr.len != 1) && (!relayclient)) { | 565 | if ((!flagbarfbmf) && (bmfnrok) && (addr.len != 1) && (!relayclient)) { |
| 558 | flagbarfbmf = bmcheck(BMCHECK_BMFNR); | 566 | flagbarfbmf = bmcheck(BMCHECK_BMFNR); |
| 559 | } | 567 | } |
| 568 | if (!(spp_val = spp_mail())) return; | ||
| 560 | seenmail = 1; | 569 | seenmail = 1; |
| 561 | if (!stralloc_copys(&rcptto,"")) die_nomem(); | 570 | if (!stralloc_copys(&rcptto,"")) die_nomem(); |
| 562 | if (!stralloc_copys(&mailfrom,addr.s)) die_nomem(); | 571 | if (!stralloc_copys(&mailfrom,addr.s)) die_nomem(); |
| @@ -599,17 +608,22 @@ void smtp_rcpt(arg) char *arg; { | |||
| 599 | err_bmt(); | 608 | err_bmt(); |
| 600 | return; | 609 | return; |
| 601 | } | 610 | } |
| 611 | if (!relayclient) allowed = addrallowed(); | ||
| 612 | else allowed = 1; | ||
| 602 | if (relayclient) { | 613 | if (relayclient) { |
| 603 | --addr.len; | 614 | --addr.len; |
| 604 | if (!stralloc_cats(&addr,relayclient)) die_nomem(); | 615 | if (!stralloc_cats(&addr,relayclient)) die_nomem(); |
| 605 | if (!stralloc_0(&addr)) die_nomem(); | 616 | if (!stralloc_0(&addr)) die_nomem(); |
| 606 | } | 617 | } |
| 607 | else | ||
| 608 | if (!addrallowed()) { err_nogateway(); return; } | ||
| 609 | if (!env_get("RELAYCLIENT") && brtcheck()) { | 618 | if (!env_get("RELAYCLIENT") && brtcheck()) { |
| 610 | flagbrt = 1; | 619 | flagbrt = 1; |
| 611 | log_deny("BAD RCPT TO", mailfrom.s,addr.s); | 620 | log_deny("BAD RCPT TO", mailfrom.s,addr.s); |
| 612 | } | 621 | } |
| 622 | if (!(spp_val = spp_rcpt(allowed))) return; | ||
| 623 | if (!relayclient && spp_val == 1) { | ||
| 624 | if (!allowed) { err_nogateway(); return; } | ||
| 625 | } | ||
| 626 | spp_rcpt_accepted(); | ||
| 613 | if (!stralloc_cats(&rcptto,"T")) die_nomem(); | 627 | if (!stralloc_cats(&rcptto,"T")) die_nomem(); |
| 614 | if (!stralloc_cats(&rcptto,addr.s)) die_nomem(); | 628 | if (!stralloc_cats(&rcptto,addr.s)) die_nomem(); |
| 615 | if (!stralloc_0(&rcptto)) die_nomem(); | 629 | if (!stralloc_0(&rcptto)) die_nomem(); |
| @@ -732,6 +746,7 @@ void smtp_data() { | |||
| 732 | if (!rcptto.len) { err_wantrcpt(); return; } | 746 | if (!rcptto.len) { err_wantrcpt(); return; } |
| 733 | if (mailfrom.len == 1 && recipcount > 1) { err_badbounce(); return; } | 747 | if (mailfrom.len == 1 && recipcount > 1) { err_badbounce(); return; } |
| 734 | if (flagbrt) { err_brt(); return; } | 748 | if (flagbrt) { err_brt(); return; } |
| 749 | if (!spp_data()) return; | ||
| 735 | seenmail = 0; | 750 | seenmail = 0; |
| 736 | if (databytes) bytestooverflow = databytes + 1; | 751 | if (databytes) bytestooverflow = databytes + 1; |
| 737 | if (qmail_open(&qqt) == -1) { err_qqt(); return; } | 752 | if (qmail_open(&qqt) == -1) { err_qqt(); return; } |
| @@ -739,6 +754,8 @@ void smtp_data() { | |||
| 739 | out("354 go ahead\r\n"); | 754 | out("354 go ahead\r\n"); |
| 740 | 755 | ||
| 741 | received(&qqt,protocol,local,remoteip,remotehost,remoteinfo,fakehelo); | 756 | received(&qqt,protocol,local,remoteip,remotehost,remoteinfo,fakehelo); |
| 757 | qmail_put(&qqt,sppheaders.s,sppheaders.len); /* set in qmail-spp.c */ | ||
| 758 | spp_rset(); | ||
| 742 | blast(&hops); | 759 | blast(&hops); |
| 743 | hops = (hops >= MAXHOPS); | 760 | hops = (hops >= MAXHOPS); |
| 744 | if (hops) qmail_fail(&qqt); | 761 | if (hops) qmail_fail(&qqt); |
| @@ -972,6 +989,7 @@ char *arg; | |||
| 972 | 989 | ||
| 973 | switch (authcmds[i].fun(arg)) { | 990 | switch (authcmds[i].fun(arg)) { |
| 974 | case 0: | 991 | case 0: |
| 992 | if (!spp_auth(authcmds[i].text, user.s)) return; | ||
| 975 | flagauth = 1; | 993 | flagauth = 1; |
| 976 | protocol = "ESMTPA"; | 994 | protocol = "ESMTPA"; |
| 977 | relayclient = ""; | 995 | relayclient = ""; |
| @@ -1250,8 +1268,10 @@ char **argv; | |||
| 1250 | if (chdir(auto_qmail) == -1) die_control(); | 1268 | if (chdir(auto_qmail) == -1) die_control(); |
| 1251 | setup(); | 1269 | setup(); |
| 1252 | if (ipme_init() != 1) die_ipme(); | 1270 | if (ipme_init() != 1) die_ipme(); |
| 1271 | if (spp_connect()) { | ||
| 1253 | smtp_greet("220 "); | 1272 | smtp_greet("220 "); |
| 1254 | out(" ESMTP\r\n"); | 1273 | out(" ESMTP\r\n"); |
| 1274 | } | ||
| 1255 | if (commands(&ssin,&smtpcommands) == 0) die_read(); | 1275 | if (commands(&ssin,&smtpcommands) == 0) die_read(); |
| 1256 | die_nomem(); | 1276 | die_nomem(); |
| 1257 | } | 1277 | } |
