Diff for /loncom/lond between versions 1.165.2.4 and 1.166

version 1.165.2.4, 2004/04/08 20:11:12 version 1.166, 2003/12/22 11:03:37
Line 162  sub ReadManagerTable { Line 162  sub ReadManagerTable {
   
     #   Clean out the old table first..      #   Clean out the old table first..
   
     foreach my $key (keys %managers) {     foreach my $key (keys %managers) {
  delete $managers{$key};        delete $managers{$key};
     }     }
   
     my $tablename = $perlvar{'lonTabDir'}."/managers.tab";     my $tablename = $perlvar{'lonTabDir'}."/managers.tab";
     if (!open (MANAGERS, $tablename)) {     if (!open (MANAGERS, $tablename)) {
  logthis('<font color="red">No manager table.  Nobody can manage!!</font>');        logthis('<font color="red">No manager table.  Nobody can manage!!</font>');
  return;        return;
     }     }
     while(my $host = <MANAGERS>) {     while(my $host = <MANAGERS>) {
  chomp($host);        chomp($host);
  if (!defined $hostip{$host}) { # This is a non cluster member        if ($host =~ "^#") {                  # Comment line.
            logthis('<font color="green"> Skipping line: '. "$host</font>\n");
            next;
         }
         if (!defined $hostip{$host}) { # This is a non cluster member
     #  The entry is of the form:      #  The entry is of the form:
     #    cluname:hostname      #    cluname:hostname
     #  cluname - A 'cluster hostname' is needed in order to negotiate      #  cluname - A 'cluster hostname' is needed in order to negotiate
     #            the host key.      #            the host key.
     #  hostname- The dns name of the host.      #  hostname- The dns name of the host.
     #      #
                 my($cluname, $dnsname) = split(/:/, $host);
     my($cluname, $dnsname) = split(/:/, $host);            
     open(MGRPIPE, "/usr/bin/host $dnsname |") || die "Can't make host pipeline";            my $ip = gethostbyname($dnsname);
     my $dnsinfo = <MGRPIPE>;            if(defined($ip)) {                 # bad names don't deserve entry.
     chomp $dnsinfo;              my $hostip = inet_ntoa($ip);
     close MGRPIPE;              $managers{$hostip} = $cluname;
     my($jname, $jhas, $jaddress, $hostip) = split(/ /, $dnsinfo);              logthis('<font color="green"> registering manager '.
     $managers{$hostip} = $cluname;                      "$dnsname as $cluname with $hostip </font>\n");
  } else {           }
     $managers{$hostip{$host}} = $host;  # Use info from cluster tab if clumemeber        } else {
  }           logthis('<font color="green"> existing host'." $host</font>\n");
     }           $managers{$hostip{$host}} = $host;  # Use info from cluster tab if clumemeber
         }
      }
 }  }
   
 #  #
Line 279  sub AdjustHostContents { Line 284  sub AdjustHostContents {
     my $adjusted;      my $adjusted;
     my $me        = $perlvar{'lonHostID'};      my $me        = $perlvar{'lonHostID'};
   
     foreach my $line (split(/\n/,$contents)) {   foreach my $line (split(/\n/,$contents)) {
  if(!(($line eq "") || ($line =~ /^ *\#/) || ($line =~ /^ *$/))) {   if(!(($line eq "") || ($line =~ /^ *\#/) || ($line =~ /^ *$/))) {
     chomp($line);      chomp($line);
     my ($id,$domain,$role,$name,$ip,$maxcon,$idleto,$mincon)=split(/:/,$line);      my ($id,$domain,$role,$name,$ip,$maxcon,$idleto,$mincon)=split(/:/,$line);
     if ($id eq $me) {      if ($id eq $me) {
  open(PIPE, " /usr/bin/host $name |") || die "Cant' make host pipeline";            my $ip = gethostbyname($name);
  my $hostinfo = <PIPE>;            my $ipnew = inet_ntoa($ip);
  close PIPE;           $ip = $ipnew;
   
  my ($hostname, $has, $address, $ipnew) = split(/ /,$hostinfo);  
  &logthis('<font color="green">'.  
  "hostname = $hostname me = $me, name = $name   actual ip = $ipnew </font>");  
   
  if ($hostname eq $name) { # Lookup succeeded..  
     &logthis('<font color="green"> look up ok <font>');  
     $ip = $ipnew;  
  } else {  
     &logthis('<font color="green"> Lookup failed: '  
      .$hostname." ne $name </font>");  
  }  
  #  Reconstruct the host line and append to adjusted:   #  Reconstruct the host line and append to adjusted:
   
  my $newline = "$id:$domain:$role:$name:$ip";     my $newline = "$id:$domain:$role:$name:$ip";
  if($maxcon ne "") { # Not all hosts have loncnew tuning params     if($maxcon ne "") { # Not all hosts have loncnew tuning params
     $newline .= ":$maxcon:$idleto:$mincon";       $newline .= ":$maxcon:$idleto:$mincon";
  }     }
  $adjusted .= $newline."\n";     $adjusted .= $newline."\n";
   
     } else { # Not me, pass unmodified.        } else { # Not me, pass unmodified.
  $adjusted .= $line."\n";     $adjusted .= $line."\n";
     }        }
  } else {                  # Blank or comment never re-written.   } else {                  # Blank or comment never re-written.
     $adjusted .= $line."\n"; # Pass blanks and comments as is.      $adjusted .= $line."\n"; # Pass blanks and comments as is.
  }   }
     }   }
     return $adjusted;   return $adjusted;
 }  }
 #  #
 #   InstallFile: Called to install an administrative file:  #   InstallFile: Called to install an administrative file:
