[8bd77b5] | 1 | #ifndef __ABAC_H__ |
---|
| 2 | #define __ABAC_H__ |
---|
| 3 | |
---|
| 4 | #include <stdlib.h> |
---|
| 5 | #include <abac_common.h> |
---|
| 6 | |
---|
| 7 | typedef struct _abac_context_t abac_context_t; |
---|
| 8 | typedef struct _abac_credential_t abac_credential_t; |
---|
| 9 | typedef struct _abac_aspect_t abac_aspect_t; |
---|
| 10 | typedef struct _abac_attribute_t abac_attribute_t; |
---|
| 11 | typedef struct _abac_id_t abac_id_t; |
---|
| 12 | typedef struct _abac_id_credential_t abac_id_credential_t; |
---|
| 13 | |
---|
| 14 | typedef struct _abac_condition_t abac_condition_t; |
---|
| 15 | typedef struct _abac_term_t abac_term_t; |
---|
[440ba20] | 16 | typedef struct _abac_item_t abac_item_t; |
---|
[8bd77b5] | 17 | typedef struct _abac_param_list_t abac_param_list_t; |
---|
| 18 | |
---|
[5d06689] | 19 | /* called within abac.hh */ |
---|
[2efdff5] | 20 | char *abac_version(); |
---|
| 21 | void abac_errx(int,const char *); |
---|
[8bd77b5] | 22 | abac_condition_t *abac_condition_dup(abac_condition_t *ptr); |
---|
| 23 | void abac_condition_free(abac_condition_t *ptr); |
---|
[5f551d3] | 24 | char *abac_constraint_string(abac_condition_t *ptr); |
---|
| 25 | char *abac_constraint_typed_string(abac_condition_t *ptr); |
---|
[5d06689] | 26 | |
---|
| 27 | void abac_terms_free(abac_term_t **terms); |
---|
| 28 | abac_term_t *abac_term_dup(abac_term_t *ptr); |
---|
| 29 | void abac_term_free(abac_term_t *); |
---|
| 30 | abac_term_t *abac_term_named_create(char*); |
---|
| 31 | abac_term_t *abac_term_create(char*, char*, abac_condition_t*); |
---|
[7211a95] | 32 | abac_term_t *abac_term_id_create(abac_id_t *ptr); |
---|
[5d06689] | 33 | abac_term_t *abac_term_dup(abac_term_t *ptr); |
---|
[8bd77b5] | 34 | char *abac_term_typed_string(abac_term_t *ptr); |
---|
| 35 | char *abac_term_string(abac_term_t *ptr); |
---|
[440ba20] | 36 | bool abac_term_is_time(abac_term_t *); |
---|
[5d06689] | 37 | bool abac_term_is_urn(abac_term_t *term); |
---|
| 38 | bool abac_term_is_integer(abac_term_t *term); |
---|
| 39 | bool abac_term_is_string(abac_term_t *term); |
---|
[8bd77b5] | 40 | abac_term_t *abac_term_add_constraint(abac_term_t *ptr, abac_condition_t *cond); |
---|
[5d06689] | 41 | int abac_term_type(abac_term_t *term); |
---|
[8bd77b5] | 42 | char *abac_term_name(abac_term_t *); |
---|
[5d06689] | 43 | |
---|
| 44 | void abac_aspects_free(abac_aspect_t **aspects); |
---|
| 45 | abac_aspect_t *abac_aspect_dup(abac_aspect_t *ptr); |
---|
| 46 | void abac_aspect_free(abac_aspect_t *); |
---|
| 47 | char *abac_aspect_string(abac_aspect_t *ptr); |
---|
| 48 | char *abac_aspect_typed_string(abac_aspect_t *ptr); |
---|
| 49 | |
---|
| 50 | abac_param_list_t *abac_aspect_aspect_params(abac_aspect_t *ptr); |
---|
[8bd77b5] | 51 | abac_term_t **abac_param_list_vectorize(abac_param_list_t *ptr); |
---|
[5d06689] | 52 | abac_param_list_t *abac_aspect_linked_role_params(abac_aspect_t *ptr); |
---|
[669b481] | 53 | char *abac_oset_string(abac_aspect_t *ptr); |
---|
| 54 | char *abac_oset_typed_string(abac_aspect_t *ptr); |
---|
| 55 | char *abac_role_string(abac_aspect_t *ptr); |
---|
| 56 | char *abac_role_typed_string(abac_aspect_t *ptr); |
---|
[5d06689] | 57 | |
---|
[2efdff5] | 58 | char *abac_id_cert_filename(abac_id_t *id); |
---|
| 59 | char *abac_id_privkey_filename(abac_id_t *id); |
---|
| 60 | char *abac_id_subject(abac_id_t *id); |
---|
| 61 | char *abac_id_issuer(abac_id_t *id); |
---|
[8bd77b5] | 62 | abac_id_t *abac_id_dup(abac_id_t *id); |
---|
[5d06689] | 63 | abac_id_t *abac_id_credential_id(abac_id_credential_t *ptr); |
---|
[8bd77b5] | 64 | abac_id_t *abac_id_from_file(char *filename); |
---|
[5d06689] | 65 | int abac_id_generate(abac_id_t **ret, char *cn, int validity); |
---|
| 66 | char *abac_id_keyid(abac_id_t *id); |
---|
| 67 | char *abac_id_cn(abac_id_t *id); |
---|
| 68 | void abac_id_free(abac_id_t *id); |
---|
[8bd77b5] | 69 | int abac_id_has_privkey(abac_id_t *id); |
---|
| 70 | void abac_id_write_cert(abac_id_t *id, FILE *out); |
---|
[5d06689] | 71 | int abac_id_write_privkey(abac_id_t *id, FILE *out); |
---|
[8bd77b5] | 72 | abac_chunk_t abac_id_cert_chunk(abac_id_t *id); |
---|
[9b43fc3] | 73 | abac_chunk_t abac_id_privkey_chunk(abac_id_t *id); |
---|
[5d06689] | 74 | char *abac_id_string(abac_id_t *id); |
---|
| 75 | int abac_id_load_privkey_file(abac_id_t *id, char *filename); |
---|
[669b481] | 76 | void abac_id_write_cert_fname(abac_id_t *id, char *filename); |
---|
| 77 | void abac_id_write_privkey_fname(abac_id_t *id, char *filename); |
---|
[8bd77b5] | 78 | |
---|
[5d06689] | 79 | abac_attribute_t *abac_attribute_dup(abac_attribute_t *ptr); |
---|
| 80 | void abac_attribute_free(abac_attribute_t *ptr); |
---|
| 81 | abac_attribute_t *abac_credential_attribute(abac_credential_t *cred); |
---|
| 82 | int abac_attribute_create(abac_attribute_t **ret,abac_aspect_t *head, abac_aspect_t *tail,int validity); |
---|
| 83 | abac_attribute_t *abac_attribute_add_tail(abac_attribute_t *ptr, abac_aspect_t *); |
---|
| 84 | char *abac_attribute_string(abac_attribute_t *ptr); |
---|
| 85 | char *abac_attribute_typed_string(abac_attribute_t *ptr); |
---|
| 86 | abac_aspect_t *abac_attribute_head(abac_attribute_t *ptr); |
---|
| 87 | abac_aspect_t *abac_attribute_tail(abac_attribute_t *ptr); |
---|
[8bd77b5] | 88 | |
---|
[5d06689] | 89 | bool abac_attribute_is_role(abac_attribute_t *ptr); |
---|
| 90 | abac_aspect_t **abac_attribute_tail_vectorized(abac_attribute_t *ptr); |
---|
| 91 | int abac_attribute_bake(abac_attribute_t *ptr); |
---|
| 92 | int abac_attribute_baked(abac_attribute_t *ptr); |
---|
| 93 | int abac_attribute_write_cert(abac_attribute_t *ptr, FILE *out); |
---|
| 94 | abac_chunk_t abac_attribute_cert_chunk(abac_attribute_t *ptr); |
---|
[669b481] | 95 | void abac_attribute_write_cert_fname(abac_attribute_t *,char*); |
---|
[5d06689] | 96 | |
---|
| 97 | void abac_context_principals_free(abac_id_credential_t **principals); |
---|
| 98 | abac_context_t *abac_context_new(void); |
---|
| 99 | abac_context_t *abac_context_dup(abac_context_t *ctx); |
---|
| 100 | void abac_context_free(abac_context_t *ctx); |
---|
[440ba20] | 101 | void show_yap_db(const char *msg); |
---|
| 102 | |
---|
[5d06689] | 103 | abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success); |
---|
| 104 | abac_credential_t **abac_context_query_with_structure(abac_context_t *, abac_aspect_t*, abac_aspect_t*, int*); |
---|
| 105 | void abac_context_credentials_free(abac_credential_t **); |
---|
| 106 | abac_credential_t **abac_context_credentials(abac_context_t *); |
---|
| 107 | abac_id_credential_t **abac_context_principals(abac_context_t *); |
---|
| 108 | |
---|
[8bd77b5] | 109 | /* |
---|
| 110 | * Error codes for loading certificates. |
---|
| 111 | */ |
---|
| 112 | #define ABAC_CERT_SUCCESS 0 // certificate loaded, all is well |
---|
| 113 | #define ABAC_CERT_INVALID -1 // invalid format; also file not found |
---|
| 114 | #define ABAC_CERT_BAD_SIG -2 // invalid signature |
---|
| 115 | #define ABAC_CERT_MISSING_ISSUER -3 // missing ID cert that issued the attribute cert |
---|
| 116 | #define ABAC_CERT_BAD_CN -4 // ID cert is not matching CN=principal format |
---|
| 117 | #define ABAC_CERT_BAD_YAP -5 // failed to insert into prolog engine |
---|
[440ba20] | 118 | #define ABAC_CERT_EXISTS 1 // ID already exists (does not default to a failure) |
---|
[8bd77b5] | 119 | |
---|
| 120 | #define ABAC_ID_SUCCESS 0 |
---|
| 121 | #define ABAC_ID_GENERATE_INVALID_CN -1 |
---|
| 122 | #define ABAC_ID_GENERATE_INVALID_VALIDITY -2 |
---|
| 123 | |
---|
| 124 | #define ABAC_ATTRIBUTE_SUCCESS 0 |
---|
| 125 | #define ABAC_ATTRIBUTE_INVALID_ROLE -1 |
---|
| 126 | #define ABAC_ATTRIBUTE_INVALID_VALIDITY -2 |
---|
| 127 | #define ABAC_ATTRIBUTE_ISSUER_NOKEY -3 |
---|
[440ba20] | 128 | #define ABAC_ATTRIBUTE_FAIL -4 |
---|
| 129 | |
---|
| 130 | #define ABAC_TERM_SUCCESS 0 |
---|
| 131 | #define ABAC_TERM_FAIL -1 |
---|
[8bd77b5] | 132 | |
---|
| 133 | #define USE(evalue) ((getenv(evalue)!=NULL)?1:0) |
---|
| 134 | |
---|
[5d06689] | 135 | /* from abac_c.c, the c interface */ |
---|
| 136 | void abac_constraint_add_integer_max(abac_condition_t *cond,int val); |
---|
| 137 | void abac_constraint_add_integer_min(abac_condition_t *cond,int val); |
---|
| 138 | void abac_constraint_add_integer_target(abac_condition_t *cond,int val); |
---|
| 139 | void abac_constraint_add_float_max(abac_condition_t *cond,float val); |
---|
| 140 | void abac_constraint_add_float_min(abac_condition_t *cond,float val); |
---|
| 141 | void abac_constraint_add_float_target(abac_condition_t *cond,float val); |
---|
| 142 | void abac_constraint_add_time_max(abac_condition_t *cond,char* val); |
---|
| 143 | void abac_constraint_add_time_min(abac_condition_t *cond,char* val); |
---|
| 144 | void abac_constraint_add_time_target(abac_condition_t *cond,char* val); |
---|
| 145 | void abac_constraint_add_urn_target(abac_condition_t *cond,char* val); |
---|
| 146 | void abac_constraint_add_string_target(abac_condition_t *cond,char* val); |
---|
| 147 | void abac_constraint_add_boolean_target(abac_condition_t *cond, char* val); |
---|
| 148 | abac_condition_t *abac_constraint_from_role(abac_aspect_t *ptr); |
---|
| 149 | abac_condition_t *abac_constraint_from_oset(abac_aspect_t *ptr); |
---|
[669b481] | 150 | abac_condition_t *abac_constraint_create(char *vtype); |
---|
| 151 | |
---|
[5d06689] | 152 | abac_aspect_t *abac_role_principal_create(char *principal_name); |
---|
| 153 | abac_aspect_t *abac_oset_principal_create(char *principal_name); |
---|
| 154 | abac_aspect_t *abac_oset_create(char *principal_name, char *oset_name); |
---|
| 155 | abac_aspect_t *abac_role_create(char *principal_name, char *role_name); |
---|
[7211a95] | 156 | abac_aspect_t *abac_oset_linked_create(char *principal_name, char* linked_role_name, char *oset_name); |
---|
| 157 | abac_aspect_t *abac_role_linked_create(char *principal_name, char* linked_role_name, char *role_name); |
---|
[5d06689] | 158 | abac_aspect_t *abac_oset_object_create(abac_term_t *object); |
---|
| 159 | abac_aspect_t *abac_oset_create(char *principal_name, char *oset_name); |
---|
| 160 | bool abac_oset_is_object(abac_aspect_t *ptr); |
---|
| 161 | bool abac_oset_is_principal(abac_aspect_t *ptr); |
---|
| 162 | bool abac_role_is_principal(abac_aspect_t *ptr); |
---|
| 163 | bool abac_oset_is_linking(abac_aspect_t *ptr); |
---|
| 164 | bool abac_role_is_linking(abac_aspect_t *ptr); |
---|
| 165 | char *abac_role_linked_role(abac_aspect_t *ptr); |
---|
| 166 | char *abac_oset_linked_role(abac_aspect_t *ptr); |
---|
| 167 | char *abac_role_name(abac_aspect_t *ptr); |
---|
| 168 | char *abac_oset_name(abac_aspect_t *ptr); |
---|
| 169 | char *abac_role_principal(abac_aspect_t *ptr); |
---|
| 170 | char *abac_oset_principal(abac_aspect_t *ptr); |
---|
| 171 | void abac_role_add_data_term(abac_aspect_t *ptr, abac_term_t *param); |
---|
| 172 | void abac_oset_add_data_term(abac_aspect_t *ptr, abac_term_t *param); |
---|
| 173 | void abac_role_add_linked_data_term(abac_aspect_t *ptr, abac_term_t *param); |
---|
| 174 | void abac_oset_add_linked_data_term(abac_aspect_t *ptr, abac_term_t *param); |
---|
| 175 | char *abac_oset_object(abac_aspect_t *ptr); |
---|
[669b481] | 176 | abac_term_t **abac_role_get_linked_data_terms(abac_aspect_t *ptr); |
---|
| 177 | abac_term_t **abac_role_get_data_terms(abac_aspect_t *ptr); |
---|
| 178 | abac_term_t **abac_oset_get_linked_data_terms(abac_aspect_t *ptr); |
---|
| 179 | abac_term_t **abac_oset_get_data_terms(abac_aspect_t *ptr); |
---|
| 180 | abac_aspect_t **abac_attribute_role_tails(abac_attribute_t *ptr); |
---|
| 181 | abac_aspect_t **abac_attribute_oset_tails(abac_attribute_t *ptr); |
---|
| 182 | |
---|
| 183 | |
---|
[5d06689] | 184 | char *abac_head_string(abac_attribute_t *ptr); |
---|
| 185 | char *abac_tail_string(abac_attribute_t *ptr); |
---|
| 186 | char *abac_head_typed_string(abac_attribute_t *ptr); |
---|
| 187 | char *abac_tail_typed_string(abac_attribute_t *ptr); |
---|
[669b481] | 188 | |
---|
[5d06689] | 189 | int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
[9b43fc3] | 190 | int abac_context_load_id_privkey_chunk(abac_context_t *ctx, abac_chunk_t cert, abac_chunk_t privkey); |
---|
[5d06689] | 191 | int abac_context_load_attribute_file(abac_context_t *ctx, char *filename); |
---|
| 192 | int abac_context_load_id(abac_context_t *ptr, abac_id_t *id); |
---|
| 193 | int abac_context_load_id_file(abac_context_t *ptr, char *filename); |
---|
| 194 | int abac_context_load_id_files(abac_context_t *ptr, char *filename, char *keyfilename); |
---|
| 195 | int abac_context_load_attribute(abac_context_t *ptr, abac_attribute_t *attr); |
---|
| 196 | void abac_context_load_directory(abac_context_t *ctx, char *path); |
---|
[2efdff5] | 197 | void abac_context_load_principals(abac_context_t *ctx, char *path); |
---|
[5d06689] | 198 | int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 199 | |
---|
[2efdff5] | 200 | int file_exist(char *filename); |
---|
[5d06689] | 201 | |
---|
[8bd77b5] | 202 | #endif /* __ABAC_H__ */ |
---|