[e95d652] | 1 | #ifndef __ABAC_H__ |
---|
| 2 | #define __ABAC_H__ |
---|
| 3 | |
---|
| 4 | #include <abac_common.h> |
---|
[202a7f9] | 5 | #include <abac_list.h> |
---|
| 6 | #include <abac_stack.h> |
---|
[e95d652] | 7 | |
---|
| 8 | typedef struct _abac_context_t abac_context_t; |
---|
| 9 | typedef struct _abac_credential_t abac_credential_t; |
---|
| 10 | typedef struct _abac_role_t abac_role_t; |
---|
[da5afdf] | 11 | typedef struct _abac_oset_t abac_oset_t; |
---|
[202a7f9] | 12 | typedef struct _abac_id_cert_t abac_id_cert_t; |
---|
| 13 | |
---|
| 14 | typedef struct _abac_condition_t abac_condition_t; |
---|
[da5afdf] | 15 | typedef struct _abac_term_t abac_term_t; |
---|
[202a7f9] | 16 | typedef struct _abac_param_list_t abac_param_list_t; |
---|
[e95d652] | 17 | |
---|
| 18 | /* |
---|
| 19 | * ABAC functions, operating on an ABAC context. |
---|
| 20 | */ |
---|
| 21 | abac_context_t *abac_context_new(void); |
---|
[202a7f9] | 22 | abac_context_t *abac_context_dup(abac_context_t *ctx); |
---|
[e95d652] | 23 | void abac_context_free(abac_context_t *ctx); |
---|
| 24 | |
---|
| 25 | /* see the bottom of the file for possible return codes */ |
---|
| 26 | int abac_context_load_id_file(abac_context_t *ctx, char *filename); |
---|
| 27 | int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 28 | int abac_context_load_attribute_file(abac_context_t *ctx, char *filename); |
---|
| 29 | int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 30 | |
---|
| 31 | /* load an entire directory full of certs */ |
---|
| 32 | void abac_context_load_directory(abac_context_t *ctx, char *path); |
---|
| 33 | |
---|
| 34 | /* abac query, returns a NULL-terminated array of credentials on success, NULL on fail */ |
---|
| 35 | abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success); |
---|
| 36 | |
---|
| 37 | /* get all the credentials from the context, returns a NULL-terminated array of credentials */ |
---|
| 38 | abac_credential_t **abac_context_credentials(abac_context_t *ctx); |
---|
| 39 | |
---|
| 40 | /* use this to free the results of either of the previous two functions */ |
---|
| 41 | void abac_context_credentials_free(abac_credential_t **credentials); |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * Operations on credentials |
---|
| 45 | */ |
---|
| 46 | abac_role_t *abac_credential_head(abac_credential_t *cred); |
---|
| 47 | abac_role_t *abac_credential_tail(abac_credential_t *cred); |
---|
| 48 | abac_chunk_t abac_credential_attribute_cert(abac_credential_t *cred); |
---|
| 49 | abac_chunk_t abac_credential_issuer_cert(abac_credential_t *cred); |
---|
| 50 | abac_credential_t *abac_credential_lookup(char *cred_string); |
---|
| 51 | char* abac_credential_clause(abac_credential_t *cred); |
---|
| 52 | |
---|
| 53 | abac_credential_t *abac_credential_dup(abac_credential_t *cred); |
---|
| 54 | void abac_credential_free(abac_credential_t *cred); |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * Operations on roles. |
---|
| 58 | */ |
---|
| 59 | abac_role_t *abac_role_principal_new(char *principal); |
---|
| 60 | abac_role_t *abac_role_role_new(char *principal, char *abac_role_name); |
---|
| 61 | abac_role_t *abac_role_linking_new(char *principal, char *linked_role, char *abac_role_name); |
---|
[202a7f9] | 62 | abac_role_t *abac_role_intersection_new(char *name, abac_list_t *prereqs); |
---|
[e95d652] | 63 | |
---|
[202a7f9] | 64 | int abac_verify_roletype(char *type); |
---|
[e95d652] | 65 | void abac_role_free(abac_role_t *role); |
---|
| 66 | |
---|
| 67 | abac_role_t *abac_role_from_string(char *string); |
---|
| 68 | abac_role_t *abac_role_dup(abac_role_t *role); |
---|
| 69 | |
---|
| 70 | int abac_role_is_principal(abac_role_t *role); |
---|
| 71 | int abac_role_is_role(abac_role_t *role); |
---|
| 72 | int abac_role_is_linking(abac_role_t *role); |
---|
| 73 | int abac_role_is_intersection(abac_role_t *role); |
---|
| 74 | |
---|
| 75 | char *abac_role_string(abac_role_t *role); |
---|
| 76 | char *abac_role_linked_role(abac_role_t *role); |
---|
| 77 | char *abac_role_role_name(abac_role_t *role); |
---|
[da5afdf] | 78 | char *abac_role_role_param_string(abac_role_t *role); |
---|
[e95d652] | 79 | char *abac_role_principal(abac_role_t *role); |
---|
[202a7f9] | 80 | abac_list_t *abac_role_prereqs(abac_role_t *role); |
---|
| 81 | |
---|
| 82 | abac_param_list_t *abac_role_linked_role_params(abac_role_t *role); |
---|
| 83 | abac_param_list_t *abac_role_role_params(abac_role_t *role); |
---|
[e95d652] | 84 | |
---|
| 85 | char *abac_role_attr_key(abac_role_t *head_role, abac_role_t *tail_role); |
---|
[da5afdf] | 86 | char *abac_role_principal_cn(abac_role_t *role); |
---|
[0d0c3a9] | 87 | char *abac_role_string_with_condition(abac_role_t *); |
---|
[e95d652] | 88 | |
---|
[202a7f9] | 89 | /* |
---|
[da5afdf] | 90 | * Operations on oset |
---|
[202a7f9] | 91 | */ |
---|
[da5afdf] | 92 | char *abac_oset_principal_cn(abac_oset_t *oset); |
---|
| 93 | char *abac_oset_oset_name(abac_oset_t *oset); |
---|
[0d0c3a9] | 94 | abac_param_list_t *abac_oset_oset_params(abac_oset_t *); |
---|
| 95 | int abac_oset_is_object(abac_oset_t *); |
---|
| 96 | char *abac_oset_object_cn(abac_oset_t *); |
---|
| 97 | char *abac_oset_linked_role(abac_oset_t *); |
---|
| 98 | abac_param_list_t *abac_oset_linked_role_params(abac_oset_t *); |
---|
| 99 | abac_list_t *abac_oset_prereqs(abac_oset_t *); |
---|
| 100 | int abac_oset_is_intersection(abac_oset_t *); |
---|
| 101 | abac_oset_t *abac_oset_principal_new(char *); |
---|
| 102 | abac_oset_t *abac_oset_intersection_new(char *, abac_list_t *); |
---|
| 103 | abac_oset_t *abac_oset_oset_new(char *, char *); |
---|
| 104 | abac_oset_t *abac_oset_object_new(abac_term_t *); |
---|
| 105 | char *abac_oset_principal(abac_oset_t *); |
---|
| 106 | abac_oset_t *abac_oset_linking_new(char *, char *, char *); |
---|
| 107 | char *abac_oset_string_with_condition(abac_oset_t *); |
---|
| 108 | char *abac_oset_oset_param_string(abac_oset_t *); |
---|
[da5afdf] | 109 | |
---|
| 110 | /* |
---|
| 111 | * Operations on term/params. |
---|
| 112 | */ |
---|
[0d0c3a9] | 113 | char *abac_term_type(int); |
---|
| 114 | abac_term_t *abac_term_new(int, char *, char *, void *); |
---|
| 115 | void abac_term_free(abac_term_t *); |
---|
[da5afdf] | 116 | int abac_term_is_time_type(int); |
---|
[0d0c3a9] | 117 | char *abac_term_name(abac_term_t *); |
---|
| 118 | abac_condition_t *abac_term_constraint(abac_term_t *term); |
---|
[da5afdf] | 119 | abac_param_list_t *abac_param_list_new(abac_term_t *term); |
---|
[202a7f9] | 120 | abac_param_list_t *abac_param_list_free(abac_param_list_t *ptr); |
---|
[da5afdf] | 121 | abac_param_list_t *abac_param_list_add_term(abac_param_list_t *, abac_term_t *term); |
---|
[202a7f9] | 122 | char* abac_param_list_string(abac_param_list_t *ptr); |
---|
| 123 | char* abac_param_list_string_with_condition(abac_param_list_t *ptr); |
---|
| 124 | |
---|
[0d0c3a9] | 125 | /* from abac_verifier */ |
---|
| 126 | char *abac_cn_with_sha(char*); |
---|
| 127 | char *abac_keyid_type(int); |
---|
| 128 | |
---|
[e95d652] | 129 | /* |
---|
| 130 | * Error codes for loading certificates. |
---|
| 131 | */ |
---|
| 132 | #define ABAC_CERT_SUCCESS 0 // certificate loaded, all is well |
---|
| 133 | #define ABAC_CERT_INVALID -1 // invalid format; also file not found |
---|
| 134 | #define ABAC_CERT_BAD_SIG -2 // invalid signature |
---|
| 135 | #define ABAC_CERT_MISSING_ISSUER -3 // missing ID cert that issued the attribute cert |
---|
| 136 | #define ABAC_CERT_BAD_CN -4 // ID cert is not matching CN=principal format |
---|
| 137 | #define ABAC_CERT_BAD_YAP -5 // failed to insert into prolog engine |
---|
| 138 | |
---|
| 139 | #endif /* __ABAC_H__ */ |
---|