From a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f Mon Sep 17 00:00:00 2001
From: Jannis Hoffmann <jannis@fehcom.de>
Date: Wed, 3 Jul 2024 15:52:39 +0200
Subject: format files

---
 src/smtpdlog.c | 387 +++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 280 insertions(+), 107 deletions(-)
 mode change 100755 => 100644 src/smtpdlog.c

(limited to 'src/smtpdlog.c')

diff --git a/src/smtpdlog.c b/src/smtpdlog.c
old mode 100755
new mode 100644
index 1b44af1..c7505af
--- a/src/smtpdlog.c
+++ b/src/smtpdlog.c
@@ -1,11 +1,13 @@
+#include "smtpdlog.h"
+
 #include <unistd.h>
+
 #include "buffer.h"
-#include "str.h"
 #include "byte.h"
 #include "env.h"
-#include "fmt.h"
 #include "exit.h"
-#include "smtpdlog.h"
+#include "fmt.h"
+#include "str.h"
 #define FDLOG 2
 
 char *reply421pgl;
@@ -21,7 +23,7 @@ char *reply554cnt;
 
 static char strnum[FMT_ULONG];
 static char logbuf[512];
-buffer bo2 = BUFFER_INIT(write,FDLOG,logbuf,sizeof(logbuf));
+buffer bo2 = BUFFER_INIT(write, FDLOG, logbuf, sizeof(logbuf));
 
 void smtpdlog_init()
 {
@@ -37,150 +39,317 @@ void smtpdlog_init()
   reply554cnt = env_get("REPLY_CONTENT");
 }
 
-static void logs(char *s) { if (buffer_puts(&bo2,s) == -1) _exit(1); }  /* single string */
-static void logp(char *s) { logs(" P:"); logs(s); }                     /* protocol */
-static void logh(char *s1,char *s2,char *s3) { logs(" S:"); logs(s1); logs(":"); logs(s2); logs(" H:"); logs(s3); }  /* host */
-static void logm(char *s) { logs(" F:"); logs(s); }                     /* mailfrom */
-static void logt(char *s) { logs(" T:"); logs(s); }                     /* rcptto */
-static void logi(char *s) { logs(" '"); logs(s); logs("'"); }           /* information */
-static void logn(char *s) { if (buffer_puts(&bo2,s) == -1 ) _exit(1); if (buffer_flush(&bo2) == -1) _exit(1); } /* end */
-static void logpid() { strnum[fmt_ulong(strnum,getpid())] = 0; logs("qmail-smtpd: pid "); logs(strnum); logs(" "); }
+static void logs(char *s)
+{
+  if (buffer_puts(&bo2, s) == -1) _exit(1);
+} /* single string */
+static void logp(char *s)
+{
+  logs(" P:");
+  logs(s);
+} /* protocol */
+static void logh(char *s1, char *s2, char *s3)
+{
+  logs(" S:");
+  logs(s1);
+  logs(":");
+  logs(s2);
+  logs(" H:");
+  logs(s3);
+} /* host */
+static void logm(char *s)
+{
+  logs(" F:");
+  logs(s);
+} /* mailfrom */
+static void logt(char *s)
+{
+  logs(" T:");
+  logs(s);
+} /* rcptto */
+static void logi(char *s)
+{
+  logs(" '");
+  logs(s);
+  logs("'");
+} /* information */
+static void logn(char *s)
+{
+  if (buffer_puts(&bo2, s) == -1) _exit(1);
+  if (buffer_flush(&bo2) == -1) _exit(1);
+} /* end */
+static void logpid()
+{
+  strnum[fmt_ulong(strnum, getpid())] = 0;
+  logs("qmail-smtpd: pid ");
+  logs(strnum);
+  logs(" ");
+}
 
