9 $verbose=1, shift @ARGV if $ARGV[0] eq "-v";
11 die "usage: nntpid messageid\n" if !defined $ARGV[0];
17 $ns=$ENV{'NNTPSERVER'};
18 if (!defined $ns or !length $ns) {
19 $ns = `cat /etc/nntpserver`;
22 $port = (getservbyname("nntp", "tcp"))[2];
24 $proto = getprotobyname("tcp");
25 $paddr = sockaddr_in($port, $ns);
27 socket(S,PF_INET,SOCK_STREAM,$proto) or die "socket: $!";
28 connect(S,$paddr) or die "connect: $!";
33 $code =~ /^2\d\d/ or die "no initial greeting from server\n";
35 &docmd("MODE READER");
36 # some servers require a GROUP before an ARTICLE command
37 &docmd("GROUP misc.misc");
38 &docmd("ARTICLE $mid");
51 print STDERR ">>> $line\n" if $verbose;
58 $code = substr($_,0,3);
59 print STDERR "<<< $_\n" if $verbose;
67 if ($code eq "480") { &auth; } else { last; }
69 $code =~ /^2\d\d/ or die "failed on `$cmd':\n$_\n";
74 if ($ENV{"NNTPAUTH"}) {
75 $auth = $ENV{"NNTPAUTH"};
76 &putline("AUTHINFO GENERIC $auth");
77 pipe AUTHSTDIN, TOAUTH or die "unable to create pipes";
78 pipe FROMAUTH, AUTHSTDOUT or die "unable to create pipes";
81 die "unable to fork for authentication helper";
84 $ENV{"NNTP_AUTH_FDS"} = "0.1";
85 open STDIN, "<&AUTHSTDIN";
86 open STDOUT, ">&AUTHSTDOUT";
94 &getline; print TOAUTH "$_\n";
101 die "failed authentication\n" unless $? == 0;