script/voms-proxy-list.pl untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 145 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::VOMS;
4 use VOMS::Lite::PEMHelper qw(readCert readAC readPrivateKey writeCertKey decodeCert);
5 use VOMS::Lite::ASN1Helper qw(ASN1Wrap ASN1Unwrap DecToHex Hex ASN1BitStr);
6 use VOMS::Lite::PROXY;
7  
8 my $name=$0;
9 my $lname=length($name);
10 $name =~ s#.*/##g;
11 my $usage = "Usage: $name vomss://voms.server:port/VO [ -cert /path/to/cert.pem ]\n".
12 " " x ($lname+8). "[ -key /path/to/cert's/key.pem ]\n".
13 " " x ($lname+8). "[ -CApath /path/to/CA/directory (to verify VOMS server against) ]\n".
14 " " x ($lname+8). "[ -verbose ]\n";
15  
16 my %Input;
17 my $HolderCert="$ENV{HOME}/.globus/usercert.pem";
18 my $HolderKey="$ENV{HOME}/.globus/userkey.pem";
19 my $CAPath="/etc/grid-security/certificates";
20 if ( defined $ENV{"X509_CERT_PATH"} && $ENV{"X509_CERT_PATH"} =~ /(.*)/ ) { $CAPath=$1; };
21 my $outfile="/tmp/x509up_u$<";
22 if ( defined $ENV{"X509_USER_PROXY"} && $ENV{"X509_USER_PROXY"} =~ /(.*)/ ) { $outfile=$1; };
23 my @VOMSURI;
24 my $verbose=0;
25  
26 while ($_=shift @ARGV) {
27 if ( /^--?cert$/ ) {
28 $HolderCert=shift @ARGV;
29 die "$& requires an argument" if ( ! defined $HolderCert );
30 die "cannot open certificate file $HolderCert" if ( ! -r $HolderCert );
31 }
32 elsif ( /^--?key$/ ) {
33 $HolderKey=shift @ARGV;
34 die "$& requires an argument" if ( ! defined $HolderKey );
35 die "cannot open certificate file $HolderKey" if ( ! -r $HolderKey );
36 }
37 elsif ( /^--?CApath$/ ) {
38 $CAPath=shift @ARGV;
39 die "$& requires an argument" if ( ! defined $CAPath );
40 die "$CAPath is not a directory" if ( ! -d $CAPath );
41 die "cannot open CA directory $CAPath" if ( ! -r $CAPath );
42 }
43 elsif ( /^vomss:\/\/.*$/ ) {
44 push @VOMSURI,$&;
45 }
46 elsif ( /^https:\/\/.*$/ ) {
47 push @VOMSURI,$&;
48 }
49 elsif ( /^--?v(?:erbose)?$/ ) { $verbose=1; }
50 elsif ( /^--?debug$/ ) { $VOMS::Lite::VOMS::DEBUG="yes"; $verbose=1; }
51 else { die "Unrecognised option \"$_\"\n$usage"; }
52 }
53  
54 # Then make load a cert
55 my @decodedCERTS=readCert($HolderCert);
56 $Input{'Cert'}=$decodedCERTS[0];
57 $Input{'Key'}=readPrivateKey($HolderKey);
58  
59 $ENV{HTTPS_CA_DIR} = $CAPath;
60 $ENV{HTTPS_CERT_FILE} = $HolderCert;
61 $ENV{HTTPS_KEY_FILE} = $HolderKey;
62  
63 my %URI;
64 foreach (@VOMSURI) {
65 if ( m|(vomss://[^:]+:[^/]+/[^/]+)| ) {
66 $URI{$1}="";
67 } elsif ( m|https://[^:]+(?::[0-9]{1,5})?/.+| ) {
68 die "https scheme currently unsupported."
69 }
70 else {
71 die "Baddly formatted VO string \"$_\"\n$usage";
72 }
73 }
74  
75 my @FQANs;
76 foreach my $URI (keys %URI) {
77 if ( $URI =~ m|vomss://([^:]+):([^/]+)/([^/]+)?| ) {
78 print "Contacting $URI for using $HolderCert\n" if ($verbose);
79 my $ref = VOMS::Lite::VOMS::List( { Server => "$1",
80 Port => $2,
81 VO => $3,
82 CAdirs => $CAPath,
83 Cert => $Input{'Cert'},
84 Key => $Input{'Key'} } );
85  
86 if (@{ ${ $ref }{Errors} } ) { print "Errors:\n ".(join "\n ", @{ ${ $ref }{Errors} }).".\n"; die "Failed to list ".$URI; }
87 if (@{ ${ $ref }{Warnings} } and $verbose==1) { print "Warnings for $1:$2\n ".(join "\n ", @{ ${ $ref }{Warnings} }).".\n"; }
88  
89 foreach (@{ ${ $ref }{FQANs} } ) { push @FQANs,$_; }
90 }
91 }
92  
93 print join("\n",@FQANs)."\n";
94 exit;
95  
96 __END__