resolve.in 2.01 KB
Newer Older
1
2
#!/usr/bin/perl -w
#
3
# GENIPUBLIC-COPYRIGHT
Leigh B Stoller's avatar
Leigh B Stoller committed
4
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
use Data::Dumper;

#
# Resolve a uuid or hrn at the clearinghouse or an SA.
# 
sub usage()
{
    print "Usage: resolve <type> [uuid | hrn]\n";
    exit(1);
}
my $optlist = "";
my $uuid;
my $hrn;

#
# Configure variables
#
my $TB		  = "@prefix@";
my $TBOPS         = "@TBOPSEMAIL@";
my $TBLOGS        = "@TBLOGSEMAIL@";
my $PGENIDOMAIN   = "@PROTOGENI_DOMAIN@";
my $PGENISUPPORT  = @PROTOGENI_SUPPORT@;
my $SACERT	  = "$TB/etc/genisa.pem";

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

# Protos
sub fatal($);

#
# Turn off line buffering on output
#
$| = 1; 

# Now we can load the libraries after setting the proper DB.
use lib '@prefix@/lib';
use libaudit;
use GeniDB;
use GeniCertificate;
use GeniAuthority;
use GeniRegistry;
use Genixmlrpc;

#
# Check args.
#
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
usage()
    if (@ARGV != 2);
my $type  = $ARGV[0];
my $token = $ARGV[1];

if ($type =~ /^([\w]*)$/) {
    $type = $1;
}
else {
    fatal("Illegal chars in type: $type");
}

#
# Load the SA cert to act as caller context.
#
my $certificate = GeniCertificate->LoadFromFile($SACERT);
if (!defined($certificate)) {
    fatal("Could not load certificate from $SACERT\n");
}
my $context = Genixmlrpc->Context($certificate);
if (!defined($context)) {
    fatal("Could not create context to talk to clearinghouse");
}
my $clearinghouse = GeniRegistry::ClearingHouse->Create($context);
if (!defined($clearinghouse)) {
    fatal("Could not create a clearinghouse client");
}

my $value;

if ($clearinghouse->Resolve($token, uc($type), \$value) != 0) {
    fatal("Could not resolve $token at the clearinghouse");
}
print Dumper($value);
exit(0);

sub fatal($)
{
    my ($msg) = @_;

    print STDERR "*** $0:\n".
	         "    $msg\n";
    # exit value important.
    exit(-1);
}