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

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since b7b2ca1 was 4721618, checked in by Mei <mei@…>, 12 years ago

1) tested out python and perl test scripts along with

abac_chunk_t calls in libabac's abac.hh

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2CAN NOT RUN
3
4   loader.c
5
6   To demonstrate how to use ABAC's api in C to load credentials
7
8   some not implemented yet
9
10   call:   abac_load
11
12**/
13
14#include <err.h>
15#include <stdio.h>
16#include <assert.h>
17#include <string.h>
18
19#include <abac.h>
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);
40XXX  not implemented yet.. 
41    rc=abac_context_load_id(ctx,tid); 
42
43fprintf(stderr, "\n         --- load from id_gen\n");
44    abac_id_t *id;
45    abac_id_generate(&id,"Mary", 0);
46    abac_id_write_cert_fname(id,"Mary_ID.pem");
47    abac_id_write_privkey_fname(id,"Mary_private.pem");
48fprintf(stderr, "\n         --- load from explicit call\n");
49/*    int rc=abac_context_load_id_id_key_files(ctx,"Mary_ID.pem","Mary_private.pem"); */ 
50    rc=abac_context_load_id(ctx,id); 
51
52   
53fprintf(stderr, "\n         --- load with idkey file\n");
54    abac_id_t *id2;
55    abac_id_generate(&id2,"Tom", 0);
56    abac_id_write_cert_fname(id2,"Tom_IDKEY.pem");
57    abac_id_write_privkey_fname(id2,"Tom_IDKEY.pem");
58    rc=abac_context_load_id_file(ctx,"Tom_IDKEY.pem"); 
59
60{
61    printf("\n\n");
62    credentials = abac_context_credentials(ctx);
63    if (credentials != NULL) {
64        puts("context credentials :");
65        for (i = 0; credentials[i] != NULL; ++i) {
66           cred = credentials[i];
67           abac_print_typed_cred_info(cred,NULL);
68        }
69    }
70    if(credentials)
71        abac_free_credentials(credentials);
72}
73{
74    abac_id_credential_t *id_cred=NULL;
75    abac_id_credential_t **id_credentials=NULL;
76    printf("\n\n");
77    id_credentials = abac_context_principals(ctx);
78    if (id_credentials != NULL) {
79        puts("principal credentials :");
80        for (i = 0; id_credentials[i] != NULL; ++i) {
81           id_cred = id_credentials[i];
82           abac_print_prin_info(id_cred,NULL);
83        }
84    }
85    if(id_credentials)
86        abac_free_principals(id_credentials);
87}
88
89    show_yap_db("yap db");
90
91fprintf(stderr,"\n          --- id free from explicit call\n");
92    abac_id_free(id);
93    abac_id_free(id2);
94
95fprintf(stderr,"\n          --- explicitly free the context \n");
96    abac_context_free(ctx);
97
98fprintf(stderr,"\n          --- that is it \n");
99    return 0;
100}
Note: See TracBrowser for help on using the repository browser.