🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #83387

Please consider this INN patch for mailpost

#83387
From: D. Stussy
Date: Sun, 22 Aug 2010 21:39
124 lines
5823 bytes
What this patch does and why:

1) Adds a "-z" parameter to remove any undesired headers from the gated
message.  It also forces removal of the "Bcc:" header.  Under SMTP, Bcc is
permitted to exist with a blank RHS, but NNTP forbids a blank RHS for any
header.  (Without this patch for "Bcc:", the script was promoting it to
"X-Bcc:" and leaving it in the article; a violation of the article format.)

2) Edits the incoming SMTP message's "Received:" header to remove any "for
<mailbox>" clause which contains the name of the news server (or its
domain).  It determines the name by examining "pathhost", "fromhost" and
"domain" (from file "inn.conf").  The reason for this is to protect the
gateway mailbox from spammers who may seek to abuse the gateway.  This will
also remove any "*-To:" headers that cite the news server host or domain
name (e.g. "Errors-To:" which are set to report back which user bounced by
using a mailbox pattern in the envelope).  As the gateway mailbox name is
now hidden, spammers will have to discover it via other means.  It's not
meant as an anti-spam measure by itself, but spammers can't spam that which
they can't find.  Since the administrator knows the message was gated, he
knows it was delivered to the gateway mailbox, so information deleted from
the trace header isn't "lost"; just merely hidden.  "For" clauses from
other "Received:" headers not specifying the mail server's host/domain are
left intact.

This diff is against INN 2.5.2:

diff -bur frontends/mailpost.in frontends/mailpost.in
--- frontends/mailpost.in       2010-03-24 20:10:36.000000000 +0000
+++ frontends/mailpost.in       2010-08-11 21:21:17.000000000 +0000
@@ -5,6 +5,7 @@
 #
 # $Id: mailpost.in 9025 2010-03-21 16:49:41Z iulius $
 #
+# 11aug10 [added -z for headers to zap; edit Received-for and *-To: for
gateway]
 # 21feb00 [added "lc" to duplicate header fixer stmt to make it
case-insensitive]
 # doka 11may99 [fixed duplicate headers problem]
 # brister 19oct98 [cleaned up somewhat for Perl v. 5. and made a little
more robust]
@@ -53,10 +54,10 @@

 $usage .= "[ -r addr ][ -f addr ][ -a approved ][ -d distribution ]" .
     " [ -m mailing-list ][ -b database ][ -o output-path ] [ -c
wait-time ]" .
-    " [ -x header[:header...] ] [ -p port ] newsgroups" ;
+    " [ -x header[:header...]] [ -z header[:header...]] [ -p port ]
newsgroups";

-use vars qw($opt_r $opt_f $opt_a $opt_d $opt_m $opt_b $opt_n $opt_o $opt_h
$opt_c $opt_x $opt_p) ;
-getopts("hr:f:a:d:m:b:no:c:x:p:") || die "usage: $usage\n" ;
+use vars qw($opt_r $opt_f $opt_a $opt_d $opt_m $opt_b $opt_n $opt_o $opt_h
$opt_c $opt_x $opt_p $opt_z) ;
+getopts("hr:f:a:d:m:b:no:c:x:p:z:") || die "usage: $usage\n" ;
 die "usage: $usage\n" if $opt_h ;

 #
@@ -70,6 +71,7 @@
 my $Maintainer = $INN::Config::newsmaster || "usenet" ;
 my $WhereTo = $opt_o || $Submit ;
 my $Mailname = $INN::Config::fromhost ;
+my $Gateway  = $INN::Config::fromhost ;

 # Can't use $INN::Config::pathtmp as we're usually not running as news.
 my $Tmpdir = "/var/tmp" ;
@@ -80,7 +82,8 @@
 }

 chop ($Mailname = `/bin/hostname`) if ! $Mailname ;
-
+$Gateway .= '|' . $INN::Config::pathhost if $INN::Config::pathhost;
+$Gateway .= '|(.+\.)?' . $INN::Config::domain if $INN::Config::domain;

 #
 # Our command-line argument(s) are the list of newsgroups to post to.
@@ -125,11 +128,16 @@
     $exclude .= '|' . join('|', split(/:/, $opt_x));
 }

+# Strip out blank Bcc: header since NNTP does not allow blank header data
+my $skip = 'Bcc';
+if ($opt_z) {
+    $skip .= '|' . join('|', split(/:/, $opt_z));
+}
+
 $newsgroups = join ",", @ARGV ;

 die "usage:  $0 newsgroup [newsgroup ...]\n" unless $newsgroups;

-
 #
 # Do the header.  Our input is a mail message, with or without the From.
 #
@@ -206,6 +214,7 @@

     push @errorText, "($_)\n";

+    next if (/^($skip):/sio);
     next if /^Approved:\s/sio && defined($approved);
     next if /^Distribution:\s/sio && defined($distribution);

@@ -289,6 +298,17 @@
         next ;
     }

+    # Strip out any Received: headers for clause to prevent spamming the
gateway
+    if (/^Received:\s*/sio) {
+       s/\s+for\s.+\@($Gateway)>?\s*//sio;
+       # FALLTHROUGH
+    }
+
+    # Strip out any headers with gateway mailbox to prevent spamming the
gateway
+    if (/^[A-Z]+-To:\s*/sio) {
+       next if /[@%=]($Gateway)/sio;
+    }
+
     # Random unknown header.  Prepend 'X-' if it is not already there.
     $_ = "X-$_" unless /^X-/sio ;
     $weird_mail_hdrs .= "$_\n";

Technical Details
Message-ID: <i4s5et$6km$1@snarked.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border1.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!postnews.google.com!news2.google.com!news.glorb.com!news.snarked.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <i4s5et$6km$1@snarked.org>
Subject: Please consider this INN patch for mailpost
Date: Sun, 22 Aug 2010 14:39:38 -0700
From: "D. Stussy" <spam+newsgroups@bde-arc.ampr.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border1.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!postnews.google.com!news2.google.com!news.glorb.com!news.snarked.org!.POSTED!not-for-mail
Newsgroups: news.software.nntp
Lines: 124
Reply-To: "D. Stussy" <replies@newsgroups.kd6lvw.ampr.org>
NNTP-Posting-Host: pool-71-106-210-230.lsanca.dsl-w.verizon.net
X-Trace: snarked.org 1282513181 6806 71.106.210.230 (22 Aug 2010 21:39:41 GMT)
X-Complaints-To: newsmaster+complaints@snarked.org
NNTP-Posting-Date: Sun, 22 Aug 2010 21:39:41 +0000 (UTC)
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1478
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478
X-Original-Bytes: 5632