[LON-CAPA-cvs] cvs: loncom / lond

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 16 Apr 2008 22:51:22 -0000


This is a MIME encoded message

--raeburn1208386282
Content-Type: text/plain

raeburn		Wed Apr 16 18:51:22 2008 EDT

  Modified files:              
    /loncom	lond 
  Log:
  - &ls3() is a replacement for &ls2.
     - Where the path needs to be constructed for user's directory when performing a directory listing, this now occurs on the homeserver side, instead of being generated in lonnet.pm on the session server side.
  
  - &du2() is a replacement for &du
     - Where the path needs to be constructed for user's directory when checking disk usage, this now occurs on the homeserver side, instead of being generated in lonnet.pm on the session server side.
  
  - Both needed for future username virtualization (changes made homeserver-side).
  
  - &ls2() and &du() retained for backwards compatibility when session server is running a legacy lonnet.pm
  
  
--raeburn1208386282
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080416185122.txt"

Index: loncom/lond
diff -u loncom/lond:1.398 loncom/lond:1.399
--- loncom/lond:1.398	Fri Mar  7 22:17:38 2008
+++ loncom/lond	Wed Apr 16 18:51:21 2008
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.398 2008/03/08 03:17:38 raeburn Exp $
+# $Id: lond,v 1.399 2008/04/16 22:51:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.398 $'; #' stupid emacs
+my $VERSION='$Revision: 1.399 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -1221,8 +1221,10 @@
 }
 &register_handler("pushfile", \&push_file_handler, 1, 0, 1);
 
+# The du_handler routine should be considered obsolete and is retained
+# for communication with legacy servers.  Please see the du2_handler.
 #
-#   du  - list the disk usuage of a directory recursively. 
+#   du  - list the disk usage of a directory recursively. 
 #    
 #   note: stolen code from the ls file handler
 #   under construction by Rick Banghart 
@@ -1272,9 +1274,73 @@
 }
 &register_handler("du", \&du_handler, 0, 1, 0);
 
+# Please also see the du_handler, which is obsoleted by du2. 
+# du2_handler differs from du_handler in that required path to directory
+# provided by &propath() is prepended in the handler instead of on the 
+# client side.
 #
-# The ls_handler routine should be considered obosolete and is retained
-# for communication with legacy servers.  Please see the ls2_handler.
+#   du2  - list the disk usage of a directory recursively.
+#
+# Parameters:
+#    $cmd        - The command that dispatched us (du).
+#    $tail       - The tail of the request that invoked us.
+#                  $tail is a : separated list of the following:
+#                   - $ududir - directory path to list (before prepending)
+#                   - $getpropath = 1 if &propath() should prepend
+#                   - $uname - username to use for &propath or user dir
+#                   - $udom - domain to use for &propath or user dir
+#                   All are escaped.
+#    $client     - Socket open on the client.
+# Returns:
+#     1 - indicating that the daemon should not disconnect.
+# Side Effects:
+#   The reply is written to $client.
+#
+
+sub du2_handler {
+    my ($cmd, $tail, $client) = @_;
+    my ($ududir,$getpropath,$uname,$udom) = map { &unescape($_) } (split(/:/, $tail));
+    my $userinput = "$cmd:$tail";
+    if (($ududir=~/\.\./) || (($ududir!~m|^/home/httpd/|) && (!$getpropath))) {
+        &Failure($client,"refused\n","$cmd:$tail");
+        return 1;
+    }
+    if ($getpropath) {
+        if (($uname =~ /^$LONCAPA::match_name$/) && ($udom =~ /^$LONCAPA::match_domain$/)) {
+            $ududir = &propath($udom,$uname).'/'.$ududir;
+        } else {
+            &Failure($client,"refused\n","$cmd:$tail");
+            return 1;
+        }
+    }
+    #  Since $ududir could have some nasties in it,
+    #  we will require that ududir is a valid
+    #  directory.  Just in case someone tries to
+    #  slip us a  line like .;(cd /home/httpd rm -rf*)
+    #  etc.
+    #
+    if (-d $ududir) {
+        my $total_size=0;
+        my $code=sub {
+            if ($_=~/\.\d+\./) { return;}
+            if ($_=~/\.meta$/) { return;}
+            if (-d $_)         { return;}
+            $total_size+=(stat($_))[7];
+        };
+        chdir($ududir);
+        find($code,$ududir);
+        $total_size=int($total_size/1024);
+        &Reply($client,\$total_size,"$cmd:$ududir");
+    } else {
+        &Failure($client, "bad_directory:$ududir\n","$cmd:$tail");
+    }
+    return 1;
+}
+&register_handler("du2", \&du2_handler, 0, 1, 0);
+
+#
+# The ls_handler routine should be considered obsolete and is retained
+# for communication with legacy servers.  Please see the ls3_handler.
 #
 #   ls  - list the contents of a directory.  For each file in the
 #    selected directory the filename followed by the full output of
@@ -1340,8 +1406,9 @@
 }
 &register_handler("ls", \&ls_handler, 0, 1, 0);
 
-#
-# Please also see the ls_handler, which this routine obosolets.
+# The ls2_handler routine should be considered obsolete and is retained
+# for communication with legacy servers.  Please see the ls3_handler.
+# Please also see the ls_handler, which was itself obsoleted by ls2.
 # ls2_handler differs from ls_handler in that it escapes its return 
 # values before concatenating them together with ':'s.
 #
