12#include "timeoutconn.h"
15#define WHO "qmail-postgrey"
23int main(
int argc,
char *
const *argv)
25 struct ip4_address
ip4;
26 struct ip6_address
ip6;
36 logmsg(
WHO,100,USAGE,
"qmail-postgrey ip%ifidx;port sender recipient client_address client_name");
45 ifidx = socket_getifidx(netif);
48 logmsg(
WHO,111,FATAL,B(
"No valid IPv6 address provided: ",
remoteip));
49 pgfd = socket(AF_INET6,SOCK_STREAM,0);
51 logmsg(
WHO,111,FATAL,
"Can't bind to IPv6 socket.");
55 logmsg(
WHO,111,FATAL,B(
"No valid IPv6 address provided: ",
remoteip));
56 pgfd = socket(AF_INET,SOCK_STREAM,0);
58 logmsg(
WHO,111,FATAL,
"Can't bind to IPv4 socket.");
59 r = timeoutconn4(pgfd,(
char *)&
ip4.d,
port,
CT);
62 if (errno == ETIMEDOUT)
64 logmsg(
WHO,111,FATAL,B(
"Can't communicate with postgrey server: ",
remoteip));
72 if (!stralloc_cats(&
query,
"\nclient_name="))
_exit(1);
74 if (!stralloc_cats(&
query,
"\nsender="))
_exit(1);
76 if (!stralloc_cats(&
query,
"\nrecipient="))
_exit(1);
82 }
while (r == -1 && errno == EINTR);
89 r = timeoutread(
RT,pgfd,
buf,
sizeof(
buf));
90 }
while (r == -1 && errno == EINTR);
92 if (r == -1) { close(pgfd);
_exit(1); }
98 if (!case_diffb(
buf,12,
"action=dunno"))
_exit(0);
100 if (!case_diffb(
buf,14,
"action=prepend"))
_exit(0);
102 if (!case_diffb(
buf,22,
"action=defer_if_permit"))
_exit(10);
int stralloc_copys(stralloc *, char const *)