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

Discussion in 'Perl Misc' started by usenet@DavidFilmer.com, Aug 9, 2006.

  1. Guest

    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('', '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.

    --
    David Filmer (http://DavidFilmer.com)
     
    , Aug 9, 2006
    #1
    1. Advertising

  2. Dr.Ruud Guest

    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('', '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.
    [...]

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Aug 9, 2006
    #2
    1. Advertising

  3. Dr.Ruud Guest

    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('', '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__

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Aug 9, 2006
    #3
  4. Guest

    Dr.Ruud wrote:
    > <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.

    --
    http://DavidFilmer.com
     
    , Aug 9, 2006
    #4
  5. Guest

    A. Sinan Unur wrote:
    > wrote in
    > > I kept relying on $!, which I don't think the module ever set

    >
    > 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...

    --
    David Filmer (http://DavidFilmer.com)
     
    , Aug 9, 2006
    #5
  6. Dr.Ruud Guest

    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 ;

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Aug 9, 2006
    #6
  7. Guest

    Dr.Ruud wrote:
    > 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 $!

    --
    David Filmer (http://DavidFilmer.com)
     
    , Aug 9, 2006
    #7
  8. Dr.Ruud Guest

    schreef:
    > Dr.Ruud:


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

    >
    > 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.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Aug 9, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alfred Salton

    Re-authenticate prior to server.transfer

    Alfred Salton, Feb 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    679
    Alfred Salton
    Feb 15, 2005
  2. Mike

    Using Exchange Server 2000 to Authenticate

    Mike, Oct 2, 2003, in forum: ASP .Net Security
    Replies:
    1
    Views:
    129
    Steve Jansen
    Oct 15, 2003
  3. JohnnyO''''

    How to authenticate to iPlanet server using LDAPS?

    JohnnyO'''', Oct 19, 2005, in forum: ASP .Net Security
    Replies:
    2
    Views:
    393
    Joe Kaplan \(MVP - ADSI\)
    May 8, 2006
  4. Anton Bangratz
    Replies:
    0
    Views:
    168
    Anton Bangratz
    Jun 4, 2008
  5. sadie-no-reply

    Posting to nntp newsgroup with Perl (Net::NNTP)

    sadie-no-reply, Mar 4, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    290
    Jamie
    Mar 5, 2007
Loading...

Share This Page