source: libabac/prover.c @ 2be12d2

abac0-leakabac0-mei
Last change on this file since 2be12d2 was 4f79997, checked in by Mei <mei@…>, 11 years ago

1) add a new scaling test -haystack/ralphs
2) tweak some libabac code here and there

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include <err.h>
2#include <stdio.h>
3
4#include <abac.h>
5#include "abac_list.h"
6#include "options.h"
7
8static 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               fprintf(fp,"id[%d] %s (%s)\n",i, abac_id_cert_keyid(cert), abac_id_cert_cn(cert));
28        }
29    abac_context_id_credentials_free(ilist);
30}
31
32int main(int argc, char **argv) {
33    int i, success;
34    abac_credential_t *cred;
35
36    options_t opts = { 0, };
37    get_options(argc, argv, &opts);
38
39    abac_context_t *ctx = abac_context_new();
40    abac_context_load_directory(ctx, opts.keystore);
41
42    if(opts.rulefile) {
43        FILE *fp=fopen(opts.rulefile,"w+");
44        if(fp) { 
45            _dump_context(fp,ctx);       
46            fclose(fp);
47        }
48        if(opts.role == NULL) { /* just a pure dump call */
49            abac_context_free(ctx);
50            return 0;
51        }
52    }
53
54    abac_credential_t **credentials = abac_context_query(ctx,
55        opts.role, opts.principal,
56        &success
57    );
58
59    if (success)
60        puts("success");
61    else
62        puts("fail, here's a partial proof");
63
64    if (credentials != NULL)
65        for (i = 0; credentials[i] != NULL; ++i) {
66            cred = credentials[i];
67            printf("credential %s <- %s\n",
68                    abac_role_string(abac_credential_head(cred)),
69                    abac_role_string(abac_credential_tail(cred))
70                  );
71        }
72
73    abac_context_credentials_free(credentials);
74    abac_context_free(ctx);
75
76    if(success) {
77        fprintf(stderr,"returning success- 0\n");
78        return 0;
79    } else {
80        fprintf(stderr,"returning failure- 1\n");
81        return 1;
82    }
83}
Note: See TracBrowser for help on using the repository browser.