--- loncom/auth/lontokacc.pm 2004/05/11 06:49:58 1.10 +++ loncom/auth/lontokacc.pm 2005/02/07 17:04:53 1.13 @@ -1,7 +1,7 @@ # The LearningOnline Network # Access Handler for User File Transfers # -# $Id: lontokacc.pm,v 1.10 2004/05/11 06:49:58 albertel Exp $ +# $Id: lontokacc.pm,v 1.13 2005/02/07 17:04:53 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,17 +32,16 @@ use strict; use Apache::Constants qw(:common :remotehost); use Apache::lonnet(); use Apache::File(); - +use IO::Socket; sub handler { my $r = shift; - my $reqhost = $r->get_remote_host(REMOTE_DOUBLE_REV); - if (!$reqhost && $r->get_remote_host(REMOTE_NOLOOKUP) eq $r->get_server_name()) { - $reqhost = $r->get_server_name(); - } - unless ($reqhost) { - $r->log_reason("Spoof request from ". $reqhost); - return FORBIDDEN; + my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP); + my $netaddr=inet_aton($reqhost); + ($reqhost) = gethostbyaddr($netaddr,AF_INET); + if (!$reqhost) { + $r->log_reason("Unable to do hostname $reqhost lookup for ".$r->get_remote_host(REMOTE_NOLOOKUP)); + return FORBIDDEN; } if ($reqhost eq 'localhost.localdomain') { return OK; @@ -56,10 +55,11 @@ sub handler { return FORBIDDEN; } while ($readline=<$fh>) { - my ($id,$domain,$role,$name,$ip)=split(/:/,$readline); - if ($name =~ /$reqhost/i) { - return OK; - } + $readline=~s/\s*$//; + my ($id,$domain,$role,$name)=split(/:/,$readline); + if ($name =~ /\Q$reqhost\E/i) { + return OK; + } } }