[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] | 11 | extern void abac_print_cred_info(abac_credential_t*, FILE*); |
---|
[5110d42] | 12 | extern void abac_print_prin_info(abac_id_credential_t*, FILE*); |
---|
[202a7f9] | 13 | |
---|
[e95d652] | 14 | int 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 | 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); |
---|
[da5afdf] | 24 | |
---|
| 25 | if(opts.filename) { |
---|
| 26 | FILE *fp=fopen(opts.filename,"w+"); |
---|
| 27 | |
---|
[5110d42] | 28 | credentials = abac_context_credentials(ctx); |
---|
[da5afdf] | 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 | } |
---|
[5110d42] | 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 | } |
---|
[da5afdf] | 45 | fclose(fp); |
---|
| 46 | return 0; |
---|
| 47 | } |
---|
| 48 | |
---|
[2efdff5] | 49 | if(opts.dbdump) { |
---|
| 50 | show_yap_db("yap db"); |
---|
| 51 | return 0; |
---|
| 52 | } |
---|
| 53 | |
---|
[da5afdf] | 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; |
---|
[c586a3c] | 62 | } |
---|
| 63 | if(opts.principal) { |
---|
[da5afdf] | 64 | with=opts.principal; |
---|
| 65 | } else if(opts.object) { |
---|
| 66 | with=opts.object; |
---|
[c586a3c] | 67 | } |
---|
| 68 | if(with==NULL || query==NULL) { |
---|
[0d0c3a9] | 69 | puts("prover eeekkk \n"); |
---|
[da5afdf] | 70 | assert(0); |
---|
| 71 | } |
---|
| 72 | } |
---|
[abf8d5d] | 73 | |
---|
[da5afdf] | 74 | credentials = abac_context_query(ctx, |
---|
| 75 | query, with, |
---|
| 76 | &success); |
---|
[e95d652] | 77 | if (success) |
---|
| 78 | puts("prover success!!"); |
---|
[da5afdf] | 79 | else puts("prover failed!!"); |
---|
[e95d652] | 80 | |
---|
[da5afdf] | 81 | if (credentials != NULL && success) { |
---|
[e95d652] | 82 | puts("credentials needed :"); |
---|
| 83 | for (i = 0; credentials[i] != NULL; ++i) { |
---|
[da5afdf] | 84 | cred = credentials[i]; |
---|
| 85 | abac_print_cred_info(cred,NULL); |
---|
[e95d652] | 86 | } |
---|
[da5afdf] | 87 | } |
---|
| 88 | if(credentials) |
---|
| 89 | abac_context_credentials_free(credentials); |
---|
[2efdff5] | 90 | |
---|
[abf8d5d] | 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 | |
---|
[e95d652] | 112 | abac_context_free(ctx); |
---|
[da5afdf] | 113 | |
---|
[e95d652] | 114 | return 0; |
---|
| 115 | } |
---|