Article View: news.software.nntp
Article #30513A channel-fed control message handler
From: Fluffy
Date: Sat, 15 Aug 1998 00:00
Date: Sat, 15 Aug 1998 00:00
221 lines
7535 bytes
7535 bytes
The sendsys thingy was a good incentive.
I've tried to be very selective about what is allowed to get passed along to
the shell scripts. This script could stand some scrutiny in that area, to
make extra sure it's not opening up any new uglies.
It works for me. No warranty etc. etc.
No attempt is made to undo the old maze of shell scripts. The whole point
of this exercise is to serialize the execution of control messages, not make
them prettier. Control.ctl and all that garbage are left unchanged.
How it's installed:
First, go into innd/art.c and comment out the following code (it's the same
in 1.7 and 2.x, and yes this means you've gotta recompile, silly):
: /* Build the command vector and execute it. */
: av[0] = buff;
: av[1] = COPY(Data->Poster);
: av[2] = COPY(Data->Replyto);
: av[3] = Data->Name;
: av[4] = (char *)Data->Feedsite;
: av[5] = NULL;
: HeaderCleanFrom(av[1]);
: HeaderCleanFrom(av[2]);
: if (Spawn(STDIN, (int)fileno(Errlog), (int)fileno(Errlog), av) < 0)
: /* We know the strrchr below can't fail. */
: syslog(L_ERROR, "%s cant spawn %s for %s %m",
: LogName, MaxLength(av[0], strrchr(av[0], '/')), Data->Name);
: DISPOSE(av[1]);
: DISPOSE(av[2]);
It's really important to do that, else you'll go and execute all your
control messages twice. That kinda defeats the purpose of this thing.
Next, make sure you really truly honestly have a control.cancel group
created. If you don't have that, this poor little program will be forced to
look at all the cancels just to ignore them. That would be Bad. We only
want to look at the expensive messages.
Now, add this entry to newsfeeds:
controlchan\
:!*,control,control.*,!control.cancel\
:Tc,Wnm\
:/news/bin/controlchan
Adjust the path to your newsbin directory, of course.
Okay, now cut out the following perl program and put it in your newsbin
directory, in the same spot you said it would be in newsfeeds. Make sure
you edit the 'require "/news/lib/innshellvars.pl" ;' to point to the
location of _your_ innshellvars.pl.
-----begin controlchan-----
#! /usr/bin/perl
###########################################################################
# controlchan - read a feed, sniff out control messages, and send them to
# the appropriate script, meow a bit as needed.
#
# Give this program its own newsfeed. Make sure that you've created the
# newsgroup control.cancel so that you don't have to scan through cancels,
# which this program won't process anyway.
#
# Make a newsfeeds entry like this:
#
# controlchan\
# :!*,control,control.*,!control.cancel\
# :Tc,Wnm\
# :/news/bin/controlchan
#
# And don't forget to comment out the dispatch stuff in art.c!
###########################################################################
require 5.004;
## *** Change this to be correct for your site. *** ##
require "/news/lib/innshellvars.pl" ;
my $SM = $inn::newsbin . "/sm";
my $WRITELOG = $inn::newsbin . "/writelog";
my (@headers, %hdrcount, %hdrval, $msgid, $token, $progname, $pathhost,
$junk);
$junk = $inn::controlprogs;
$junk = $inn::spool;
CHANITEM:
while (<STDIN>) {
undef(@headers);
undef(%hdrcount);
undef(%hdrval);
chomp;
($token, $msgid) = split(/\s+/, $_);
if (not ($token =~ /^\@.*\@$/ or /^\//)) {
$token = $inn::spool . '/' . $token;
}
open(ARTICLE, "$SM $token|");
# suck in headers, normalize the strange ones.
GETHEADERS:
while (<ARTICLE>) {
chomp;
last GETHEADERS if $_ =~ /^$/;
s/Also-Control:/Control:/i;
s/Supersedes:/Control: cancel/i;
push @headers, $_;
s/:.+//;
$hdrcount{lc($_)}++;
}
close ARTICLE;
# warn on failed header retrieval?
if (1) {
if (not @headers) {
open(LOG, "|$WRITELOG $inn::most_logs/controlchan.log" .
"No headers. Cancelled? Hosed spool?");
print LOG "in article $msgid\n";
close LOG;
next CHANITEM;
}
} # (0/1)
next CHANITEM if (not exists $hdrcount{control});
# Check for duplicate controls/supersedes; these are goof-ups or
# denial-of-service attacks, don't process.
if ($hdrcount{control} > 1) {
open(LOG, "|$WRITELOG $inn::most_logs/controlchan.log" .
"Multiple control headers");
open(ARTICLE, "$SM $token|");
while(<ARTICLE>) {
chomp;
print LOG "$_\n";
}
close LOG;
next CHANITEM;
}
# Dig out Sender, From, Reply-to, Control, Path. If duplicates,
# use the first found. Innd should have taken care of some
# dups already.
for (@headers) {
if ((/^Sender:/i) && (not defined($hdrval{Sender}))) {
$hdrval{Sender} = $_;
$hdrval{Sender} =~ s/^[^:]*:\s+//;
}
elsif ((/^From:/i) && (not defined($hdrval{From}))) {
$hdrval{From} = $_;
$hdrval{From} =~ s/^[^:]*:\s+//;
}
elsif ((/^Reply-To:/i) && (not defined($hdrval{'Reply-To'}))) {
$hdrval{'Reply-To'} = $_;
$hdrval{'Reply-To'} =~ s/^[^:]*:\s+//;
}
elsif ((/^Control:/i) && (not defined($hdrval{Control}))) {
$hdrval{Control} = $_;
$hdrval{Control} =~ s/^[^:]+:\s+//;
}
elsif ((/^Path:/i) && (not defined($hdrval{Path}))) {
$hdrval{Path} = $_;
$hdrval{Path} =~ s/^[^:]*:\s+//;
}
}
if (not defined($hdrval{Sender})) {
$hdrval{Sender} = $hdrval{From};
}
$hdrval{Sender} = CleanAddy($hdrval{Sender});
if (not defined($hdrval{'Reply-To'})) {
$hdrval{'Reply-To'} = $hdrval{From};
}
$hdrval{'Reply-To'} = CleanAddy($hdrval{'Reply-To'});
$hdrval{Path} =~ s/^[^!]+!//;
$hdrval{Path} =~ s/[^\w\d\.-].+//;
$hdrval{Control} =~ s/\s+/ /;
if ($hdrval{Control} =~ /\s/) {
$hdrval{Control} =~ /^(\S+)/;
$progname = lc($1);
} else {
$progname = lc($hdrval{Control});
}
next CHANITEN if ($progname eq 'cancel');
if ($progname =~ /[^\w\d-]/) {
open(LOG, "|$WRITELOG $inn::most_logs/controlchan.log " .
"Naughty control message");
open(ARTICLE, "$SM $token|");
while(<ARTICLE>) {
chomp;
print LOG "$_\n";
}
close LOG;
next CHANITEM;
}
$progname = $inn::controlprogs . '/' . $progname ;
system("'$progname' '$hdrval{Sender}' " .
"'$hdrval{'Reply-To'}' '$token' '$hdrval{Path}'");
}
sub CleanAddy {
s/(\s+)?\(.*\)(\s+)?//g;
s/^.*<(.*)>.*$/$1/;
return $_;
}
-----end controlchan-----
Meow.
Technical Details
Message-ID:
<6r3u38$joa$1@fluffy.meow.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.mbox.zip!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <6r3u38$joa$1@fluffy.meow.org> Subject: A channel-fed control message handler Date: Sat, 15 Aug 1998 00:00:00 +0000 From: fluffy@meow.org (Fluffy) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 381394093 X-Complaints-To: mom X-Trace: fluffy.meow.org 903183272 20235 127.0.0.1 (15 Aug 1998 12:14:32 GMT) Organization: meow NNTP-Posting-Date: 15 Aug 1998 12:14:32 GMT Newsgroups: news.software.nntp