summaryrefslogtreecommitdiff
path: root/src/qmail-postgrey.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/qmail-postgrey.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/qmail-postgrey.c')
-rw-r--r--src/qmail-postgrey.c88
1 files changed, 46 insertions, 42 deletions
diff --git a/src/qmail-postgrey.c b/src/qmail-postgrey.c
index bd88389..942dee6 100644
--- a/src/qmail-postgrey.c
+++ b/src/qmail-postgrey.c
@@ -1,16 +1,17 @@
-#include <unistd.h>
-#include <sys/socket.h>
#include <netinet/in.h>
-#include "stralloc.h"
-#include "logmsg.h"
-#include "ip.h"
+#include <sys/socket.h>
+#include <unistd.h>
+
#include "case.h"
-#include "str.h"
#include "exit.h"
+#include "ip.h"
+#include "logmsg.h"
#include "scan.h"
+#include "socket_if.h"
+#include "str.h"
+#include "stralloc.h"
#include "timeout.h"
#include "timeoutconn.h"
-#include "socket_if.h"
#define WHO "qmail-postgrey"
@@ -33,73 +34,76 @@ int main(int argc, char **argv)
int i, j, r;
if (argc != 6)
- logmsg(WHO,100,USAGE,"qmail-postgrey ip%ifidx;port sender recipient client_address client_name");
+ logmsg(WHO, 100, USAGE, "qmail-postgrey ip%ifidx;port sender recipient client_address client_name");
remoteip = argv[1];
- i = str_chr(remoteip,':');
+ i = str_chr(remoteip, ':');
if (remoteip[i] == ':') {
- j = str_chr(remoteip,'%'); /* IF index */
+ j = str_chr(remoteip, '%'); /* IF index */
if (remoteip[j] == '%') {
remoteip[j] = 0;
netif = &remoteip[j + 1];
ifidx = socket_getifidx(netif);
}
- if (!ip6_scan(remoteip,(char *)&ip6.d))
- logmsg(WHO,111,FATAL,B("No valid IPv6 address provided: ",remoteip));
- pgfd = socket(AF_INET6,SOCK_STREAM,0);
- if (pgfd == -1)
- logmsg(WHO,111,FATAL,"Can't bind to IPv6 socket.");
- r = timeoutconn6(pgfd,(char *)&ip6.d,port,CT,ifidx);
+ if (!ip6_scan(remoteip, (char *)&ip6.d))
+ logmsg(WHO, 111, FATAL, B("No valid IPv6 address provided: ", remoteip));
+ pgfd = socket(AF_INET6, SOCK_STREAM, 0);
+ if (pgfd == -1) logmsg(WHO, 111, FATAL, "Can't bind to IPv6 socket.");
+ r = timeoutconn6(pgfd, (char *)&ip6.d, port, CT, ifidx);
} else {
- if (!ip4_scan(remoteip,(char *)&ip4.d))
- logmsg(WHO,111,FATAL,B("No valid IPv6 address provided: ",remoteip));
- pgfd = socket(AF_INET,SOCK_STREAM,0);
- if (pgfd == -1)
- logmsg(WHO,111,FATAL,"Can't bind to IPv4 socket.");
- r = timeoutconn4(pgfd,(char *)&ip4.d,port,CT);
+ if (!ip4_scan(remoteip, (char *)&ip4.d))
+ logmsg(WHO, 111, FATAL, B("No valid IPv6 address provided: ", remoteip));
+ pgfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (pgfd == -1) logmsg(WHO, 111, FATAL, "Can't bind to IPv4 socket.");
+ r = timeoutconn4(pgfd, (char *)&ip4.d, port, CT);
}
if (r != 0) {
- if (errno == ETIMEDOUT)
- close(pgfd);
- logmsg(WHO,111,FATAL,B("Can't communicate with postgrey server: ",remoteip));
+ if (errno == ETIMEDOUT) close(pgfd);
+ logmsg(WHO, 111, FATAL, B("Can't communicate with postgrey server: ", remoteip));
_exit(1);
}
/* Provide SMTP connect vector to postgrey server */
- if (!stralloc_copys(&query,"request=smtpd_access_policy\nclient_address=")) _exit(1);
- if (!stralloc_cats(&query,argv[4])) _exit(1);
- if (!stralloc_cats(&query,"\nclient_name=")) _exit(1);
- if (!stralloc_cats(&query,argv[5])) _exit(1);
- if (!stralloc_cats(&query,"\nsender=")) _exit(1);
- if (!stralloc_cats(&query,argv[2])) _exit(1);
- if (!stralloc_cats(&query,"\nrecipient=")) _exit(1);
- if (!stralloc_cats(&query,argv[3])) _exit(1);
- if (!stralloc_cats(&query,"\n\n")) _exit(1);
+ if (!stralloc_copys(&query, "request=smtpd_access_policy\nclient_address=")) _exit(1);
+ if (!stralloc_cats(&query, argv[4])) _exit(1);
+ if (!stralloc_cats(&query, "\nclient_name=")) _exit(1);
+ if (!stralloc_cats(&query, argv[5])) _exit(1);
+ if (!stralloc_cats(&query, "\nsender=")) _exit(1);
+ if (!stralloc_cats(&query, argv[2])) _exit(1);
+ if (!stralloc_cats(&query, "\nrecipient=")) _exit(1);
+ if (!stralloc_cats(&query, argv[3])) _exit(1);
+ if (!stralloc_cats(&query, "\n\n")) _exit(1);
do {
- r = timeoutwrite(WT,pgfd,query.s,query.len);
+ r = timeoutwrite(WT, pgfd, query.s, query.len);
} while (r == -1 && errno == EINTR);
- if (r != query.len) { close(pgfd); _exit(1); }
+ if (r != query.len) {
+ close(pgfd);
+ _exit(1);
+ }
/* Read response */
do {
- r = timeoutread(RT,pgfd,buf,sizeof(buf));
+ r = timeoutread(RT, pgfd, buf, sizeof(buf));
} while (r == -1 && errno == EINTR);
- if (r == -1) { close(pgfd); _exit(1); }
+ if (r == -1) {
+ close(pgfd);
+ _exit(1);
+ }
close(pgfd);
-// logmsg(WHO,0,INFO,buf);
+ // logmsg(WHO,0,INFO,buf);
if (r >= 12)
- if (!case_diffb(buf,12,"action=dunno")) _exit(0);
+ if (!case_diffb(buf, 12, "action=dunno")) _exit(0);
if (r >= 14)
- if (!case_diffb(buf,14,"action=prepend")) _exit(0);
+ if (!case_diffb(buf, 14, "action=prepend")) _exit(0);
if (r >= 22)
- if (!case_diffb(buf,22,"action=defer_if_permit")) _exit(10);
+ if (!case_diffb(buf, 22, "action=defer_if_permit")) _exit(10);
exit(1);
}