script/examineAC.pl untested

filter: Statementstmt 0.0% 0 / 90 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 242 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use VOMS::Lite::PEMHelper qw(readAC);
4 use VOMS::Lite::ASN1Helper qw(Hex);
5 use VOMS::Lite::AC;
6 use Pod::Simple::Text;
7 use VOMS::Lite::PEMHelper qw(encodeAC);
8  
9 my $ac=undef;
10 my %input=(End=>"",FQANs=>"",HolderIssuerDN=>"",Start=>"",IssuerDN=>"",Verify=>"");
11 my $name=$0;
12 my ($basename)=$name =~ m|([^/]*)$|;
13 my $noout=0;
14  
15 while ($_=shift @ARGV) {
16 if ( /^(--?ac)$/ ) {
17 $ac=shift @ARGV;
18 die "$1 requires an argument" if ( ! defined $ac );
19 die "cannot open ac file $ac" if ( ! -r "$ac" );
20 }
21 elsif ( /--?noout$/ ) {
22 $noout=1;
23 }
24 elsif ( /^(--?help)$/ ) { Pod::Simple::Text->filter($name); exit 0; }
25 else { die "Unrecognised option: try \"$basename -help\""; }
26 }
27  
28 if ( ! defined $ac ) {
29 if ( defined $ENV{VOMS_USER_AC} && $ENV{VOMS_USER_AC} =~ /(.*)/ ) { $ac=$1; }
30 else { $ac="/tmp/vomsAC_u$<" };
31 }
32  
33 my @ac=readAC($ac);
34  
35 my @AC=VOMS::Lite::AC::Examine($ac[0],{End=>"",FQANs=>"",HolderIssuerDN=>"",Start=>"",IssuerDN=>"",Verify=>""} );
36  
37 my $time=time();
38  
39 foreach (@AC) {
40 my %hash=%{ $_ };
41 if ( $hash{Verify} ) {
42 print "The AC validates against the ".(($hash{InternalVOMSCert} eq "Attached" )?"attached":"locally stored")." valid certificate $hash{IssuerDN}\n";
43 }
44 foreach (keys %hash ) {
45 if (defined $hash{$_} ) {
46
47 if ( $_ ne "Verify" ) {print "$_, ".((ref($hash{$_}) eq "ARRAY")?join(', ',@{ $hash{$_} }):$hash{$_})."\n"; }
48 }
49 }
50  
51 if ( $time < $hash{'Start'} ) {
52 my $tl=$hash{Start};
53 my $y = int( $tl / 31556736 ); $tl %= 31556736;
54 my $d = int( $tl / 86400 ); $tl %= 86400;
55 my $h = int( $tl / 3600 ); $tl %= 3600;
56 my $m = int( $tl / 60 ); $tl %= 60;
57 my $s = $tl;
58 my $timeleftstr = (($timeleft>0) ? (( ($y>0) ? "$y years, " : "").
59 ( ($d>0||$y>0) ? "$d days, " : "").
60 ( ($h>0||$d>0||$y>0) ? "$h hours, " : "").
61 ( ($m>0||$h>0||$d>0||$y>0) ? "$m minutes, " : "").
62 ( ($s>0||$m>0||$h>0||$d>0||$y>0) ? "$s seconds, " : ""))
63 : "0 seconds" );
64 print "Valid in $timeleftstr\n";
65 }
66  
67 if ( $time > $hash{'End'} ) {
68 my $tl=$hash{End};
69 my $y = int( $tl / 31556736 ); $tl %= 31556736;
70 my $d = int( $tl / 86400 ); $tl %= 86400;
71 my $h = int( $tl / 3600 ); $tl %= 3600;
72 my $m = int( $tl / 60 ); $tl %= 60;
73 my $s = $tl;
74 my $timeleftstr = (($timeleft>0) ? (( ($y>0) ? "$y years, " : "").
75 ( ($d>0||$y>0) ? "$d days, " : "").
76 ( ($h>0||$d>0||$y>0) ? "$h hours, " : "").
77 ( ($m>0||$h>0||$d>0||$y>0) ? "$m minutes, " : "").
78 ( ($s>0||$m>0||$h>0||$d>0||$y>0) ? "$s seconds, " : ""))
79 : "0 seconds" );
80 print "Expires in $timeleftstr\n";
81 }
82 print "\n";
83 }
84  
85 print "".encodeAC(@ac)."\n" if ( $noout == 0 );
86  
87 __END__