[LON-CAPA-cvs] cvs: loncom /auth lonracc.pm lontokacc.pm /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 05 Feb 2005 22:20:57 -0000


albertel		Sat Feb  5 17:20:57 2005 EDT

  Modified files:              
    /loncom/auth	lonracc.pm lontokacc.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - removing IP number use from webserver some of BUG#2330
  
  
Index: loncom/auth/lonracc.pm
diff -u loncom/auth/lonracc.pm:1.13 loncom/auth/lonracc.pm:1.14
--- loncom/auth/lonracc.pm:1.13	Mon May  3 15:52:19 2004
+++ loncom/auth/lonracc.pm	Sat Feb  5 17:20:56 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Access Handler for File Transfers
 #
-# $Id: lonracc.pm,v 1.13 2004/05/03 19:52:19 www Exp $
+# $Id: lonracc.pm,v 1.14 2005/02/05 22:20:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,11 +32,15 @@
 use Apache::Constants qw(:common :remotehost);
 use Apache::lonnet();
 use Apache::File();
+use IO::Socket;
 
 sub subscribed {
     my ($filename,$id) = @_;
     my $found=0;
-    my $expr='^'.$id.':'.$Apache::lonnet::hostip{$id}.':';
+    my $hostname=$Apache::lonnet::hostname{$id};
+    my (undef,undef,undef,undef,$ip) = gethostbyname($hostname);
+    $ip=inet_ntoa($ip);
+    my $expr='^'.$id.':'.$ip.':';
     $expr =~ s/\./\\\./g;
     my $sh;
     if ($sh=Apache::File->new("$filename.subscription")) {
@@ -48,22 +52,18 @@
 
 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 ".$ENV{'REMOTE_ADDR'});
-       return FORBIDDEN;
+    my $reqhost = $r->get_remote_host(REMOTE_HOST);
+    if (!$reqhost) {
+	$r->log_reason("Unable to do hostname lookup for ".$ENV{'REMOTE_ADDR'});
     }
     if ($reqhost eq 'localhost.localdomain') {
-       return OK;
+	return OK;
     }
     my $return;
     my @ids=();
     my $id;
     foreach $id (keys %Apache::lonnet::hostname) {
-	if ($Apache::lonnet::hostname{$id} =~ /$reqhost/i) {
+	if ($Apache::lonnet::hostname{$id} =~ /\Q$reqhost\E/i) {
 	    my $filename=$r->filename;
 	    my $uri =$r->uri;
 	    if ((-e "$filename.$id") ||
Index: loncom/auth/lontokacc.pm
diff -u loncom/auth/lontokacc.pm:1.10 loncom/auth/lontokacc.pm:1.11
--- loncom/auth/lontokacc.pm:1.10	Tue May 11 02:49:58 2004
+++ loncom/auth/lontokacc.pm	Sat Feb  5 17:20:56 2005
@@ -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.11 2005/02/05 22:20:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,14 +36,7 @@
 
 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_HOST);
     if ($reqhost eq 'localhost.localdomain') {
        return OK;
     }
@@ -56,10 +49,11 @@
           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; 
+	   }
        }
 
     }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.594 loncom/lonnet/perl/lonnet.pm:1.595
--- loncom/lonnet/perl/lonnet.pm:1.594	Sat Feb  5 01:48:38 2005
+++ loncom/lonnet/perl/lonnet.pm	Sat Feb  5 17:20:56 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.594 2005/02/05 06:48:38 albertel Exp $
+# $Id: lonnet.pm,v 1.595 2005/02/05 22:20:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,7 +35,7 @@
 use HTTP::Date;
 # use Date::Parse;
 use vars 
-qw(%perlvar %hostname %homecache %badServerCache %hostip %iphost %spareid %hostdom 
+qw(%perlvar %hostname %homecache %badServerCache %spareid %hostdom 
    %libserv %pr %prp %metacache %packagetab %titlecache %courseresversioncache %resversioncache
    %courselogs %accesshash %userrolehash $processmarker $dumpcount 
    %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseownerbuf %courseresdatacache 
@@ -1817,7 +1817,7 @@
     my $now=time;
     my ($ta,$tb,$lonhost)=split(/\*/,$token);
     $lonhost=~tr/A-Z/a-z/;
-    my $dtoken=$ta.'_'.$hostip{$lonhost}.'_'.$tb;
+    my $dtoken=$ta.'_'.$hostname{$lonhost}.'_'.$tb;
     $dtoken=~s/\W/\_/g;
     my ($dummy,$tuname,$tudom,$tcrsid,$symb,$chtim,$rmaddr)=
                  split(/\&/,&unescape(&reply('tmpget:'.$dtoken,$lonhost)));
@@ -5682,12 +5682,10 @@
     while (my $configline=<$config>) {
        next if ($configline =~ /^(\#|\s*$)/);
        chomp($configline);
-       my ($id,$domain,$role,$name,$ip,$domdescr)=split(/:/,$configline);
-       if ($id && $domain && $role && $name && $ip) {
+       my ($id,$domain,$role,$name)=split(/:/,$configline);
+       if ($id && $domain && $role && $name) {
 	 $hostname{$id}=$name;
 	 $hostdom{$id}=$domain;
-	 $hostip{$id}=$ip;
-	 $iphost{$ip}=$id;
 	 if ($role eq 'library') { $libserv{$id}=$name; }
        }
     }