line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::License; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
21270
|
use Filter::Util::Call 1.04; |
|
3
|
|
|
|
|
6274
|
|
|
3
|
|
|
|
|
810
|
|
4
|
3
|
|
|
3
|
|
9117
|
use Crypt::CapnMidNite 1.00; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Time::Local; |
6
|
|
|
|
|
|
|
use Sys::Hostname; |
7
|
|
|
|
|
|
|
use vars qw($VERSION $ptr2_License); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$ptr2_License = {'next' => ''}; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 2.04 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# put the package name of the segement to print in DEBUG |
14
|
|
|
|
|
|
|
# or 'ALL' to print all packages |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
my $DEBUG = 0;#'ALL'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
##### pre-defines |
19
|
|
|
|
|
|
|
my $seek_caller = sub { |
20
|
|
|
|
|
|
|
my ($i) = @_; # exclude call to this sub |
21
|
|
|
|
|
|
|
$i++; |
22
|
|
|
|
|
|
|
my $p; |
23
|
|
|
|
|
|
|
while(@_=caller($i)){ |
24
|
|
|
|
|
|
|
$last = $i; |
25
|
|
|
|
|
|
|
($p = $_[0]) =~ s#::#/#g; |
26
|
|
|
|
|
|
|
# print STDERR ($i-1),' 0=',$_[0],' 2=', $_[2], ' 3=', $_[3], "\n"; |
27
|
|
|
|
|
|
|
last if $_[2] > 2 && $_[0] !~ /AutoLoader/ && |
28
|
|
|
|
|
|
|
$_[1] !~ /^\(eval/ && $_[1] !~ m|$p/.+\.al$|; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
++$i; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
return ($i-1,@_); |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $print_err = sub { |
36
|
|
|
|
|
|
|
print STDERR @_; |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# useage: (callerlevel, @caller) |
40
|
|
|
|
|
|
|
my $pcaller = sub { |
41
|
|
|
|
|
|
|
&$print_err('########## level ', (shift @_), "\n") if $DEBUG; |
42
|
|
|
|
|
|
|
my @caller = ('package','file','line','subr','hasargs','wantary','evaltxt','require',); |
43
|
|
|
|
|
|
|
# ignored => 'hints','bitmask'); |
44
|
|
|
|
|
|
|
my $end = ($#_ < 7) ? $#_ : 7; |
45
|
|
|
|
|
|
|
foreach my $i(0..$end) { |
46
|
|
|
|
|
|
|
$_[$i] = '' unless $_[$i]; |
47
|
|
|
|
|
|
|
&$print_err("$caller[$i]\t= $_[$i]\n") if $DEBUG; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my ($user,$grp,$pwd); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$user_info = sub { |
54
|
|
|
|
|
|
|
($pwd) = @_; |
55
|
|
|
|
|
|
|
$user = (getpwuid( (stat($pwd))[4] ))[0]; |
56
|
|
|
|
|
|
|
$grp = (getgrgid( (stat($pwd))[5] ))[0]; |
57
|
|
|
|
|
|
|
my $i; |
58
|
|
|
|
|
|
|
if ( $pwd !~ m|^/| ) { |
59
|
|
|
|
|
|
|
$i = `/bin/pwd`; |
60
|
|
|
|
|
|
|
$i =~ s/\s+//g; |
61
|
|
|
|
|
|
|
$pwd = $i .'/'. $pwd; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
$pwd =~ s#/\./#/#g; |
64
|
|
|
|
|
|
|
@_ = split('/',$pwd); |
65
|
|
|
|
|
|
|
$pwd= ''; |
66
|
|
|
|
|
|
|
$#_ -=1; |
67
|
|
|
|
|
|
|
while($i = pop @_) { |
68
|
|
|
|
|
|
|
do { pop @_; next; } if $i eq '..'; |
69
|
|
|
|
|
|
|
$pwd = "/$i" . $pwd; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
##### code |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $host = &Sys::Hostname::hostname; |
76
|
|
|
|
|
|
|
($host = "\L$host") =~ s/\s+//g; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
&$user_info((caller)[1]); # defaults |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub import { |
81
|
|
|
|
|
|
|
my ($alm) = ((caller)[1] =~ m|.+/auto/(.+)/.+\.al$|); |
82
|
|
|
|
|
|
|
my $level=0; |
83
|
|
|
|
|
|
|
my $i; |
84
|
|
|
|
|
|
|
my $ptr; |
85
|
|
|
|
|
|
|
while (1) { |
86
|
|
|
|
|
|
|
($level, @_) = &$seek_caller($level); |
87
|
|
|
|
|
|
|
# package name in [0] |
88
|
|
|
|
|
|
|
###$i=0; |
89
|
|
|
|
|
|
|
###while(caller($i)) { ++$i } |
90
|
|
|
|
|
|
|
###@_ = caller($i-1); |
91
|
|
|
|
|
|
|
$ptr = (defined ${"$_[0]::ptr2_License"}) |
92
|
|
|
|
|
|
|
? ${"$_[0]::ptr2_License"} : ''; |
93
|
|
|
|
|
|
|
last unless $ptr; |
94
|
|
|
|
|
|
|
last unless exists $ptr->{next}; |
95
|
|
|
|
|
|
|
++$level; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
if($DEBUG){ |
98
|
|
|
|
|
|
|
&$print_err("\n\t\t\tXxXxXxXxXxXxXx $level\n"); |
99
|
|
|
|
|
|
|
$i=0; |
100
|
|
|
|
|
|
|
while(@_=caller($i)){ |
101
|
|
|
|
|
|
|
&$pcaller($i,@_); |
102
|
|
|
|
|
|
|
++$i; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if ( $ptr ) { |
107
|
|
|
|
|
|
|
&$user_info($ptr->{path}); |
108
|
|
|
|
|
|
|
(my @lic = &get_file($ptr->{path})) || |
109
|
|
|
|
|
|
|
die "could not open license file for $user"; |
110
|
|
|
|
|
|
|
my %parms; |
111
|
|
|
|
|
|
|
$#lic = &extract(\@lic,\%parms) -1; |
112
|
|
|
|
|
|
|
my $expire = 0; |
113
|
|
|
|
|
|
|
if ( exists $parms{EXP} ) { # if the EXPiration is present |
114
|
|
|
|
|
|
|
($expire = &date2time($parms{EXP})) || |
115
|
|
|
|
|
|
|
die "invalid expiration date $user license"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
@_ = split('/',(caller)[1]); # last element |
118
|
|
|
|
|
|
|
if ( $_[$#_] =~ /\.pm$/ ) { |
119
|
|
|
|
|
|
|
@_ = split(/\./,$_[$#_]); # remove extension |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
my $key = $_[$#_-1]; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
unless ( exists $ptr->{$key} ) { |
124
|
|
|
|
|
|
|
@_ = (); |
125
|
|
|
|
|
|
|
if (exists $ptr->{private}) { |
126
|
|
|
|
|
|
|
@_ = split(',',$ptr->{private}); |
127
|
|
|
|
|
|
|
foreach $i (0..$#_) { |
128
|
|
|
|
|
|
|
$_[$i] = join('/',split('::',$_[$i])); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
my $match = (caller)[1]; |
132
|
|
|
|
|
|
|
if (grep($match =~ /$_\.pm$/,@_)) { |
133
|
|
|
|
|
|
|
$ptr->{$key} = $parms{KEY} or die "missing private key $user"; |
134
|
|
|
|
|
|
|
} else { |
135
|
|
|
|
|
|
|
$ptr->{$key} = $parms{PKEY} or die "missing public key $user"; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
delete $parms{KEY}; |
139
|
|
|
|
|
|
|
delete $parms{PKEY}; |
140
|
|
|
|
|
|
|
my %chk; |
141
|
|
|
|
|
|
|
&get_vals(\%parms,\%chk); |
142
|
|
|
|
|
|
|
@_ = keys %chk; |
143
|
|
|
|
|
|
|
@{parms}{@_} = @{chk}{@_}; |
144
|
|
|
|
|
|
|
@_ = sort keys %parms; |
145
|
|
|
|
|
|
|
push @lic,@_,@{parms}{@_},$expire,$ptr->{$key}; |
146
|
|
|
|
|
|
|
my $bu = Crypt::CapnMidNite->new; |
147
|
|
|
|
|
|
|
my $expires = $bu->license(@lic); |
148
|
|
|
|
|
|
|
$ptr->{expires} = $expires if $expires; |
149
|
|
|
|
|
|
|
my $h = '# Module'; |
150
|
|
|
|
|
|
|
my $f = length $h; |
151
|
|
|
|
|
|
|
my $s = ''; |
152
|
|
|
|
|
|
|
filter_add( |
153
|
|
|
|
|
|
|
sub { |
154
|
|
|
|
|
|
|
my $status = filter_read; |
155
|
|
|
|
|
|
|
$bu->crypt($_); |
156
|
|
|
|
|
|
|
$s .= $_ if $f; |
157
|
|
|
|
|
|
|
$f = 0 if $s =~ /^$h/o; |
158
|
|
|
|
|
|
|
if ( $f && length($s) > $f) { |
159
|
|
|
|
|
|
|
$_ = ''; |
160
|
|
|
|
|
|
|
$status = -1; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
if (!$status && $alm) { |
163
|
|
|
|
|
|
|
$alm =~ s#/#::#g; |
164
|
|
|
|
|
|
|
unless (defined ${"${alm}::ptr2_License"}) { |
165
|
|
|
|
|
|
|
%{"${alm}::_LicHash"} = ('next' => $alm); |
166
|
|
|
|
|
|
|
${"${alm}::ptr2_License"} = \%{"${alm}::_LicHash"}; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
return $status; |
170
|
|
|
|
|
|
|
}); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
############################################################# |
176
|
|
|
|
|
|
|
# check each field for validity |
177
|
|
|
|
|
|
|
# |
178
|
|
|
|
|
|
|
# input: parm |
179
|
|
|
|
|
|
|
# |
180
|
|
|
|
|
|
|
my $check = { |
181
|
|
|
|
|
|
|
'SERV' => sub { # http server domain or input string |
182
|
|
|
|
|
|
|
return ( exists $ENV{SERVER_NAME} ) ? "\L$ENV{SERVER_NAME}" : $_[0]; }, |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
'HOST' => sub { # local fqdn |
185
|
|
|
|
|
|
|
return $host; }, |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
'USER' => sub { # local user name |
188
|
|
|
|
|
|
|
return $user; }, |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
'GROUP' => sub { # local group name |
191
|
|
|
|
|
|
|
return $grp; }, |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
'HOME' => sub { # check for match on working directory path to input string |
194
|
|
|
|
|
|
|
$pwd =~ /($_[0])/; # contains the match string |
195
|
|
|
|
|
|
|
return $1 || ''; }, |
196
|
|
|
|
|
|
|
}; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub date2time { |
199
|
|
|
|
|
|
|
my ($ds) = @_; |
200
|
|
|
|
|
|
|
return 0 unless $ds; |
201
|
|
|
|
|
|
|
my %month = ( |
202
|
|
|
|
|
|
|
'jan' => 0, |
203
|
|
|
|
|
|
|
'feb' => 1, |
204
|
|
|
|
|
|
|
'mar' => 2, |
205
|
|
|
|
|
|
|
'apr' => 3, |
206
|
|
|
|
|
|
|
'may' => 4, |
207
|
|
|
|
|
|
|
'jun' => 5, |
208
|
|
|
|
|
|
|
'jul' => 6, |
209
|
|
|
|
|
|
|
'aug' => 7, |
210
|
|
|
|
|
|
|
'sep' => 8, |
211
|
|
|
|
|
|
|
'oct' => 9, |
212
|
|
|
|
|
|
|
'nov' => 10, |
213
|
|
|
|
|
|
|
'dec' => 11, |
214
|
|
|
|
|
|
|
); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
$ds =~ s/\s+/ /g; # all white space to space |
217
|
|
|
|
|
|
|
$ds =~ s/^\s+//; # zap leading white space |
218
|
|
|
|
|
|
|
$ds =~ s/\s+$//; # zap trailing white space |
219
|
|
|
|
|
|
|
$ds =~ s/,//g; # zap commas |
220
|
|
|
|
|
|
|
$ds = "\L$ds"; # lower case |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
return 0 unless $ds; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
my ($m,$d,$y) = split(m|[\- /]|,$ds); |
225
|
|
|
|
|
|
|
if ( $m =~ /\D/ ) { |
226
|
|
|
|
|
|
|
@_ = grep($m =~ /^$_/, keys %month); |
227
|
|
|
|
|
|
|
return 0 unless @_ && exists $month{$_[0]}; |
228
|
|
|
|
|
|
|
$m = $month{$_[0]}; |
229
|
|
|
|
|
|
|
} else { |
230
|
|
|
|
|
|
|
--$m; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
return 0 if ($m . $d . $y) =~ /\D/; |
233
|
|
|
|
|
|
|
$y -= 1900 if $y > 1900; |
234
|
|
|
|
|
|
|
# # NOTE: Y 2070 problem <<<**** |
235
|
|
|
|
|
|
|
$y += 100 if $y < 70; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# range check |
238
|
|
|
|
|
|
|
return 0 if ( "$m$d$y" =~ /\D/ ); # not numeric |
239
|
|
|
|
|
|
|
# return 0 if $y < 70; |
240
|
|
|
|
|
|
|
return 0 if $y > 169; # NOTE: Y 2070 problem <<<**** |
241
|
|
|
|
|
|
|
return 0 if $m > 11 || $m < 0; |
242
|
|
|
|
|
|
|
return 0 if $d > 31 || $d < 1; |
243
|
|
|
|
|
|
|
return timelocal(59,59,23,$d,$m,$y); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub get_file { |
247
|
|
|
|
|
|
|
my($fd) = @_; |
248
|
|
|
|
|
|
|
my $i; |
249
|
|
|
|
|
|
|
return () unless (-e $fd) && # punt if the file is missing |
250
|
|
|
|
|
|
|
open(F,$fd); # or won't open |
251
|
|
|
|
|
|
|
my @txt = (); |
252
|
|
|
|
|
|
|
my $started = 0; |
253
|
|
|
|
|
|
|
while ($i = ) { |
254
|
|
|
|
|
|
|
next unless $started || $i =~ /\S/; # strip leading blank lines |
255
|
|
|
|
|
|
|
$started = 1 unless $started; |
256
|
|
|
|
|
|
|
$i =~ s/\t+/ /g; |
257
|
|
|
|
|
|
|
$i =~ s/\s+$//; # strip trailing white space |
258
|
|
|
|
|
|
|
push(@txt, $i); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
return @txt; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub extract { |
264
|
|
|
|
|
|
|
my($txt,$parms) = @_; |
265
|
|
|
|
|
|
|
my ($i,$rv); |
266
|
|
|
|
|
|
|
foreach $i (0..$#{$txt}) { |
267
|
|
|
|
|
|
|
next unless $txt->[$i] =~ /:\s*:/; # find lines with tags |
268
|
|
|
|
|
|
|
$rv = $i unless $rv; # save first pointer |
269
|
|
|
|
|
|
|
my($tag,$val) = split(/:\s*:/, $txt->[$i], 2); |
270
|
|
|
|
|
|
|
$tag =~ s/\s+//; # remove any white space in tag |
271
|
|
|
|
|
|
|
$val = '' unless $val; |
272
|
|
|
|
|
|
|
$val = "\L$val" if $tag eq 'HOST' || $tag eq 'SERV'; |
273
|
|
|
|
|
|
|
$parms->{$tag} = $val; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
return $rv; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
# if check subroutine exists, return value with parms value as input |
279
|
|
|
|
|
|
|
sub get_vals { |
280
|
|
|
|
|
|
|
my($parms,$chk_vals) = @_; |
281
|
|
|
|
|
|
|
foreach my $i (keys %$parms) { |
282
|
|
|
|
|
|
|
$chk_vals->{$i} = &{$check->{$i}}($parms->{$i}) if exists $check->{$i}; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
1; |