--- loncom/lonnet/perl/lonnet.pm 2007/10/01 21:06:04 1.915 +++ loncom/lonnet/perl/lonnet.pm 2007/10/01 21:52:57 1.916 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.915 2007/10/01 21:06:04 albertel Exp $ +# $Id: lonnet.pm,v 1.916 2007/10/01 21:52:57 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -397,6 +397,34 @@ sub transfer_profile_to_env { } } +# ---------------------------------------------------- Check for valid session +sub check_for_valid_session { + my ($r) = @_; + my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); + my $lonid=$cookies{'lonID'}; + return undef if (!$lonid); + + my $handle=&LONCAPA::clean_handle($lonid->value); + my $lonidsdir=$r->dir_config('lonIDsDir'); + return undef if (!-e "$lonidsdir/$handle.id"); + + open(my $idf,'+<',"$lonidsdir/$handle.id"); + return undef if (!$idf); + + flock($idf,LOCK_SH); + my %disk_env; + if (!tie(%disk_env,'GDBM_File',"$lonidsdir/$handle.id", + &GDBM_READER(),0640)) { + return undef; + } + + if (!defined($disk_env{'user.name'}) + || !defined($disk_env{'user.domain'})) { + return undef; + } + return $handle; +} + sub timed_flock { my ($file,$lock_type) = @_; my $failed=0;