#! /usr/local/bin/perl use strict; our %attributes; my $MAX = 4; my $FILE = '/etc/news/users'; sub auth_init { # } sub authenticate { my $oc = 0; my $ok = 0; open(P, '/bin/ps -ax |') && do { while(

) { if(/nnrpd: (\S*)/) { if($1 eq $attributes{hostname}) { $oc++; } } } close(P); }; if($oc > $MAX) { sleep(2); return ( '502', 'Too many connections from your host' ); } my $p; open(F, $FILE) && do { while() { if(/^$attributes{username}:([^:]*):/) { my $salt; $salt = substr($1, 0, 2); if(crypt($attributes{password}, $salt) eq $1) { $ok = 1; } last; } } close(F); }; if($ok) { return ( '281', 'Ok' ); } else { sleep(2); return ( '502', 'Authentication error' ); } }