From 25d1d56767989bf9f07f7d62654c738cf6b2d3e9 Mon Sep 17 00:00:00 2001 From: Manvendra Bhangui Date: Mon, 2 Oct 2023 17:59:48 +0530 Subject: [PATCH] updated , smtpd.c, autoresponder.c, svctool 1. smtpd.c: Fix (double) error message for unsupported AUTH method 2. smtpd.c: Fix SEGV when decoding SRS recipient address 3. autoresponder.c: decode SRS return path address 4. svctool: make QmailHOME, INDIMAILDIR configurable through env variable --- indimail-mta-x/autoresponder.c | 27 ++++++++++++---- indimail-mta-x/doc/ChangeLog | 7 ++-- indimail-mta-x/smtpd.c | 29 +++++++++++------ indimail-mta-x/svctool.in | 58 ++++++++++++++++++++-------------- 4 files changed, 78 insertions(+), 43 deletions(-) diff --git a/indimail-mta-x/autoresponder.c b/indimail-mta-x/autoresponder.c index dcf2e49702..023da39c6b 100644 --- a/indimail-mta-x/autoresponder.c +++ b/indimail-mta-x/autoresponder.c @@ -1,5 +1,5 @@ /* - * $Id: autoresponder.c,v 1.39 2023-10-01 11:44:44+05:30 Cprogrammer Exp mbhangui $ + * $Id: autoresponder.c,v 1.39 2023-10-02 17:40:58+05:30 Cprogrammer Exp mbhangui $ * * This is a simple program to automatically respond to emails. * @@ -73,7 +73,7 @@ static char ssinbuf[512], ssoutbuf[512]; static char strnum[FMT_ULONG]; substdio ssin, ssout; static pid_t inject_pid; -static stralloc liphost = { 0 }, content_type = { 0 }; +static stralloc liphost = { 0 }, content_type = { 0 }, srs_domain = { 0 }; struct header { char *returnpath; @@ -993,7 +993,7 @@ mkTempFile(int seekfd) int main(int argc, char *argv[]) { - int fdout, match; + int fdout, match, len, do_srs = 0, at; char *sender, *dtrecip, *host, *ptr; char dbuf[DATE822FMT]; #ifdef MIME @@ -1026,6 +1026,11 @@ main(int argc, char *argv[]) strerr_die2sys(111, FATAL, "unable to read doublebounceto controls: "); if ((liphostok = control_rldef(&liphost, "localiphost", 1, (char *) 0)) == -1) strerr_die2sys(111, FATAL, "unable to read localiphost controls: "); + if (control_readline(&srs_domain, (ptr = env_get("SRS_DOMAIN")) && *ptr ? ptr : (ptr = "srs_domain")) == -1) + strerr_die4sys(111, FATAL, "unable to read ", ptr, " controls: "); + if (srs_domain.len && !stralloc_0(&srs_domain)) + strerr_die2x(111, FATAL, "out of memory"); + srs_domain.len--; /*- substract length due to stralloc_0 */ if (env_get("MAKE_SEEKABLE") && mkTempFile(0)) strerr_die2sys(111, FATAL, "makeseekable: "); get_arguments(argc, argv); @@ -1036,7 +1041,15 @@ main(int argc, char *argv[]) usage("DTLINE is not set; must be run from .qmail"); dtline_len = str_len(dtline); #ifdef HAVESRS - if (*sender && (case_starts(sender, "SRS0=") || case_starts(sender, "SRS1="))) { + if (srs_domain.len && (case_starts(sender, "SRS0=") || case_starts(sender, "SRS1="))) { + len = str_len(sender); + if ((at = byte_rchr(sender, len, '@')) < len - 2) { + if (!str_diffn(srs_domain.s, sender + at + 1, + srs_domain.len > (len - at - 1) ? srs_domain.len + 1 : len - at)) + do_srs = 1; + } + } + if (do_srs) { switch (srsreverse(sender)) { case -3: @@ -1286,15 +1299,15 @@ main(int argc, char *argv[]) void getversion_qmail_autoresponder_c() { - static char *x = "$Id: autoresponder.c,v 1.39 2023-10-01 11:44:44+05:30 Cprogrammer Exp mbhangui $"; + static char *x = "$Id: autoresponder.c,v 1.39 2023-10-02 17:40:58+05:30 Cprogrammer Exp mbhangui $"; x++; } /* * $Log: autoresponder.c,v $ - * Revision 1.39 2023-10-01 11:44:44+05:30 Cprogrammer - * decode SRS return path address + * Revision 1.39 2023-10-02 17:40:58+05:30 Cprogrammer + * decode srs return path address * * Revision 1.38 2023-03-26 01:52:43+05:30 Cprogrammer * fixed code using wait_handler. diff --git a/indimail-mta-x/doc/ChangeLog b/indimail-mta-x/doc/ChangeLog index 2ef0951d44..fc2589291f 100644 --- a/indimail-mta-x/doc/ChangeLog +++ b/indimail-mta-x/doc/ChangeLog @@ -51,8 +51,11 @@ Release @version@-@release@ Start 11/09/2023 End --/--/---- - 30/09/2023 41. svctool: added --chksender option to enable CHECKSENDER 42. qmail-lspawn.c: skip setuser_privileges for non-etc-passwd users -- 01/10/2023 -43. autoresponder.c: decode SRS return path address +- 02/10/2023 +43. smtpd.c: Fix (double) error message for unsupported AUTH method +44. smtpd.c: Fix SEGV when decoding SRS recipient address +45. svctool: make QmailHOME, INDIMAILDIR configurable through env variable +46. autoresponder.c: decode SRS return path address * Fri Sep 08 2023 11:58:03 +0000 Manvendra Bhangui 3.0.4-1.1%{?dist} Release 3.0.4-1.1 Start 24/04/2023 End 08/09/2023 diff --git a/indimail-mta-x/smtpd.c b/indimail-mta-x/smtpd.c index a40b8c931f..e743fdb6a5 100644 --- a/indimail-mta-x/smtpd.c +++ b/indimail-mta-x/smtpd.c @@ -1,6 +1,6 @@ /* * RCS log at bottom - * $Id: smtpd.c,v 1.302 2023-09-28 01:12:49+05:30 Cprogrammer Exp mbhangui $ + * $Id: smtpd.c,v 1.303 2023-10-02 17:46:10+05:30 Cprogrammer Exp mbhangui $ */ #include #include @@ -155,7 +155,7 @@ static SSL *ssl = NULL; static struct strerr *se; #endif static int tr_success = 0; -static char *revision = "$Revision: 1.302 $"; +static char *revision = "$Revision: 1.303 $"; static char *protocol = "SMTP"; static stralloc proto = { 0 }; static stralloc Revision = { 0 }; @@ -1764,7 +1764,7 @@ err_noauth() { out("504 auth type unimplemented (#5.5.1)\r\n", NULL); flush(); - return -1; + return -3; } #ifdef TLS @@ -2556,8 +2556,6 @@ open_control_files1() die_control("locals"); if (!constmap_init(&maplocals, locals.s, locals.len, 0)) die_nomem(); -#ifdef USE_SPF -#endif } /* @@ -2655,6 +2653,11 @@ open_control_files2() } #endif #ifdef HAVESRS + if (control_readline(&srs_domain, (x = env_get("SRS_DOMAIN")) && *x ? x : "srs_domain") == -1) + die_control(x); + if (srs_domain.len && !stralloc_0(&srs_domain)) + die_nomem(); + srs_domain.len--; /*- substract length due to stralloc_0 */ if ((r = srs_setup(0)) < 0) { logerr(1, "srs_setup failed\n", NULL); logflush(); @@ -2662,8 +2665,6 @@ open_control_files2() flush(); _exit(1); } - if (r) - srs_domain.len--; /*- substract length due to stralloc_0 */ #endif open_control_once(&acclistok, 0, &accFn, 0, "ACCESSLIST", 0, "accesslist", 0, &acclist, 0, 0); if ((x = env_get("BODYCHECK"))) { @@ -4139,8 +4140,9 @@ smtp_rcpt(char *arg) #ifdef HAVESRS do_srs = 0; if (srs_domain.len && (case_starts(addr.s, "SRS0=") || case_starts(addr.s, "SRS1="))) { - if ((at = byte_rchr(addr.s, addr.len - 1, '@')) < addr.len - 1) { - if (!str_diffn(srs_domain.s, addr.s + at + 1, srs_domain.len > (addr.len - 2 - at) ? srs_domain.len : addr.len - at - 1)) + if ((at = byte_rchr(addr.s, addr.len - 1, '@')) < addr.len - 3) { + if (!str_diffn(srs_domain.s, addr.s + at + 1, + srs_domain.len > (addr.len - at - 2) ? srs_domain.len + 1 : addr.len - at - 1)) do_srs = 1; } } @@ -6294,6 +6296,9 @@ smtp_auth(char *arg) case -2: /*- returned by err_noauthallowed() when SECURE_AUTH is set and TLS isn't used */ err_authinsecure(j); break; + case -3: /*- returned by err_noauth() for invalid auth type */ + err_authfailure(user.len ? user.s : 0, j); + break; default: err_child(); break; @@ -7173,6 +7178,10 @@ addrrelay() /* * $Log: smtpd.c,v $ + * Revision 1.303 2023-10-02 17:46:10+05:30 Cprogrammer + * Fix (double) error message for unsupported AUTH method + * Fix SEGV when decoding SRS recipient address + * * Revision 1.302 2023-09-28 01:12:49+05:30 Cprogrammer * added check sender feature * @@ -7535,7 +7544,7 @@ addrrelay() char * getversion_smtpd_c() { - static char *x = "$Id: smtpd.c,v 1.302 2023-09-28 01:12:49+05:30 Cprogrammer Exp mbhangui $"; + static char *x = "$Id: smtpd.c,v 1.303 2023-10-02 17:46:10+05:30 Cprogrammer Exp mbhangui $"; x++; return revision + 11; diff --git a/indimail-mta-x/svctool.in b/indimail-mta-x/svctool.in index c32ddb3c62..ddca79c27b 100644 --- a/indimail-mta-x/svctool.in +++ b/indimail-mta-x/svctool.in @@ -1,19 +1,20 @@ # -# $Id: svctool.in,v 2.706 2023-09-30 11:10:32+05:30 Cprogrammer Exp mbhangui $ +# $Id: svctool.in,v 2.707 2023-10-02 02:44:38+05:30 Cprogrammer Exp mbhangui $ # # # User Configuration # -QmailHOME=@qmaildir@ -indimaildir=@indimaildir@ +[ -z "$QmailHOME" ] && QmailHOME="/var/indimail" +[ -z "$INDIMAILDIR" ] && INDIMAILDIR="/var/indimail" +#indimaildir=`awk -F: '{print $6}' /etc/passwd|grep indimail|head -1` +indimaildir=$INDIMAILDIR QmailBinPrefix=@prefix@ mandir=@mandir@ libexecdir=@libexecdir@ sysconfdir=@sysconfdir@ shareddir=@shareddir@ LOGDIR=@logdir@ -#indimaildir=`awk -F: '{print $6}' /etc/passwd|grep indimail|head -1` CONCURRENCYINCOMING=150 min_free=52428800 DATABYTES=20971520 @@ -26,7 +27,7 @@ host=@HOST@ shared_objects=0 use_dlmopen=0 skip_sendmail_check=0 -RCSID="# \$Id: svctool.in,v 2.706 2023-09-30 11:10:32+05:30 Cprogrammer Exp mbhangui $" +RCSID="# \$Id: svctool.in,v 2.707 2023-10-02 02:44:38+05:30 Cprogrammer Exp mbhangui $" # # End of User Configuration @@ -8700,6 +8701,9 @@ default_alias_config() if [ ! -d $t -o ! -d $t/new -o ! -d $t/cur -o ! -d $t/tmp ] ; then echo "Creating catch-all alias ($t) for all system users" fi + if [ ! -d $QmailHOME/alias ] ; then + mkdir -p $QmailHOME/alias + fi if [ -x "$DESTDIR"$QmailBinPrefix/bin/maildirmake ] ; then "$DESTDIR"$QmailBinPrefix/bin/maildirmake "$DESTDIR"$t >/dev/null 2>&1 else @@ -8711,29 +8715,35 @@ default_alias_config() $chown -R alias:qmail "$DESTDIR"$t /bin/chmod -R 775 "$DESTDIR"$t fi - /bin/rm -f "$DESTDIR"$QmailHOME/alias/.qmail-postmaster - first_char=`echo $postmaster | cut -c1` - if [ " $first_char" = " /" ] ; then - if [ -x "$DESTDIR"$QmailBinPrefix/bin/maildirmake ] ; then - "$DESTDIR"$QmailBinPrefix/bin/maildirmake "$DESTDIR"$postmaster >/dev/null 2>&1 - else - /bin/mkdir -p "$DESTDIR"$postmaster/tmp >/dev/null 2>&1 - /bin/mkdir -p "$DESTDIR"$postmaster/new >/dev/null 2>&1 - /bin/mkdir -p "$DESTDIR"$postmaster/cur >/dev/null 2>&1 - fi - if [ $? -eq 0 ] ; then - $chown -R alias:qmail "$DESTDIR"$postmaster - /bin/chmod -R 775 "$DESTDIR"$postmaster + if [ $force -eq 1 -o ! -f "$DESTDIR"$QmailHOME/alias/.qmail-postmaster ] ; then + /bin/rm -f "$DESTDIR"$QmailHOME/alias/.qmail-postmaster + first_char=`echo $postmaster | cut -c1` + if [ " $first_char" = " /" ] ; then + if [ -x "$DESTDIR"$QmailBinPrefix/bin/maildirmake ] ; then + "$DESTDIR"$QmailBinPrefix/bin/maildirmake "$DESTDIR"$postmaster >/dev/null 2>&1 + else + /bin/mkdir -p "$DESTDIR"$postmaster/tmp >/dev/null 2>&1 + /bin/mkdir -p "$DESTDIR"$postmaster/new >/dev/null 2>&1 + /bin/mkdir -p "$DESTDIR"$postmaster/cur >/dev/null 2>&1 + fi + if [ $? -eq 0 ] ; then + $chown -R alias:qmail "$DESTDIR"$postmaster + /bin/chmod -R 775 "$DESTDIR"$postmaster + fi fi + echo $postmaster > "$DESTDIR"$QmailHOME/alias/.qmail-postmaster + $chown -R alias:qmail "$DESTDIR"$QmailHOME/alias/.qmail-postmaster fi - echo $postmaster > "$DESTDIR"$QmailHOME/alias/.qmail-postmaster - $chown -R alias:qmail "$DESTDIR"$QmailHOME/alias/.qmail-postmaster cd "$DESTDIR"$QmailHOME/alias if [ $? -eq 0 ] ; then - /bin/rm -f .qmail-root - /bin/rm -f .qmail-mailer-daemon - /bin/ln -s .qmail-postmaster .qmail-root - /bin/ln -s .qmail-postmaster .qmail-mailer-daemon + if [ ! -f .qmail-root -o $force -eq 1 ] ; then + /bin/rm -f .qmail-root + /bin/ln -s .qmail-postmaster .qmail-root + fi + if [ ! -f .qmail-mailer-daemon -o $force -eq 1 ] ; then + /bin/rm -f .qmail-mailer-daemon + /bin/ln -s .qmail-postmaster .qmail-mailer-daemon + fi fi }