source: libabac/prover.c @ b8a6c918

abac0-leak
Last change on this file since b8a6c918 was ad13a62, checked in by Ted Faber <faber@…>, 11 years ago

Find declarations of certificat manipulation functions

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