--- loncom/auth/loncacc.pm 2000/12/25 12:44:43 1.12 +++ loncom/auth/loncacc.pm 2002/01/04 14:57:14 1.19 @@ -2,7 +2,8 @@ # Cookie Based Access Handler for Construction Area # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer) # 6/15,16/11,22/11, -# 01/06,01/11,6/1,9/25,9/28,11/22,12/25 Gerd Kortemeyer +# 01/06,01/11,6/1,9/25,9/28,11/22,12/25,12/26, +# 01/06/01,05/04,05/05,05/09 Gerd Kortemeyer package Apache::loncacc; @@ -10,6 +11,29 @@ use strict; use Apache::Constants qw(:common :http :methods); use Apache::File; use CGI::Cookie(); +use Fcntl qw(:flock); + +sub constructaccess { + my ($url,$ownerdomain)=@_; + my ($ownername)=($url=~/\/(?:\~|priv\/|home\/)(\w+)/); + unless (($ownername) && ($ownerdomain)) { return ''; } + + if (($ownername eq $ENV{'user.name'}) && + ($ownerdomain eq $ENV{'user.domain'})) { + return ($ownername,$ownerdomain); + } + + my $capriv='user.priv.ca./'. + $ownerdomain.'/'.$ownername.'./'. + $ownerdomain.'/'.$ownername; + map { + if ($_ eq $capriv) { + return ($ownername,$ownerdomain); + } + } keys %ENV; + + return ''; +} sub handler { my $r = shift; @@ -22,21 +46,12 @@ sub handler { $handle=~s/\W//g; my $lonidsdir=$r->dir_config('lonIDsDir'); if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) { - my $ownername=$requrl; - $ownername=~s/\/(?:\~|priv\/)(\w+).*/\1/; - my $ownerdomain=$r->dir_config('lonDefDomain'); - my @handleparts=split(/\_/,$handle); - my $username=$handleparts[0]; - my $domain=$handleparts[2]; - if (($username ne $ownername) || ($domain ne $ownerdomain)) { - $r->log_reason - ("$username at $domain not authorized", $r->filename); - return HTTP_NOT_ACCEPTABLE; - } my @profile; { my $idf=Apache::File->new("$lonidsdir/$handle.id"); + flock($idf,LOCK_SH); @profile=<$idf>; + $idf->close(); } my $envi; for ($envi=0;$envi<=$#profile;$envi++) { @@ -48,6 +63,11 @@ sub handler { $ENV{'request.state'} = "construct"; $ENV{'request.filename'} = $r->filename; + unless (&constructaccess($requrl,$r->dir_config('lonDefDomain'))) { + $r->log_reason("Unauthorized $requrl", $r->filename); + return HTTP_NOT_ACCEPTABLE; + } + # -------------------------------------------------------- Load POST parameters @@ -78,11 +98,13 @@ sub handler { if ($lines[$i]=~/^$contentsep/) { if ($name) { chomp($value); - $ENV{"form.$name"}=$value; if ($fname) { $ENV{"form.$name.filename"}=$fname; $ENV{"form.$name.mimetype"}=$fmime; + } else { + $value=~s/\s+$//s; } + $ENV{"form.$name"}=$value; } if ($i<$#lines) { $i++; @@ -110,6 +132,7 @@ sub handler { } } } + $ENV{'request.method'}=$ENV{'REQUEST_METHOD'}; $r->method_number(M_GET); $r->method('GET'); $r->headers_in->unset('Content-length');