source: libabac/prover_yap.c @ 7211a95

mei_rt2mei_rt2_fix_1
Last change on this file since 7211a95 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
RevLine 
[e95d652]1
2#include <err.h>
3#include <stdio.h>
[da5afdf]4#include <assert.h>
[e95d652]5
[202a7f9]6
[8bd77b5]7#include "abac_internal.h"
[e95d652]8
9#include "options.h"
10
[da5afdf]11extern void abac_print_cred_info(abac_credential_t*, FILE*);
[5110d42]12extern void abac_print_prin_info(abac_id_credential_t*, FILE*);
[202a7f9]13
[e95d652]14int main(int argc, char **argv) {
[da5afdf]15    int i, success=0;
16    abac_credential_t *cred=NULL;
17    abac_credential_t **credentials=NULL;
[5110d42]18    abac_id_credential_t *prin=NULL;
19    abac_id_credential_t **principals=NULL;
[e95d652]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);
[da5afdf]25
26    if(opts.filename) { 
27        FILE *fp=fopen(opts.filename,"w+");
28
[5110d42]29        credentials = abac_context_credentials(ctx);
[da5afdf]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        }
[5110d42]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        }
[da5afdf]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;
[c586a3c]58            } 
59            if(opts.principal) {
[da5afdf]60                with=opts.principal;
61            } else if(opts.object) {
62                with=opts.object;
[c586a3c]63            }
64            if(with==NULL || query==NULL) {
[0d0c3a9]65                puts("prover eeekkk \n");
[da5afdf]66                assert(0);
67            }
68    }
69    credentials = abac_context_query(ctx,
70                            query, with,
71                            &success);
[e95d652]72    if (success)
73        puts("prover success!!");
[da5afdf]74        else puts("prover failed!!");
[e95d652]75
[da5afdf]76    if (credentials != NULL && success) {
[e95d652]77        puts("credentials needed :");
78        for (i = 0; credentials[i] != NULL; ++i) {
[da5afdf]79           cred = credentials[i];
80           abac_print_cred_info(cred,NULL);
[e95d652]81        }
[da5afdf]82    }
83    if(credentials)
84        abac_context_credentials_free(credentials);
[e95d652]85    abac_context_free(ctx);
[da5afdf]86   
[e95d652]87    return 0;
88}
Note: See TracBrowser for help on using the repository browser.