[8bd77b5] | 1 | #ifndef __ABAC_H__ |
---|
| 2 | #define __ABAC_H__ |
---|
| 3 | |
---|
| 4 | #include <stdlib.h> |
---|
| 5 | #include <abac_list.h> |
---|
| 6 | #include <abac_stack.h> |
---|
| 7 | #include <abac_common.h> |
---|
| 8 | |
---|
| 9 | typedef struct _abac_context_t abac_context_t; |
---|
| 10 | typedef struct _abac_credential_t abac_credential_t; |
---|
| 11 | typedef struct _abac_aspect_t abac_aspect_t; |
---|
| 12 | typedef struct _abac_attribute_t abac_attribute_t; |
---|
| 13 | typedef struct _abac_id_t abac_id_t; |
---|
| 14 | typedef struct _abac_id_credential_t abac_id_credential_t; |
---|
| 15 | |
---|
| 16 | typedef struct _abac_condition_t abac_condition_t; |
---|
| 17 | typedef struct _abac_term_t abac_term_t; |
---|
[440ba20] | 18 | typedef struct _abac_item_t abac_item_t; |
---|
[8bd77b5] | 19 | typedef struct _abac_param_list_t abac_param_list_t; |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * ABAC functions, operating on an ABAC context. |
---|
| 23 | */ |
---|
| 24 | abac_context_t *abac_context_new(void); |
---|
| 25 | abac_context_t *abac_context_dup(abac_context_t *ctx); |
---|
[440ba20] | 26 | abac_context_t *abac_context_dup(abac_context_t *ctx); |
---|
[8bd77b5] | 27 | void abac_context_free(abac_context_t *ctx); |
---|
| 28 | |
---|
| 29 | /* see the bottom of the file for possible return codes */ |
---|
| 30 | int abac_context_load_id_id(abac_context_t *ctx, abac_id_t *); |
---|
[d037f54] | 31 | int abac_context_load_id_file(abac_context_t *ctx, char *filename, char* keyfielname); |
---|
[8bd77b5] | 32 | int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 33 | int abac_context_load_attribute_attribute(abac_context_t *ctx, abac_attribute_t *); |
---|
| 34 | int abac_context_load_attribute_file(abac_context_t *ctx, char *filename); |
---|
| 35 | int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 36 | |
---|
| 37 | /* load an entire directory full of certs */ |
---|
| 38 | void abac_context_load_directory(abac_context_t *ctx, char *path); |
---|
| 39 | |
---|
| 40 | /* abac query, returns a NULL-terminated array of credentials on success, NULL on fail */ |
---|
| 41 | abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success); |
---|
| 42 | |
---|
| 43 | /* get all the credentials from the context, returns a NULL-terminated array of credentials */ |
---|
| 44 | abac_credential_t **abac_context_credentials(abac_context_t *ctx); |
---|
| 45 | |
---|
| 46 | /* use this to free the results of either of the previous two functions */ |
---|
| 47 | void abac_context_credentials_free(abac_credential_t **credentials); |
---|
| 48 | |
---|
| 49 | /* |
---|
| 50 | * Operations on credentials |
---|
| 51 | */ |
---|
| 52 | abac_aspect_t *abac_credential_head(abac_credential_t *cred); |
---|
| 53 | abac_aspect_t *abac_credential_tail(abac_credential_t *cred); |
---|
| 54 | abac_chunk_t abac_credential_attribute_cert(abac_credential_t *cred); |
---|
| 55 | abac_chunk_t abac_credential_issuer_cert(abac_credential_t *cred); |
---|
| 56 | abac_credential_t *abac_credential_lookup(char *cred_string); |
---|
| 57 | abac_id_credential_t *abac_id_credential_lookup(char*); |
---|
| 58 | abac_id_t *abac_id_credential_id(abac_id_credential_t *ptr); |
---|
| 59 | |
---|
| 60 | abac_credential_t *abac_credential_dup(abac_credential_t *cred); |
---|
| 61 | abac_attribute_t *abac_credential_attribute(abac_credential_t *cred); |
---|
| 62 | void abac_credential_free(abac_credential_t *cred); |
---|
| 63 | |
---|
| 64 | /* |
---|
| 65 | * Operations on aspect. |
---|
| 66 | */ |
---|
| 67 | abac_aspect_t *abac_aspect_role_principal_create(char *principal_name); |
---|
| 68 | abac_aspect_t *abac_aspect_oset_principal_create(char *principal_name); |
---|
| 69 | abac_aspect_t *abac_aspect_role_create(char *principal_name, char *role_name); |
---|
| 70 | abac_aspect_t *abac_aspect_oset_create(char *principal_name, char *oset_name); |
---|
| 71 | |
---|
| 72 | bool abac_aspect_is_principal(abac_aspect_t *ptr); |
---|
| 73 | abac_aspect_t *abac_aspect_dup(abac_aspect_t *ptr); |
---|
| 74 | char *abac_aspect_string(abac_aspect_t *ptr); |
---|
| 75 | bool abac_aspect_is_linking(abac_aspect_t *ptr); |
---|
| 76 | char *abac_aspect_typed_string(abac_aspect_t *ptr); |
---|
| 77 | abac_aspect_t *abac_aspect_add_param(abac_aspect_t *ptr, abac_term_t *param); |
---|
| 78 | abac_aspect_t *abac_aspect_add_linked_param(abac_aspect_t *ptr, abac_term_t *param); |
---|
| 79 | bool abac_aspect_is_object(abac_aspect_t *ptr); |
---|
| 80 | char *abac_aspect_principal_name(abac_aspect_t *ptr); |
---|
| 81 | char* abac_aspect_type_string(abac_aspect_t *ptr); |
---|
| 82 | char *abac_aspect_aspect_name(abac_aspect_t *ptr); |
---|
| 83 | int abac_aspect_aspect_type(abac_aspect_t *ptr); |
---|
| 84 | abac_param_list_t *abac_aspect_aspect_params(abac_aspect_t *ptr); |
---|
| 85 | abac_param_list_t *abac_aspect_linked_role_params(abac_aspect_t *ptr); |
---|
| 86 | abac_aspect_t *abac_aspect_oset_linking_new(char *principal_name, |
---|
| 87 | char *linked_role_name, char *oset_name); |
---|
| 88 | abac_aspect_t *abac_aspect_role_linking_new(char *principal_name, |
---|
| 89 | char *linked_role_name, char *role_name); |
---|
| 90 | abac_aspect_t *abac_aspect_role_new(char *principal_name, char *role_name); |
---|
| 91 | abac_aspect_t *abac_aspect_oset_new(char *principal_name, char *oset_name); |
---|
| 92 | abac_aspect_t *abac_aspect_oset_principal_new(char *principal_name); |
---|
| 93 | abac_aspect_t *abac_aspect_role_principal_new(char *principal_name); |
---|
| 94 | abac_aspect_t *abac_aspect_oset_object_new(abac_term_t *object); |
---|
| 95 | char *abac_aspect_linked_role_name(abac_aspect_t *ptr); |
---|
| 96 | char *abac_aspect_object_name(abac_aspect_t *ptr); |
---|
| 97 | char *abac_aspect_object_type(abac_aspect_t *ptr); |
---|
| 98 | abac_list_t *abac_aspect_prereqs(abac_aspect_t *ptr); |
---|
| 99 | char *abac_aspect_string_with_condition(abac_aspect_t *); |
---|
| 100 | char *abac_aspect_typed_string_with_condition(abac_aspect_t *); |
---|
| 101 | char *abac_aspect_principal_principalname(abac_aspect_t *ptr); |
---|
| 102 | void abac_print_aspect_string_with_condition(abac_aspect_t *ptr,FILE *fp); |
---|
| 103 | char *abac_aspect_aspect_param_string(abac_aspect_t *ptr); |
---|
| 104 | abac_aspect_t *abac_aspect_intersection_new(abac_aspect_t *); |
---|
| 105 | abac_aspect_t *abac_aspect_add_intersecting_aspect(abac_aspect_t *ptr, abac_aspect_t *aspect); |
---|
| 106 | abac_id_t *abac_aspect_get_issuer_id(abac_aspect_t *ptr); |
---|
| 107 | int abac_aspect_intersecting_aspect_type(abac_aspect_t *ptr); |
---|
| 108 | |
---|
| 109 | /* abac_attribute */ |
---|
| 110 | abac_chunk_t abac_attribute_cert_chunk(abac_attribute_t *ptr); |
---|
| 111 | int abac_attribute_write(abac_attribute_t *ptr, FILE *out); |
---|
| 112 | int abac_attribute_bake(abac_attribute_t *ptr); |
---|
| 113 | int abac_attribute_baked(abac_attribute_t *ptr); |
---|
| 114 | abac_aspect_t *abac_attribute_head(abac_attribute_t *ptr); |
---|
| 115 | abac_aspect_t *abac_attribute_tail(abac_attribute_t *ptr); |
---|
| 116 | int abac_attribute_lastone(abac_attribute_t *ptr); |
---|
| 117 | int abac_attribute_create(abac_attribute_t **ret,abac_aspect_t *head, abac_aspect_t *tail,int validity); |
---|
| 118 | abac_attribute_t *abac_attribute_set_head(abac_attribute_t *ptr, abac_aspect_t *); |
---|
| 119 | abac_attribute_t *abac_attribute_add_tail(abac_attribute_t *ptr, abac_aspect_t *); |
---|
| 120 | abac_attribute_t *abac_attribute_dup(abac_attribute_t *ptr); |
---|
| 121 | abac_aspect_t **abac_attribute_tail_vectorized(abac_attribute_t *ptr); |
---|
| 122 | void abac_attribute_free(abac_attribute_t *ptr); |
---|
| 123 | void abac_aspects_free(abac_aspect_t **aspects); |
---|
| 124 | |
---|
| 125 | /* |
---|
| 126 | * Operations on term/params. |
---|
| 127 | */ |
---|
[ca72963] | 128 | int abac_max_item_type(); |
---|
| 129 | int abac_min_item_type(); |
---|
| 130 | int abac_target_item_type(); |
---|
| 131 | |
---|
| 132 | void abac_condition_add_range_integer_item(abac_condition_t *ptr, int itype, int val); |
---|
| 133 | void abac_condition_add_range_float_item(abac_condition_t *ptr, int itype, float val); |
---|
| 134 | void abac_condition_add_range_time_item(abac_condition_t *ptr, int itype, char* val); |
---|
| 135 | void abac_condition_add_range_urn_item(abac_condition_t *ptr, char *val); |
---|
| 136 | void abac_condition_add_range_string_item(abac_condition_t *ptr, char *val); |
---|
| 137 | void abac_condition_add_range_boolean_item(abac_condition_t *ptr, char* val); |
---|
| 138 | |
---|
[440ba20] | 139 | abac_condition_t *abac_condition_create(char *vtype); |
---|
| 140 | abac_condition_t *abac_condition_create_from_aspect(abac_aspect_t *ptr); |
---|
[8bd77b5] | 141 | abac_condition_t *abac_condition_dup(abac_condition_t *ptr); |
---|
| 142 | void abac_condition_free(abac_condition_t *ptr); |
---|
| 143 | char *abac_condition_typed_string(abac_condition_t *ptr); |
---|
| 144 | char *abac_condition_string(abac_condition_t *ptr); |
---|
| 145 | char *abac_term_to_time(char *string); |
---|
[440ba20] | 146 | int abac_term_isvar(abac_term_t *term); |
---|
[8bd77b5] | 147 | char *abac_term_typed_string(abac_term_t *ptr); |
---|
| 148 | char *abac_term_string(abac_term_t *ptr); |
---|
| 149 | char *abac_term_type_name(abac_term_t *term); |
---|
| 150 | abac_term_t *abac_term_dup(abac_term_t *ptr); |
---|
[d037f54] | 151 | abac_term_t *abac_term_create(int, char*, abac_condition_t*); |
---|
| 152 | abac_term_t *abac_term_named_create(int, char*); |
---|
[440ba20] | 153 | bool abac_term_is_numeric(abac_term_t *); |
---|
| 154 | bool abac_term_is_alpha(abac_term_t *); |
---|
| 155 | bool abac_term_is_time(abac_term_t *); |
---|
| 156 | bool abac_term_is_integer_type(abac_term_t *term); |
---|
| 157 | bool abac_term_is_urn_type(abac_term_t *term); |
---|
| 158 | bool abac_term_is_string_type(abac_term_t *term); |
---|
| 159 | bool abac_term_is_time_type(abac_term_t *term); |
---|
[8bd77b5] | 160 | int abac_term_type(abac_term_t *term); |
---|
| 161 | abac_term_t *abac_term_add_constraint(abac_term_t *ptr, abac_condition_t *cond); |
---|
[440ba20] | 162 | abac_term_t *abac_term_new(int, char *, int, char *, void *); |
---|
[d037f54] | 163 | abac_term_t *abac_term_named_new(int, char *); |
---|
[8bd77b5] | 164 | void abac_term_free(abac_term_t *); |
---|
| 165 | bool abac_term_is_time_type(abac_term_t *); |
---|
| 166 | bool abac_term_is_string_type(abac_term_t *); |
---|
| 167 | char *abac_term_name(abac_term_t *); |
---|
| 168 | abac_condition_t *abac_term_constraint(abac_term_t *term); |
---|
| 169 | abac_param_list_t *abac_param_list_new(abac_term_t *term); |
---|
| 170 | abac_param_list_t *abac_param_list_free(abac_param_list_t *ptr); |
---|
| 171 | abac_param_list_t *abac_param_list_add_term(abac_param_list_t *, abac_term_t *term); |
---|
| 172 | char* abac_param_list_string(abac_param_list_t *ptr); |
---|
| 173 | char* abac_param_list_string_with_condition(abac_param_list_t *ptr); |
---|
| 174 | char* abac_param_list_typed_string_with_condition(abac_param_list_t *ptr); |
---|
| 175 | abac_term_t **abac_param_list_vectorize(abac_param_list_t *ptr); |
---|
| 176 | void abac_terms_free(abac_term_t **terms); |
---|
[440ba20] | 177 | int abac_verify_term_type(char *); |
---|
[8bd77b5] | 178 | |
---|
| 179 | /* from abac_verifier */ |
---|
| 180 | char *abac_cn_with_sha(char*); |
---|
| 181 | char *abac_idtype_with_sha(char*); |
---|
| 182 | abac_stack_t *abac_verifier_dump_creds(); |
---|
| 183 | abac_id_credential_t *abac_verifier_add_id_credential(abac_id_t *a_id); |
---|
| 184 | |
---|
| 185 | /* from abac_id */ |
---|
| 186 | int abac_id_lastone(abac_id_t *ptr); |
---|
| 187 | abac_id_t *abac_id_dup(abac_id_t *id); |
---|
| 188 | void abac_id_free(abac_id_t *id); |
---|
| 189 | char *abac_id_cn(abac_id_t *id); |
---|
| 190 | char *abac_id_keyid(abac_id_t *id); |
---|
| 191 | abac_id_t *abac_id_from_file(char *filename); |
---|
| 192 | int abac_id_load_privkey(abac_id_t *id, char *filename); |
---|
| 193 | int abac_id_write_privkey(abac_id_t *id, FILE *out); |
---|
| 194 | int abac_id_has_privkey(abac_id_t *id); |
---|
| 195 | void abac_id_write_cert(abac_id_t *id, FILE *out); |
---|
| 196 | int abac_id_generate(abac_id_t **ret, char *cn, int validity); |
---|
| 197 | abac_chunk_t abac_id_cert_chunk(abac_id_t *id); |
---|
| 198 | |
---|
| 199 | /* from abac_aspect */ |
---|
| 200 | void abac_aspect_free(abac_aspect_t *); |
---|
[d037f54] | 201 | void abac_errx(int val, const char *string); |
---|
[8bd77b5] | 202 | |
---|
[440ba20] | 203 | /* from abac_pl_yap */ |
---|
| 204 | void show_yap_db(const char *msg); |
---|
| 205 | |
---|
[8bd77b5] | 206 | /* |
---|
| 207 | * Error codes for loading certificates. |
---|
| 208 | */ |
---|
| 209 | #define ABAC_CERT_SUCCESS 0 // certificate loaded, all is well |
---|
| 210 | #define ABAC_CERT_INVALID -1 // invalid format; also file not found |
---|
| 211 | #define ABAC_CERT_BAD_SIG -2 // invalid signature |
---|
| 212 | #define ABAC_CERT_MISSING_ISSUER -3 // missing ID cert that issued the attribute cert |
---|
| 213 | #define ABAC_CERT_BAD_CN -4 // ID cert is not matching CN=principal format |
---|
| 214 | #define ABAC_CERT_BAD_YAP -5 // failed to insert into prolog engine |
---|
[440ba20] | 215 | #define ABAC_CERT_EXISTS 1 // ID already exists (does not default to a failure) |
---|
[8bd77b5] | 216 | |
---|
| 217 | #define ABAC_ID_SUCCESS 0 |
---|
| 218 | #define ABAC_ID_GENERATE_INVALID_CN -1 |
---|
| 219 | #define ABAC_ID_GENERATE_INVALID_VALIDITY -2 |
---|
| 220 | |
---|
| 221 | #define ABAC_ATTRIBUTE_SUCCESS 0 |
---|
| 222 | #define ABAC_ATTRIBUTE_INVALID_ROLE -1 |
---|
| 223 | #define ABAC_ATTRIBUTE_INVALID_VALIDITY -2 |
---|
| 224 | #define ABAC_ATTRIBUTE_ISSUER_NOKEY -3 |
---|
[440ba20] | 225 | #define ABAC_ATTRIBUTE_FAIL -4 |
---|
| 226 | |
---|
| 227 | #define ABAC_TERM_SUCCESS 0 |
---|
| 228 | #define ABAC_TERM_FAIL -1 |
---|
[8bd77b5] | 229 | |
---|
| 230 | |
---|
| 231 | #define USE(evalue) ((getenv(evalue)!=NULL)?1:0) |
---|
| 232 | |
---|
| 233 | #endif /* __ABAC_H__ */ |
---|