source: examples/example_scripts/perl/abac_attr.pl @ d6439d4

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since d6439d4 was 4721618, checked in by Mei <mei@…>, 12 years ago

1) tested out python and perl test scripts along with

abac_chunk_t calls in libabac's abac.hh

  • Property mode set to 100755
File size: 1.3 KB
RevLine 
[4721618]1#!/usr/bin/perl
2
3use strict;
4use ABAC;
5use Getopt::Long;
6use Data::Dumper;
7$Data::Dumper::Indent = 1;
8
9my ($idfile, $keyfile, $id2file, $attrxml);
10GetOptions(
11    'id=s'      => \$idfile,
12    'key=s'     => \$keyfile,
13    'id2=s'     => \$id2file,
14    'attr=s'    => \$attrxml,
15) || usage();
16
17usage() unless defined $idfile && defined $keyfile && $id2file && defined $attrxml;
18
19my $ctx = ABAC::Context->new;
20
21my $ice;
22my $choco;
23eval {
24    # will throw a RuntimeException if it can't load the cert
25    $ice = ABAC::ID->new($idfile);
26    $ice->load_privkey($keyfile);
27    $choco = ABAC::ID->new($id2file);
28};
29if ($@) {
30    print "ERROR, Problem loading cert: $@";
31    exit;
32}
33print $ice->keyid, "   , ice cream\n";
34print $choco->keyid, "   , chocolate\n";
35
36my $attr;
37eval {
38    $attr = ABAC::Attribute->new($ice,"delicious",1000);
39    $attr->principal($choco->keyid());
40    $attr->bake();
41};
42
43if ($@) {
44    print "ERROR, Problem baking attribute: $@";
45    exit;
46}
47
48eval {
49    $attr->write_file($attrxml);
50};
51if ($@) {
52    print "ERROR, Problem writing attribute's xml file: $@";
53    exit;
54}
55
56sub usage {
57    print "Usage: $0 \\\n";
58    print "        --id <idfile> --key <keyfile> \n";
59    print "        --id2 <id2file> --attr <attrxml>\n";
60    print "    loads id/key, id2, and makes attr\n";
61    exit 1;
62}
63
Note: See TracBrowser for help on using the repository browser.