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

www lon-capa-cvs@mail.lon-capa.org
Mon, 03 May 2004 19:52:19 -0000


www		Mon May  3 15:52:19 2004 EDT

  Modified files:              
    /loncom/auth	lonracc.pm 
  Log:
  Bug #2951: do not read hosts.tab every time somebody wants a /raw resource.
  
  Need to make sure that this still works for multi-domain servers, since I
  remember that at some point the order of entries in either hosts.tab or
  domain.tab mattered - this is now in random hash order.
  
  
Index: loncom/auth/lonracc.pm
diff -u loncom/auth/lonracc.pm:1.12 loncom/auth/lonracc.pm:1.13
--- loncom/auth/lonracc.pm:1.12	Sun Apr 25 20:07:29 2004
+++ loncom/auth/lonracc.pm	Mon May  3 15:52:19 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Access Handler for File Transfers
 #
-# $Id: lonracc.pm,v 1.12 2004/04/26 00:07:29 www Exp $
+# $Id: lonracc.pm,v 1.13 2004/05/03 19:52:19 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,36 +59,27 @@
     if ($reqhost eq 'localhost.localdomain') {
        return OK;
     }
-    my $readline;
-    my $lontabdir=$r->dir_config('lonTabDir');
-    {
-       my $fh;
-       unless ($fh=Apache::File->new("$lontabdir/hosts.tab")) {
-          $r->log_reason("Could not find host tab file");
-          return FORBIDDEN;
-       }
-       my $return;
-       my @ids=();
-       while ($readline=<$fh>) {
-          my ($id,$domain,$role,$name,$ip)=split(/:/,$readline);
-          if ($name =~ /$reqhost/i) {
-              my $filename=$r->filename;
-              my $uri =$r->uri;
-              if ((-e "$filename.$id") ||
-		  &subscribed($filename,$id) ||
-		  ($filename=~/\.meta$/) ||
-                  ($uri=~m|^/raw/uploaded|)) {
-	         return OK;
-              } else {
-                 $return=FORBIDDEN;
-		 push(@ids,$id);
-              }
-          }
-       }
-       if ($return == FORBIDDEN) {
-	   $r->log_reason(join(':',@ids)." not subscribed", $r->filename);
-	   return FORBIDDEN;
-       }
+    my $return;
+    my @ids=();
+    my $id;
+    foreach $id (keys %Apache::lonnet::hostname) {
+	if ($Apache::lonnet::hostname{$id} =~ /$reqhost/i) {
+	    my $filename=$r->filename;
+	    my $uri =$r->uri;
+	    if ((-e "$filename.$id") ||
+		&subscribed($filename,$id) ||
+		($filename=~/\.meta$/) ||
+		($uri=~m|^/raw/uploaded|)) {
+		return OK;
+	    } else {
+		$return=FORBIDDEN;
+		push(@ids,$id);
+	    }
+	}
+    }
+    if ($return == FORBIDDEN) {
+	$r->log_reason(join(':',@ids)." not subscribed", $r->filename);
+	return FORBIDDEN;
     }
     $r->log_reason("Invalid request for file transfer from $reqhost", 
                    $r->filename);