Cannot authenticate to NNTP server with Net::NNTP authinfo()

U

usenet

Greetings. Kindly consider the following code which illustrates my
question regarding authentication on an NNTP server via the authinfo
method of Net::NNTP:
http://search.cpan.org/~gbarr/libnet-1.19/Net/NNTP.pm

For the purpose of this posting, I have opened a throwaway free (but
authenticating) news account which I will close shortly (to avoid
abuse). The logon/account info in this script IS VALID, and I have
verified that the account works fine in my slrn news client. You have
my permission to use this account (while it exists, if you wish) for
your own testing and debugging purposes regarding this post.

#!/usr/bin/perl
use strict; use warnings;
use Net::NNTP;
my $server = 'news6.open-news-network.org'; #auth required
#my $server = 'allnews.readfreenews.net'; #no authentication

my $nntp = new Net::NNTP($server) or die $!;
print "Date: " . $nntp -> date() ."\n"; #verify server connection

if ($server =~/news\d.open-news-network.org/) {
print "Authenticating to $server\n";
$nntp->authinfo('(e-mail address removed)', '6boc&8qfGO');
}
$nntp -> group('comp.lang.perl.misc');
print map "$_\n", @{$nntp->newnews ( $nntp -> date() - 7200 )};

__END__

(the userid shown is NOT a typo - it really is 'nopam', not 'nospam')

The program should print the msgid's for the past couple hours'
activity in this newsgroup.

Please note that the $server variable may be declared using a different
server (allnews.readfreenews.net). This is a free newsserver which
does not require authentication. If you switch which $server is
commented-out, you will observe that the script works as expected using
the non-authenticating server.

With either server, the validity of the nntp object is established by
querying the server for it's datestamp (which does not require
authentication). So I know I'm talking to both servers, but I'm unable
to pull data from the one which requires authentication. My problem
seems realted to the authinfo method, but I cannot see what I've done
wrong.

I observed this problem on my "real" newsserver (giganews). I opened
the throwaway account mentioned here for additional testing and for
posting here.

Any assistance is greatly appreciated.
 
D

Dr.Ruud

(e-mail address removed) schreef:
Greetings. Kindly consider the following code which illustrates my
question regarding authentication on an NNTP server via the authinfo
method of Net::NNTP:
http://search.cpan.org/~gbarr/libnet-1.19/Net/NNTP.pm

For the purpose of this posting, I have opened a throwaway free (but
authenticating) news account which I will close shortly (to avoid
abuse). The logon/account info in this script IS VALID, and I have
verified that the account works fine in my slrn news client. You have
my permission to use this account (while it exists, if you wish) for
your own testing and debugging purposes regarding this post.

#!/usr/bin/perl
use strict; use warnings;
use Net::NNTP;
my $server = 'news6.open-news-network.org'; #auth required
#my $server = 'allnews.readfreenews.net'; #no authentication

my $nntp = new Net::NNTP($server) or die $!;

my $nntp = new Net::NNTP($server, Debug => 1) or die $! ;

print "Date: " . $nntp -> date() ."\n"; #verify server connection

