Mailing List Archive

c-nocem and gpg (Re: default keyring)
Hi,

Marco d'Itri:
> How can I select the keyring where newly imported keys will go?
>
Tell it to not have a defauolt keyring and that's all that will happen.

> BTW, I'm porting c-nocem to gnupg.
>
I did a minimal version last month or so.
No config file, just the bare bones, but it works.
Advantage: All these cancels are processed in real time.
(I don't need to run the thing five minutes later, when all the 'bad'
articles have been transmitted already.)

You'll also need to patch INN to handle "CANCEL <id>" on the Unix-domain
NNTP socket (IMHO, anything else just plain doesn't make sense). It's
appended below.


#!/usr/bin/perl
## ncmrun.minimal (c) 1999, Matthias Urlichs <smurf@noris.de>
## based on c.nocem
## TODO: use status channel, add config file, add CANCEL streaming, clean
## up, ...

require '/usr/lib/news/innshellvars.pl';

die "Usage: $0 keyfile\n" unless @ARGV == 1;

my $keys = $ARGV[0];
my $gpg="/usr/bin/gpg --textmode --batch --no-default-keyring --keyring=$keys --secret-keyring /dev/null";

my $act = qr/^(abuse|spam|binary|unapproved|retromod|velveeta)$/;

my $stream = undef;
sub cancel($) {
use IO::Socket;

my $success = 0;
my($id) = @_;
my $count = 10;
my $retry = 0;
my $res;

while(not $success) {
unless(defined $stream) {
print STDERR "Opening channel\n";
$stream = IO::Socket::UNIX->new(Peer => $inn::nntpconnect);
next unless ref $stream;
$stream->autoflush(1);
$res = <$stream>;
unless($res =~ /^2/) {
$stream = undef;
next;
}
$retry = 0;
}
print $stream "CANCEL $id\015\012";
$res = <$stream>;
return 1 if $res =~ /^2/;
return 0 if $res == 435;
$stream = undef if ++$retry >= 3;
return 0 if $retry > 10;
} continue {
print STDERR "Problem ($res)\n";
sleep($count *= 2);
};
}

while(<STDIN>) {
chop;
my $art = $_;
pipe(ER,EW);
pipe(DR,DW);
my $pid;
sleep 10 while not defined($pid = fork());
if($pid == 0) {
close(ER); close(DR);
open(STDOUT,">&DW");
open(STDERR,">&EW");
close(EW); close(DW);
exec("sm '$art' | $gpg");
die "EXIT ERROR";
}
close(EW); close(DW);
my $state = 0;
my $msgid = "";
my $id;
my $issuer;
my $type;
my %line;
while(<DR>) {
s/\015?\012$//;
if($state == 0) {
$state = 1 if /^\@\@BEGIN NCM HEADERS\s*$/;
} elsif($state == 1) {
$issuer = $_ if s/^Issuer:\s+//i;
$type = $_ if s/^Type:\s+//i;
$id = $_ if s/^Notice-ID:\s+//i;
$action = $_ if s/^Action:\s+//i;
$state = 2 if /^\@\@BEGIN NCM BODY\s*$/;
} elsif($state == 2) {
$state = 3 if /^\@\@END NCM BODY\s*$/;
$msgid = $1 if s/^(\<\S+\>)//;
next if $msgid eq "";
$line{$msgid} .= $_ if /^\s/;
}
}
close(DR);
my $good;
my $auth;
while(<ER>) {
# print STDERR $_;
($good,$auth) = ($1,$2) if /(Good|Bad) signature from (".+")/i;
}
close(ER);
waitpid($pid,0);
if($good eq "") {
print STDERR "Unknown '$issuer' $art\n";
next;
}
if($good =~ /bad/i) {
print STDERR "Bad '$issuer' $auth $art\n";
next;
}
if($action ne "hide") {
print STDERR "Action '$issuer' '$action' $art\n";
next;
}
if($type !~ $act) {
print STDERR "Type '$issuer' '$type' $art\n";
next;
}
my $start = time;
my $ns=0;
foreach my $id(keys %line) {
$ns++;
cancel($id);
}
print STDERR "$ns articles, ".(time-$start)." seconds, $auth '$type'.\n";
}
__END__


Index: base.305/innd/nc.c
--- base.305/innd/nc.c Wed, 27 Jan 1999 10:09:05 +0100 smurf (net_news_inn/d/49_nc.c 1.36.1.2 644)
+++ test.8(w)/innd/nc.c Wed, 27 Jan 1999 10:48:43 +0100 smurf (net_news_inn/d/49_nc.c 1.36.1.3 664)
@@ -42,6 +42,7 @@
/* new modules for streaming */
static FUNCTYPE NCxbatch();
static FUNCTYPE NCcheck();
+static FUNCTYPE NCcancel();
static FUNCTYPE NCtakethis();
static FUNCTYPE NCwritedone();

@@ -56,6 +57,7 @@
{ "help", NChelp },
{ "ihave", NCihave },
{ "check", NCcheck },
+ { "cancel", NCcancel },
{ "takethis", NCtakethis },
{ "list", NClist },
{ "mode", NCmode },
@@ -1085,6 +1087,7 @@
syslog(L_NOTICE, "%s accepted batch size %ld",
CHANname(cp), cp->XBatchSize);
cp->State = CSgetcmd;
+ cp->XBatchSize = 0;

/* Clear the work-in-progress entry. */
NCclearwip(cp);
@@ -1264,6 +1267,7 @@
}
cp->BadReads = 0;
cp->BadCommands = 0;
+ cp->IsLocal = IsLocal;
NCwritereply(cp, (char *)NCgreeting);
return cp;
}
@@ -1345,6 +1349,61 @@
NCwritereply(cp, cp->Sendid.Data);
}
/* stay in command mode */
+}
+
+/*
+** The "cancel" command. Kill the article.
+** Allowed on local connections only.
+*/
+STATIC FUNCTYPE
+NCcancel(CHANNEL *cp)
+{
+ char *p;
+ int msglen;
+#if defined(DO_PERL)
+ char *perlrc;
+#endif /* DO_PERL */
+ ARTDATA Data;
+ static BUFFER Reply;
+
+ if(!cp->IsLocal) {
+ (void)sprintf(cp->Sendid.Data, "%d %s", NNTP_CANTPOST_VAL, p);
+ NCwritereply(cp, cp->Sendid.Data);
+ return;
+ }
+ /* Snip off the Message-ID. */
+ for (p = cp->In.Data + STRLEN("cancel"); ISWHITE(*p); p++)
+ continue;
+ if (NCbadid(cp, p))
+ return;
+
+ Data.Posted = Data.Arrived = Now.time;
+ Data.Expires = 0;
+ Data.Feedsite = "?";
+ Data.MessageID = p;
+
+ msglen = 3 + 2 + strlen(p);
+ if (Reply.Data == NULL) {
+ Reply.Size = msglen;
+ Reply.Data = NEW(char, msglen + 1);
+ }
+ else if (Reply.Size < msglen) {
+ Reply.Size = msglen;
+ RENEW(Reply.Data, char, msglen + 1);
+ }
+ if (Mode == OMrunning)
+ ARTcancel(&Data, Data.MessageID, TRUE);
+ else {
+ (void)sprintf(Reply.Data, "%d %s", NNTP_RESENDIT_VAL, Data.MessageID);
+ NCwritereply(cp, Reply.Data);
+ return;
+ }
+ if (innconf->logcancelcomm)
+ syslog(L_NOTICE, "%s cancelled %s", LogName, Data.MessageID);
+
+ (void)sprintf(Reply.Data, "%d %s", NNTP_TOOKIT_VAL, Data.MessageID);
+ NCwritereply(cp, Reply.Data);
+ return;
}

