source: libabac/prover.c

Last change on this file was 4571abc, checked in by Mei-Hui Su <mei@…>, 6 years ago

1) tweak for leak

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[7f25a67f]1#include <err.h>
2#include <stdio.h>
[4571abc]3#include <stdlib.h>
[7f25a67f]4
[6ede88c]5#include <abac.h>
[4721618]6#include "abac_list.h"
[7af34ed]7#include "options.h"
8
[13b087a]9static void _dump_context(FILE *fp, abac_context_t *ctx)
10{
11    int i;
12    abac_credential_t **credentials = abac_context_credentials(ctx);
13    abac_credential_t *cred;
14    if (credentials != NULL)
15        for (i = 0; credentials[i] != NULL; ++i) {
16            cred = credentials[i];
17            fprintf(fp,"%s <- %s\n",
18                abac_role_string(abac_credential_head(cred)),
19                abac_role_string(abac_credential_tail(cred)));
20        }
21    abac_context_credentials_free(credentials);
22
23    abac_id_cert_t **ilist=abac_context_principals(ctx);
24    abac_id_cert_t *cert;
25    if (ilist != NULL)
26        for (i = 0; ilist[i] != NULL; ++i) {
27               cert = ilist[i];
[4f79997]28               fprintf(fp,"id[%d] %s (%s)\n",i, abac_id_cert_keyid(cert), abac_id_cert_cn(cert));
[13b087a]29        }
30    abac_context_id_credentials_free(ilist);
31}
32
[7f25a67f]33int main(int argc, char **argv) {
[4e426c9]34    int i, success;
[401a054]35    abac_credential_t *cred;
[dc62c68]36
[7af34ed]37    options_t opts = { 0, };
38    get_options(argc, argv, &opts);
[7f25a67f]39
[390f749]40    abac_context_t *ctx = abac_context_new();
[7af34ed]41    abac_context_load_directory(ctx, opts.keystore);
[186cb75]42
[461541a]43    if(opts.rulefile) {
44        FILE *fp=fopen(opts.rulefile,"w+");
45        if(fp) { 
[13b087a]46            _dump_context(fp,ctx);       
[461541a]47            fclose(fp);
48        }
[4f79997]49        if(opts.role == NULL) { /* just a pure dump call */
[4571abc]50            free_options(&opts);
[4f79997]51            abac_context_free(ctx);
52            return 0;
53        }
[461541a]54    }
55
[401a054]56    abac_credential_t **credentials = abac_context_query(ctx,
[7af34ed]57        opts.role, opts.principal,
[4e426c9]58        &success
[dc62c68]59    );
60
[91a6b20]61
[4e426c9]62    if (success)
63        puts("success");
[605ee1d]64    else
65        puts("fail, here's a partial proof");
[4e426c9]66
67    if (credentials != NULL)
68        for (i = 0; credentials[i] != NULL; ++i) {
69            cred = credentials[i];
70            printf("credential %s <- %s\n",
71                    abac_role_string(abac_credential_head(cred)),
[9a411d7]72                    abac_role_string(abac_credential_tail(cred))
[4e426c9]73                  );
74        }
75
[3c4fd68]76    abac_context_credentials_free(credentials);
[390f749]77    abac_context_free(ctx);
[91a6b20]78    free_options(&opts);
[ea401bc]79
[3c30b59]80    if(success) {
81        fprintf(stderr,"returning success- 0\n");
82        return 0;
83    } else {
84        fprintf(stderr,"returning failure- 1\n");
85        return 1;
86    }
[7f25a67f]87}
Note: See TracBrowser for help on using the repository browser.