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

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 10 Aug 2004 11:38:11 -0000


foxr		Tue Aug 10 07:38:11 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Add tokenauthuserfile processing in hander form.
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.226 loncom/lond:1.227
--- loncom/lond:1.226	Tue Aug 10 07:30:24 2004
+++ loncom/lond	Tue Aug 10 07:38:11 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.226 2004/08/10 11:30:24 foxr Exp $
+# $Id: lond,v 1.227 2004/08/10 11:38:11 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,7 +57,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.226 $'; #' stupid emacs
+my $VERSION='$Revision: 1.227 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -1839,6 +1839,40 @@
 }
 &register_handler("removeuserfile", \&remove_user_file_handler, 0,1,0);
 
+
+#
+#  Authenticate access to a user file by checking the user's 
+#  session token(?)
+#
+# Parameters:
+#   cmd      - The request keyword that dispatched to tus.
+#   tail     - The tail of the request (colon separated parameters).
+#   client   - Filehandle open on the client.
+# Return:
+#    1.
+
+sub token_auth_user_file_handler {
+    my ($cmd, $tail, $client) = @_;
+
+    my ($fname, $session) = split(/:/, $tail);
+    
+    chomp($session);
+    my $reply='non_auth';
+    if (open(ENVIN,$perlvar{'lonIDsDir'}.'/'.
+	     $session.'.id')) {
+	while (my $line=<ENVIN>) {
+	    if ($line=~ m|userfile\.\Q$fname\E\=|) { $reply='ok'; }
+	}
+	close(ENVIN);
+	&Reply($client, $reply);
+    } else {
+	&Failure($client, "invalid_token\n", "$cmd:$tail");
+    }
+    return 1;
+
+}
+
+&register_handler("tokenauthuserfile", \&token_auth_user_file_handler, 0,1,0);
 #---------------------------------------------------------------
 #
 #   Getting, decoding and dispatching requests:
@@ -1954,29 +1988,8 @@
 
 
 
-# ------------------------------------------ authenticate access to a user file
-
-    if ($userinput =~ /^tokenauthuserfile/) { # Client only
-	if(isClient) {
-	    my ($cmd,$fname,$session)=split(/:/,$userinput);
-	    chomp($session);
-	    my $reply='non_auth';
-	    if (open(ENVIN,$perlvar{'lonIDsDir'}.'/'.
-		     $session.'.id')) {
-		while (my $line=<ENVIN>) {
-		    if ($line=~ m|userfile\.\Q$fname\E\=|) { $reply='ok'; }
-			    }
-		close(ENVIN);
-		print $client $reply."\n";
-	    } else {
-		print $client "invalid_token\n";
-	    }
-	} else {
-	    Reply($client, "refused\n", $userinput);
-	    
-	}
 # ----------------------------------------------------------------- unsubscribe
-    } elsif ($userinput =~ /^unsub/) {
+    if ($userinput =~ /^unsub/) {
 	if(isClient) {
 	    my ($cmd,$fname)=split(/:/,$userinput);
 	    if (-e $fname) {