--- loncom/auth/lonauth.pm 2006/06/02 21:23:49 1.79 +++ loncom/auth/lonauth.pm 2006/09/19 21:36:24 1.83 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.79 2006/06/02 21:23:49 albertel Exp $ +# $Id: lonauth.pm,v 1.83 2006/09/19 21:36:24 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,13 +40,13 @@ use Apache::lonnet; use Apache::lonmenu(); use Fcntl qw(:flock); use Apache::lonlocal; - +use GDBM_File; my %FORM; # ------------------------------------------------------------ Successful login sub success { - my ($r, $username, $domain, $authhost,$lowerurl) = @_; + my ($r, $username, $domain, $authhost, $lowerurl, $extra_env) = @_; my $lonids=$r->dir_config('lonIDsDir'); my $public=($username eq 'public' && $domain eq 'public'); @@ -170,24 +170,20 @@ sub success { } } - open(my $idf,">$lonids/$cookie.id"); - unless (flock($idf,LOCK_EX)) { + $env{'user.environment'} = "$lonids/$cookie.id"; + + if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id", + &GDBM_WRCREAT(),0640)) { + &add_to_env(\%disk_env,\%initial_env); + &add_to_env(\%disk_env,\%userenv,'environment.'); + &add_to_env(\%disk_env,$userroles); + &add_to_env(\%disk_env,$extra_env); + untie(%disk_env); + } else { &Apache::lonnet::logthis("WARNING: ". - 'Could not obtain exclusive lock in lonauth: '.$!); - close($idf); + 'Could not create environment storage in lonauth: '.$!); return 'error: '.$!; } - - while (my ($key,$value) = each(%initial_env)) { - print $idf (&escape($key).'='.&escape($value)."\n"); - } - while (my ($key,$value) = each(%userenv)) { - print $idf (&escape('environment.'.$key).'='.&escape($value)."\n"); - } - while (my ($key,$value) = each(%{$userroles})) { - print $idf (&escape($key).'='.&escape($value)."\n"); - } - close($idf); } $env{'request.role'}='cm'; $env{'request.role.adv'}=$env{'user.adv'}; @@ -253,6 +249,14 @@ $end_page ENDSUCCESS } +sub add_to_env { + my ($idf,$env_data,$prefix) = @_; + while (my ($key,$value) = each(%$env_data)) { + $idf->{$prefix.$key} = $value; + $env{$prefix.$key} = $value; + } +} + # --------------------------------------------------------------- Failed login! sub failed { @@ -446,7 +450,12 @@ ENDFAILED &Apache::lonnet::logthis('Non-privileged user attempting switch user'); } } - &success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$firsturl); + if ($r->dir_config("lonBalancer") eq 'yes') { + &success($r,$FORM{'uname'},$FORM{'udom'},$authhost,'noredirect'); + $r->internal_redirect('/adm/switchserver'); + } else { + &success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$firsturl); + } return OK; }