source: libabac/prover.c @ 80f0770

abac0-leak
Last change on this file since 80f0770 was 91a6b20, checked in by Mei-Hui Su <mei@…>, 11 years ago

1) add cleanup for options(leak)

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[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]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];
[4f79997]27               fprintf(fp,"id[%d] %s (%s)\n",i, abac_id_cert_keyid(cert), abac_id_cert_cn(cert));
[13b087a]28        }
29    abac_context_id_credentials_free(ilist);
30}
31
[7f25a67f]32int 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        }
[4f79997]48        if(opts.role == NULL) { /* just a pure dump call */
49            abac_context_free(ctx);
50            return 0;
51        }
[461541a]52    }
53
[401a054]54    abac_credential_t **credentials = abac_context_query(ctx,
[7af34ed]55        opts.role, opts.principal,
[4e426c9]56        &success
[dc62c68]57    );
58
[91a6b20]59
[4e426c9]60    if (success)
61        puts("success");
[605ee1d]62    else
63        puts("fail, here's a partial proof");
[4e426c9]64
65    if (credentials != NULL)
66        for (i = 0; credentials[i] != NULL; ++i) {
67            cred = credentials[i];
68            printf("credential %s <- %s\n",
69                    abac_role_string(abac_credential_head(cred)),
[9a411d7]70                    abac_role_string(abac_credential_tail(cred))
[4e426c9]71                  );
72        }
73
[3c4fd68]74    abac_context_credentials_free(credentials);
[390f749]75    abac_context_free(ctx);
[91a6b20]76    free_options(&opts);
[ea401bc]77
[3c30b59]78    if(success) {
79        fprintf(stderr,"returning success- 0\n");
80        return 0;
81    } else {
82        fprintf(stderr,"returning failure- 1\n");
83        return 1;
84    }
[7f25a67f]85}
Note: See TracBrowser for help on using the repository browser.