1 | #ifndef __ABAC_H__ |
---|
2 | #define __ABAC_H__ |
---|
3 | |
---|
4 | typedef struct _abac_context_t abac_context_t; |
---|
5 | typedef struct _abac_credential_t abac_credential_t; |
---|
6 | typedef struct _abac_role_t abac_role_t; |
---|
7 | |
---|
8 | typedef struct _abac_chunk_t { |
---|
9 | unsigned char *ptr; |
---|
10 | int len; |
---|
11 | } abac_chunk_t; |
---|
12 | |
---|
13 | /* |
---|
14 | * Init/deinit the library. |
---|
15 | */ |
---|
16 | void libabac_init(void); |
---|
17 | void libabac_deinit(void); |
---|
18 | |
---|
19 | /* |
---|
20 | * ABAC functions, operating on an ABAC context. |
---|
21 | */ |
---|
22 | abac_context_t *abac_context_new(void); |
---|
23 | abac_context_t *abac_context_dup(abac_context_t *ctx); |
---|
24 | void abac_context_free(abac_context_t *ctx); |
---|
25 | |
---|
26 | /* see the bottom of the file for possible return codes */ |
---|
27 | int abac_context_load_id_file(abac_context_t *ctx, char *filename); |
---|
28 | int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
29 | int abac_context_load_attribute_file(abac_context_t *ctx, char *filename); |
---|
30 | int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
31 | |
---|
32 | /* load an entire directory full of certs */ |
---|
33 | void abac_context_load_directory(abac_context_t *ctx, char *path); |
---|
34 | |
---|
35 | /* abac query, returns a NULL-terminated array of credentials on success, NULL on fail */ |
---|
36 | abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success); |
---|
37 | |
---|
38 | /* get all the credentials from the context, returns a NULL-terminated array of credentials */ |
---|
39 | abac_credential_t **abac_context_credentials(abac_context_t *ctx); |
---|
40 | |
---|
41 | /* use this to free the results of either of the previous two functions */ |
---|
42 | void abac_context_credentials_free(abac_credential_t **credentials); |
---|
43 | |
---|
44 | /* |
---|
45 | * Operations on credentials |
---|
46 | */ |
---|
47 | abac_role_t *abac_credential_head(abac_credential_t *cred); |
---|
48 | abac_role_t *abac_credential_tail(abac_credential_t *cred); |
---|
49 | abac_chunk_t abac_credential_attribute_cert(abac_credential_t *cred); |
---|
50 | abac_chunk_t abac_credential_issuer_cert(abac_credential_t *cred); |
---|
51 | |
---|
52 | abac_credential_t *abac_credential_dup(abac_credential_t *cred); |
---|
53 | void abac_credential_free(abac_credential_t *cred); |
---|
54 | |
---|
55 | /* |
---|
56 | * Operations on roles. |
---|
57 | */ |
---|
58 | abac_role_t *abac_role_principal_new(char *principal); |
---|
59 | abac_role_t *abac_role_role_new(char *principal, char *abac_role_name); |
---|
60 | abac_role_t *abac_role_linking_new(char *principal, char *linked_role, char *abac_role_name); |
---|
61 | |
---|
62 | void abac_role_free(abac_role_t *role); |
---|
63 | |
---|
64 | abac_role_t *abac_role_from_string(char *string); |
---|
65 | abac_role_t *abac_role_dup(abac_role_t *role); |
---|
66 | |
---|
67 | int abac_role_is_principal(abac_role_t *role); |
---|
68 | int abac_role_is_role(abac_role_t *role); |
---|
69 | int abac_role_is_linking(abac_role_t *role); |
---|
70 | |
---|
71 | char *abac_role_string(abac_role_t *role); |
---|
72 | char *abac_role_linked_role(abac_role_t *role); |
---|
73 | char *abac_role_role_name(abac_role_t *role); |
---|
74 | char *abac_role_principal(abac_role_t *role); |
---|
75 | |
---|
76 | char *abac_role_attr_key(abac_role_t *head_role, abac_role_t *tail_role); |
---|
77 | |
---|
78 | /* |
---|
79 | * Error codes for loading certificates. |
---|
80 | */ |
---|
81 | #define ABAC_CERT_SUCCESS 0 // certificate loaded, all is well |
---|
82 | #define ABAC_CERT_INVALID -1 // invalid format; also file not found |
---|
83 | #define ABAC_CERT_BAD_SIG -2 // invalid signature |
---|
84 | #define ABAC_CERT_MISSING_ISSUER -3 // missing ID cert that issued the attribute cert |
---|
85 | |
---|
86 | #endif /* __ABAC_H__ */ |
---|