--- loncom/auth/lonauth.pm 2017/02/17 14:34:21 1.142 +++ loncom/auth/lonauth.pm 2017/02/25 20:00:36 1.143 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.142 2017/02/17 14:34:21 raeburn Exp $ +# $Id: lonauth.pm,v 1.143 2017/02/25 20:00:36 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,6 +42,7 @@ use Fcntl qw(:flock); use Apache::lonlocal; use Apache::File(); use HTML::Entities; +use Digest::MD5; # ------------------------------------------------------------ Successful login sub success { @@ -72,8 +73,26 @@ sub success { } } -# ------------------------------------------------------------ Get cookie ready - $cookie="lonID=$cookie; path=/; HttpOnly"; +# ----------------------------------------------------------- Get cookies ready + my ($securecookie,$defaultcookie); + if ($ENV{'SERVER_PORT'} == 443) { + $securecookie="lonID=$cookie; path=/; HttpOnly; secure"; + my $lonidsdir=$r->dir_config('lonIDsDir'); + if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) { + my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked'; + if (-e "$lonidsdir/$linkname.id") { + unlink("$lonidsdir/$linkname.id"); + } + my $made_symlink = eval { symlink("$lonidsdir/$cookie.id", + "$lonidsdir/$linkname.id"); 1 }; + if ($made_symlink) { + $defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;"; + &Apache::lonnet::appenv({'user.linkedenv' => "$lonidsdir/$linkname.id"}); + } + } + } else { + $defaultcookie = "lonID=$cookie; path=/; HttpOnly;"; + } # -------------------------------------------------------- Menu script and info my $destination = $lowerurl; @@ -152,7 +171,12 @@ sub success { # ------------------------------------------------- Output for successful login &Apache::loncommon::content_type($r,'text/html'); - $r->header_out('Set-cookie' => $cookie); + if ($securecookie) { + $r->headers_out->add('Set-cookie' => $securecookie); + } + if ($defaultcookie) { + $r->headers_out->add('Set-cookie' => $defaultcookie); + } $r->send_http_header; my %lt=&Apache::lonlocal::texthash(