--- loncom/lonnet/perl/lonnet.pm	2002/05/18 19:59:07	1.228
+++ loncom/lonnet/perl/lonnet.pm	2002/05/22 13:56:43	1.231
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.228 2002/05/18 19:59:07 harris41 Exp $
+# $Id: lonnet.pm,v 1.231 2002/05/22 13:56:43 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -77,7 +77,7 @@ use Apache::File;
 use LWP::UserAgent();
 use HTTP::Headers;
 use vars 
-qw(%perlvar %hostname %homecache %badhomecache %hostip %spareid %hostdom 
+qw(%perlvar %hostname %homecache %badServerCache %hostip %spareid %hostdom 
    %libserv %pr %prp %metacache %packagetab 
    %courselogs %accesshash $processmarker $dumpcount 
    %coursedombuf %coursehombuf %courseresdatacache);
@@ -481,24 +481,23 @@ sub authenticate {
 # ---------------------- Find the homebase for a user from domain's lib servers
 
 sub homeserver {
-    my ($uname,$udom)=@_;
+    my ($uname,$udom,$ignoreBadCache)=@_;
     my $index="$uname:$udom";
     if ($homecache{$index}) { 
         return "$homecache{$index}"; 
     }
     my $tryserver;
     foreach $tryserver (keys %libserv) {
-        next if (exists($badhomecache{$index}->{$tryserver}));
+        next if ($ignoreBadCache ne 'true' && 
+		 exists($badServerCache{$tryserver}));
 	if ($hostdom{$tryserver} eq $udom) {
            my $answer=reply("home:$udom:$uname",$tryserver);
            if ($answer eq 'found') { 
               $homecache{$index}=$tryserver;
               return $tryserver; 
-           } else {
-               $badhomecache{$index}->{$tryserver}=1;
+           } elsif ($answer eq 'no_host') {
+	       $badServerCache{$tryserver}=1;
            }
-       } else {
-           $badhomecache{$index}->{$tryserver}=1;
        }
     }    
     return 'no_host';
@@ -1880,7 +1879,7 @@ sub modifyuser {
              (defined($desiredhome) ? ' desiredhome = '.$desiredhome :
                                      ' desiredhome not specified'). 
              ' by '.$ENV{'user.name'}.' at '.$ENV{'user.domain'});
-    my $uhome=&homeserver($uname,$udom);
+    my $uhome=&homeserver($uname,$udom,'true');
 # ----------------------------------------------------------------- Create User
     if (($uhome eq 'no_host') && ($umode) && ($upass)) {
         my $unhome='';
@@ -1910,7 +1909,7 @@ sub modifyuser {
 	unless ($reply eq 'ok') {
             return 'error: '.$reply;
         }   
-        $uhome=&homeserver($uname,$udom);
+        $uhome=&homeserver($uname,$udom,'true');
         if (($uhome eq '') || ($uhome eq 'no_host') || ($uhome ne $unhome)) {
 	    return 'error: verify home';
         }
@@ -2017,11 +2016,11 @@ sub createcourse {
    my $uname=substr($$.time,0,5).unpack("H8",pack("I32",time)).
        unpack("H2",pack("I32",int(rand(255)))).$perlvar{'lonHostID'};
 # ----------------------------------------------- Make sure that does not exist
-   my $uhome=&homeserver($uname,$udom);
+   my $uhome=&homeserver($uname,$udom,'true');
    unless (($uhome eq '') || ($uhome eq 'no_host')) {
        $uname=substr($$.time,0,5).unpack("H8",pack("I32",time)).
         unpack("H2",pack("I32",int(rand(255)))).$perlvar{'lonHostID'};
-       $uhome=&homeserver($uname,$udom);       
+       $uhome=&homeserver($uname,$udom,'true');       
        unless (($uhome eq '') || ($uhome eq 'no_host')) {
            return 'error: unable to generate unique course-ID';
        } 
@@ -2030,7 +2029,7 @@ sub createcourse {
     my $reply=&reply('encrypt:makeuser:'.$udom.':'.$uname.':none::',
                       $ENV{'user.home'});
     unless ($reply eq 'ok') { return 'error: '.$reply; }
-    $uhome=&homeserver($uname,$udom);
+    $uhome=&homeserver($uname,$udom,'true');
     if (($uhome eq '') || ($uhome eq 'no_host')) { 
 	return 'error: no such course';
     }