Index: examples/example_scripts/Makefile
===================================================================
--- examples/example_scripts/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,28 @@
+
+DIRECTORY=c perl python
+
+.PHONY : runcheck clean 
+runcheck: $(DIRECTORY)
+
+clean:
+	@for i in $(DIRECTORY); do \
+	here=`pwd`; \
+	cd $$i; \
+	make -s clean; \
+	cd $$here; \
+	done 
+	@rm -rf allout.tmp
+
+runcheck:
+	@echo 'running libabac SCRIPT testing...'
+	@for i in $(DIRECTORY); do \
+	here=`pwd`; \
+	cd $$i; \
+	printf "\n ==> RUN on %s\n" "$$i" >> ../allout.tmp ; \
+	./run_test 1 >> ../allout.tmp 2>& 1; \
+	cd $$here; \
+	done 
+	@if test -f allout.tmp && test `diff -q allout.save allout.tmp |wc -l ` -eq 0 ; \
+	then echo "   PASSED"; \
+	else echo "   ERROR:got changes!!!"; \
+	fi
Index: examples/example_scripts/README
===================================================================
--- examples/example_scripts/README	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/README	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,15 @@
+
+
+This directory does regression testing of
+example scripts that were under libabac's swig 
+directory
+
+
+to run,  
+   
+   runcheck
+
+
+NOTE:
+   Perl, make sure your perl is linked with a thread library even if
+it is not thread enabled. Check with ldd or perl -V
Index: examples/example_scripts/allout.save
===================================================================
--- examples/example_scripts/allout.save	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/allout.save	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,28 @@
+
+ ==> RUN on c
+---running (c) attr script
+   PASSED
+---running (c) prover script
+   PASSED
+
+ ==> RUN on perl
+---running (perl) id script
+   PASSED
+---running (perl) id2 script, expected failure
+   PASSED
+---running (perl) attr script
+   PASSED
+---running (perl) prover script
+   PASSED
+
+ ==> RUN on python
+---running (python) attr script
+   PASSED
+---running (python) id script
+   PASSED
+---running (python) id2 script, expect failure
+   PASSED
+---running (python) id3 script, expect failure
+   PASSED
+---running (python) prover script
+   PASSED
Index: examples/example_scripts/c/Makefile
===================================================================
--- examples/example_scripts/c/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,53 @@
+
+LDFLAGS =-L/usr/local/lib -labac -lm -lpthread -Wl,-rpath
+
+all: attr prove tt
+
+abac_attr.o: abac_attr.c
+	gcc -g -I/usr/local/include -c abac_attr.c -o abac_attr.o
+
+abac_attr: abac_attr.o
+	gcc -g -o abac_attr abac_attr.o $(LDFLAGS)
+
+abac_prover.o: abac_prover.c
+	gcc -g -I/usr/local/include -c abac_prover.c -o abac_prover.o
+
+abac_prover: abac_prover.o
+	gcc -g -o abac_prover abac_prover.o $(LDFLAGS)
+
+tchunk: tchunk.c
+	gcc -g -I/usr/local/include -c tchunk.c -o tchunk.o
+	gcc -g -o tchunk tchunk.o $(LDFLAGS)
+	./tchunk 0 IceCream_ID.pem IceCream_private.pem
+	./tchunk 1 IceCream_ID.pem IceCream_private.pem
+
+tt: tbasic.c
+	gcc -g -I/usr/local/include -c tbasic.c -o tbasic.o
+	gcc -g -o tt tbasic.o $(LDFLAGS)
+	./tt
+
+clean:
+	@rm -rf abac_attr.o abac_attr *.pem *.xml abac_prover.o 
+	@rm -rf abac_prover *.log 
+	@rm -rf tt tbasic.o tbasic
+
+setup2: abac_attr abac_prover abac_attr_partial
+
+setup: abac_attr 
+	creddy --generate --cn IceCream
+	creddy --generate --cn Chocolate
+
+attr: 
+	rm -rf attr.log
+	make setup
+	./abac_attr IceCream_ID.pem  IceCream_private.pem IceCream_attr.xml Chocolate_ID.pem 1>attr.log 2>&1
+
+prove: abac_prover 
+	rm -rf prover.log
+	make attr
+	./run_prover 1>prover.log 2>&1
+
+mattr: attr.c
+	gcc -g -o mattr attr.c $(LDFLAGS)
+mload: loader.c
+	gcc -g -o mload loader.c $(LDFLAGS)
Index: examples/example_scripts/c/abac_attr.c
===================================================================
--- examples/example_scripts/c/abac_attr.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/abac_attr.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,88 @@
+/**
+   attr_abac.c
+
+   To demonstrate how to use ABAC's api in C
+
+   call:   attr_abac IceCream_ID.pem IceCream_private.pem IceCream_attr.der
+
+   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
+           creddy --generate --cn IceCream
+                  generate Chocolate_ID.pem and Chocolate_private.pem with
+           creddy --generate --cn IceCream
+
+   This program will generate an attribute rule, write it out to an external
+           file and also load it into the context (prolog db)
+           [keyid:IceCream].delicious <- [Keyid:Chocolate]
+
+   Then, a query is made against the context to see if it is populated correctly.
+
+./abac_attr IceCream_ID.pem  IceCream_private.pem IceCream_attr.der Chocolate_ID.pem
+**/
+
+#define _GNU_SOURCE
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <abac.h>
+
+extern char *abac_id_keyid(abac_id_t *id);
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+
+    if(argc != 5) return 1;
+
+    /* build up structure */
+    abac_id_t *id =NULL;
+    id = abac_id_from_file(argv[1]);
+    int rc=abac_id_privkey_from_file(id,argv[2]);
+
+    rc=abac_context_load_id_chunk(ctx, abac_id_cert_chunk(id));
+
+    abac_id_t *chocolate_id = abac_id_from_file(argv[4]);
+    rc=abac_context_load_id_chunk(ctx, abac_id_cert_chunk(chocolate_id));
+
+    abac_attribute_t *attr;
+    rc=abac_attribute_create(&attr, id, "delicious", 1800);
+    abac_attribute_principal(attr, abac_id_keyid(chocolate_id));
+    rc=abac_attribute_bake(attr);
+
+    printf(" attribute being made : %s\n",abac_attribute_role_string(attr));
+
+    abac_attribute_write_file(attr,argv[3]);
+    abac_context_load_attribute_chunk(ctx,abac_attribute_cert_chunk(attr));
+
+    char *tmp=NULL;
+    asprintf(&tmp,"%s.delicious",abac_id_keyid(id));
+
+    /* make a query */
+    credentials = abac_context_query(ctx,
+        tmp, abac_id_keyid(chocolate_id),
+        &success
+    );
+    fprintf(stderr,"query with %s\n",tmp);
+    fprintf(stderr,"      for %s\n",abac_id_keyid(chocolate_id));
+    int sz=abac_list_size(credentials);
+
+    if (success)
+        puts("attr success");
+    else
+        puts("fail, here's a partial proof");
+
+    if (credentials != NULL)
+        for (i = 0; credentials[i] != NULL; ++i) {
+            cred = credentials[i];
+            printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred))
+                  );
+        }
+    abac_context_credentials_free(credentials);
+    abac_context_free(ctx);
+    return 0;
+}
Index: examples/example_scripts/c/abac_prover.c
===================================================================
--- examples/example_scripts/c/abac_prover.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/abac_prover.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,99 @@
+/**
+   abac_prover.c
+
+   To demonstrate how to use ABAC's api in C to make a query
+
+   call:   abac_prover "keystorestring" "rolestring" "principalstring"
+
+   pre-condition: run make attr_abac  generate IceCream_ID.pem and IceCream_private.pem with
+
+   This program will make a prover call using 
+           rolestring <- principalstring
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+    abac_context_load_directory(ctx, argv[1]);
+
+    char *query=strdup(argv[2]);
+    char *with=strdup(argv[3]);
+
+    printf("query %s \n", query);
+    printf("with %s\n", with);
+
+int k=1; /* use to do repetitions */
+while(k) {
+    credentials = abac_context_query(ctx,
+                            query, with,
+                            &success);
+    if (success)
+        puts("prover success!!");
+        else puts("prover failed!!");
+
+    if (credentials != NULL && success) {
+        puts("credentials needed :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred)));
+        }
+    }
+    if(credentials)
+        abac_context_credentials_free(credentials);
+    k=k-1;
+}
+
+
+{ /* dump credentials from context */
+    printf("\n\n");
+    credentials = abac_context_credentials(ctx);
+    printf("Dump context credentials, original ctx \n");
+    if (credentials != NULL) {
+        puts("context credentials :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred)));
+        }
+    }
+    if(credentials)
+        abac_context_credentials_free(credentials);
+}
+
+    abac_context_t *ctx2 = abac_context_dup(ctx);
+{ /* dump credentials from context */
+    printf("\n\n");
+    credentials = abac_context_credentials(ctx);
+    printf("Dump context credentials, original ctx2 \n");
+    if (credentials != NULL) {
+        puts("context credentials :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred)));
+        }
+    }
+    if(credentials)
+        abac_context_credentials_free(credentials);
+}
+
+    abac_context_free(ctx);
+    abac_context_free(ctx2);
+
+    return 0;
+}
Index: examples/example_scripts/c/loader.c
===================================================================
--- examples/example_scripts/c/loader.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/loader.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,100 @@
+/**
+CAN NOT RUN
+
+   loader.c
+
+   To demonstrate how to use ABAC's api in C to load credentials
+
+   some not implemented yet 
+
+   call:   abac_load 
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+    int rc;
+
+fprintf(stderr, "\n         --- load from directory\n");
+    if(argc==2)
+        abac_context_load_directory(ctx, argv[1]); 
+        else
+            abac_context_load_directory(ctx, "."); 
+
+fprintf(stderr, "\n         --- load from chunk\n");
+    abac_id_t *tid;
+    abac_id_generate(&tid,"Tim", 0);
+    abac_chunk_t chunk=abac_id_cert_chunk(tid);
+    tid=abac_id_from_chunk(chunk);
+XXX  not implemented yet.. 
+    rc=abac_context_load_id(ctx,tid); 
+
+fprintf(stderr, "\n         --- load from id_gen\n");
+    abac_id_t *id;
+    abac_id_generate(&id,"Mary", 0);
+    abac_id_write_cert_fname(id,"Mary_ID.pem");
+    abac_id_write_privkey_fname(id,"Mary_private.pem");
+fprintf(stderr, "\n         --- load from explicit call\n");
+/*    int rc=abac_context_load_id_id_key_files(ctx,"Mary_ID.pem","Mary_private.pem"); */ 
+    rc=abac_context_load_id(ctx,id); 
+
+   
+fprintf(stderr, "\n         --- load with idkey file\n");
+    abac_id_t *id2;
+    abac_id_generate(&id2,"Tom", 0);
+    abac_id_write_cert_fname(id2,"Tom_IDKEY.pem");
+    abac_id_write_privkey_fname(id2,"Tom_IDKEY.pem");
+    rc=abac_context_load_id_file(ctx,"Tom_IDKEY.pem"); 
+
+{
+    printf("\n\n");
+    credentials = abac_context_credentials(ctx);
+    if (credentials != NULL) {
+        puts("context credentials :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           abac_print_typed_cred_info(cred,NULL);
+        }
+    }
+    if(credentials)
+        abac_free_credentials(credentials);
+}
+{
+    abac_id_credential_t *id_cred=NULL;
+    abac_id_credential_t **id_credentials=NULL;
+    printf("\n\n");
+    id_credentials = abac_context_principals(ctx);
+    if (id_credentials != NULL) {
+        puts("principal credentials :");
+        for (i = 0; id_credentials[i] != NULL; ++i) {
+           id_cred = id_credentials[i];
+           abac_print_prin_info(id_cred,NULL);
+        }
+    }
+    if(id_credentials)
+        abac_free_principals(id_credentials);
+}
+
+    show_yap_db("yap db");
+
+fprintf(stderr,"\n          --- id free from explicit call\n");
+    abac_id_free(id);
+    abac_id_free(id2);
+
+fprintf(stderr,"\n          --- explicitly free the context \n");
+    abac_context_free(ctx);
+
+fprintf(stderr,"\n          --- that is it \n");
+    return 0;
+}
Index: examples/example_scripts/c/run_prover
===================================================================
--- examples/example_scripts/c/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+keystore=`pwd`
+pID=`creddy --keyid --cert ${keystore}/IceCream_ID.pem`
+cID=`creddy --keyid --cert ${keystore}/Chocolate_ID.pem`
+
+role="${pID}.delicious"
+principal="${cID}"
+
+./abac_prover "$keystore" "$role" "$principal"
+
+#echo "$keystore" "$role" "$principal"
+#gdb ./abac_prover
+
+
+
Index: examples/example_scripts/c/run_test
===================================================================
--- examples/example_scripts/c/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,22 @@
+#!/bin/sh 
+
+make -s clean
+
+echo '---running (c) attr script'
+make attr 1>/dev/null 2>& 1
+result=`grep "attr success" attr.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (c) prover script'
+make prove 1>/dev/null 2>& 1
+result=`grep "prover success" prover.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
Index: examples/example_scripts/c/tbasic.c
===================================================================
--- examples/example_scripts/c/tbasic.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/tbasic.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,27 @@
+/**
+   tbasic.c
+
+   bring up and taking down a context
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    printf("calling main ..\n");
+    abac_context_t *ctxt = abac_context_new();
+    abac_context_t *ctxt2 = abac_context_new();
+    printf("done calling main ..\n");
+
+    abac_context_free(ctxt2);
+
+    return 0;
+}
Index: examples/example_scripts/c/tchunk.c
===================================================================
--- examples/example_scripts/c/tchunk.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/c/tchunk.c	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,44 @@
+/**
+CAN NOT RUN
+   tchunk.c
+   chunking test, no ready yet
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <abac.h>
+
+extern void abac_print_cred_info(abac_credential_t*, FILE*);
+extern char *abac_id_keyid(abac_id_t *id);
+extern abac_attribute_t *abac_attribute_add_tail(abac_attribute_t *ptr, abac_aspect_t *);
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+
+    if(argc != 4) return 1;
+
+    /* build up structure */
+    abac_id_t *id =NULL;
+    id = abac_id_from_file(argv[2]);
+    int rc=abac_id_privkey_from_file(id,argv[3]);
+
+    int w=atoi(argv[1]);
+    if(w==0) {
+        printf("USING chunk...\n");
+        rc=abac_context_load_id_chunk(ctx, abac_id_cert_chunk(id));
+    } else {
+        printf("USING NO chunk...\n");
+/* no implemented 
+        rc=abac_context_load_id_id(ctx, id);  
+*/
+    }
+    abac_context_free(ctx);
+    return 0;
+}
Index: examples/example_scripts/perl/Makefile
===================================================================
--- examples/example_scripts/perl/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,28 @@
+all: run bad prove
+
+clean:
+	@rm -rf *.pem *.xml *.log 
+
+setup: 
+	creddy --generate --cn IceCream
+	creddy --generate --cn Chocolate
+	
+run: 
+	make clean
+	make setup
+	./abac_keyid.pl IceCream_ID.pem 1>id.log 2>&1 
+
+bad: 
+	make clean
+	make setup
+	./abac_keyid.pl IceCream_private.pem 1>id2.log 2>&1 
+
+attr: 
+	make clean
+	make setup
+	./run_attr 1 >attr.log 2>&1
+
+prove: 
+	make attr
+	./run_prover 1 >prover.log 2>&1
+
Index: examples/example_scripts/perl/abac_attr.pl
===================================================================
--- examples/example_scripts/perl/abac_attr.pl	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/abac_attr.pl	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+use strict;
+use ABAC;
+use Getopt::Long;
+use Data::Dumper;
+$Data::Dumper::Indent = 1;
+
+my ($idfile, $keyfile, $id2file, $attrxml);
+GetOptions(
+    'id=s'      => \$idfile,
+    'key=s'     => \$keyfile,
+    'id2=s'     => \$id2file,
+    'attr=s'    => \$attrxml,
+) || usage();
+
+usage() unless defined $idfile && defined $keyfile && $id2file && defined $attrxml;
+
+my $ctx = ABAC::Context->new;
+
+my $ice;
+my $choco;
+eval {
+    # will throw a RuntimeException if it can't load the cert
+    $ice = ABAC::ID->new($idfile);
+    $ice->load_privkey($keyfile);
+    $choco = ABAC::ID->new($id2file);
+};
+if ($@) {
+    print "ERROR, Problem loading cert: $@";
+    exit;
+}
+print $ice->keyid, "   , ice cream\n";
+print $choco->keyid, "   , chocolate\n";
+
+my $attr;
+eval {
+    $attr = ABAC::Attribute->new($ice,"delicious",1000);
+    $attr->principal($choco->keyid());
+    $attr->bake();
+};
+
+if ($@) {
+    print "ERROR, Problem baking attribute: $@";
+    exit;
+}
+
+eval {
+    $attr->write_file($attrxml);
+};
+if ($@) {
+    print "ERROR, Problem writing attribute's xml file: $@";
+    exit;
+}
+
+sub usage {
+    print "Usage: $0 \\\n";
+    print "        --id <idfile> --key <keyfile> \n";
+    print "        --id2 <id2file> --attr <attrxml>\n";
+    print "    loads id/key, id2, and makes attr\n";
+    exit 1;
+}
+
Index: examples/example_scripts/perl/abac_keyid.pl
===================================================================
--- examples/example_scripts/perl/abac_keyid.pl	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/abac_keyid.pl	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use ABAC;
+
+my $filename = shift || die "Usage: abac_keyid.pl <cert.pem>\n";
+
+my $id;
+eval {
+    # will throw a RuntimeException if it can't load the cert
+    $id = ABAC::ID->new($filename);
+};
+if ($@) {
+    print "ERROR, Problem loading cert: $@";
+    exit;
+}
+
+print $id->keyid, "    OKAY\n";
Index: examples/example_scripts/perl/abac_prover.pl
===================================================================
--- examples/example_scripts/perl/abac_prover.pl	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/abac_prover.pl	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+use ABAC;
+use Getopt::Long;
+use Data::Dumper;
+$Data::Dumper::Indent = 1;
+
+my ($keystore, $role, $principal);
+GetOptions(
+    'keystore=s'    => \$keystore,
+    'role=s'        => \$role,
+    'principal=s'   => \$principal,
+) || usage();
+
+usage() unless defined $keystore && defined $role && defined $principal;
+
+# code starts here
+
+my $ctx = ABAC::Context->new;
+$ctx->load_directory($keystore);
+
+my ($success, $credentials) = $ctx->query($role, $principal);
+
+if ($success) {
+    print "Success\n";
+}
+
+foreach my $credential (@$credentials) {
+    printf "credential %s <- %s\n",
+        $credential->head->string,
+        $credential->tail->string;
+}
+
+sub usage {
+    print "Usage: $0 \\\n";
+    print "        --keystore <keystore> \\\n";
+    print "        --role <role> --principal <principal> \\\n";
+    print "    loads the keystore and runs the query role <-?- principal\n";
+    exit 1;
+}
Index: examples/example_scripts/perl/run_attr
===================================================================
--- examples/example_scripts/perl/run_attr	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/run_attr	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+./abac_attr.pl --id IceCream_ID.pem --key IceCream_private.pem --id2 Chocolate_ID.pem --attr delicious_attr.xml
+
+
+
Index: examples/example_scripts/perl/run_prover
===================================================================
--- examples/example_scripts/perl/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+keystore=`pwd`
+pID=`creddy --keyid --cert ${keystore}/IceCream_ID.pem`
+cID=`creddy --keyid --cert ${keystore}/Chocolate_ID.pem`
+
+role="${pID}.delicious"
+principal="${cID}"
+
+./abac_prover.pl --keystore="$keystore" --role="$role" --principal="$principal"
+
+
+
Index: examples/example_scripts/perl/run_test
===================================================================
--- examples/example_scripts/perl/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/perl/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,40 @@
+#!/bin/sh 
+
+make -s clean
+
+echo '---running (perl) id script'
+make -s run 1>/dev/null 2>&1 
+result=`grep OKAY id.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (perl) id2 script, expected failure'
+make -s bad 1>/dev/null 2>&1
+result=`grep "Aborted" id2.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (perl) attr script'
+make -s attr 1>/dev/null 2>&1
+result=`grep "chocolate" attr.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+
+echo '---running (perl) prover script'
+make -s prove 1>/dev/null 2>&1
+result=`grep "Success" prover.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
Index: examples/example_scripts/python/Makefile
===================================================================
--- examples/example_scripts/python/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/Makefile	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,47 @@
+
+all: run_attr run_e_attr run_id run_id2 run_prove
+
+clean:
+	@rm -f *.pem *.xml *.log pfile
+
+setup:
+	creddy --generate --cn IceCream
+	creddy --generate --cn Chocolate
+
+run_attr: 
+	make clean
+	rm -rf attr.log
+	make setup
+	./abac_attr.py IceCream_ID.pem IceCream_private.pem IceCream_attr.xml Chocolate_ID.pem 1>attr.log 2>&1
+
+run_e_attr: 
+	make clean
+	rm -rf e_attr.log pfile
+	echo "dumdum" > pfile
+	openssl genrsa -des3 -out Soda_private.pem -passout file:pfile
+	creddy --generate --cn Soda --key Soda_private.pem --p=pfile
+	creddy --generate --cn Cream
+	./abac_e_attr.py Soda_ID.pem Soda_private.pem Soda_attr.xml pfile Cream_ID.pem 1>e_attr.log 2>&1
+
+run_id: 
+	make clean
+	rm -rf id.log
+	make setup
+	./abac_keyid.py IceCream_ID.pem 1>id.log 2>&1
+
+run_id2: 
+	make clean
+	rm -rf id2.log
+	make setup
+	./abac_keyid.py IceCream_private.pem 1>id2.log 2>&1
+
+run_id3: 
+	make clean
+	rm -rf id3.log
+	make setup
+	./abac_keyid2.py IceCream_ID.pem IceCream_private.pem 1>id3.log 2>&1
+
+run_prove:
+	rm -rf prover.log
+	make run_attr
+	./run_prover 1>prover.log 2>& 1
Index: examples/example_scripts/python/abac_attr.py
===================================================================
--- examples/example_scripts/python/abac_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+"""
+     abac_attr.py
+
+     To demonstrate how to use ABAC's api in python 
+  
+     call:   attr_abac IceCream_ID.pem IceCream_private.pem IceCream_attr.xml Chocolate_ID.pem
+  
+     pre-conditions: generate IceCream_ID.pem and IceCream_private.pem with
+             creddy --generate --cn IceCream
+                     generate Chocolate_ID.pem and Chocolate_private.pem with
+             creddy --generate --cn Chocolate
+  
+     This program will generate an attribute rule, write it out to an external
+             file and also load it into the context (prolog db)
+             IceCream.delicious <- Chocolate
+  
+     Then, a query is made against the context to see if it is populated correctly.
+  
+     Note: Chocolate's principal is loaded without it private key. It does not
+           need to because it is not being used to generate attribute credential
+  
+"""
+
+from sys import argv, exit
+from ABAC import Context
+from ABAC import ID, Attribute, Role
+
+debug=0
+
+## initial context
+ctxt = Context()
+
+print len(argv)
+
+if len(argv) != 5:
+    print "Usage: abac_attr.py <cert.pem> <key.pem> <attr.xml> <pcert.pem>"
+    exit(1)
+
+# load the ID and its key
+id = None
+cid = None
+
+try:
+    id = ID(argv[1])
+    id.load_privkey(argv[2])
+    cid = ID(argv[4])
+except Exception, e:
+    print "Problem loading ID cert: %s" % e
+    exit(1)
+
+# load the id into the context
+ctxt.load_id_chunk(id.cert_chunk())
+# another way to load the id into the context
+#XXX  not implemented yet...ctxt.load_id(cid)
+ctxt.load_id_chunk(cid.cert_chunk())
+
+#out = ctxt.credentials()
+#print "\n...final principal set..."
+#for x in out[1]:
+#    print "%s " % x.string()
+
+# create an attribute cert
+# iceCream.delicous <- chocolate
+attr = Attribute(id, "delicious", 1000)
+attr.principal(cid.keyid())
+attr.bake()
+
+# load attribute cert into the context
+ctxt.load_attribute_chunk(attr.cert_chunk())
+
+# another way to load the attribute cert into the context,
+# not implemented, ctxt.load_attribute(attr)
+
+# yet another way to load the attribute cert into the context,
+attr.write_file(argv[3])
+# ctxt.load_attribute_file(argv[3])
+
+# run a proof
+(success, credentials) = ctxt.query("%s.delicious" % id.keyid(), cid.keyid())
+
+if success:
+    print "success!"
+
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+
+
Index: examples/example_scripts/python/abac_e_attr.py
===================================================================
--- examples/example_scripts/python/abac_e_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_e_attr.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+"""
+   abac_e_attr.py
+
+   To demonstrate how to use ABAC's api in python with principal credential that uses
+   encrypted private key
+
+   call:   attr_e_abac Soda_ID.pem Soda_private.pem Soda_attr.der pfile Cream_ID.pem
+
+   pre-conditions: make a passpphrase file and
+                   generate a Soda_private.pem with passphrase with openssl
+                   generate Soda_ID.pem with creddy with supplied private key
+                   generate Cream_ID.pem and clear Cream_private.pem with
+                          creddy --generate --cn Cream
+
+   This program will generate an attribute rule, write it out to an external
+           file and also load it into the context 
+           Soda.delicious <- Cream
+
+   Then, a query is made against the context to see if it is populated correctly.
+
+   Note: Cream's principal is loaded without it private key. It does not
+         need to because it is not being used to generate attribute credential
+
+"""
+
+
+
+
+from sys import argv, exit
+from ABAC import Context
+from ABAC import ID, Attribute, Role
+
+debug=0
+
+## initial context
+ctxt = Context()
+
+if len(argv) != 6:
+    print "Usage: abac_attr.py <cert.pem> <key.pem> <attr.xml> <pfile> <c_cert.pem>"
+    exit(1)
+
+# load the ID and its key
+id = None
+try:
+    id = ID(argv[1])
+    id.load_privkey(argv[2])
+    cream_id = ID(argv[5])
+except Exception, e:
+    print "Problem loading ID cert: %s" % e
+    exit(1)
+
+# load the id into the context
+ctxt.load_id_chunk(id.cert_chunk())
+# another way to load the id into the context
+# ctxt.load_id(cream_id), not implemented
+ctxt.load_id_chunk(cream_id.cert_chunk())
+
+# create an attribute cert
+attr = Attribute(id, "delicious", 1000)
+attr.principal(cream_id.keyid())
+attr.bake()
+
+# load attribute cert into the context
+ctxt.load_attribute_chunk(attr.cert_chunk())
+
+# another way to load the attribute cert into the context,
+# ctxt.load_attribute(attr)
+
+# yet another way to load the attribute cert into the context,
+attr.write_file(argv[3])
+# ctxt.load_attribute_file(argv[3])
+
+print '---------'
+(credentials) = ctxt.credentials()
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+print '---------'
+
+
+(success, credentials) = ctxt.query("%s.delicious" % id.keyid(), cream_id.keyid())
+if success:
+    print "success!"
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+
Index: examples/example_scripts/python/abac_keyid.py
===================================================================
--- examples/example_scripts/python/abac_keyid.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_keyid.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+"""
+  abac_keyid.py
+
+   To demonstrate how to use ABAC's api in python to access keyid of a 
+principal credential
+
+   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
+           creddy --generate --cn IceCream
+
+   keyid of the loaded principal credential is printed
+
+"""
+
+from sys import argv, exit
+from ABAC import ID
+
+if len(argv) < 2:
+    print "Usage: abac_keyid.py <cert.pem>"
+    exit(1)
+
+id = None
+try:
+    print argv[1]
+    id = ID(argv[1])
+except Exception, e:
+    print "Problem loading cert: %s" % e
+    exit(1)
+
+print id.keyid()
+print "okay"
+
Index: examples/example_scripts/python/abac_keyid2.py
===================================================================
--- examples/example_scripts/python/abac_keyid2.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_keyid2.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+"""
+  abac_keyid2.py
+
+   To demonstrate how to use ABAC's api in python to access keyid of a 
+principal credential
+
+   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
+           creddy --generate --cn IceCream
+
+   keyid of the loaded principal credential is printed
+
+"""
+
+from sys import argv, exit
+from ABAC import ID
+
+if len(argv) < 2:
+    print "Usage: abac_keyid.py <cert.pem>"
+    exit(1)
+
+id = None
+try:
+    print argv[1]
+    id = ID(argv[1])
+    id.load_privkey(argv[2])
+except Exception, e:
+    print "Problem loading cert: %s" % e
+    exit(1)
+
+print id.keyid()
+print 'okay'
+
Index: examples/example_scripts/python/abac_prover.py
===================================================================
--- examples/example_scripts/python/abac_prover.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/abac_prover.py	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+"""
+   abac_prover.py
+    
+   To demonstrate how to use ABAC's api in python to make a query
+
+   call:   abac_prover "keystorestring" "rolestring" "principalstring"
+
+   pre-condition: run make attr_abac  generate IceCream_ID.pem and IceCream_private.pem with
+
+   This program will make a prover call using
+           rolestring <- principalstring
+
+"""
+
+import getopt
+import sys
+from ABAC import Context
+
+
+def usage():
+    print "Usage: abac_prover.py \\"
+    print "        --keystore <keystore> \\"
+    print "        --role <role> --principal <principal> "
+    print "    loads the keystore and runs the query role <-?- principal"
+    sys.exit(1)
+
+keystore = ''
+role = ''
+principal = ''
+
+try:
+    opts, args = getopt.getopt(sys.argv[1:], '', ['keystore=', 'role=', 'principal='])
+except getopt.GetoptError, err:
+    print str(err)
+    sys.exit(1)
+
+for o, a in opts:
+    if o == '--keystore':
+        keystore = a
+    elif o == '--role':
+        role = a
+    elif o == '--principal':
+        principal = a
+    else:
+        assert False, "WAT"
+
+if keystore == '' or role == '' or principal == '':
+    usage()
+
+# code begins here! sorry about that
+
+print keystore
+print role
+print principal
+
+ctx = Context()
+ctx.load_directory(keystore)
+
+(success, credentials) = ctx.query(role, principal)
+
+if success:
+    print "success"
+
+for credential in credentials:
+    print "credential %s <- %s" % (credential.head().string(), credential.tail().string())
+
Index: examples/example_scripts/python/run_e_prover
===================================================================
--- examples/example_scripts/python/run_e_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/run_e_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+keystore=`pwd`
+
+echo "dumdum" > pfile
+openssl genrsa -des3 -out Soda_private.pem -passout file:pfile
+creddy --generate --cn Soda --key Soda_private.pem
+creddy --generate --cn Cream 
+./abac_e_attr.py Soda_ID.pem Soda_private.pem Soda_attr.xml pfile Cream_ID.pem 
+
+
Index: examples/example_scripts/python/run_prover
===================================================================
--- examples/example_scripts/python/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/run_prover	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+keystore=`pwd`
+pID=`creddy --keyid --cert ${keystore}/IceCream_ID.pem`
+cID=`creddy --keyid --cert ${keystore}/Chocolate_ID.pem`
+
+role="${pID}.delicious"
+principal="${cID}"
+
+./abac_prover.py --keystore "$keystore" --role "$role" --principal "$principal"
+
+
+
Index: examples/example_scripts/python/run_test
===================================================================
--- examples/example_scripts/python/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
+++ examples/example_scripts/python/run_test	(revision 472161887a4822e907c5e9d23bd1a4a0ec6f950b)
@@ -0,0 +1,55 @@
+#!/bin/sh 
+
+echo '---running (python) attr script'
+make run_attr 1>/dev/null 2>& 1
+result=`grep success attr.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+#echo '---running (python) encrypted key attr script'
+#make run_e_attr 1>/dev/null 2>& 1
+#result=`grep succeed e_attr.log 2>/dev/null`
+#if [ "$result" = "" ]; then
+#   echo "   ERROR"
+#else   
+#   echo "   PASSED"
+#fi
+
+echo '---running (python) id script'
+make run_id 1>/dev/null 2>& 1
+result=`grep okay id.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (python) id2 script, expect failure'
+make run_id2 1>/dev/null 2>& 1
+result=`grep "okay" id2.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   PASSED"
+else   
+   echo "   ERROR"
+fi
+
+echo '---running (python) id3 script, expect failure'
+make run_id3 1>/dev/null 2>& 1
+result=`grep "okay" id3.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (python) prover script'
+make run_prove 1>/dev/null 2>& 1
+result=`grep success prover.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
