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