-void smtp_loga(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8,char *s9)
-  { logpid(); logs(s1); logs(s9); logp(s2); logh(s3,s4,s5); logm(s6); logt(s7), logs(" ?~"); logi(s8); logn("\n"); }  /* Auth info */
-void smtp_logb(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
-  { logpid(); logs(s1); logs(s7); logp(s2); logh(s3,s4,s5); logs(" ?~"); logi(s6); logn("\n"); }  /* Auth info */
-void smtp_logg(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
-  { logpid(); logs(s1); logp(s2); logh(s3,s4,s5); logm(s6); logt(s7); logn("\n"); } /* Generic */
-void smtp_logh(char *s1,char *s2,char *s3,char *s4,char *s5)
-  { logpid(); logs(s1); logp(s2); logh(s3,s4,s5); logn("\n"); }                     /* Host */
-void smtp_logi(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
-  { logpid(); logs(s1); logp(s2); logh(s3,s4,s5); logm(s6); logt(s7); logi(s8); logn("\n"); }  /* Generic + Info */
-void smtp_logr(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
-  { logpid(); logs(s1); logs(s2); logp(s3); logh(s4,s5,s6); logm(s7); logt(s8); logn("\n"); }  /* Recipient */
+void smtp_loga(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9)
+{
+  logpid();
+  logs(s1);
+  logs(s9);
+  logp(s2);
+  logh(s3, s4, s5);
+  logm(s6);
+  logt(s7), logs(" ?~");
+  logi(s8);
+  logn("\n");
+} /* Auth info */
+void smtp_logb(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
+{
+  logpid();
+  logs(s1);
+  logs(s7);
+  logp(s2);
+  logh(s3, s4, s5);
+  logs(" ?~");
+  logi(s6);
+  logn("\n");
+} /* Auth info */
+void smtp_logg(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
+{
+  logpid();
+  logs(s1);
+  logp(s2);
+  logh(s3, s4, s5);
+  logm(s6);
+  logt(s7);
+  logn("\n");
+} /* Generic */
+void smtp_logh(char *s1, char *s2, char *s3, char *s4, char *s5)
+{
+  logpid();
+  logs(s1);
+  logp(s2);
+  logh(s3, s4, s5);
+  logn("\n");
+} /* Host */
+void smtp_logi(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
+{
+  logpid();
+  logs(s1);
+  logp(s2);
+  logh(s3, s4, s5);
+  logm(s6);
+  logt(s7);
+  logi(s8);
+  logn("\n");
+} /* Generic + Info */
+void smtp_logr(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
+{
+  logpid();
+  logs(s1);
+  logs(s2);
+  logp(s3);
+  logh(s4, s5, s6);
+  logm(s7);
+  logt(s8);
+  logn("\n");
+} /* Recipient */
 
-void die_read() { _exit(1); }
-void die_alarm() { out("451 timeout (#4.4.2)\r\n"); flush(); _exit(1); }
-void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); }
-void die_control() { out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); }
-void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); }
-void die_starttls() { out("454 TLS not available due to temporary reason (#5.7.3)\r\n"); flush(); _exit(1); }
-void die_recipients() { out("421 unable to check recipients (#4.3.0)\r\n"); flush(); _exit(1); }
+void die_read()
+{
+  _exit(1);
+}
+void die_alarm()
+{
+  out("451 timeout (#4.4.2)\r\n");
+  flush();
+  _exit(1);
+}
+void die_nomem()
+{
+  out("421 out of memory (#4.3.0)\r\n");
+  flush();
+  _exit(1);
+}
+void die_control()
+{
+  out("421 unable to read controls (#4.3.0)\r\n");
+  flush();
+  _exit(1);
+}
+void die_ipme()
+{
+  out("421 unable to figure out my IP addresses (#4.3.0)\r\n");
+  flush();
+  _exit(1);
+}
+void die_starttls()
+{
+  out("454 TLS not available due to temporary reason (#5.7.3)\r\n");
+  flush();
+  _exit(1);
+}
+void die_recipients()
+{
+  out("421 unable to check recipients (#4.3.0)\r\n");
+  flush();
+  _exit(1);
+}
 
-void err_unimpl() { out("500 unimplemented (#5.5.1)\r\n"); }
-void err_syntax() { out("555 syntax error (#5.5.4)\r\n"); }
-void err_noop() { out("250 ok\r\n"); }
-void err_vrfy() { out("252 send some mail, i'll try my best\r\n"); }
-void err_qqt() { out("451 qqt failure (#4.3.0)\r\n"); }
+void err_unimpl()
+{
+  out("500 unimplemented (#5.5.1)\r\n");
+}
+void err_syntax()
+{
+  out("555 syntax error (#5.5.4)\r\n");
+}
+void err_noop()
+{
+  out("250 ok\r\n");
+}
+void err_vrfy()
+{
+  out("252 send some mail, i'll try my best\r\n");
+}
+void err_qqt()
+{
+  out("451 qqt failure (#4.3.0)\r\n");
+}
 
-int err_child() { out("454 problem with child and I can't auth (#4.3.0)\r\n"); return -1; }
-int err_fork() { out("454 child won't start and I can't auth (#4.3.0)\r\n"); return -1; }
-int err_pipe() { out("454 unable to open pipe and I can't auth (#4.3.0)\r\n"); return -1; }
-int err_write() { out("454 unable to write pipe and I can't auth (#4.3.0)\r\n"); return -1; }
+int err_child()
+{
+  out("454 problem with child and I can't auth (#4.3.0)\r\n");
+  return -1;
+}
+int err_fork()
+{
+  out("454 child won't start and I can't auth (#4.3.0)\r\n");
+  return -1;
+}
+int err_pipe()
+{
+  out("454 unable to open pipe and I can't auth (#4.3.0)\r\n");
+  return -1;
+}
+int err_write()
+{
+  out("454 unable to write pipe and I can't auth (#4.3.0)\r\n");
+  return -1;
+}
 
-int err_postgl() { out("454 problem with child and I can't greylist (#4.3.0)\r\n"); return -1; }
-int err_forkgl() { out("454 problem with child and I can't greylist (#4.3.0)\r\n"); return -1; }
+int err_postgl()
+{
+  out("454 problem with child and I can't greylist (#4.3.0)\r\n");
+  return -1;
+}
+int err_forkgl()
+{
+  out("454 problem with child and I can't greylist (#4.3.0)\r\n");
+  return -1;
+}
 
 /* TLS */
 
-int err_starttls() 
-{ 
+int err_starttls()
+{
   out("454 TLS not available due to temporary reason (#5.7.3)\r\n");
-  _exit(1); 
+  _exit(1);
 }
-void err_tlsreq(char *s1,char *s2,char *s3,char *s4,char *s5)
+void err_tlsreq(char *s1, char *s2, char *s3, char *s4, char *s5)
 {
-  out("535 STARTTLS required (#5.7.1)\r\n"); 
-  smtp_logh(s1,s2,s3,s4,s5); 
+  out("535 STARTTLS required (#5.7.1)\r\n");
+  smtp_logh(s1, s2, s3, s4, s5);
 }
 
 /* Helo */
 
-void err_helo(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
+void err_helo(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
 {
   out("550 sorry, invalid HELO/EHLO greeting ");
   if (reply550hlo) out(reply550hlo);
   out(" (#5.7.1)\r\n");
-  smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
- }
+  smtp_logi(s1, s2, s3, s4, s5, s6, s7, s8);
+}
 
 /* Auth */
 
-void err_authsetup(char *s1,char *s2,char *s3,char *s4,char *s5)
+void err_authsetup(char *s1, char *s2, char *s3, char *s4, char *s5)
+{
+  out("530 Auth not available (#5.7.1)\r\n");
+  smtp_logh(s1, s2, s3, s4, s5);
+}
+void err_authd()
 {
-  out("530 Auth not available (#5.7.1)\r\n"); 
-  smtp_logh(s1,s2,s3,s4,s5); 
-} 
-void err_authd() 
-{ 
   out("503 you're already authenticated (#5.5.0)\r\n");
 }
-void err_authmail() 
-{ 
+void err_authmail()
+{
   out("503 no auth during mail transaction (#5.5.0)\r\n");
 }
-void err_authfail(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_authfail(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
-  out("535 authentication failed (#5.7.1)\r\n"); smtp_logb(s1,s2,s3,s4,s5,s6,s7);
+  out("535 authentication failed (#5.7.1)\r\n");
+  smtp_logb(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_authreq(char *s1,char *s2,char *s3,char *s4,char *s5)
+void err_authreq(char *s1, char *s2, char *s3, char *s4, char *s5)
 {
-  out("535 authentication required (#5.7.1)\r\n"); smtp_logh(s1,s2,s3,s4,s5);
+  out("535 authentication required (#5.7.1)\r\n");
+  smtp_logh(s1, s2, s3, s4, s5);
 }
-void err_submission(char *s1,char *s2,char *s3,char *s4,char *s5)
-{ 
-  out("530 Authorization required (#5.7.1) \r\n"); smtp_logh(s1,s2,s3,s4,s5);
+void err_submission(char *s1, char *s2, char *s3, char *s4, char *s5)
+{
+  out("530 Authorization required (#5.7.1) \r\n");
+  smtp_logh(s1, s2, s3, s4, s5);
 }
-int err_authabort() 
-{ 
+int err_authabort()
+{
   out("501 auth exchange canceled (#5.0.0)\r\n");
   return -1;
 }
-int err_authinput() 
-{ 
+int err_authinput()
+{
   out("501 malformed auth input (#5.5.4)\r\n");
   return -1;
 }
-void err_authinvalid(char *s1,char *s2,char *s3,char *s4,char *s5)
-{ 
+void err_authinvalid(char *s1, char *s2, char *s3, char *s4, char *s5)
+{
   out("504 auth type unimplemented (#5.5.1)\r\n");
-  smtp_logh(s1,s2,s3,s4,s5); 
+  smtp_logh(s1, s2, s3, s4, s5);
 }
-int err_noauth() 
-{ 
+int err_noauth()
+{
   out("504 auth type unimplemented (#5.5.1)\r\n");
   return -1;
 }
 
 /* Mail From: */
 
-void err_wantmail() { out("503 MAIL first (#5.5.1)\r\n"); }
+void err_wantmail()
+{
+  out("503 MAIL first (#5.5.1)\r\n");
+}
 
-void err_mav(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_mav(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   out("553 sorry, invalid sender address specified ");
   if (reply553inv) out(reply553inv);
   out(" (#5.7.1)\r\n");
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_bmf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
+void err_bmf(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
 {
   out("553 sorry, your envelope sender is in my badmailfrom list ");
   if (reply553bmf) out(reply553bmf);
   out(" (#5.7.1)\r\n");
-  smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
+  smtp_logi(s1, s2, s3, s4, s5, s6, s7, s8);
 }
-void err_mfdns(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_mfdns(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   out("553 sorry, your envelope sender must exist ");
   if (reply553env) out(reply553env);
   out(" (#5.7.1)\r\n");
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
 
 /* SPF */
 
-void err_spf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *msg)
+void err_spf(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *msg)
 {
   int i, j;
   int len = str_len(msg);
@@ -196,76 +365,80 @@ void err_spf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char
       out("550 ");
       out(msg);
     }
-  } 
+  }
   out(" (#5.7.1)\r\n");
 
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
 
 /* Rcpt To: */
 
-void err_wantrcpt() { out("503 RCPT first (#5.5.1)\r\n"); }
+void err_wantrcpt()
+{
+  out("503 RCPT first (#5.5.1)\r\n");
+}
 
-void postgrey(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7) 
+void postgrey(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   out("421 greylisted");
   if (reply421pgl) out(reply421pgl);
   out(" (#4.3.0)\r\n");
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_nogateway(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_nogateway(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   out("553 sorry, that domain isn't in my list of allowed rcpthosts ");
   if (reply553ngw) out(reply553ngw);
   out(" (#5.7.1)\r\n");
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_brt(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_brt(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   out("553 sorry, your envelope recipient is in my badrcptto list ");
   if (reply553brt) out(reply553brt);
   out(" (#5.7.1)\r\n");
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_rcpts(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_rcpts(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
-  out("452 sorry, too many recipients (#4.5.3)\r\n");   /* RFC 5321 */
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  out("452 sorry, too many recipients (#4.5.3)\r\n"); /* RFC 5321 */
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_recipient(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_recipient(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   if (env_get("RECIPIENTS450"))
     out("450 sorry, mailbox currently unavailable (#4.2.1)\r\n");
   else {
     out("550 sorry, no mailbox by that name ");
-    if (reply550mbx) out(reply550mbx); out(" (#5.7.1)\r\n");
+    if (reply550mbx) out(reply550mbx);
+    out(" (#5.7.1)\r\n");
   }
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
 
 /* Data */
 
-void straynewline() 
+void straynewline()
 {
   out("451 Bare Line Feeds (LF) are not accepted in SMTP; CRLF is required according to RFC 2822.\r\n");
-  flush(); 
-  _exit(1); 
+  flush();
+  _exit(1);
 }
-void err_notorious() 
-{ 
+void err_notorious()
+{
   out("503 DATA command not accepted at this time (#5.5.1)\r\n");
   flush();
   _exit(1);
 }
-void err_size(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
+void err_size(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
 {
   out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n");
-  smtp_logg(s1,s2,s3,s4,s5,s6,s7);
+  smtp_logg(s1, s2, s3, s4, s5, s6, s7);
 }
-void err_data(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
+void err_data(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
 {
   out("554 sorry, invalid message content ");
   if (reply554cnt) out(reply554cnt);
   out(" (#5.3.2)\r\n");
-  smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
+  smtp_logi(s1, s2, s3, s4, s5, s6, s7, s8);
 }
-- 
cgit v1.2.3