Thread View: news.software.nntp
3 messages
3 total messages
Started by Fluffy
Sat, 15 Aug 1998 00:00
A channel-fed control message handler
Author: 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.
Re: A channel-fed control message handler
Author: Fluffy
Date: Sat, 15 Aug 1998 00:00
Date: Sat, 15 Aug 1998 00:00
64 lines
2843 bytes
2843 bytes
Olaf Titz <olaf@bigred.inka.de> wrote: > Fluffy <fluffy@meow.org> wrote: > > controlchan\ > > :!*,control,control.*,!control.cancel\ > > :Tc,Wnm\ > > :/news/bin/controlchan > > I'm not sure how and if that works. Distribution of control messages > contains a few "gotchas". E.g. on an unwanted newgrouper we just had > to find out that newgroups and rmgroups, as opposed to other controls, > are never "junked"[1] and the documentation is a bit fuzzy on how > exactly controls are propagated. What the control messages do is like this: - Are any of the existing groups in the Newsgroups: header accepted by this feed? If yes, send it. - If a newgroup is being sent to the group being created, and that group doesn't yet exist, would this newsfeed be carrying the group if it *did* already exist? If yes, send it. - Does the feed accept the control pseudogroup that holds the message? If yes, send it. (There's still the old *.ctl hack in there too.) > In fact, it looks to me like the code in ARTpost() first finds out all > the sites an article is propagated to based on the Newsgroups header, > then files them in control.* if a Control header is there. This would > mean that your controlchan entry only applies to postings which have > control.something in their Newsgroups header. Nope. I've got it running with INN 2.1 and it's propagating to the channel feed: Date: 15 Aug 1998 13:58:25 -0000 From: usenet@fluffy.meow.org To: usenet@fluffy.meow.org Subject: newgroup meow.config y created fluffy@meow.org Path: meow.org!not-for-mail From: fluffy@meow.org Newsgroups: meow.general Subject: junk Control: newgroup meow.config Date: 15 Aug 1998 13:58:22 GMT Organization: Fluffy's Meow Server Lines: 1 Approved: fluffy Distribution: local Message-ID: <6r445u$n64$1@fluffy.meow.org> NNTP-Posting-Host: localhost X-Trace: fluffy.meow.org 903189502 23748 127.0.0.1 (15 Aug 1998 13:58:22 GMT) X-Complaints-To: mom NNTP-Posting-Date: 15 Aug 1998 13:58:22 GMT Xref: meow.org control.newgroup:21 meow
Re: A channel-fed control message handler
Author: Fluffy
Date: Sat, 15 Aug 1998 00:00
Date: Sat, 15 Aug 1998 00:00
13 lines
989 bytes
989 bytes
Fluffy <fluffy@meow.org> wrote:
> sub CleanAddy {
+++ $_ = $_[0];
> s/(\s+)?\(.*\)(\s+)?//g;
> s/^.*<(.*)>.*$/$1/;
> return $_;
> }
Cut and paste is going to be the death of me. Line with +++ needs to
be there. Eurkh.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads