line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::BancaSella::Ric::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = "0.11"; |
4
|
0
|
|
|
0
|
0
|
0
|
sub Version { $VERSION; } |
5
|
|
|
|
|
|
|
require 5.004; |
6
|
1
|
|
|
1
|
|
882
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1036
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %fields = |
11
|
|
|
|
|
|
|
( |
12
|
|
|
|
|
|
|
file => undef, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @fields_req = qw/file/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
1
|
|
|
1
|
0
|
14
|
my $proto = shift; |
21
|
1
|
|
33
|
|
|
8
|
my $class = ref($proto) || $proto; |
22
|
1
|
|
|
|
|
2
|
my $self = {}; |
23
|
1
|
|
|
|
|
3
|
bless $self,$class; |
24
|
1
|
|
|
|
|
6
|
$self->init(@_); |
25
|
1
|
|
|
|
|
3
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init { |
29
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
30
|
1
|
|
|
|
|
4
|
my (%options) = @_; |
31
|
|
|
|
|
|
|
# Assign default options |
32
|
1
|
|
|
|
|
6
|
while (my ($key,$value) = each(%fields)) { |
33
|
1
|
|
33
|
|
|
13
|
$self->{$key} = $self->{$key} || $value; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
# Assign options |
36
|
1
|
|
|
|
|
5
|
while (my ($key,$value) = each(%options)) { |
37
|
1
|
|
|
|
|
5
|
$self->{$key} = $value |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
# Check required params |
40
|
1
|
|
|
|
|
2
|
foreach (@fields_req) { |
41
|
1
|
50
|
|
|
|
6
|
croak "You must declare '$_' in " . ref($self) . "::new" |
42
|
|
|
|
|
|
|
if (!defined $self->{$_}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub extract { |
47
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
1
|
my $password; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# open the file |
52
|
1
|
50
|
|
|
|
52
|
open(REQUEST,"+<$self->{'file'}") |
53
|
|
|
|
|
|
|
|| die "SYSTEM. opening $self->{'file'} : $!\n"; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
3
|
eval { |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# lock the file |
58
|
1
|
|
|
|
|
1
|
my $has_lock = eval { flock(REQUEST,2) }; |
|
1
|
|
|
|
|
8
|
|
59
|
1
|
50
|
|
|
|
6
|
if ( $@ ) { |
|
|
50
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
warn "WARNING. this platform don't implements 'flock'\n"; |
61
|
|
|
|
|
|
|
} elsif ( ! $has_lock ) { |
62
|
0
|
|
|
|
|
0
|
die "SYSTEM. locking $self->{'file'} : $!\n"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# length of a row of password |
66
|
1
|
|
|
|
|
2
|
my $row_length = 33; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
1
|
my $size_bytes; |
69
|
1
|
50
|
|
|
|
16
|
unless ( $size_bytes = (stat(REQUEST))[7] ) { |
70
|
0
|
0
|
|
|
|
0
|
die (( $! ) ? $! : "EMPTY : the file $self->{'file'} is empty\n" ); |
71
|
|
|
|
|
|
|
} |
72
|
1
|
50
|
|
|
|
4
|
if ( $size_bytes % $row_length != 0 ) { |
73
|
0
|
|
|
|
|
0
|
die "CORRUPT. dimension of $self->{'file'} is wrong\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# number of passwords in the file |
77
|
1
|
|
|
|
|
3
|
my $size = $size_bytes / $row_length; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# read the last password |
80
|
1
|
|
|
|
|
1
|
my $row; |
81
|
1
|
50
|
|
|
|
10
|
seek(REQUEST,($size-1)*$row_length,0) |
82
|
|
|
|
|
|
|
|| die "SYSTEM. while seek in $self->{'file'} : $!\n"; |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
30
|
read(REQUEST,$row,$row_length) || die "SYSTEM. reading $self->{'file'} : $!\n"; |
85
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
8
|
unless ( $row =~ /^([a-zA-Z0-9]{32})\n$/ ) { |
87
|
0
|
|
|
|
|
0
|
die "CORRUPT. file $self->{'file'} corrupted at last line\n"; |
88
|
|
|
|
|
|
|
} |
89
|
1
|
|
|
|
|
6
|
$password = $1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# delete the last password |
92
|
1
|
|
|
|
|
2
|
my $is_truncate = eval { truncate(REQUEST,($size-1)*$row_length) }; |
|
1
|
|
|
|
|
82
|
|
93
|
1
|
50
|
|
|
|
5
|
if ( $@ ) { |
94
|
0
|
|
|
|
|
0
|
die "SYSTEM. the 'truncate' function is not implemented on this platform!\n"; |
95
|
|
|
|
|
|
|
} |
96
|
1
|
50
|
|
|
|
4
|
unless ( $is_truncate ) { |
97
|
0
|
|
|
|
|
0
|
die "SYSTEM. while truncate $self->{'file'} : $!\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
}; # end eval |
101
|
1
|
|
|
|
|
3
|
my $error = $@; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# close the file |
104
|
1
|
|
|
|
|
12
|
close(REQUEST); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# die on error |
107
|
1
|
50
|
|
|
|
4
|
die $error if $error; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# return the password |
110
|
1
|
|
|
|
|
331
|
return $password; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub prepare { |
114
|
0
|
|
|
0
|
1
|
|
my ($self,$source_file) = @_; |
115
|
|
|
|
|
|
|
# don't do nothing :) |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
0
|
1
|
|
sub file { my $s=shift; return @_ ? ($s->{file}=shift) : $s->{file} } |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
__END__ |