diff options
| -rw-r--r-- | Makefile | 11 | ||||
| -rw-r--r-- | qmail-smtpd.c | 24 | ||||
| -rw-r--r-- | qmail-spp.c | 259 | ||||
| -rw-r--r-- | qmail-spp.h | 14 |
4 files changed, 303 insertions, 5 deletions
| @@ -1598,17 +1598,22 @@ auto_uids.h auto_qmail.h auto_break.h auto_patrn.h auto_spawn.h \ | |||
| 1598 | auto_split.h | 1598 | auto_split.h |
| 1599 | ./compile qmail-showctl.c | 1599 | ./compile qmail-showctl.c |
| 1600 | 1600 | ||
| 1601 | qmail-spp.o: \ | ||
| 1602 | compile qmail-spp.c readwrite.h stralloc.h substdio.h control.h str.h \ | ||
| 1603 | byte.h env.h exit.h wait.h fork.h fd.h fmt.h getln.h | ||
| 1604 | ./compile qmail-spp.c | ||
| 1605 | |||
| 1601 | qmail-smtpd: \ | 1606 | qmail-smtpd: \ |
| 1602 | load qmail-smtpd.o rcpthosts.o qregex.o commands.o timeoutread.o \ | 1607 | load qmail-smtpd.o rcpthosts.o qregex.o commands.o timeoutread.o \ |
| 1603 | timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o received.o \ | 1608 | timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o received.o \ |
| 1604 | date822fmt.o now.o qmail.o cdb.a fd.a wait.a datetime.a getln.a \ | 1609 | date822fmt.o now.o qmail.o cdb.a fd.a wait.a datetime.a getln.a \ |
| 1605 | open.a sig.a case.a env.a stralloc.a alloc.a strerr.a substdio.a error.a str.a \ | 1610 | open.a sig.a case.a env.a stralloc.a alloc.a strerr.a substdio.a error.a str.a \ |
| 1606 | fs.a auto_qmail.o base64.o socket.lib | 1611 | fs.a auto_qmail.o base64.o qmail-spp.o socket.lib |
| 1607 | ./load qmail-smtpd qregex.o rcpthosts.o commands.o timeoutread.o \ | 1612 | ./load qmail-smtpd qregex.o rcpthosts.o commands.o timeoutread.o \ |
| 1608 | timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o \ | 1613 | timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o \ |
| 1609 | tls.o ssl_timeoutio.o ndelay.a -L/usr/local/ssl/lib -lssl -lcrypto \ | 1614 | tls.o ssl_timeoutio.o ndelay.a -L/usr/local/ssl/lib -lssl -lcrypto \ |
| 1610 | received.o date822fmt.o now.o qmail.o cdb.a fd.a wait.a \ | 1615 | received.o date822fmt.o now.o qmail.o cdb.a fd.a wait.a \ |
| 1611 | datetime.a getln.a open.a sig.a case.a env.a stralloc.a \ | 1616 | datetime.a getln.a open.a sig.a case.a qmail-spp.o env.a stralloc.a \ |
| 1612 | alloc.a strerr.a substdio.a error.a str.a fs.a auto_qmail.o base64.o `cat \ | 1617 | alloc.a strerr.a substdio.a error.a str.a fs.a auto_qmail.o base64.o `cat \ |
| 1613 | socket.lib` | 1618 | socket.lib` |
| 1614 | 1619 | ||
| @@ -1619,7 +1624,7 @@ qmail-smtpd.8 | |||
| 1619 | qmail-smtpd.o: \ | 1624 | qmail-smtpd.o: \ |
| 1620 | compile qmail-smtpd.c sig.h readwrite.h stralloc.h gen_alloc.h \ | 1625 | compile qmail-smtpd.c sig.h readwrite.h stralloc.h gen_alloc.h \ |
| 1621 | substdio.h alloc.h auto_qmail.h control.h received.h constmap.h \ | 1626 | substdio.h alloc.h auto_qmail.h control.h received.h constmap.h \ |
| 1622 | error.h ipme.h ip.h ipalloc.h ip.h gen_alloc.h ip.h qmail.h \ | 1627 | error.h ipme.h ip.h ipalloc.h ip.h gen_alloc.h ip.h qmail.h qmail-spp.h \ |
| 1623 | substdio.h str.h fmt.h scan.h byte.h case.h env.h now.h datetime.h \ | 1628 | substdio.h str.h fmt.h scan.h byte.h case.h env.h now.h datetime.h \ |
| 1624 | exit.h rcpthosts.h timeoutread.h timeoutwrite.h commands.h base64.h | 1629 | exit.h rcpthosts.h timeoutread.h timeoutwrite.h commands.h base64.h |
| 1625 | ./compile qmail-smtpd.c | 1630 | ./compile qmail-smtpd.c |
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 | } |
diff --git a/qmail-spp.c b/qmail-spp.c new file mode 100644 index 0000000..78ab9e7 --- /dev/null +++ b/qmail-spp.c | |||
| @@ -0,0 +1,259 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2004-2005 Pawel Foremski <pjf@asn.pl> | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU General Public License | ||
| 6 | * as published by the Free Software Foundation; either | ||
| 7 | * version 2 of the License, or (at your option) any later | ||
| 8 | * version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software Foundation, | ||
| 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | * | ||
| 19 | *** Note | ||
| 20 | * | ||
| 21 | * This is the core of qmail-spp patch for qmail | ||
| 22 | * | ||
| 23 | * Why I made it a separate file? Because I wanted qmail-spp to apply more | ||
| 24 | * cleanly on heavily patched qmail sources and to make it bit simpler to | ||
| 25 | * maintain, so don't treat it as a library. | ||
| 26 | * | ||
| 27 | * "..." comments marks places where code for other SMTP commands should be | ||
| 28 | * added, if needed. | ||
| 29 | * | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include "readwrite.h" | ||
| 33 | #include "stralloc.h" | ||
| 34 | #include "substdio.h" | ||
| 35 | #include "control.h" | ||
| 36 | #include "str.h" | ||
| 37 | #include "byte.h" | ||
| 38 | #include "env.h" | ||
| 39 | #include "exit.h" | ||
| 40 | #include "wait.h" | ||
| 41 | #include "fork.h" | ||
| 42 | #include "fd.h" | ||
| 43 | #include "fmt.h" | ||
| 44 | #include "getln.h" | ||
| 45 | |||
| 46 | /* stuff needed from qmail-smtpd */ | ||
| 47 | extern void flush(); | ||
| 48 | extern void out(); | ||
| 49 | extern void die_nomem(); | ||
| 50 | extern stralloc addr; | ||
| 51 | /* *** */ | ||
| 52 | |||
| 53 | stralloc sppheaders = {0}; | ||
| 54 | static int spprun = 0; | ||
| 55 | static int sppfok = 0; | ||
| 56 | static int sppret; | ||
| 57 | static stralloc sppf = {0}; | ||
| 58 | static stralloc plugins_dummy = {0}, plugins_connect = {0}, plugins_helo = {0}, plugins_mail = {0}, | ||
| 59 | plugins_rcpt = {0}, plugins_data = {0}, plugins_auth = {0}; /* ... */ | ||
| 60 | static stralloc error_mail = {0}, error_rcpt = {0}, error_data = {0}; /* ... */ | ||
| 61 | static stralloc sppmsg = {0}; | ||
| 62 | static char rcptcountstr[FMT_ULONG]; | ||
| 63 | static unsigned long rcptcount; | ||
| 64 | static unsigned long rcptcountall; | ||
| 65 | static substdio ssdown; | ||
| 66 | static char downbuf[128]; | ||
| 67 | |||
| 68 | static void err_spp(s1, s2) char *s1, *s2; { out("451 qmail-spp failure: "); out(s1); out(": "); out(s2); out(" (#4.3.0)\r\n"); } | ||
| 69 | |||
| 70 | int spp_init() | ||
| 71 | { | ||
| 72 | int i, len = 0; | ||
| 73 | stralloc *plugins_to; | ||
| 74 | char *x, *conffile = "control/smtpplugins"; | ||
| 75 | |||
| 76 | if (!env_get("NOSPP")) { | ||
| 77 | spprun = 1; | ||
| 78 | plugins_to = &plugins_dummy; | ||
| 79 | x = env_get("SPPCONFFILE"); | ||
| 80 | if (x && *x) conffile = x; | ||
| 81 | sppfok = control_readfile(&sppf, conffile, 0); | ||
| 82 | if (sppfok != 1) return -1; | ||
| 83 | for (i = 0; i < sppf.len; i += len) { | ||
| 84 | len = str_len(sppf.s + i) + 1; | ||
| 85 | if (sppf.s[i] == '[') | ||
| 86 | switch (sppf.s[i + 1]) { | ||
| 87 | case 'c': plugins_to = &plugins_connect; break; | ||
| 88 | case 'h': plugins_to = &plugins_helo; break; | ||
| 89 | case 'm': plugins_to = &plugins_mail; break; | ||
| 90 | case 'r': plugins_to = &plugins_rcpt; break; | ||
| 91 | case 'd': plugins_to = &plugins_data; break; | ||
| 92 | case 'a': plugins_to = &plugins_auth; break; | ||
| 93 | /* ... */ | ||
| 94 | default: plugins_to = &plugins_dummy; | ||
| 95 | } | ||
| 96 | else | ||
| 97 | if (!stralloc_catb(plugins_to, sppf.s + i, len)) die_nomem(); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | void sppout() { if (sppmsg.len) out(sppmsg.s); out("\r\n"); } | ||
| 105 | |||
| 106 | int spp(plugins, addrenv) stralloc *plugins; char *addrenv; | ||
| 107 | { | ||
| 108 | static int pipes[2]; | ||
| 109 | static int i, pid, wstat, match, last; | ||
| 110 | static stralloc data = {0}; | ||
| 111 | static char *(args[4]); | ||
| 112 | static stralloc *errors_to; | ||
| 113 | |||
| 114 | if (!spprun) return 1; | ||
| 115 | if (addrenv) if (!env_put2(addrenv, addr.s)) die_nomem(); | ||
| 116 | last = 0; | ||
| 117 | |||
| 118 | for (i = 0; i < plugins->len; i += str_len(plugins->s + i) + 1) { | ||
| 119 | if (plugins->s[i] == ':') | ||
| 120 | { args[0] = "/bin/sh"; args[1] = "-c"; args[2] = plugins->s + i + 1; args[3] = 0; } | ||
| 121 | else | ||
| 122 | { args[0] = plugins->s + i; args[1] = 0; } | ||
| 123 | |||
| 124 | if (pipe(pipes) == -1) | ||
| 125 | { err_spp(plugins->s + i, "can't pipe()"); return 0; } | ||
| 126 | |||
| 127 | switch (pid = vfork()) { | ||
| 128 | case -1: | ||
| 129 | err_spp(plugins->s + i, "vfork() failed"); | ||
| 130 | return 0; | ||
| 131 | case 0: | ||
| 132 | close(0); close(pipes[0]); fd_move(1, pipes[1]); | ||
| 133 | execv(*args, args); | ||
| 134 | _exit(120); | ||
| 135 | } | ||
| 136 | |||
| 137 | close(pipes[1]); | ||
| 138 | substdio_fdbuf(&ssdown, read, pipes[0], downbuf, sizeof(downbuf)); | ||
| 139 | do { | ||
| 140 | if (getln(&ssdown, &data, &match, '\n') == -1) die_nomem(); | ||
| 141 | if (data.len > 1) { | ||
| 142 | data.s[data.len - 1] = 0; | ||
| 143 | switch (data.s[0]) { | ||
| 144 | case 'H': | ||
| 145 | if (!stralloc_catb(&sppheaders, data.s + 1, data.len - 2)) die_nomem(); | ||
| 146 | if (!stralloc_append(&sppheaders, "\n")) die_nomem(); | ||
| 147 | break; | ||
| 148 | case 'C': | ||
| 149 | if (addrenv) { | ||
| 150 | if (!stralloc_copyb(&addr, data.s + 1, data.len - 1)) die_nomem(); | ||
| 151 | if (!env_put2(addrenv, addr.s)) die_nomem(); | ||
| 152 | } | ||
| 153 | break; | ||
| 154 | case 'S': if (!env_put(data.s + 1)) die_nomem(); break; | ||
| 155 | case 'U': if (!env_unset(data.s + 1)) die_nomem(); break; | ||
| 156 | case 'A': spprun = 0; | ||
| 157 | case 'O': | ||
| 158 | case 'N': | ||
| 159 | case 'D': last = 1; match = 0; break; | ||
| 160 | case 'E': | ||
| 161 | case 'R': last = 1; match = 0; | ||
| 162 | case 'P': out(data.s + 1); out("\r\n"); break; | ||
| 163 | case 'L': | ||
| 164 | switch (data.s[1]) { | ||
| 165 | case 'M': errors_to = &error_mail; break; | ||
| 166 | case 'R': errors_to = &error_rcpt; break; | ||
| 167 | case 'D': errors_to = &error_data; break; | ||
| 168 | /* ... */ | ||
| 169 | default: errors_to = 0; | ||
| 170 | } | ||
| 171 | if (errors_to) { | ||
| 172 | if (!stralloc_catb(errors_to, data.s + 2, data.len - 3)) die_nomem(); | ||
| 173 | if (!stralloc_catb(errors_to, "\r\n", 2)) die_nomem(); | ||
| 174 | } | ||
| 175 | break; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } while (match); | ||
| 179 | |||
| 180 | close(pipes[0]); | ||
| 181 | if (wait_pid(&wstat,pid) == -1) { err_spp(plugins->s + i, "wait_pid() failed"); return 0; } | ||
| 182 | if (wait_crashed(wstat)) { err_spp(plugins->s + i, "child crashed"); return 0; } | ||
| 183 | if (wait_exitcode(wstat) == 120) { err_spp(plugins->s + i, "can't execute"); return 0; } | ||
| 184 | |||
| 185 | if (last) | ||
| 186 | switch (*data.s) { | ||
| 187 | case 'E': return 0; | ||
| 188 | case 'A': | ||
| 189 | case 'N': return 1; | ||
| 190 | case 'O': return 2; | ||
| 191 | case 'R': | ||
| 192 | case 'D': flush(); _exit(0); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | return 1; | ||
| 197 | } | ||
| 198 | |||
| 199 | int spp_errors(errors) stralloc *errors; | ||
| 200 | { | ||
| 201 | if (!errors->len) return 1; | ||
| 202 | if (!stralloc_0(errors)) die_nomem(); | ||
| 203 | out(errors->s); | ||
| 204 | return 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | int spp_connect() { return spp(&plugins_connect, 0); } | ||
| 208 | |||
| 209 | int spp_helo(arg) char *arg; | ||
| 210 | { | ||
| 211 | if (!env_put2("SMTPHELOHOST", arg)) die_nomem(); | ||
| 212 | return spp(&plugins_helo, 0); | ||
| 213 | } | ||
| 214 | |||
| 215 | void spp_rset() | ||
| 216 | { | ||
| 217 | if (!stralloc_copys(&sppheaders, "")) die_nomem(); | ||
| 218 | if (!stralloc_copys(&error_mail, "")) die_nomem(); | ||
| 219 | if (!stralloc_copys(&error_rcpt, "")) die_nomem(); | ||
| 220 | if (!stralloc_copys(&error_data, "")) die_nomem(); | ||
| 221 | /* ... */ | ||
| 222 | rcptcount = rcptcountall = 0; | ||
| 223 | } | ||
| 224 | |||
| 225 | int spp_mail() | ||
| 226 | { | ||
| 227 | if (!spp_errors(&error_mail)) return 0; | ||
| 228 | rcptcount = rcptcountall = 0; | ||
| 229 | return spp(&plugins_mail, "SMTPMAILFROM"); | ||
| 230 | } | ||
| 231 | |||
| 232 | int spp_rcpt(allowed) int allowed; | ||
| 233 | { | ||
| 234 | if (!spp_errors(&error_rcpt)) return 0; | ||
| 235 | rcptcountstr[fmt_ulong(rcptcountstr, rcptcount)] = 0; | ||
| 236 | if (!env_put2("SMTPRCPTCOUNT", rcptcountstr)) die_nomem(); | ||
| 237 | rcptcountstr[fmt_ulong(rcptcountstr, ++rcptcountall)] = 0; | ||
| 238 | if (!env_put2("SMTPRCPTCOUNTALL", rcptcountstr)) die_nomem(); | ||
| 239 | if (!env_put2("SMTPRCPTHOSTSOK", allowed ? "1" : "0")) die_nomem(); | ||
| 240 | sppret = spp(&plugins_rcpt, "SMTPRCPTTO"); | ||
| 241 | return sppret; | ||
| 242 | } | ||
| 243 | |||
| 244 | void spp_rcpt_accepted() { rcptcount++; } | ||
| 245 | |||
| 246 | int spp_data() | ||
| 247 | { | ||
| 248 | if (!spp_errors(&error_data)) return 0; | ||
| 249 | return spp(&plugins_data, 0); | ||
| 250 | } | ||
| 251 | |||
| 252 | int spp_auth(method, user) char *method, *user; | ||
| 253 | { | ||
| 254 | if (!env_put2("SMTPAUTHMETHOD", method)) die_nomem(); | ||
| 255 | if (!env_put2("SMTPAUTHUSER", user)) die_nomem(); | ||
| 256 | return spp(&plugins_auth, 0); | ||
| 257 | } | ||
| 258 | |||
| 259 | /* ... */ | ||
diff --git a/qmail-spp.h b/qmail-spp.h new file mode 100644 index 0000000..b4d7154 --- /dev/null +++ b/qmail-spp.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #ifndef QMAIL_SPP_H | ||
| 2 | #define QMAIL_SPP_H | ||
| 3 | |||
| 4 | extern stralloc sppheaders; | ||
| 5 | extern int spp_init(); | ||
| 6 | extern int spp_connect(); | ||
| 7 | extern int spp_helo(); | ||
| 8 | extern void spp_rset(); | ||
| 9 | extern int spp_mail(); | ||
| 10 | extern int spp_rcpt(); | ||
| 11 | extern int spp_data(); | ||
| 12 | extern int spp_auth(); | ||
| 13 | |||
| 14 | #endif | ||