Line 577  $server = IO::Socket::INET->new(LocalPor Line 570  $server = IO::Socket::INET->new(LocalPor
 # global variables  # global variables
   
 my %children               = ();       # keys are current child process IDs  my %children               = ();       # keys are current child process IDs
   my $children               = 0;        # current number of children
   
 sub REAPER {                        # takes care of dead children  sub REAPER {                        # takes care of dead children
     $SIG{CHLD} = \&REAPER;      $SIG{CHLD} = \&REAPER;
     &status("Handling child death");      &status("Handling child death");
     my $pid;      my $pid = wait;
     do {      if (defined($children{$pid})) {
  $pid = waitpid(-1,&WNOHANG());   &logthis("Child $pid died");
  if (defined($children{$pid})) {   $children --;
     &logthis("Child $pid died");   delete $children{$pid};
     delete($children{$pid});      } else {
  } else {   &logthis("Unknown Child $pid died");
     &logthis("Unknown Child $pid died");  
  }  
     } while ( $pid > 0 );  
     foreach my $child (keys(%children)) {  
  $pid = waitpid($child,&WNOHANG());  
  if ($pid > 0) {  
     &logthis("Child $child - $pid looks like we missed it's death");  
     delete($children{$pid});  
  }  
     }      }
     &status("Finished Handling child death");      &status("Finished Handling child death");
 }  }
Line 652  sub ReadHostTable { Line 637  sub ReadHostTable {
     open (CONFIG,"$perlvar{'lonTabDir'}/hosts.tab") || die "Can't read host file";      open (CONFIG,"$perlvar{'lonTabDir'}/hosts.tab") || die "Can't read host file";
           
     while (my $configline=<CONFIG>) {      while (my $configline=<CONFIG>) {
  if (!($configline =~ /^\s*\#/)) {   my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
     my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);   chomp($ip); $ip=~s/\D+$//;
     chomp($ip); $ip=~s/\D+$//;   $hostid{$ip}=$id;
     $hostid{$ip}=$id;   $hostdom{$id}=$domain;
     $hostdom{$id}=$domain;   $hostip{$id}=$ip;
     $hostip{$id}=$ip;   if ($id eq $perlvar{'lonHostID'}) { $thisserver=$name; }
     if ($id eq $perlvar{'lonHostID'}) { $thisserver=$name; }  
  }  
     }      }
     close(CONFIG);      close(CONFIG);
 }  }
Line 795  sub logstatus { Line 778  sub logstatus {
     my $docdir=$perlvar{'lonDocRoot'};      my $docdir=$perlvar{'lonDocRoot'};
     {      {
     my $fh=IO::File->new(">>$docdir/lon-status/londstatus.txt");      my $fh=IO::File->new(">>$docdir/lon-status/londstatus.txt");
     print $fh $$."\t".$clientname."\t".$currenthostid."\t".$status."\t".$lastlog."\n";      print $fh $$."\t".$currenthostid."\t".$status."\t".$lastlog."\n";
     $fh->close();      $fh->close();
     }      }
     &status("Finished londstatus.txt");      &status("Finished londstatus.txt");
Line 1031  sub make_new_child { Line 1014  sub make_new_child {
         sigprocmask(SIG_UNBLOCK, $sigset)          sigprocmask(SIG_UNBLOCK, $sigset)
             or die "Can't unblock SIGINT for fork: $!\n";              or die "Can't unblock SIGINT for fork: $!\n";
         $children{$pid} = $clientip;          $children{$pid} = $clientip;
           $children++;
         &status('Started child '.$pid);          &status('Started child '.$pid);
         return;          return;
     } else {      } else {
Line 1233  sub make_new_child { Line 1217  sub make_new_child {
     }      }
 #--------------------------------------------------------------------- reinit  #--------------------------------------------------------------------- reinit
  } elsif($userinput =~ /^reinit/) { # Encoded and manager   } elsif($userinput =~ /^reinit/) { # Encoded and manager
     if (($wasenc == 1) && isManager) {   if (($wasenc == 1) && isManager) {
  my $cert = GetCertificate($userinput);   my $cert = GetCertificate($userinput);
  if(ValidManager($cert)) {   if(ValidManager($cert)) {
     chomp($userinput);   chomp($userinput);
     my $reply = ReinitProcess($userinput);   my $reply = ReinitProcess($userinput);
     print $client  "$reply\n";   print $client  "$reply\n";
    } else {
    print $client "refused\n";
    }
  } else {   } else {
     print $client "refused\n";   Reply($client, "refused\n", $userinput);
  }   }
     } else {  #------------------------------------------------------------------------- edit
  Reply($client, "refused\n", $userinput);      } elsif ($userinput =~ /^edit/) {    # encoded and manager:
    if(($wasenc ==1) && (isManager)) {
       my $cert = GetCertificate($userinput);
     }      if(ValidManager($cert)) {
                  my($command, $filetype, $script) = split(/:/, $userinput);
                  if (($filetype eq "hosts") || ($filetype eq "domain")) {
                     if($script ne "") {
                        Reply($client,"ok\n",$userinput);       # DEBUG: Call EditFile here.
                     } else {
                        Reply($client,"refused\n",$userinput);
                     }
                  } else {
                     Reply($client,"refused\n",$userinput);
                  }
               } else {
                  Reply($client,"refused\n",$userinput);
               }
            } else {
        Reply($client,"refused\n",$userinput);
    }
 # ------------------------------------------------------------------------ auth  # ------------------------------------------------------------------------ auth
  } elsif ($userinput =~ /^auth/) { # Encoded and client only.      } elsif ($userinput =~ /^auth/) { # Encoded and client only.
     if (($wasenc==1) && isClient) {      if (($wasenc==1) && isClient) {
  my ($cmd,$udom,$uname,$upass)=split(/:/,$userinput);   my ($cmd,$udom,$uname,$upass)=split(/:/,$userinput);
  chomp($upass);   chomp($upass);
Line 1448  sub make_new_child { Line 1451  sub make_new_child {
     unless (mkdir($fpnow,0777)) {      unless (mkdir($fpnow,0777)) {
  $fperror="error: ".($!+0)   $fperror="error: ".($!+0)
     ." mkdir failed while attempting "      ." mkdir failed while attempting "
     ."makeuser";      ."makeuser\n";
     }      }
  }   }
     }      }
Line 2856  sub make_passwd_file { Line 2859  sub make_passwd_file {
  }   }
     } elsif ($umode eq 'unix') {      } elsif ($umode eq 'unix') {
  {   {
     #  
     #  Don't allow the creation of privileged accounts!!! that would  
     #  be real bad!!!  
     #  
     my $uid = getpwnam($uname);  
     if((defined $uid) && ($uid == 0)) {  
  &logthis(">>>Attempted to create privilged account blocked");  
  return "no_priv_account_error\n";  
     }  
   
     my $execpath="$perlvar{'lonDaemons'}/"."lcuseradd";      my $execpath="$perlvar{'lonDaemons'}/"."lcuseradd";
     {      {
  &Debug("Executing external: ".$execpath);   &Debug("Executing external: ".$execpath);

Removed from v.1.165.2.4  
changed lines
  Added in v.1.166


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>