source: examples/example_scripts/c/loader.c @ f89b991

mei_rt2
Last change on this file since f89b991 was d0efdec, checked in by Mei <mei@…>, 11 years ago

1) less bsd compiler complaints

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2   abac_prover.c
3
4   To demonstrate how to use ABAC's api in C to load credentials
5
6   call:   abac_load
7
8**/
9
10#include <err.h>
11#include <stdio.h>
12#include <assert.h>
13#include <string.h>
14
15#include <abac.h>
16#include "abac_c.h"
17
18extern void abac_print_cred_info(abac_credential_t*, FILE*);
19extern void abac_print_prin_info(abac_id_credential_t*, FILE*);
20
21int main(int argc, char **argv) {
22    int i, success=0;
23    abac_credential_t *cred=NULL;
24    abac_credential_t **credentials=NULL;
25
26    abac_context_t *ctx = abac_context_new();
27    int rc;
28
29fprintf(stderr, "\n         --- load from directory\n");
30    if(argc==2)
31        abac_context_load_directory(ctx, argv[1]); 
32        else
33            abac_context_load_directory(ctx, "."); 
34
35fprintf(stderr, "\n         --- load from chunk\n");
36    abac_id_t *tid;
37    abac_id_generate(&tid,"Tim", 0);
38    abac_chunk_t chunk=abac_id_cert_chunk(tid);
39    tid=abac_id_from_chunk(chunk);
40    rc=abac_context_load_id(ctx,tid); 
41
42fprintf(stderr, "\n         --- load from id_gen\n");
43    abac_id_t *id;
44    abac_id_generate(&id,"Mary", 0);
45    abac_id_write_cert_fname(id,"Mary_ID.pem");
46    abac_id_write_privkey_fname(id,"Mary_private.pem");
47fprintf(stderr, "\n         --- load from explicit call\n");
48/*    int rc=abac_context_load_id_id_key_files(ctx,"Mary_ID.pem","Mary_private.pem"); */ 
49    rc=abac_context_load_id(ctx,id); 
50
51   
52fprintf(stderr, "\n         --- load with idkey file\n");
53    abac_id_t *id2;
54    abac_id_generate(&id2,"Tom", 0);
55    abac_id_write_cert_fname(id2,"Tom_IDKEY.pem");
56    abac_id_write_privkey_fname(id2,"Tom_IDKEY.pem");
57    rc=abac_context_load_id_file(ctx,"Tom_IDKEY.pem"); 
58
59{
60    printf("\n\n");
61    credentials = abac_context_credentials(ctx);
62    if (credentials != NULL) {
63        puts("context credentials :");
64        for (i = 0; credentials[i] != NULL; ++i) {
65           cred = credentials[i];
66           abac_print_typed_cred_info(cred,NULL);
67        }
68    }
69    if(credentials)
70        abac_free_credentials(credentials);
71}
72{
73    abac_id_credential_t *id_cred=NULL;
74    abac_id_credential_t **id_credentials=NULL;
75    printf("\n\n");
76    id_credentials = abac_context_principals(ctx);
77    if (id_credentials != NULL) {
78        puts("principal credentials :");
79        for (i = 0; id_credentials[i] != NULL; ++i) {
80           id_cred = id_credentials[i];
81           abac_print_prin_info(id_cred,NULL);
82        }
83    }
84    if(id_credentials)
85        abac_free_principals(id_credentials);
86}
87
88    show_yap_db("yap db");
89
90fprintf(stderr,"\n          --- id free from explicit call\n");
91    abac_id_free(id);
92    abac_id_free(id2);
93
94fprintf(stderr,"\n          --- explicitly free the context \n");
95    abac_context_free(ctx);
96
97fprintf(stderr,"\n          --- that is it \n");
98    return 0;
99}
Note: See TracBrowser for help on using the repository browser.