source: examples/example_scripts/c/abac_prover.c @ 2be9809

mei_rt2mei_rt2_fix_1
Last change on this file since 2be9809 was 08b8da7, checked in by Mei <mei@…>, 12 years ago

1) rework examples directory with Makefile
2) update scaling with plotting scripts
3) add more doc in there

  • Property mode set to 100644
File size: 1.5 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    int k=100;
40while(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--;
58}
59
60    abac_context_free(ctx);
61   
62    return 0;
63}
Note: See TracBrowser for help on using the repository browser.