[7f25a67f] | 1 | #include <err.h> |
---|
| 2 | #include <stdio.h> |
---|
| 3 | |
---|
[6ede88c] | 4 | #include <abac.h> |
---|
[4721618] | 5 | #include "abac_list.h" |
---|
[7af34ed] | 6 | #include "options.h" |
---|
| 7 | |
---|
[13b087a] | 8 | static void _dump_context(FILE *fp, abac_context_t *ctx) |
---|
| 9 | { |
---|
| 10 | int i; |
---|
| 11 | abac_credential_t **credentials = abac_context_credentials(ctx); |
---|
| 12 | abac_credential_t *cred; |
---|
| 13 | if (credentials != NULL) |
---|
| 14 | for (i = 0; credentials[i] != NULL; ++i) { |
---|
| 15 | cred = credentials[i]; |
---|
| 16 | fprintf(fp,"%s <- %s\n", |
---|
| 17 | abac_role_string(abac_credential_head(cred)), |
---|
| 18 | abac_role_string(abac_credential_tail(cred))); |
---|
| 19 | } |
---|
| 20 | abac_context_credentials_free(credentials); |
---|
| 21 | |
---|
| 22 | abac_id_cert_t **ilist=abac_context_principals(ctx); |
---|
| 23 | abac_id_cert_t *cert; |
---|
| 24 | if (ilist != NULL) |
---|
| 25 | for (i = 0; ilist[i] != NULL; ++i) { |
---|
| 26 | cert = ilist[i]; |
---|
| 27 | printf("id[%d] %s\n",i, abac_id_cert_keyid(cert)); |
---|
| 28 | } |
---|
| 29 | abac_context_id_credentials_free(ilist); |
---|
| 30 | } |
---|
| 31 | |
---|
[7f25a67f] | 32 | int main(int argc, char **argv) { |
---|
[4e426c9] | 33 | int i, success; |
---|
[401a054] | 34 | abac_credential_t *cred; |
---|
[dc62c68] | 35 | |
---|
[7af34ed] | 36 | options_t opts = { 0, }; |
---|
| 37 | get_options(argc, argv, &opts); |
---|
[7f25a67f] | 38 | |
---|
[390f749] | 39 | abac_context_t *ctx = abac_context_new(); |
---|
[7af34ed] | 40 | abac_context_load_directory(ctx, opts.keystore); |
---|
[186cb75] | 41 | |
---|
[461541a] | 42 | if(opts.rulefile) { |
---|
| 43 | FILE *fp=fopen(opts.rulefile,"w+"); |
---|
| 44 | if(fp) { |
---|
[13b087a] | 45 | _dump_context(fp,ctx); |
---|
[461541a] | 46 | fclose(fp); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
[401a054] | 50 | abac_credential_t **credentials = abac_context_query(ctx, |
---|
[7af34ed] | 51 | opts.role, opts.principal, |
---|
[4e426c9] | 52 | &success |
---|
[dc62c68] | 53 | ); |
---|
| 54 | |
---|
[4e426c9] | 55 | if (success) |
---|
| 56 | puts("success"); |
---|
[605ee1d] | 57 | else |
---|
| 58 | puts("fail, here's a partial proof"); |
---|
[4e426c9] | 59 | |
---|
| 60 | if (credentials != NULL) |
---|
| 61 | for (i = 0; credentials[i] != NULL; ++i) { |
---|
| 62 | cred = credentials[i]; |
---|
| 63 | printf("credential %s <- %s\n", |
---|
| 64 | abac_role_string(abac_credential_head(cred)), |
---|
[9a411d7] | 65 | abac_role_string(abac_credential_tail(cred)) |
---|
[4e426c9] | 66 | ); |
---|
| 67 | } |
---|
| 68 | |
---|
[3c4fd68] | 69 | abac_context_credentials_free(credentials); |
---|
[902d079] | 70 | |
---|
[390f749] | 71 | abac_context_free(ctx); |
---|
[ea401bc] | 72 | |
---|
[7f25a67f] | 73 | return 0; |
---|
| 74 | } |
---|