@@ -1406,6 +1473,115 @@
    return 1;
 }
 &register_handler("ls2", \&ls2_handler, 0, 1, 0);
+#
+#   ls3  - list the contents of a directory.  For each file in the
+#    selected directory the filename followed by the full output of
+#    the stat function is returned.  The returned info for each
+#    file are separated by ':'.  The stat fields are separated by &'s.
+# Parameters:
+#    $cmd        - The command that dispatched us (ls).
+#    $tail       - The tail of the request that invoked us.
+#                  $tail is a : separated list of the following:
+#                   - $ulsdir - directory path to list (before prepending)
+#                   - $getpropath = 1 if &propath() should prepend
+#                   - $getuserdir = 1 if path to user dir in lonUsers should
+#                                     prepend
+#                   - $alternate_root - path to prepend
+#                   - $uname - username to use for &propath or user dir
+#                   - $udom - domain to use for &propath or user dir
+#            All of these except $getpropath and &getuserdir are escaped.    
+#                  no_such_dir.
+#    $client     - Socket open on the client.
+# Returns:
+#     1 - indicating that the daemon should not disconnect.
+# Side Effects:
+#   The reply is written to $client.
+#
+
+sub ls3_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($ulsdir,$getpropath,$getuserdir,$alternate_root,$uname,$udom) =
+        split(/:/,$tail);
+    if (defined($ulsdir)) {
+        $ulsdir = &unescape($ulsdir);
+    }
+    if (defined($alternate_root)) {
+        $alternate_root = &unescape($alternate_root);
+    }
+    if (defined($uname)) {
+        $uname = &unescape($uname);
+    }
+    if (defined($udom)) {
+        $udom = &unescape($udom);
+    }
+
+    my $dir_root = $perlvar{'lonDocRoot'};
+    if ($getpropath) {
+        if (($uname =~ /^$LONCAPA::match_name$/) && ($udom =~ /^$LONCAPA::match_domain$/)) {
+            $dir_root = &propath($udom,$uname);
+            $dir_root =~ s/\/$//;
+        } else {
+            &Failure($client,"refused\n","$cmd:$tail");
+            return 1;
+        }
+    } elsif ($getuserdir) {
+        if (($uname =~ /^$LONCAPA::match_name$/) && ($udom =~ /^$LONCAPA::match_domain$/)) {
+            my $subdir=$uname.'__';
+            $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
+            $dir_root = $Apache::lonnet::perlvar{'lonUsersDir'}
+                       ."/$udom/$subdir/$uname";
+        } else {
+            &Failure($client,"refused\n","$cmd:$tail");
+            return 1;
+        }
+    } elsif (defined($alternate_root)) {
+        $dir_root = $alternate_root;
+    }
+    if (defined($dir_root)) {
+        $ulsdir = $dir_root.'/'.$ulsdir;
+    }
+    my $obs;
+    my $rights;
+    my $ulsout='';
+    my $ulsfn;
+    if (-e $ulsdir) {
+        if(-d $ulsdir) {
+            if (opendir(LSDIR,$ulsdir)) {
+                while ($ulsfn=readdir(LSDIR)) {
+                    undef($obs);
+                    undef($rights);
+                    my @ulsstats=stat($ulsdir.'/'.$ulsfn);
+                    #We do some obsolete checking here
+                    if(-e $ulsdir.'/'.$ulsfn.".meta") {
+                        open(FILE, $ulsdir.'/'.$ulsfn.".meta");
+                        my @obsolete=<FILE>;
+                        foreach my $obsolete (@obsolete) {
+                            if($obsolete =~ m/(<obsolete>)(on|1)/) { $obs = 1; }
+                            if($obsolete =~ m|(<copyright>)(default)|) {
+                                $rights = 1;
+                            }
+                        }
+                    }
+                    my $tmp = $ulsfn.'&'.join('&',@ulsstats);
+                    if ($obs    eq '1') { $tmp.="&1"; } else { $tmp.="&0"; }
+                    if ($rights eq '1') { $tmp.="&1"; } else { $tmp.="&0"; }
+                    $ulsout.= &escape($tmp).':';
+                }
+                closedir(LSDIR);
+            }
+        } else {
+            my @ulsstats=stat($ulsdir);
+            $ulsout.=$ulsfn.'&'.join('&',@ulsstats).':';
+        }
+    } else {
+        $ulsout='no_such_dir';
+   }
+   if ($ulsout eq '') { $ulsout='empty'; }
+   &Reply($client, \$ulsout, $userinput); # This supports debug logging.
+   return 1;
+}
+&register_handler("ls3", \&ls3_handler, 0, 1, 0);
 
 #   Process a reinit request.  Reinit requests that either
 #   lonc or lond be reinitialized so that an updated 
@@ -1518,7 +1694,7 @@
     #                 with default auth type(s) if no user account.
     
     my ($udom, $uname, $upass, $checkdefauth)=split(/:/,$tail);
-    &Debug(" Authenticate domain = $udom, user = $uname, password = $upass");
+    &Debug(" Authenticate domain = $udom, user = $uname, password = $upass,  checkdefauth = $checkdefauth");
     chomp($upass);
     $upass=&unescape($upass);
 

--raeburn1208386282--