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