nnrp conf

Jeffrey M. Vinocur jeff at litech.org
Fri Dec 5 10:00:48 UTC 2014


On Tue, 2 Dec 2014, Russ Allbery wrote:

> Edwardo Garcia <wdgarc88 at gmail.com> writes:
>
>> Can we please have the access methods of nnrp,conf brought back!!?!
>
> [...]

> If someone feels up to tackling this, the easiest approach at this point
> would probably be to write a program that took the old syntax as input and
> converted it to an equivalent readers.conf file.  It's not as good as
> being able to use the old syntax directly, but it might provide most of
> the benefits and would be considerably less work.

Funny you mention it.

I have the below "nnrp.access2readers.conf.pl" on my server, timestamped 
from 2003.  I have no recollection of how well it works, presumably I 
shared it on inn-workers or news.software.nntp at the time although I find 
only a passing allusion to it in google.  Anyway, it would probably meet 
Edwardo's needs.

Edwardo, it appears I intended for this to be included with INN and never 
finished that process, so I apologize if it would have been helpful for 
you.

(Russ or Julien, I am a little fuzzy on the svn process these days but if 
either of you thinks this is worth throwing in contrib/ feel free.)


#!/usr/bin/perl -w
# (XXX - this should be a .pl.in file)

# Written by Jeffrey M. Vinocur <jeff at litech.org>
# This work is hereby placed in the public domain by its author.

use strict;

my ($src, $passwd, $dst, $debug);

if(@ARGV == 1) {
     $src = shift;
     $passwd = 'passwd';
     $debug = 1;
} elsif(@ARGV == 3) {
     ($src, $passwd, $dst) = @ARGV;
     $debug = 0;
} else {
     usage();
}

my ($address, $access, $user, $pass, $groups);
my %passwords;
my @badsyntax;
my @duplicates;
my $OUT;

open(SRC, $src) or die "Could not open $src: $!\n";

if($debug) {
     $OUT = \*STDOUT;
} else {
     open(DST, ">$dst") or die "Could not open $dst: $!\n";
     $OUT = \*DST;
}

while(<SRC>) {
     chomp;
     next if /^\#/;
     s/\#.*//;
     ($address, $access, $user, $pass, $groups) = split /:/;
     unless (defined $groups) {
         push @badsyntax, $.;
         next;
     }

     # XXX - what exactly were the semantics of using
     # whitespace in user/pass to disable access?

     unless($user eq '') {
         push @duplicates, $. if defined $passwords{$user};
         $passwords{$user} = $pass;
     }

     print $OUT "auth \"$address\" {\n";
     print $OUT "    hosts: \"$address\"\n";
     print $OUT "    key: \"line$.\"\n";
     print $OUT "    auth: \"ckpasswd -f $passwd\"\n" unless $user eq '';
     print $OUT "}\n";
     print $OUT "access \"$address\" {\n";
     print $OUT "    key: \"line$.\"\n";
     print $OUT "    newsgroups: \"$groups\"\n";
     print $OUT "    access: \"$access\"\n";
     print $OUT "    users: \"$user\"\n" unless $user eq '';
     print $OUT "}\n\n";

}
close SRC;

srand($$^time);

# XXX - if $passwd exists, should we overwrite, append, or merge?
if(!$debug) {
     close $OUT;
     open(PASSWD, ">$passwd") or die "Could not open $passwd: $!\n";
     $OUT = \*PASSWD;
}
while (my ($user, $pass) = each %passwords) {
     $pass = crypt($pass, seedchar().seedchar());
     print $OUT "$user:$pass\n";
}
close PASSWD unless $debug;

print STDERR "Had trouble with syntax on line",
              @badsyntax > 1 ? 's ' : ' ',
              join(", ", @badsyntax), ".\n"
     if @badsyntax;

print STDERR "Found username duplication on line",
              @duplicates > 1 ? 's ' : ' ',
              join(", ", @duplicates), ".\n"
     if @duplicates;


sub seedchar {  # from Randal Schwarz
     ('a'..'z','A'..'Z','0'..'9','.','/')[rand(64)];
}

sub usage {
     print STDERR << "__END__";
Usage:

$0 <nnrp.access file> [<passwd file> <readers.conf file>]

Use $0 to convert an old-style nnrp.access file to readers.conf 
format.  All unique user/password pairs from the nnrp.access file are 
placed in the passwd file (in format suitable for ckpasswd).

If the second and third arguments are missing, everything is 
printed instead to stdout for examination purposes.

__END__

exit 1;

}

-- 
Jeffrey M. Vinocur
jeff at litech.org


More information about the inn-workers mailing list