Diff for /loncom/lond between versions 1.29 and 1.52

version 1.29, 2000/12/06 18:05:51 version 1.52, 2001/09/30 18:32:31
Line 9 Line 9
 # 06/26 Scott Harrison  # 06/26 Scott Harrison
 # 06/29,06/30,07/14,07/15,07/17,07/20,07/25,09/18 Gerd Kortemeyer  # 06/29,06/30,07/14,07/15,07/17,07/20,07/25,09/18 Gerd Kortemeyer
 # 12/05 Scott Harrison  # 12/05 Scott Harrison
 # 12/05 Gerd Kortemeyer  # 12/05,12/13,12/29 Gerd Kortemeyer
   # Jan 01 Scott Harrison
   # 02/12 Gerd Kortemeyer
   # 03/15 Scott Harrison
   # 03/24 Gerd Kortemeyer
   # 04/02 Scott Harrison
   # 05/11,05/28,08/30 Gerd Kortemeyer
   # 9/30 Scott Harrison
 #  #
 # based on "Perl Cookbook" ISBN 1-56592-243-3  # based on "Perl Cookbook" ISBN 1-56592-243-3
 # preforker - server who forks first  # preforker - server who forks first
Line 26  use Crypt::IDEA; Line 33  use Crypt::IDEA;
 use LWP::UserAgent();  use LWP::UserAgent();
 use GDBM_File;  use GDBM_File;
 use Authen::Krb4;  use Authen::Krb4;
   use lib '/home/httpd/lib/perl/';
   use localauth;
   
 # grabs exception and records it to log before exiting  # grabs exception and records it to log before exiting
 sub catchexception {  sub catchexception {
Line 57  while ($configline=<CONFIG>) { Line 66  while ($configline=<CONFIG>) {
 }  }
 close(CONFIG);  close(CONFIG);
   
   # ----------------------------- Make sure this process is running from user=www
   my $wwwid=getpwnam('www');
   if ($wwwid!=$<) {
      $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
      $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
      system("echo 'User ID mismatch.  lond must be run as user www.' |\
    mailto $emailto -s '$subj' > /dev/null");
      exit 1;
   }
   
 # --------------------------------------------- Check if other instance running  # --------------------------------------------- Check if other instance running
   
 my $pidfile="$perlvar{'lonDaemons'}/logs/lond.pid";  my $pidfile="$perlvar{'lonDaemons'}/logs/lond.pid";
Line 122  sub HUPSMAN {                      # sig Line 141  sub HUPSMAN {                      # sig
     kill 'INT' => keys %children;      kill 'INT' => keys %children;
     close($server);                # free up socket      close($server);                # free up socket
     &logthis("<font color=red>CRITICAL: Restarting</font>");      &logthis("<font color=red>CRITICAL: Restarting</font>");
       unlink("$execdir/logs/lond.pid");
     my $execdir=$perlvar{'lonDaemons'};      my $execdir=$perlvar{'lonDaemons'};
     exec("$execdir/lond");         # here we go again      exec("$execdir/lond");         # here we go again
 }  }
Line 347  sub make_new_child { Line 367  sub make_new_child {
             my $clientip=inet_ntoa($iaddr);              my $clientip=inet_ntoa($iaddr);
             my $clientrec=($hostid{$clientip} ne undef);              my $clientrec=($hostid{$clientip} ne undef);
             &logthis(              &logthis(
 "<font color=yellow>INFO: Connect from $clientip ($hostid{$clientip})</font>");  "<font color=yellow>INFO: Connection $i, $clientip ($hostid{$clientip})</font>"
               );
             my $clientok;              my $clientok;
             if ($clientrec) {              if ($clientrec) {
       my $remotereq=<$client>;        my $remotereq=<$client>;
Line 451  sub make_new_child { Line 472  sub make_new_child {
   (crypt($upass,$contentpwd) eq $contentpwd);    (crypt($upass,$contentpwd) eq $contentpwd);
                           } elsif ($howpwd eq 'unix') {                            } elsif ($howpwd eq 'unix') {
                               $contentpwd=(getpwnam($uname))[1];                                $contentpwd=(getpwnam($uname))[1];
                               $pwdcorrect=        my $pwauth_path="/usr/local/sbin/pwauth";
                                   (crypt($upass,$contentpwd) eq $contentpwd);        unless ($contentpwd eq 'x') {
     $pwdcorrect=
                                       (crypt($upass,$contentpwd) eq $contentpwd);
         }
         elsif (-e $pwauth_path) {
     open PWAUTH, "|$pwauth_path" or
         die "Cannot invoke authentication";
     print PWAUTH "$uname\n$upass\n";
     close PWAUTH;
     $pwdcorrect=!$?;
         }
                           } elsif ($howpwd eq 'krb4') {                            } elsif ($howpwd eq 'krb4') {
                               $pwdcorrect=(                                $pwdcorrect=(
                                  Authen::Krb4::get_pw_in_tkt($uname,"",                                   Authen::Krb4::get_pw_in_tkt($uname,"",
                                         $contentpwd,'krbtgt',$contentpwd,1,                                          $contentpwd,'krbtgt',$contentpwd,1,
      $upass) == 0);       $upass) == 0);
                           }                            } elsif ($howpwd eq 'localauth') {
       $pwdcorrect=&localauth::localauth($uname,$upass,
         $contentpwd);
     }
                           if ($pwdcorrect) {                            if ($pwdcorrect) {
                              print $client "authorized\n";                               print $client "authorized\n";
                           } else {                            } else {
Line 476  sub make_new_child { Line 510  sub make_new_child {
                        my                          my 
                        ($cmd,$udom,$uname,$upass,$npass)=split(/:/,$userinput);                         ($cmd,$udom,$uname,$upass,$npass)=split(/:/,$userinput);
                        chomp($npass);                         chomp($npass);
                          $upass=&unescape($upass);
                          $npass=&unescape($npass);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $passfilename="$proname/passwd";                         my $passfilename="$proname/passwd";
                        if (-e $passfilename) {                         if (-e $passfilename) {
Line 490  sub make_new_child { Line 526  sub make_new_child {
                              $salt=substr($salt,6,2);                               $salt=substr($salt,6,2);
      my $ncpass=crypt($npass,$salt);       my $ncpass=crypt($npass,$salt);
                              { my $pf = IO::File->new(">$passfilename");                               { my $pf = IO::File->new(">$passfilename");
           print $pf "internal:$ncpass\n";; }                         print $pf "internal:$ncpass\n"; }             
                              print $client "ok\n";                               print $client "ok\n";
                            } else {                             } else {
                              print $client "non_authorized\n";                               print $client "non_authorized\n";
Line 504  sub make_new_child { Line 540  sub make_new_child {
      } else {       } else {
        print $client "refused\n";         print $client "refused\n";
      }       }
   # -------------------------------------------------------------------- makeuser
                      } elsif ($userinput =~ /^makeuser/) {
        if ($wasenc==1) {
                          my 
                          ($cmd,$udom,$uname,$umode,$npass)=split(/:/,$userinput);
                          chomp($npass);
                          $npass=&unescape($npass);
                          my $proname=propath($udom,$uname);
                          my $passfilename="$proname/passwd";
                          if (-e $passfilename) {
      print $client "already_exists\n";
                          } elsif ($udom ne $perlvar{'lonDefDomain'}) {
                              print $client "not_right_domain\n";
                          } else {
                              @fpparts=split(/\//,$proname);
                              $fpnow=$fpparts[0].'/'.$fpparts[1].'/'.$fpparts[2];
                              $fperror='';
                              for ($i=3;$i<=$#fpparts;$i++) {
                                  $fpnow.='/'.$fpparts[$i]; 
                                  unless (-e $fpnow) {
      unless (mkdir($fpnow,0777)) {
                                         $fperror="error:$!\n";
                                      }
                                  }
                              }
                              unless ($fperror) {
        if ($umode eq 'krb4') {
                                  { 
                                    my $pf = IO::File->new(">$passfilename");
               print $pf "krb4:$npass\n"; 
                                  }             
                                  print $client "ok\n";
                                } elsif ($umode eq 'internal') {
          my $salt=time;
                                  $salt=substr($salt,6,2);
          my $ncpass=crypt($npass,$salt);
                                  { 
                                    my $pf = IO::File->new(">$passfilename");
               print $pf "internal:$ncpass\n"; 
                                  }
                                  print $client "ok\n";
        } elsif ($umode eq 'localauth') {
          {
    my $pf = IO::File->new(">$passfilename");
               print $pf "localauth:$npass\n";
          }
          print $client "ok\n";
                                } elsif ($umode eq 'none') {
                                  { 
                                    my $pf = IO::File->new(">$passfilename");
               print $pf "none:\n"; 
                                  }             
                                  print $client "ok\n";
                                } else {
                                  print $client "auth_mode_error\n";
                                }  
                              } else {
                                  print $client "$fperror\n";
                              }
                          }
        } else {
          print $client "refused\n";
        }
 # ------------------------------------------------------------------------ home  # ------------------------------------------------------------------------ home
                    } elsif ($userinput =~ /^home/) {                     } elsif ($userinput =~ /^home/) {
                        my ($cmd,$udom,$uname)=split(/:/,$userinput);                         my ($cmd,$udom,$uname)=split(/:/,$userinput);
Line 595  sub make_new_child { Line 694  sub make_new_child {
                                print $sh "$clientip:$now\n";                                 print $sh "$clientip:$now\n";
     }      }
    }     }
                              unless ($fname=~/\.meta$/) {
          unlink("$fname.meta.$hostid{$clientip}");
                              }
                            $fname=~s/\/home\/httpd\/html\/res/raw/;                             $fname=~s/\/home\/httpd\/html\/res/raw/;
                            $fname="http://$thisserver/".$fname;                             $fname="http://$thisserver/".$fname;
                            print $client "$fname\n";                             print $client "$fname\n";
Line 630  sub make_new_child { Line 732  sub make_new_child {
                        chomp($what);                         chomp($what);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $now=time;                         my $now=time;
                        {                         unless ($namespace=~/^nohist\_/) {
    my $hfh;     my $hfh;
    if (     if (
                              $hfh=IO::File->new(">>$proname/$namespace.hist")                               $hfh=IO::File->new(">>$proname/$namespace.hist")
Line 755  sub make_new_child { Line 857  sub make_new_child {
                        chomp($what);                         chomp($what);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $now=time;                         my $now=time;
                        {                         unless ($namespace=~/^nohist\_/) {
    my $hfh;     my $hfh;
    if (     if (
                              $hfh=IO::File->new(">>$proname/$namespace.hist")                               $hfh=IO::File->new(">>$proname/$namespace.hist")
Line 826  sub make_new_child { Line 928  sub make_new_child {
                        chomp($what);                         chomp($what);
                        my $proname=propath($udom,$uname);                         my $proname=propath($udom,$uname);
                        my $now=time;                         my $now=time;
                        {                         unless ($namespace=~/^nohist\_/) {
    my $hfh;     my $hfh;
    if (     if (
                              $hfh=IO::File->new(">>$proname/$namespace.hist")                               $hfh=IO::File->new(">>$proname/$namespace.hist")
Line 845  sub make_new_child { Line 947  sub make_new_child {
                                $allkeys.=$key.':';                                 $allkeys.=$key.':';
                                $hash{"$version:$rid:$key"}=$value;                                 $hash{"$version:$rid:$key"}=$value;
                            }                             }
                            $allkeys=~s/:$//;                             $hash{"$version:$rid:timestamp"}=$now;
                              $allkeys.='timestamp';
                            $hash{"$version:keys:$rid"}=$allkeys;                             $hash{"$version:keys:$rid"}=$allkeys;
    if (untie(%hash)) {     if (untie(%hash)) {
                               print $client "ok\n";                                print $client "ok\n";
Line 891  sub make_new_child { Line 994  sub make_new_child {
                        }                         }
 # ------------------------------------------------------------------- querysend  # ------------------------------------------------------------------- querysend
                    } elsif ($userinput =~ /^querysend/) {                     } elsif ($userinput =~ /^querysend/) {
                        my ($cmd,$query)=split(/:/,$userinput);                         my ($cmd,$query,
      $custom,$customshow)=split(/:/,$userinput);
        $query=~s/\n*$//g;         $query=~s/\n*$//g;
                      print $client sqlreply("$hostid{$clientip}\&$query")."\n";         unless ($custom or $customshow) {
      print $client "".
          sqlreply("$hostid{$clientip}\&$query")."\n";
          }
          else {
      print $client "".
          sqlreply("$hostid{$clientip}\&$query".
    "\&$custom"."\&$customshow")."\n";
          }
 # ------------------------------------------------------------------ queryreply  # ------------------------------------------------------------------ queryreply
                    } elsif ($userinput =~ /^queryreply/) {                     } elsif ($userinput =~ /^queryreply/) {
                        my ($cmd,$id,$reply)=split(/:/,$userinput);                          my ($cmd,$id,$reply)=split(/:/,$userinput); 
        my $store;         my $store;
                        my $execdir=$perlvar{'lonDaemons'};                         my $execdir=$perlvar{'lonDaemons'};
                        if ($store=IO::File->new(">$execdir/tmp/$id")) {                         if ($store=IO::File->new(">$execdir/tmp/$id")) {
      $reply=~s/\&/\n/g;
    print $store $reply;     print $store $reply;
    close $store;     close $store;
      my $store2=IO::File->new(">$execdir/tmp/$id.end");
      print $store2 "done\n";
      close $store2;
    print $client "ok\n";     print $client "ok\n";
        }         }
        else {         else {
Line 995  sub make_new_child { Line 1111  sub make_new_child {
                        my $ulsout='';                         my $ulsout='';
                        my $ulsfn;                         my $ulsfn;
                        if (-e $ulsdir) {                         if (-e $ulsdir) {
                           while ($ulsfn=<$ulsdir/*>) {   if (opendir(LSDIR,$ulsdir)) {
      my @ulsstats=stat($ulsfn);                            while ($ulsfn=readdir(LSDIR)) {
        my @ulsstats=stat($ulsdir.'/'.$ulsfn);
                              $ulsout.=$ulsfn.'&'.join('&',@ulsstats).':';                               $ulsout.=$ulsfn.'&'.join('&',@ulsstats).':';
                           }                            }
                             closedir(LSDIR);
           }
        } else {         } else {
                           $ulsout='no_such_dir';                            $ulsout='no_such_dir';
                        }                         }
                        if ($ulsout eq '') { $ulsout='empty'; }                         if ($ulsout eq '') { $ulsout='empty'; }
                        print $client "$ulsout\n";                         print $client "$ulsout\n";
   # ------------------------------------------------------------------ Hanging up
                      } elsif (($userinput =~ /^exit/) ||
                               ($userinput =~ /^init/)) {
                          &logthis(
         "Client $clientip ($hostid{$clientip}) hanging up: $userinput");
                          print $client "bye\n";
          last;
 # ------------------------------------------------------------- unknown command  # ------------------------------------------------------------- unknown command
                    } else {                     } else {
                        # unknown command                         # unknown command

Removed from v.1.29  
changed lines
  Added in v.1.52


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