if ($server =~/news\d.open-news-network.org/) {

if ($server =~/^news\d+\.open-news-network\.org/$) {

print "Authenticating to $server\n";
$nntp->authinfo('(e-mail address removed)', '6boc&8qfGO');
}
$nntp -> group('comp.lang.perl.misc');
print map "$_\n", @{$nntp->newnews ( $nntp -> date() - 7200 )};

__END__

(the userid shown is NOT a typo - it really is 'nopam', not 'nospam')

The program should print the msgid's for the past couple hours'
activity in this newsgroup.

[...]
Net::NNTP=GLOB(0x81f3b50)>>> NEWNEWS comp.lang.perl.misc 060808 232753
GMT
Net::NNTP=GLOB(0x81f3b50)<<< 502 NEWNEWS command disabled by
administrator
Can't use an undefined value as an ARRAY reference at ./Net_NNTP.pl line
19.
[...]
 
D

Dr.Ruud

(e-mail address removed) schreef:

$nntp -> group('comp.lang.perl.misc');

#!/usr/bin/perl
use strict ;
use warnings ;

use Net::NNTP ;
use Data::Dumper ;

sub max { $_[0] > $_[1] ? $_[0] : $_[1] } ;

my $server = 1 # authentication required
? 'news6.open-news-network.org'
: 'allnews.readfreenews.net' ;

my $nntp = new Net::NNTP $server, Debug => 1
or die $! ;

# verify server connection
print "=> Date: ". $nntp->date() ."\n" ;

if ($server =~ /^news\d+\.open-news-network\.org$/)
{
print "=> Authenticating to $server\n";
$nntp->authinfo('(e-mail address removed)', '6boc&8qfGO')
or die $! ;
}

my ($articles, $first, $last) =
$nntp->group('comp.lang.perl.misc')
or die $! ;

print "=> Articles: $first-$last\n" ;
my $xover = $nntp->xover(max($last-2, $first), $last)
or die $! ;
print "=> ", Data::Dumper->Dump([$xover], [qw(*xover)]) ;

my $newnews = $nntp->newnews($nntp->date() - 7200)
or die $! ;
print map "=> $_\n", @$newnews ;

__END__
 
U

usenet

Dr.Ruud said:
<SNIP a fixed version of my program>

Ah, I see. I had not noticed the DEBUG constructor option - that would
have made life much easier. I kept relying on $!, which I don't think
the module ever sets (it is always empty, even when I force errors to
occur).

For the benefit of interested lurkers who may not care to run the
code...

Dr.Ruud's response code shows that I wasn't having a problem with the
authinfo method (which is what I suspected), but rather with the
newnews method, which isn't allowed by either authenticating server (my
regular server or the free server) but that method IS allowed by the
free non-authenticating server. Go figure - Murphy's Law meets Perl
program test cases (again). The xover query method works either way,
though.

Thanks, Doc! (that's about the millionth time you've helped me out...).

FWIW, I will close that temporary account now on the free server.
 
U

usenet

A. Sinan Unur said:
(e-mail address removed) wrote in

How about $@?

$nntp->group('comp.lang.perl.XYZ') # invalid group!
or die "I'm dead, Jim - $! $@\n" ;

I'm dead, Jim -

Nothing. Nada. Zip. It seems DEBUG is the only way to get error
messages...
 
D

Dr.Ruud

(e-mail address removed) schreef:
It seems DEBUG is the only way to get error
messages...

my $newnews = $nntp->newnews($nntp->date() - 7200) ;

print '=> code:', $nntp->code, "\n" ;
print '=> mesg:', $nntp->message, "\n" ;

print map "=> $_\n", @$newnews if (@$newnews) ;

$nntp->quit ;
 
U

usenet

Dr.Ruud said:
print '=> code:', $nntp->code, "\n" ;
print '=> mesg:', $nntp->message, "\n" ;

Hmmm. Where did you dig these methods up? They're not in the module's
perldocs...

Even so, neither the code nor the messages seem especially useful...

Failure:
=> code:599
=> mesg:Connection closed

Success:
=> code:230
=> mesg:New news follows.

I don't have my NNTP secret decoder ring handy, so I'm not sure if a
code 599 gives any indication of WHY it failed, but the message is not
very helpful. I wouldn't consider this information on-par with what
would normally be expected of $!
 
D

Dr.Ruud

(e-mail address removed) schreef:
Dr.Ruud:

Hmmm. Where did you dig these methods up?

NNTP.pm etc.

Even so, neither the code nor the messages seem especially useful...

$nntp->newnews or die $nntp->code ." ". $nntp->message ;

There can be a better way; consult clp.modules (I x-posted) or the
author.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top