--- loncom/lond 2004/08/10 11:30:24 1.226 +++ loncom/lond 2004/08/10 11:38:11 1.227 @@ -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 $DEBUG = 0; # Non zero to ena 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 @@ sub remove_user_file_handler { } ®ister_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=) { + if ($line=~ m|userfile\.\Q$fname\E\=|) { $reply='ok'; } + } + close(ENVIN); + &Reply($client, $reply); + } else { + &Failure($client, "invalid_token\n", "$cmd:$tail"); + } + return 1; + +} + +®ister_handler("tokenauthuserfile", \&token_auth_user_file_handler, 0,1,0); #--------------------------------------------------------------- # # Getting, decoding and dispatching requests: @@ -1954,29 +1988,8 @@ sub process_request { -# ------------------------------------------ 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=) { - 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) {