-sub auth {
- # Authentication.
- if ($ENV{"NNTPAUTH"}) {
- $auth = $ENV{"NNTPAUTH"};
- &putline("AUTHINFO GENERIC $auth");
- pipe AUTHSTDIN, TOAUTH or die "unable to create pipes";
- pipe FROMAUTH, AUTHSTDOUT or die "unable to create pipes";
- $pid = fork;
- if (!defined $pid) {
- die "unable to fork for authentication helper";
- } elsif ($pid == 0) {
- # we are child
- $ENV{"NNTP_AUTH_FDS"} = "0.1";
- open STDIN, "<&AUTHSTDIN";
- open STDOUT, ">&AUTHSTDOUT";
- close S;
- exec $auth;
- }
- # we are parent
- close AUTHSTDIN;
- close AUTHSTDOUT;
- autoflush TOAUTH 1;
- &getline; print TOAUTH "$_\n";
- while (<FROMAUTH>) {
- s/[\r\n]*$//s;
- &putline($_);
- &getline;
- print TOAUTH "$_\n";
- }
- die "failed authentication\n" unless $? == 0;