Apache/iNcom/Session.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 64 CC 2 SCAR 9.8
CC
2
Cov
0%
generate_id
6.0
BEGIN
2.0
get_object_store
2.0
CRAP 2.7
1 #
2 # Session.pm - Apache::Session implementation for iNcom application.
3 #
4 # This file is part of Apache::iNcom.
5 #
6 # Author: Francis J. Lacoste <francis.lacoste@iNsu.COM>
7 #
8 # Copyright (C) 1999 Francis J. Lacoste, iNsu Innovations
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #
24 package Apache::iNcom::Session;
25  
26 use strict;
27 use vars qw(@ISA $VERSION);
28  
29 BEGIN {
30 ($VERSION) = '$Revision: 1.5 $' =~ /Revision: ([\d.]+)/;
31 @ISA = qw(Apache::Session);
32 }
33  
34 use Digest::MD5 qw( md5_hex );
35  
36 use Apache::Session;
37 use Apache::iNcom::SessionLocker;
38 use Apache::Session::DBIBase64Store;
39  
40 use Symbol;
41  
42 my $HAVE_RANDOM_DEV = -c "/dev/urandom";
43 warn __PACKAGE__ . ": no random device found: using insecure session id\n"
44 unless $HAVE_RANDOM_DEV;
45 my $random_dev = gensym;
46  
47 sub get_object_store {
48 my $self = shift;
49  
50 return new Apache::Session::DBIBase64Store $self;
51 }
52  
53 sub get_lock_manager {
54 my $self = shift;
55  
56 return new Apache::iNcom::SessionLocker;
57 }
58  
59 # We want longer session id than the 16 characters of
60 # Apache::Session
61 # We override the method
62 sub generate_id {
63 # Collision generates error on insert. So we don't
64 # really care here if we generate same if twice.
65 # Besides with the random device, this probability
66 # is really low.
67 SAFE_ID:
68 {
69 last SAFE_ID unless $HAVE_RANDOM_DEV;
70 open $random_dev, "/dev/urandom" or last SAFE_ID;
71 my $session_id;
72 read $random_dev, $session_id, 16 or last SAFE_ID;
73 close $random_dev;
74  
75 return unpack( "H*", $session_id );
76 }
77  
78 # If we got here, this system doesn't have
79 # a random device, so we fudge.
80  
81 # How much real entropy we got in this ???
82 return md5_hex( time(), {}, rand(), $$, 'foo' );
83 }
84  
85 1;
86  
87 __END__