source: tests/example_scripts/c/abac_prover.c @ e825c38

abac0-leak
Last change on this file since e825c38 was ec550f7, checked in by Mei <mei@…>, 11 years ago

1) reworked how API doc is generated
2) tweak top level Makefile.am
3) loading issuer principal as side-effect of loading

an attribute credentials

4) add examples of GENI specific attribute credentials

and principal certificates into the regression testing

5) rename examples to tests

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2   abac_prover.c
3
4   To demonstrate how to use ABAC's api in C to make a query
5
6   call:   abac_prover "keystorestring" "rolestring" "principalstring"
7
8   pre-condition: run make attr_abac  generate IceCream_ID.pem and IceCream_private.pem with
9
10   This program will make a prover call using
11           rolestring <- principalstring
12
13**/
14
15#include <err.h>
16#include <stdio.h>
17#include <assert.h>
18#include <string.h>
19
20#include <abac.h>
21
22int main(int argc, char **argv) {
23    int i, success=0;
24    abac_credential_t *cred=NULL;
25    abac_credential_t **credentials=NULL;
26
27    abac_context_t *ctx = abac_context_new();
28    abac_context_load_directory(ctx, argv[1]);
29
30    char *query=strdup(argv[2]);
31    char *with=strdup(argv[3]);
32
33    printf("query %s \n", query);
34    printf("with %s\n", with);
35
36int k=1; /* use to do repetitions */
37while(k) {
38    credentials = abac_context_query(ctx,
39                            query, with,
40                            &success);
41    if (success)
42        puts("prover success!!");
43        else puts("prover failed!!");
44
45    if (credentials != NULL && success) {
46        puts("credentials needed :");
47        for (i = 0; credentials[i] != NULL; ++i) {
48           cred = credentials[i];
49           printf("credential %s <- %s\n",
50                    abac_role_string(abac_credential_head(cred)),
51                    abac_role_string(abac_credential_tail(cred)));
52        }
53    }
54    if(credentials)
55        abac_context_credentials_free(credentials);
56    k=k-1;
57}
58
59
60{ /* dump credentials from context */
61    printf("\n\n");
62    credentials = abac_context_credentials(ctx);
63    printf("Dump context credentials, original ctx \n");
64    if (credentials != NULL) {
65        puts("context credentials :");
66        for (i = 0; credentials[i] != NULL; ++i) {
67           cred = credentials[i];
68           printf("credential %s <- %s\n",
69                    abac_role_string(abac_credential_head(cred)),
70                    abac_role_string(abac_credential_tail(cred)));
71        }
72    }
73    if(credentials)
74        abac_context_credentials_free(credentials);
75}
76
77    abac_context_t *ctx2 = abac_context_dup(ctx);
78{ /* dump credentials from context */
79    printf("\n\n");
80    credentials = abac_context_credentials(ctx);
81    printf("Dump context credentials, original ctx2 \n");
82    if (credentials != NULL) {
83        puts("context credentials :");
84        for (i = 0; credentials[i] != NULL; ++i) {
85           cred = credentials[i];
86           printf("credential %s <- %s\n",
87                    abac_role_string(abac_credential_head(cred)),
88                    abac_role_string(abac_credential_tail(cred)));
89        }
90    }
91    if(credentials)
92        abac_context_credentials_free(credentials);
93}
94
95    abac_context_free(ctx);
96    abac_context_free(ctx2);
97
98    return 0;
99}
Note: See TracBrowser for help on using the repository browser.