commit 9e99181f7f34b859b62efb9c44fff0daa27ff253
parent efa1c86a8900037a0d48f193143ebb55a24e0018
Author: Ellenor Malik <ellenor@umbrellix.net>
Date: Fri, 23 Sep 2022 18:43:21 +0000
just gonna last commit the old mxf-remote stuff. it's gonna be gone.
Diffstat:
1 file changed, 124 insertions(+), 0 deletions(-)
diff --git a/src/mxf-remote/mxf-remote-connector.c b/src/mxf-remote/mxf-remote-connector.c
@@ -29,6 +29,130 @@
#include "timeoutread.h"
#include "timeoutwrite.h"
+#define HUGESMTPTEXT 5000
+
+#define PORT_SMTP 25 /* silly rabbit, /etc/services is for users */
+unsigned long port = PORT_SMTP;
+
+/* mxfnotes
+ * How much of this is really the remit of
+ */
+GEN_ALLOC_typedef(saa,stralloc,sa,len,a)
+GEN_ALLOC_readyplus(saa,stralloc,sa,len,a,10,saa_readyplus)
+static stralloc sauninit = {0};
+
+stralloc helohost = {0};
+stralloc routes = {0};
+struct constmap maproutes;
+stralloc host = {0};
+stralloc sender = {0};
+
+saa reciplist = {0};
+
+struct ip_address partner;
+
+void out(char *s)
+{
+ if (substdio_puts(subfdoutsmall,s) == -1) _exit(0);
+}
+void zero() {
+ if (substdio_put(subfdoutsmall,"\0",1) == -1) _exit(0);
+}
+void _noreturn_ zerodie() {
+ zero(); substdio_flush(subfdoutsmall); _exit(0);
+}
+void outsafe(stralloc *sa) {
+ int i;
+ char ch;
+ for (i = 0;i < sa->len;++i) {
+ ch = sa->s[i];
+ if (ch < 33) ch = '?';
+ if (ch > 126) ch = '?';
+ if (substdio_put(subfdoutsmall,&ch,1) == -1) _exit(0);
+ }
+}
+
+void _noreturn_ temp_nomem() {
+ out("ZOut of memory. (#4.3.0)\n"); zerodie();
+}
+void _noreturn_ temp_oserr() {
+ out("ZSystem resources temporarily unavailable. (#4.3.0)\n"); zerodie();
+}
+void _noreturn_ temp_noconn() {
+ out("ZSorry, I wasn't able to establish an SMTP connection. (#4.4.1)\n");
+ zerodie();
+}
+void _noreturn_ temp_read() {
+ out("ZUnable to read message. (#4.3.0)\n");
+ zerodie();
+}
+void _noreturn_ temp_dnscanon() {
+ out("ZCNAME lookup failed temporarily. (#4.4.3)\n");
+ zerodie();
+}
+void _noreturn_ temp_dns() {
+ out("ZSorry, I couldn't find any host by that name. (#4.1.2)\n"); zerodie();
+}
+void _noreturn_ temp_chdir() {
+ out("ZUnable to switch to home directory. (#4.3.0)\n"); zerodie();
+}
+void _noreturn_ temp_control() {
+ out("ZUnable to read control files. (#4.3.0)\n"); zerodie();
+}
+void _noreturn_ perm_partialline() {
+ out("DSMTP cannot transfer messages with partial final lines. (#5.6.2)\n"); zerodie();
+}
+void _noreturn_ perm_usage() {
+ out("DI (qmail-remote) was invoked improperly. (#5.3.5)\n"); zerodie();
+}
+void _noreturn_ perm_dns() {
+ out("DSorry, I couldn't find any host named ");
+ outsafe(&host);
+ out(". (#5.1.2)\n"); zerodie();
+}
+void _noreturn_ perm_nomx() {
+ out("DSorry, I couldn't find a mail exchanger or IP address. (#5.4.4)\n");
+ zerodie();
+}
+void _noreturn_ perm_ambigmx() {
+ out("DSorry. Although I'm listed as a best-preference MX or A for that host,\n\
+ it isn't in my control/locals file, so I don't treat it as local. (#5.4.6)\n");
+ zerodie();
+}
+
+void outhost()
+{
+ char x[IPFMT];
+ if (substdio_put(subfdoutsmall,x,ip_fmt(x,&partner)) == -1) _exit(0);
+}
+
+int flagcritical = 0;
+
+void _noreturn_ dropped() {
+ out("ZConnected to ");
+ outhost();
+ out(" but connection died. ");
+ if (flagcritical) out("Possible duplicate! ");
+ out("(#4.4.2)\n");
+ zerodie();
+}
+
+int timeoutconnect = 60;
+int smtpfd;
+int timeout = 1200;
+
+GEN_SAFE_TIMEOUTREAD(saferead,timeout,smtpfd,dropped())
+GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,smtpfd,dropped())
+
+char inbuf[1024];
+substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf));
+char smtptobuf[1024];
+substdio smtpto = SUBSTDIO_FDBUF(safewrite,-1,smtptobuf,sizeof(smtptobuf));
+char smtpfrombuf[128];
+substdio smtpfrom = SUBSTDIO_FDBUF(saferead,-1,smtpfrombuf,sizeof(smtpfrombuf));
+
+stralloc smtptext = {0};
+
void getcontrols()
{
if (control_init() == -1) temp_control();