source: examples/example_scripts/c/abac_prover.c @ 43478b1

mei_rt2mei_rt2_fix_1
Last change on this file since 43478b1 was bea18ef, checked in by Mei <mei@…>, 12 years ago

1) add more tiny prover tests in examples/example_scripts
2) reverted the changes to ABAC_VERSION in libabac's abac_util.c

  • Property mode set to 100644
File size: 1.4 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
22extern void abac_print_cred_info(abac_credential_t*, FILE*);
23extern void abac_print_prin_info(abac_id_credential_t*, FILE*);
24
25int 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    credentials = abac_context_query(ctx,
40                            query, with,
41                            &success);
42    if (success)
43        puts("prover success!!");
44        else puts("prover failed!!");
45
46    if (credentials != NULL && success) {
47        puts("credentials needed :");
48        for (i = 0; credentials[i] != NULL; ++i) {
49           cred = credentials[i];
50           abac_print_cred_info(cred,NULL);
51        }
52    }
53    if(credentials)
54        abac_context_credentials_free(credentials);
55
56    abac_context_free(ctx);
57   
58    return 0;
59}
Note: See TracBrowser for help on using the repository browser.