/*
Index: base.305/innd/innd.h
--- base.305/innd/innd.h Wed, 27 Jan 1999 09:51:04 +0100 smurf (net_news_inn/e/0_innd.h 1.41 644)
+++ test.8(w)/innd/innd.h Wed, 27 Jan 1999 10:48:44 +0100 smurf (net_news_inn/e/0_innd.h 1.42 664)
@@ -182,6 +182,7 @@
BUFFER In;
BUFFER Out;
BOOL Tracing;
+ BOOL IsLocal;
BUFFER Sendid;
HASH CurrentMessageIDHash;
#define PRECOMMITCACHESIZE 128


--
Matthias Urlichs | noris network GmbH | smurf@noris.de | ICQ: 20193661
The quote was selected randomly. Really. | http://www.noris.de/~smurf/
--
Alimony is paying for something you don't get.
Re: c-nocem and gpg (Re: default keyring) [ In reply to ]
On Feb 24, Matthias Urlichs <smurf@noris.de> wrote:

>Marco d'Itri:
>> How can I select the keyring where newly imported keys will go?
>Tell it to not have a defauolt keyring and that's all that will happen.
This option is not documented AFAICS.
And it should disable the secret keyring as well:

$LANG= gpgm --no-default-keyring
gpgm: key E1EE3FB1: secret key without public key - skipped
...

>> BTW, I'm porting c-nocem to gnupg.
Done. If anyone cares about it, just ask.

I don't think you need to patch innd, you could use the same socket
ctlinnd uses. Today I wrote a News::INN::ICC perl module implementing
inndcomm.c, anyone wants it? It should work with cleanfeed as well.
Tomorrow I'll try signing NoCeM notices with GNUPG...

--
ciao,
Marco
Re: c-nocem and gpg (Re: default keyring) [ In reply to ]
Hi,

Marco d'Itri:
> I don't think you need to patch innd, you could use the same socket
> ctlinnd uses. Today I wrote a News::INN::ICC perl module implementing
> inndcomm.c, anyone wants it? It should work with cleanfeed as well.

I'd like to have this module.

In the past, however, the processing delay for the ctlinnd socket was too
high to do this efficiently. With the streamed CANCEL I played with
yesterday, on the other hand, I can kill off 250 articles per second. ;-)

--
Matthias Urlichs | noris network GmbH | smurf@noris.de | ICQ: 20193661
The quote was selected randomly. Really. | http://www.noris.de/~smurf/
--
"Well, it don't make the sun shine, but at least it don't deepen the shit."
-- Straiter Empy, in _Riddley_Walker_ by Russell Hoban