Index: examples/python_tests/access_rt2/README
===================================================================
--- examples/python_tests/access_rt2/README	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/access_rt2/README	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+#####################################################################
+# This directory contains examples that use libabac api call to
+# access and generate attribute policy rules using python
+#
+# Two pre-existing id credentials are generated using separate python
+# script
+
+
Index: examples/python_tests/access_rt2/access.save
===================================================================
--- examples/python_tests/access_rt2/access.save	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/access_rt2/access.save	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,14 @@
+% Restoring file /usr/local/lib/Yap/startup.yss
+
+===good============ Alpha.access(Read,fileA)<-?-Bob
+YAP query succeed
+pAlpha.access('Read',F:pAlpha.documents(P)) <- pAlpha.team(P)
+pAlpha.documents('proj1') <- 'file//fileA'
+pAlpha.team('proj1') <- pBob
+
+===bad============ Alpha.access(Read,fileA)<-?-Joe
+YAP query failed
+
+===good============ Alpha.team(proj2)<-?-Joe
+YAP query succeed
+pAlpha.team('proj2') <- pJoe
Index: examples/python_tests/access_rt2/attr.py
===================================================================
--- examples/python_tests/access_rt2/attr.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/access_rt2/attr.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+
+"""
+  to test with python
+
+cmd1:env keystore=`pwd` ./attr.py 
+expect this to fail,
+cmd2: env ABAC_CN=1 keystore=`pwd` ./attr.py
+
+"""
+
+import os
+import ABAC
+
+keystore=os.environ["keystore"]
+
+ctxt = ABAC.Context()
+print "ABAC version %s" % ctxt.version()
+
+ctxt.load_directory(keystore)
+
+out = ctxt.context_principals()
+print "...initial principal set..."
+for x in out[1]:
+    print "%s " % x.string()
+print "\n" 
+
+out = ctxt.context_credentials()
+print "...initial policy attribute set..."
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+print "\n"
+
+joeID=ABAC.ID("Joe", 0)
+ctxt.load_id(joeID)
+#joeID.write_privkey("Joe_IDKEY.pem")
+#joeID.write_cert("Joe_IDKEY.pem")
+joeID.write_privkey("Joe_private.pem")
+joeID.write_cert("Joe_ID.pem")
+joe=joeID.keyid()
+
+#ctxt.load_id_file("Alpha_ID.pem","Alpha_private.pem")
+alphaID=ABAC.ID("Alpha_ID.pem")
+alphaID.load_privkey("Alpha_private.pem");
+alpha=alphaID.keyid()
+
+#ctxt.load_id_file("Bob_ID.pem","Bob_private.pem")
+bobID=ABAC.ID("Bob_ID.pem")
+bobID.load_privkey("Bob_private.pem");
+bob=bobID.keyid()
+
+################################################
+# [keyid:alpha].role:access([string:'Read'],[urn:'file//fileB']) <- [keyid:bob]
+param1=ABAC.DataTerm("string", "'Read'")
+param2=ABAC.DataTerm("urn","'file//fileB'")
+role = ABAC.Role(alpha,"access")
+role.add_data_term(param1)
+role.add_data_term(param2)
+p = ABAC.Role(bob)
+attr=ABAC.Attribute(role, 1800)
+attr.add_tail(p)
+attr.bake()
+attr.write_cert("Alpha_access_fileB__Bob_attr.der")
+ctxt.load_attribute_file("Alpha_access_fileB__Bob_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+## [keyid:alpha].role:team([string:'proj1'])<-[keyid:bob]
+param1=ABAC.DataTerm("string", "'proj1'")
+role = ABAC.Role(alpha,"team")
+role.add_data_term(param1)
+tail = ABAC.Role(bob)
+attr=ABAC.Attribute(role, 1800)
+attr.add_tail(tail)
+attr.bake()
+attr.write_cert("Alpha_team_proj1__Bob_attr.der")
+ctxt.load_attribute_file("Alpha_team_proj1__Bob_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#################################################
+## [keyid:alpha].role:team([string:'proj2'])<-[keyid:Joe]
+param1=ABAC.DataTerm("string", "'proj2'")
+role = ABAC.Role(alpha,"team")
+role.add_data_term(param1)
+tail = ABAC.Role(joe)
+attr=ABAC.Attribute(role, 1800)
+attr.add_tail(tail)
+attr.bake()
+attr.write_cert("Alpha_team_proj2__Joe_attr.der")
+ctxt.load_attribute_file("Alpha_team_proj2__Joe_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+## bad beause of that constraint.. 
+################################################
+# [keyid:alpha].role:access([string:'Read',
+#                [urn:?F[keyid:alpha].oset:documents([string:?P])])
+#                                 <- [keyid:alpha].role:team([string:?P]) 
+param=ABAC.DataTerm("string", "P")
+oset=ABAC.Oset(alpha,"documents")
+oset.add_data_term(param)
+cond=ABAC.Constraint(oset)
+param2=ABAC.DataTerm("urn", "F", cond)
+param1=ABAC.DataTerm("string", "'Read'")
+head = ABAC.Role(alpha,"access")
+head.add_data_term(param1)
+head.add_data_term(param2)
+param3=ABAC.DataTerm("string", "P")
+tail = ABAC.Role(alpha,"team")
+tail.add_data_term(param3)
+
+attr=ABAC.Attribute(head, 1800)
+attr.add_tail(tail)
+attr.bake()
+attr.write_cert("Alpha_access_qFqP__alpha_team_qP_attr.der")
+#ctxt.load_attribute_file("Alpha_access_qFqP__alpha_team_qP_attr.der")
+ctxt.load_attribute(attr)
+#print attr.string() 
+#print attr.typed_string()
+#print "\n"
+
+
+#################################################
+## [keyid:alpha].oset:documents([string:'proj1'])<-[urn:'file//fileA']
+param1=ABAC.DataTerm("string", "'proj1'")
+oset = ABAC.Oset(alpha,"documents")
+oset.add_data_term(param1)
+obj = ABAC.DataTerm("urn", "'file//fileA'")
+tail= ABAC.Oset(obj)
+attr=ABAC.Attribute(oset, 1800)
+attr.add_tail(tail)
+attr.bake()
+attr.write_cert("Alpha_team_proj1__fileA_attr.der")
+ctxt.load_attribute_file("Alpha_team_proj1__fileA_attr.der")
+print attr.string() 
+print attr.typed_string()
+print "\n"
+
+#ctxt.dump_yap()
+##
Index: examples/python_tests/access_rt2/query.py
===================================================================
--- examples/python_tests/access_rt2/query.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/access_rt2/query.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+
+"""
+  to test with python
+
+cmd1:env keystore=`pwd` ./query.py 
+cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
+
+"""
+
+import os
+import ABAC
+
+ctxt = ABAC.Context()
+
+# print "ABAC version %s" % ctxt.version()
+
+keystore=os.environ["keystore"]
+
+ctxt.load_directory(keystore)
+
+alphaID=ABAC.ID("Alpha_ID.pem");
+alphaID.load_privkey("Alpha_private.pem");
+#ctxt.load_id(alphaID)
+alpha=alphaID.keyid()
+
+bobID=ABAC.ID("Bob_ID.pem");
+bobID.load_privkey("Bob_private.pem");
+#ctxt.load_id(bobID)
+bob=bobID.keyid()
+
+joeID=ABAC.ID("Joe_ID.pem");
+joeID.load_privkey("Joe_private.pem");
+joe=joeID.keyid()
+
+
+##########################################################################
+# role =[keyid:alpha].role:access([string:'Read'],[urn:'file//fileA'])
+# p = "[keyid:bob]" 
+param1=ABAC.DataTerm("string", "'Read'")
+param2=ABAC.DataTerm("urn","'file//fileA'")
+role = ABAC.Role(alpha,"access")
+role.add_data_term(param1)
+role.add_data_term(param2)
+p = ABAC.Role(bob)
+
+print "\n===good============ Alpha.access(Read,fileA)<-?-Bob"
+out = ctxt.query(role, p)
+
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
+##########################################################################
+# role =[keyid:alpha].role:access([string:'Read'],[urn:'file//fileA'])
+# p = "[keyid:joe]" 
+param1=ABAC.DataTerm("string", "'Read'")
+param2=ABAC.DataTerm("urn","'file//fileA'")
+role = ABAC.Role(alpha,"access")
+role.add_data_term(param1)
+role.add_data_term(param2)
+p = ABAC.Role(joe)
+
+print "\n===bad============ Alpha.access(Read,fileA)<-?-Joe"
+out = ctxt.query(role,p)
+
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
+
+##########################################################################
+# role =[keyid:alpha].role:team([string:'proj2'])
+# p = "[keyid:joe]" 
+param=ABAC.DataTerm("string", "'proj2'")
+role = ABAC.Role(alpha,"team")
+role.add_data_term(param)
+p = ABAC.Role(joe)
+print "\n===good============ Alpha.team(proj2)<-?-Joe"
+out = ctxt.query(role,p)
+
+for c in out[1]:
+    print "%s <- %s" % (c.head_string(), c.tail_string())
+
Index: examples/python_tests/access_rt2/run_test
===================================================================
--- examples/python_tests/access_rt2/run_test	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/access_rt2/run_test	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,38 @@
+#!/bin/sh 
+
+ABAC_PROVER_PATH="/home/mei/Deter/abac/libabac"
+export ABAC_PROVER_PATH
+
+echo '---setup principals'
+# Two pre-existing id credentials are generated using separate python
+# script (just to show we can)
+env keystore=`pwd` ./setup.py 1>/dev/null 2>& 1
+
+# Add policy attribute credentials along with a new id credential
+echo '---setup attributes'
+env keystore=`pwd` ./attr.py 1>/dev/null 2>& 1
+
+echo '---run queries'
+
+# Make prover queries
+g_cmd_sha=`grep "cmd1:" query.py |sed "s/cmd1://g" `
+g_cmd_cn=`grep "cmd2:" query.py |sed "s/cmd2://g" `
+
+echo '...with sha'
+eval $g_cmd_sha 2>/dev/null 1 > access.sha
+
+echo '...with cn'
+eval $g_cmd_cn 1>access.cn 2>&1
+
+result=`diff access.cn access.save 2>/dev/null`
+if [ $? -eq 0 ]; then
+    if [ "$result" = "" ]; then
+       echo "   PASSED"
+    else
+       echo "   ERROR:access_rt2 test result differs!!!"
+    fi
+else
+    echo "   ERROR:access_rt2 test result differs!!!"
+fi
+
+
Index: examples/python_tests/access_rt2/setup.py
===================================================================
--- examples/python_tests/access_rt2/setup.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/access_rt2/setup.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+"""
+  to test with python
+
+
+"""
+import os
+import ABAC
+
+ctxt = ABAC.Context()
+
+id=ABAC.ID("Alpha", 0)
+id.write_cert("Alpha_ID.pem")
+id.write_privkey("Alpha_private.pem")
+
+id=ABAC.ID("Bob", 0)
+id.write_cert("Bob_ID.pem")
+id.write_privkey("Bob_private.pem")
Index: examples/python_tests/allout.save
===================================================================
--- examples/python_tests/allout.save	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/allout.save	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,12 @@
+
+ ==> RUN on basic_api
+---setup precondition
+Generating key, this will take a while. Create entropy!
+    - move the mouse
+    - generate disk activity (run find)
+Generating key, this will take a while. Create entropy!
+    - move the mouse
+    - generate disk activity (run find)
+---run with sha
+---run with cn
+   PASSED
Index: examples/python_tests/basic_id/README
===================================================================
--- examples/python_tests/basic_id/README	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/basic_id/README	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#####################################################################
+# This example demonstrates various ways to access and create 
+# ID credentials using libabac api using python
+# In yap db, the ID credential is stored as: isType(pIDname,keyid)
+
+# Two pre-existing id credentials are generated using creddy, this is
+# to test the load_directory api call
+creddy --generate --cn CreddyBob
+creddy --generate --cn CreddyJack
+
+#  
Index: examples/python_tests/basic_id/id.py
===================================================================
--- examples/python_tests/basic_id/id.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/basic_id/id.py	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+"""
+  to test with python
+
+cmd1:env keystore=`pwd` ./id.py 
+cmd2:env ABAC_CN=1 keystore=`pwd` ./id.py
+
+"""
+
+import os
+import ABAC
+
+ctxt = ABAC.Context()
+
+print "ABAC version %s" % ctxt.version()
+
+keystore=os.environ["keystore"]
+
+ctxt.load_directory(keystore)
+out = ctxt.context_principals()
+print "...initial principal set..."
+for x in out[1]:
+    print "%s " % x.string()
+print "\n" 
+
+id=ABAC.ID("Mary", 0)
+print "adding -> %s(good)" % id.name()
+id.write_cert("Mary_ID.pem")
+id.write_privkey("Mary_private.pem")
+ctxt.load_id_file("Mary_ID.pem","Mary_private.pem")
+
+nid=ABAC.ID("Jack", 0)
+print "adding -> %s(good)" % nid.name()
+ctxt.load_id(nid)
+
+id=ABAC.ID("Mark", 0)
+print "adding -> %s(good)" % id.name()
+id.write_privkey("Mark_IDKEY.pem")
+id.write_cert("Mark_IDKEY.pem")
+ctxt.load_id_file("Mark_IDKEY.pem")
+
+id=ABAC.ID("John", 0)
+print "adding -> %s(good,invisible)" % id.name()
+id.write_privkey("John_idkey.pem")
+id.write_cert("John_idkey.pem")
+ctxt.load_id_file("John_idkey.pem")
+
+id=ABAC.ID("Lori", 0)
+print "adding -> %s(good,nokey)" % id.name()
+id.write_cert("Lori_IDKEY.pem")
+ctxt.load_id_file("Lori_IDKEY.pem")
+
+id=ABAC.ID("Tom", 0)
+print "adding -> %s(bad,nocert)" % id.name()
+id.write_privkey("Tom_IDKEY.pem")
+ctxt.load_id_file("Tom_IDKEY.pem")
+
+print "adding -> Casper(bad,unknown file)"
+ctxt.load_id_file("Casper_IDKEY.pem")
+
+print "...final principal set..."
+out = ctxt.context_principals()
+for x in out[1]:
+    print "%s " % x.string()
+print "\n"
+
+ctxt.dump_yap()
Index: examples/python_tests/basic_id/id.save
===================================================================
--- examples/python_tests/basic_id/id.save	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/basic_id/id.save	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,59 @@
+% Restoring file /usr/local/lib/Yap/startup.yss
+python: Couldn't load ID/KEY IDKEY cert /home/mei/Deter/abac/examples/python_tests/basic_id/Tom_IDKEY.pem
+ABAC version 1.0
+...initial principal set...
+(pCreddyBob,keyid,y) 
+(pCreddyJack,keyid,y) 
+(pMary,keyid,y) 
+(pLori,keyid,n) 
+(pMark,keyid,y) 
+
+
+adding -> pMary(good)
+adding -> pJack(good)
+adding -> pMark(good)
+adding -> pJohn(good,invisible)
+adding -> pLori(good,nokey)
+adding -> pTom(bad,nocert)
+adding -> Casper(bad,unknown file)
+...final principal set...
+(pCreddyBob,keyid,y) 
+(pCreddyJack,keyid,y) 
+(pMary,keyid,y) 
+(pLori,keyid,n) 
+(pMark,keyid,y) 
+(pJack,keyid,y) 
+(pJohn,keyid,y) 
+
+
+
+
+========= yap db (dump_yap)
+isType(pCreddyBob,keyid).
+isType(pCreddyJack,keyid).
+isType(pMary,keyid).
+isType(pLori,keyid).
+isType(pMark,keyid).
+isType(pJack,keyid).
+isType(pJohn,keyid).
+appendL([],[]).
+appendL([B|C],A) :-
+   appendL(C,D),
+   append(B,D,A).
+append([],A,A).
+append([B|C],A,[B|D]) :-
+   append(C,A,D).
+file_search_path(library,A) :-
+   library_directory(A).
+file_search_path(commons,_) :-
+   commons_directory(_).
+file_search_path(swi,A) :-
+   current_prolog_flag(home,A).
+file_search_path(yap,A) :-
+   current_prolog_flag(home,A).
+file_search_path(system,A) :-
+   prolog_flag(host_type,A).
+file_search_path(foreign,yap('lib/Yap')).
+listing ok.. 
+========= 
+
Index: examples/python_tests/basic_id/run_test
===================================================================
--- examples/python_tests/basic_id/run_test	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/basic_id/run_test	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,30 @@
+#!/bin/sh 
+
+ABAC_PROVER_PATH="/home/mei/Deter/abac/libabac"
+export ABAC_PROVER_PATH
+
+g_cmd_sha=`grep "cmd1:" id.py |sed "s/cmd1://g" `
+g_cmd_cn=`grep "cmd2:" id.py |sed "s/cmd2://g" `
+
+echo '---setup principals'
+./README
+
+echo '---run with sha'
+eval $g_cmd_sha 2>/dev/null 1 > id.sha
+
+echo '---run with cn'
+eval $g_cmd_cn 1>id.cn 2>&1
+result=`diff id.cn id.save 2>/dev/null`
+if [ $? -eq 0 ]; then
+    if [ "$result" = "" ]; then
+       echo "   PASSED"
+    else
+       echo "   ERROR:id test result differs!!!"
+    fi
+else
+    echo "   ERROR:id test result differs!!!"
+fi
+
+
+
+
Index: examples/python_tests/runall
===================================================================
--- examples/python_tests/runall	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/runall	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,35 @@
+#!/bin/sh 
+
+# format,
+#   runall clean
+#   runall run
+
+progname=$(basename $0)
+
+if [ $# -eq 0 ]; then
+    echo "Usage: $progname (clean|setup|run)" >&2;
+    exit 1
+fi
+
+ABAC_PROVER_PATH="/home/mei/Deter/abac/libabac"
+export ABAC_PROVER_PATH
+
+for i in `ls -1 `; do
+   if ( file $i | grep -Fq directory ); then
+       cd $i;
+       if [ "$1" = "clean" ]; then
+           rm -rf ../allout.tmp
+           printf "\n ==> CLEANING on %s\n" "$i" >& 2 ;
+           rm -rf *.der *.pem *.cn *.sha
+       elif [ "$1" = "setup" ]; then
+           printf "\n ==> SETUP on %s\n" "$i"  >& 2;
+           ./README
+       elif [ "$1" = "run" ] ; then
+           if(file run_test | grep -vq ERROR); then
+               printf "\n ==> RUN on %s\n" "$i" >& 2;
+               ./run_test
+           fi
+       fi 
+       cd ..;
+   fi
+done
Index: examples/python_tests/runcheck
===================================================================
--- examples/python_tests/runcheck	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
+++ examples/python_tests/runcheck	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -0,0 +1,18 @@
+#!/bin/sh 
+
+rm -rf allout.tmp
+
+ABAC_PROVER_PATH="/home/mei/Deter/abac/libabac"
+export ABAC_PROVER_PATH
+
+echo 'running PYTHON testing...'
+
+env ./runall run 1> allout.tmp 2>& 1
+
+result=`diff allout.tmp allout.save`
+
+if [ "$result" = "" ]; then
+   echo "   PASSED"
+else
+   echo "   ERROR:got changes!!!"
+fi
