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 | |
---|
22 | extern void abac_print_cred_info(abac_credential_t*, FILE*); |
---|
23 | extern void abac_print_prin_info(abac_id_credential_t*, FILE*); |
---|
24 | |
---|
25 | int main(int argc, char **argv) { |
---|
26 | int i, success=0; |
---|
27 | abac_credential_t *cred=NULL; |
---|
28 | abac_credential_t **credentials=NULL; |
---|
29 | |
---|
30 | abac_context_t *ctx = abac_context_new(); |
---|
31 | abac_context_load_directory(ctx, argv[1]); |
---|
32 | |
---|
33 | char *query=strdup(argv[2]); |
---|
34 | char *with=strdup(argv[3]); |
---|
35 | |
---|
36 | printf("query %s \n", query); |
---|
37 | printf("with %s\n", with); |
---|
38 | |
---|
39 | int k=1; /* use to do repetitions */ |
---|
40 | while(k) { |
---|
41 | credentials = abac_context_query(ctx, |
---|
42 | query, with, |
---|
43 | &success); |
---|
44 | if (success) |
---|
45 | puts("prover success!!"); |
---|
46 | else puts("prover failed!!"); |
---|
47 | |
---|
48 | if (credentials != NULL && success) { |
---|
49 | puts("credentials needed :"); |
---|
50 | for (i = 0; credentials[i] != NULL; ++i) { |
---|
51 | cred = credentials[i]; |
---|
52 | abac_print_cred_info(cred,NULL); |
---|
53 | } |
---|
54 | } |
---|
55 | if(credentials) |
---|
56 | abac_context_credentials_free(credentials); |
---|
57 | k=k-1; |
---|
58 | } |
---|
59 | |
---|
60 | abac_context_free(ctx); |
---|
61 | |
---|
62 | return 0; |
---|
63 | } |
---|