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 | |
---|
11 | extern void abac_print_cred_info(abac_credential_t*, FILE*); |
---|
12 | extern void abac_print_prin_info(abac_id_credential_t*, FILE*); |
---|
13 | |
---|
14 | int 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 | credentials = abac_context_query(ctx, |
---|
74 | query, with, |
---|
75 | &success); |
---|
76 | if (success) |
---|
77 | puts("prover success!!"); |
---|
78 | else puts("prover failed!!"); |
---|
79 | |
---|
80 | if (credentials != NULL && success) { |
---|
81 | puts("credentials needed :"); |
---|
82 | for (i = 0; credentials[i] != NULL; ++i) { |
---|
83 | cred = credentials[i]; |
---|
84 | abac_print_cred_info(cred,NULL); |
---|
85 | } |
---|
86 | } |
---|
87 | if(credentials) |
---|
88 | abac_context_credentials_free(credentials); |
---|
89 | |
---|
90 | abac_context_free(ctx); |
---|
91 | |
---|
92 | return 0; |
---|
93 | } |
---|