31#include "timeoutconn.h"
37#define MAX_SIZE 200000000
38#define HUGESMTPTEXT 5000
44#define WHO "qmail-smtpam"
86void out(
char *s) {
if (buffer_puts(buffer_1small,s) == -1)
_exit(111); }
87void zero() {
if (buffer_put(buffer_1small,
"\0",1) == -1)
_exit(111); }
93 for (i = 0; i <
sa->len; ++i) {
95 if (ch < 33) ch =
'?';
96 if (ch > 126) ch =
'?';
97 if (buffer_put(buffer_1small,&ch,1) == -1)
_exit(111);
103 out(
"Zinvalid ipaddr in control/domainips (#4.3.0)\n");
108 out(
"ZOut of memory. (#4.3.0)\n");
113 out(
"ZSystem resources temporarily unavailable. (#4.3.0)\n");
118 out(
"ZCan't bind to local ip address: ");
125 out(
"ZSorry, I wasn't able to establish an SMTP connection. (#4.4.1)\n");
130 out(
"ZCNAME lookup failed temporarily for: ");
137 out(
"ZSorry, I couldn't find any host named: ");
144 out(
"ZUnable to switch to home directory. (#4.3.0)\n");
149 out(
"ZUnable to read control files. (#4.3.0)\n");
154 out(
"Dqmail-smtpam was invoked improperly. (#5.3.5)\n");
159 out(
"DSorry, I couldn't find any host named: ");
175 if (buffer_put(buffer_1small,
ipaddr,len) == -1)
_exit(0);
182 out(
"ZConnected to ");
184 out(
" but connection died. ");
219 buffer_get(&
bi,ch,1);
237 if (ch !=
'-')
break;
238 while (ch !=
'\n')
get(&ch);
243 while (ch !=
'\n')
get(&ch);
252 out(
"Remote host said: ");
260void quit(
char *prepend,
char *append)
262 buffer_putsflush(&
bo,
"QUIT\r\n");
329 while ( (i += str_chr(
smtptext.s + i,
'\n') + 1) &&
331 if (!str_diffn(
smtptext.s + i + 4,
"STARTTLS",8))
return 1; }
340 cert = SSL_get_peer_certificate(
ssl);
341 if (!cert) {
flagtls = 100;
return; }
373 if (ch[i++] > 127)
return 1;
383 buffer_puts(&
bo,
"EHLO ");
385 buffer_puts(&
bo,
"\r\n");
389 buffer_puts(&
bo,
"HELO ");
391 buffer_puts(&
bo,
"\r\n");
394 if (
code >= 500)
quit(
"DConnected to",
" but my name was rejected");
395 if (
code != 250)
quit(
"ZConnected to",
" but my name was rejected");
401 buffer_puts(&
bo,
"STARTTLS\r\n");
409 quit(
"ZConnected to",
" but STARTTLS was rejected");
422 if (
code >= 500)
quit(
"DConnected to ",
" but sender was rejected");
423 if (
code >= 400)
quit(
"ZConnected to ",
" but sender was probably greylisted");
436 buffer_puts(&
bo,
"MAIL FROM:<>");
438 buffer_puts(&
bo,
" SMTPUTF8");
439 buffer_puts(&
bo,
"\r\n");
442 if (
code >= 500)
quit(
"DConnected to ",
" but sender was rejected");
443 if (
code >= 400)
quit(
"ZConnected to ",
" but sender was rejected");
445 buffer_puts(&
bo,
"RCPT TO:<");
447 buffer_puts(&
bo,
">\r\n");
481 static ipalloc ip = {0};
482 stralloc netif = {0};
510 j = str_chr(localip,
'%');
511 if (localip[
j] !=
'%')
j = 0;
512 k = str_chr(localip,
'|');
513 if (localip[
k] !=
'|')
k = 0;
583 while ((r == -1) && (errno == EINTR));
584 if (r == -1)
_exit(111);
602 default:
if (ip.len <= 0)
perm_dns();
605 smtpfd = socket(ip.ix[i].af,SOCK_STREAM,0);
610 j = str_chr(localip,
':');
611 if (
j && localip[
j] ==
':') {
613 ifidx = socket_getifidx(netif.s);
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
int control_readint(int *i, char *fn)
int control_rldef(stralloc *sa, char *fn, int flagme, char *def)
int control_readfile(stralloc *sa, char *fn, int flagme)
int stralloc_copys(stralloc *, char const *)
int dns_ip(ipalloc *ia, stralloc *sa)
void p(char *, char *, int, int, int)
GEN_ALLOC_readyplus(prioq, struct prioq_elt, p, len, a, i, n, x, 100, prioq_readyplus)
ssize_t saferead(int fd, char *buf, int len)
struct constmap maproutes
struct constmap mapdomainips
GEN_ALLOC_typedef(GEN_ALLOC_readyplus(saa, GEN_ALLOC_readyplus(stralloc, GEN_ALLOC_readyplus(sa, GEN_ALLOC_readyplus(len, GEN_ALLOC_readyplus(a)
struct constmap maptlsdestinations
void quit(char *prepend, char *append)
unsigned long verifydepth
void outsafe(stralloc *sa)
struct constmap mapdomaincerts
int utf8flag(unsigned char *ch, int len)
void temp_tlscipher(void)
void temp_tlsdigest(void)
void temp_tlspeerverify()
void temp_tlscertfp(void)
void temp_invaliddigest(void)
int tls_destination(const stralloc)
tls_destination
int tls_fingerprint(X509 *, const char *, const int)
int tls_checkpeer(SSL *, X509 *, const stralloc, const int, const int)
int tls_timeoutconn(int t, int rfd, int wfd, SSL *tls)
int ssl_ciphers(SSL_CTX *, const char *)
SSL * ssl_new(SSL_CTX *, int)
int ssl_ca(SSL_CTX *, const char *, const char *, int)