source: libabac/prover_yap.c @ dfe6b61

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

1) add backtrack/multiple solutions proof code changes and new

examples.

  • Property mode set to 100644
File size: 3.1 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    options_t opts = { 0, };
21    get_options(argc, argv, &opts);
22    abac_context_t *ctx = abac_context_new();
23    abac_context_load_directory(ctx, opts.keystore);
24
25    if(opts.filename) { 
26        FILE *fp=fopen(opts.filename,"w+");
27
28        credentials = abac_context_credentials(ctx);
29        if (credentials != NULL) {
30            for (i = 0; credentials[i] != NULL; ++i) {
31                cred = credentials[i];
32                abac_print_cred_info(cred,fp);
33            }
34            abac_context_credentials_free(credentials);
35        }
36
37        principals = abac_context_principals(ctx);
38        if (principals != NULL) {
39            for (i = 0; principals[i] != NULL; ++i) {
40                prin = principals[i];
41                abac_print_prin_info(prin,fp);
42            }
43            abac_context_principals_free(principals);
44        }
45        fclose(fp);
46        return 0;
47    }
48
49    if(opts.dbdump) {
50        show_yap_db("yap db");
51        return 0;
52    }
53
54    char *query=NULL;
55    char *with=NULL;
56    if(opts.role && opts.principal) {
57        query=opts.role;
58        with=opts.principal;
59        } else {
60            if(opts.oset) {
61                query=opts.oset;
62            } 
63            if(opts.principal) {
64                with=opts.principal;
65            } else if(opts.object) {
66                with=opts.object;
67            }
68            if(with==NULL || query==NULL) {
69                puts("prover eeekkk \n");
70                assert(0);
71            }
72    }
73
74    credentials = abac_context_query(ctx,
75                            query, with,
76                            &success);
77    if (success)
78        puts("prover success!!");
79        else puts("prover failed!!");
80
81    if (credentials != NULL && success) {
82        puts("credentials needed :");
83        for (i = 0; credentials[i] != NULL; ++i) {
84           cred = credentials[i];
85           abac_print_cred_info(cred,NULL);
86        }
87    }
88    if(credentials)
89        abac_context_credentials_free(credentials);
90
91/** limit at most 2 more solution proof **/
92    if(success && opts.all) {
93        int n=2;
94        while(n && success) {
95            credentials = abac_context_query_again(ctx, &success);
96            if (success)
97                puts("another proof!!");
98                else puts("no more!!");
99            if (credentials != NULL && success) {
100                puts("credentials needed :");
101                for (i = 0; credentials[i] != NULL; ++i) {
102                    cred = credentials[i];
103                    abac_print_cred_info(cred,NULL);
104                }
105            }
106            if(credentials)
107                abac_context_credentials_free(credentials);
108            n=n-1;
109        }
110    }
111
112    abac_context_free(ctx);
113   
114    return 0;
115}
Note: See TracBrowser for help on using the repository browser.