source: libabac/prover_yap.c @ 2cdbe49

mei_rt2mei_rt2_fix_1
Last change on this file since 2cdbe49 was 5110d42, checked in by Mei <mei@…>, 12 years ago

1) reorganized the test directory to include python tests
2) attribute via api and principal via api from python scripts is

working (although there is a annoying seg fault at the very end
that must be related to something not been dup()ed.. need to wait
for c example to debug it)

3) able to query via api
4) replicated access_rt2 example in python and the query result matches
5) expanded api to make it easier to generate rt2 structure

  • Property mode set to 100644
File size: 2.4 KB
Line 
1
2#include <err.h>
3#include <stdio.h>
4#include <assert.h>
5
6
7#include "abac_internal.h"
8
9#include "options.h"
10
11extern void abac_print_cred_info(abac_credential_t*, FILE*);
12extern void abac_print_prin_info(abac_id_credential_t*, FILE*);
13
14int main(int argc, char **argv) {
15    int i, success=0;
16    abac_credential_t *cred=NULL;
17    abac_credential_t **credentials=NULL;
18    abac_id_credential_t *prin=NULL;
19    abac_id_credential_t **principals=NULL;
20
21    options_t opts = { 0, };
22    get_options(argc, argv, &opts);
23    abac_context_t *ctx = abac_context_new();
24    abac_context_load_directory(ctx, opts.keystore);
25
26    if(opts.filename) { 
27        FILE *fp=fopen(opts.filename,"w+");
28
29        credentials = abac_context_credentials(ctx);
30        if (credentials != NULL) {
31            for (i = 0; credentials[i] != NULL; ++i) {
32                cred = credentials[i];
33                abac_print_cred_info(cred,fp);
34            }
35            abac_context_credentials_free(credentials);
36        }
37
38        principals = abac_context_principals(ctx);
39        if (principals != NULL) {
40            for (i = 0; principals[i] != NULL; ++i) {
41                prin = principals[i];
42                abac_print_prin_info(prin,fp);
43            }
44            abac_context_principals_free(principals);
45        }
46        fclose(fp);
47        return 0;
48    }
49
50    char *query=NULL;
51    char *with=NULL;
52    if(opts.role && opts.principal) {
53        query=opts.role;
54        with=opts.principal;
55        } else {
56            if(opts.oset) {
57                query=opts.oset;
58            } 
59            if(opts.principal) {
60                with=opts.principal;
61            } else if(opts.object) {
62                with=opts.object;
63            }
64            if(with==NULL || query==NULL) {
65                puts("prover eeekkk \n");
66                assert(0);
67            }
68    }
69    credentials = abac_context_query(ctx,
70                            query, with,
71                            &success);
72    if (success)
73        puts("prover success!!");
74        else puts("prover failed!!");
75
76    if (credentials != NULL && success) {
77        puts("credentials needed :");
78        for (i = 0; credentials[i] != NULL; ++i) {
79           cred = credentials[i];
80           abac_print_cred_info(cred,NULL);
81        }
82    }
83    if(credentials)
84        abac_context_credentials_free(credentials);
85    abac_context_free(ctx);
86   
87    return 0;
88}
Note: See TracBrowser for help on using the repository browser.