Changeset 440ba20
- Timestamp:
- 04/30/12 17:31:19 (14 months ago)
- Branches:
- mei_rt2, mei_rt2_fix_1
- Children:
- ca72963
- Parents:
- d037f54
- git-author:
- Mei <mei@…> (04/30/12 17:31:19)
- git-committer:
- Mei <mei@…> (04/30/12 17:31:19)
- Files:
-
- 1 added
- 15 edited
-
Makefile.am (modified) (1 diff)
-
examples/access_rt2_typed/README (modified) (1 diff)
-
libabac/abac.h (modified) (8 diffs)
-
libabac/abac.hh (modified) (7 diffs)
-
libabac/abac_aspect.c (modified) (3 diffs)
-
libabac/abac_common.h (modified) (1 diff)
-
libabac/abac_id.c (modified) (3 diffs)
-
libabac/abac_internal.h (modified) (1 diff)
-
libabac/abac_pl_gen.c (modified) (6 diffs)
-
libabac/abac_pl_pre.c (added)
-
libabac/abac_pl_yap.c (modified) (4 diffs)
-
libabac/abac_pl_yy.c (modified) (35 diffs)
-
libabac/abac_pl_yy.h (modified) (1 diff)
-
libabac/abac_term.c (modified) (19 diffs)
-
libabac/abac_verifier.c (modified) (6 diffs)
-
libabac/rt2.y (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
r8bd77b5 r440ba20 27 27 libabac/abac_term.c \ 28 28 libabac/abac_pl_gen.c \ 29 libabac/abac_pl_pre.c \ 29 30 libabac/abac_pl_yy.c \ 30 31 libabac/abac_pl_yy.h \ -
examples/access_rt2_typed/README
r9502c50 r440ba20 85 85 # 86 86 # [keyid:alpha].role:access([string:'Read'], [urn:?F])<- [principal:?B] 87 # [keyid:alpha].oset:documents([string:?P ) <- [urn:?F]87 # [keyid:alpha].oset:documents([string:?P]) <- [urn:?F] 88 88 # [keyid:alpha].role:team([string:?P]) <- [principal:?B] 89 89 # -
libabac/abac.h
rd037f54 r440ba20 16 16 typedef struct _abac_condition_t abac_condition_t; 17 17 typedef struct _abac_term_t abac_term_t; 18 typedef struct _abac_item_t abac_item_t; 18 19 typedef struct _abac_param_list_t abac_param_list_t; 19 20 … … 22 23 */ 23 24 abac_context_t *abac_context_new(void); 25 abac_context_t *abac_context_dup(abac_context_t *ctx); 24 26 abac_context_t *abac_context_dup(abac_context_t *ctx); 25 27 void abac_context_free(abac_context_t *ctx); … … 124 126 * Operations on term/params. 125 127 */ 128 abac_condition_t *abac_condition_create(char *vtype); 129 abac_condition_t *abac_condition_create_from_aspect(abac_aspect_t *ptr); 126 130 abac_condition_t *abac_condition_dup(abac_condition_t *ptr); 131 int abac_condition_add_range_item(abac_condition_t*, char*, char*, char*); 127 132 void abac_condition_free(abac_condition_t *ptr); 128 abac_condition_t *abac_condition_from_string(char *string);129 abac_condition_t *abac_condition_from_aspect(abac_aspect_t *ptr);130 133 char *abac_condition_typed_string(abac_condition_t *ptr); 131 134 char *abac_condition_string(abac_condition_t *ptr); 132 char *abac_condtype_name(int);133 135 char *abac_term_to_time(char *string); 136 int abac_term_isvar(abac_term_t *term); 134 137 char *abac_term_typed_string(abac_term_t *ptr); 135 138 char *abac_term_string(abac_term_t *ptr); … … 138 141 abac_term_t *abac_term_create(int, char*, abac_condition_t*); 139 142 abac_term_t *abac_term_named_create(int, char*); 140 bool abac_term_is_urn_type(abac_term_t *); 141 bool abac_term_is_integer_type(abac_term_t *); 143 bool abac_term_is_numeric(abac_term_t *); 144 bool abac_term_is_alpha(abac_term_t *); 145 bool abac_term_is_time(abac_term_t *); 146 bool abac_term_is_integer_type(abac_term_t *term); 147 bool abac_term_is_urn_type(abac_term_t *term); 148 bool abac_term_is_string_type(abac_term_t *term); 149 bool abac_term_is_time_type(abac_term_t *term); 142 150 int abac_term_type(abac_term_t *term); 143 151 abac_term_t *abac_term_add_constraint(abac_term_t *ptr, abac_condition_t *cond); 144 abac_term_t *abac_term_new(int, char *, char *, abac_aspect_t*);152 abac_term_t *abac_term_new(int, char *, int, char *, void *); 145 153 abac_term_t *abac_term_named_new(int, char *); 146 154 void abac_term_free(abac_term_t *); … … 157 165 abac_term_t **abac_param_list_vectorize(abac_param_list_t *ptr); 158 166 void abac_terms_free(abac_term_t **terms); 167 int abac_verify_term_type(char *); 159 168 160 169 /* from abac_verifier */ … … 182 191 void abac_errx(int val, const char *string); 183 192 193 /* from abac_pl_yap */ 194 void show_yap_db(const char *msg); 195 184 196 /* 185 197 * Error codes for loading certificates. … … 191 203 #define ABAC_CERT_BAD_CN -4 // ID cert is not matching CN=principal format 192 204 #define ABAC_CERT_BAD_YAP -5 // failed to insert into prolog engine 205 #define ABAC_CERT_EXISTS 1 // ID already exists (does not default to a failure) 193 206 194 207 #define ABAC_ID_SUCCESS 0 … … 200 213 #define ABAC_ATTRIBUTE_INVALID_VALIDITY -2 201 214 #define ABAC_ATTRIBUTE_ISSUER_NOKEY -3 215 #define ABAC_ATTRIBUTE_FAIL -4 216 217 #define ABAC_TERM_SUCCESS 0 218 #define ABAC_TERM_FAIL -1 202 219 203 220 -
libabac/abac.hh
rd037f54 r440ba20 28 28 } 29 29 /* range constraint */ 30 Constraint(char *constraint) { 31 m_constraint=abac_condition_from_string(constraint); 30 Constraint(char *vartype) { 31 m_constraint=abac_condition_create(vartype); 32 } 33 /* min, max, target */ 34 int add_constraint_item(char *vtype,char *itype, char *val) { 35 return abac_condition_add_range_item(m_constraint,vtype,itype,val); 36 } 37 void add_constraint_item_help() { 38 printf(" USAGE: add_constraint_item(\"integer\",\"max\",\"2000\"); \n"); 39 printf(" add_constraint_item(\"time\",\"target\",\"20201101T182930\"); \n"); 32 40 } 33 41 /* role constraint */ … … 76 84 } 77 85 /* can be an a variable data term or a specific value */ 78 DataTerm(int type, char *name, Constraint *cond=NULL) { 86 DataTerm(char* typenm, char *name, Constraint *cond=NULL) { 87 int type=abac_verify_term_type(typenm); 79 88 if(debug) printf("adding a Dataterm (%s)\n",name); 89 if(type==ABAC_TERM_FAIL) 90 abac_errx(1, "DataTerm, fail to create the term"); 80 91 if(cond) { 81 92 m_cond=cond; … … 493 504 This will throw an exception if the cert's already been baked. */ 494 505 bool bake() { 506 /* can not bake in ABAC_CN mode */ 507 if(USE("ABAC_CN")) 508 abac_errx(1, "bake, can not bake the cert with env(ABAC_CN) set"); 495 509 int rt=abac_attribute_bake(m_attr); 496 510 if(rt!=1) … … 524 538 return abac_attribute_cert_chunk(m_attr); 525 539 } 540 /* generate yap clauses and injected into db */ 541 int consume() { 542 /* attribute needs to be baked */ 543 if(!baked()) { 544 return ABAC_ATTRIBUTE_FAIL; 545 } 546 } 526 547 private: 527 548 abac_attribute_t *m_attr; … … 545 566 ABAC_CERT_INVALID invalid certificate (or file not found) 546 567 ABAC_CERT_BAD_SIG invalid signature */ 568 void dump_yap() { 569 show_yap_db("dump_yap"); 570 } 547 571 int load_id(ABAC::ID& id) { 548 572 return abac_context_load_id_id(m_ctx, id.id()); … … 610 634 611 635 abac_context_credentials_free(creds); 636 if(debug) show_yap_db("calling from context_credentials"); 612 637 return attributes; 613 638 } … … 621 646 622 647 Constraint::Constraint(Role *role) 623 { m_constraint=abac_condition_ from_aspect(role->role()); }648 { m_constraint=abac_condition_create_from_aspect(role->role()); } 624 649 Constraint::Constraint(Oset *oset) 625 { m_constraint=abac_condition_ from_aspect(oset->oset()); }650 { m_constraint=abac_condition_create_from_aspect(oset->oset()); } 626 651 } 627 652 -
libabac/abac_aspect.c
rd037f54 r440ba20 49 49 50 50 /**************************************************************/ 51 void abac_aspect_dump(abac_aspect_t *ptr, char* offset) 52 { 53 char *tmp=NULL; 54 asprintf(&tmp," %s",offset); 55 if(ptr->prereqs != 0) { 56 abac_aspect_t *cur; 57 abac_list_foreach(ptr->prereqs, cur, 58 if(cur) 59 abac_aspect_dump(cur, tmp); 60 ); 61 return; 62 } 63 64 printf("\n..... an aspect .....\n"); 65 printf("%s aspect_type: %d(%s)\n", offset, ptr->aspect_type, abac_aspect_type_string(ptr)); 66 printf("%s is_object: %d\n", offset, ptr->is_object); 67 printf("%s principal_name: %s\n", offset, ptr->principal_name); 68 if(ptr->principal_name_p) 69 printf("%s principal_name_p: %s\n", offset, ptr->principal_name_p); 70 else printf("%s principal_name_p: --\n", offset); 71 if(ptr->principal_object) 72 abac_term_dump(ptr->principal_object, tmp); 73 else ("%s principal_object: --\n", offset); 74 if(ptr->linked_role_name) 75 printf("%s linked_role_name: %s\n", offset, ptr->linked_role_name); 76 else printf("%s linked_role_name: --\n", offset); 77 if(ptr->linked_role_params) 78 abac_param_dump(ptr->linked_role_params, tmp); 79 else printf("%s linked_role_params: --\n", offset); 80 if(ptr->aspect_name) 81 printf("%s aspect_name: %s\n", offset, ptr->aspect_name); 82 else printf("%s aspect_name: --\n", offset); 83 if(ptr->aspect_params) 84 abac_param_dump(ptr->aspect_params, tmp); 85 else printf("%s aspect_params: --\n", offset); 86 if(ptr->type_string) 87 printf("%s type_string:- %s\n", offset, ptr->type_string); 88 else printf("%s type_string: --\n", offset); 89 printf("%s refcount:- %d\n", offset, ptr->refcount); 90 printf(".................................."); 91 free(tmp); 92 } 93 51 94 bool abac_aspect_is_oset(abac_aspect_t *ptr) 52 95 { … … 226 269 } 227 270 271 abac_term_t *abac_aspect_object_term(abac_aspect_t *ptr) 272 { 273 return ptr->principal_object; 274 } 275 228 276 char *abac_aspect_object_name(abac_aspect_t *ptr) 229 277 { … … 250 298 abac_term_t *obj=ptr->principal_object; 251 299 return abac_term_constraint(obj); 300 } 301 302 char* abac_aspect_get_issuer_keytype(abac_aspect_t *ptr) 303 { 304 abac_id_t *issuer_id; 305 char *principalname=abac_aspect_principal_principalname(ptr); 306 if(principalname) { 307 abac_id_credential_t *id_cred=abac_id_credential_lookup(principalname); 308 if(id_cred) { 309 issuer_id=abac_id_credential_id(id_cred); 310 return abac_id_keyid(issuer_id); 311 } 312 } 313 return NULL; 314 } 315 316 int abac_aspect_get_issuer_idtype(abac_aspect_t *ptr) 317 { 318 abac_id_t *issuer_id; 319 char *principalname=abac_aspect_principal_principalname(ptr); 320 if(principalname) { 321 abac_id_credential_t *id_cred=abac_id_credential_lookup(principalname); 322 if(id_cred) { 323 issuer_id=abac_id_credential_id(id_cred); 324 return abac_id_idtype(issuer_id); 325 } 326 } 327 return 0; 252 328 } 253 329 -
libabac/abac_common.h
rd037f54 r440ba20 65 65 } abac_aspecttype_t; 66 66 67 typedef enum _itemtype_t { 68 e_ITEM_MIN = 1, 69 e_ITEM_MAX = 2, 70 e_ITEM_TARGET = 3 71 } abac_itemtype_t; 72 73 /* itemname[itemtype] */ 74 static const char *const _itemname[] = 75 { 76 "baditem", 77 "min", 78 "max", 79 "target" 80 }; 81 static int _itemname_cnt=3; 82 67 83 #endif -
libabac/abac_id.c
r8bd77b5 r440ba20 16 16 #include "abac_internal.h" 17 17 #include "abac_util.h" 18 19 static int debug=0; 18 20 19 21 #define KEY_SUFFIX "_private.pem" … … 425 427 id->key = NULL; 426 428 id->refcount = 1; 429 if(debug) printf("abac_id_new: made a new id, %ld\n",(long) id); 427 430 return id; 428 431 } … … 515 518 abac_id_t *id = abac_xmalloc(sizeof(abac_id_t)); 516 519 520 char *tmp=NULL; 521 asprintf(&tmp,"p%s",cn); 517 522 id->idtype = e_KEYID; 518 id->cn = abac_xstrdup(cn);523 id->cn = tmp; 519 524 id->key = _generate_key(); 520 525 id->cert = _generate_cert(id->key, cn, validity); -
libabac/abac_internal.h
rd037f54 r440ba20 8 8 9 9 #include "abac.h" 10 11 int abac_condition_set_aspect_ptr(abac_condition_t *ptr, abac_aspect_t *aptr); 12 int abac_condition_set_aspect_string(abac_condition_t *ptr, char *str); 13 int abac_condition_set_range_string(abac_condition_t *ptr); 14 int abac_condition_is_range(abac_condition_t *ptr); 15 abac_aspect_t *abac_condition_of_aspect(abac_condition_t *ptr); 16 17 void abac_aspect_dump(abac_aspect_t *ptr, char* offset); 18 abac_term_t *abac_aspect_object_term(abac_aspect_t *ptr); 19 20 void abac_condition_dump(abac_condition_t *ptr, char *offset); 21 abac_list_t *abac_condition_range_list(abac_condition_t *ptr); 22 23 void abac_term_dump(abac_term_t *ptr, char *offset); 24 25 abac_item_t *abac_item_new(char *itype, char *val); 26 int abac_item_type(abac_item_t *); 27 char* abac_item_val(abac_item_t *); 28 void abac_param_dump(abac_param_list_t *ptr, char *offset); 29 abac_list_t *abac_param_list(abac_param_list_t *ptr); 30 char* abac_aspect_get_issuer_keytype(abac_aspect_t *ptr); 31 int abac_aspect_get_issuer_idtype(abac_aspect_t *ptr); 10 32 11 33 certificate_t *abac_attribute_issuer_cert(abac_attribute_t *ptr); -
libabac/abac_pl_gen.c
rd037f54 r440ba20 24 24 int ABAC_IN_PROLOG=0; 25 25 26 abac_list_t *abac_pl_constraints=NULL; 27 28 /* to track id certs within a rule clause */ 29 typedef struct _abac_id_cert_t { 30 char *principalname; 31 int type; /* keyidtype */ 32 char *clause; 33 } abac_id_cert_t; 34 abac_list_t *abac_pl_id_certs = NULL; 35 26 36 extern int using_this; 27 37 28 29 38 extern char* abac_yyfptr_encoded; 30 extern int abac_yy_cnt_yy_id_certs(); 31 extern void abac_yy_free_yy_id_certs(); 32 extern char *abac_yy_string_yy_id_certs(); 33 extern void abac_yy_free_yy_constraints(); 34 extern char *abac_yy_string_yy_constraints(); 39 40 char *generate_pl_type_clause(char *principalname, int type); 41 35 42 36 43 /***********************************************************************/ … … 74 81 } 75 82 return clist; 83 } 84 85 86 /************************************************************************/ 87 /* this is for tracking prolog constraints */ 88 void abac_pl_init_constraints() 89 { 90 abac_pl_constraints = abac_list_new(); 91 } 92 93 void abac_pl_free_constraints() 94 { 95 char *cur; 96 abac_list_foreach(abac_pl_constraints, cur, 97 if(cur) 98 free(cur); 99 ); 100 abac_list_free(abac_pl_constraints); 101 abac_pl_constraints=NULL; 102 } 103 104 int abac_pl_cnt_constraints() 105 { 106 return abac_list_size(abac_pl_constraints); 107 } 108 109 char *abac_pl_string_constraints() 110 { 111 int first=1; 112 char *tmp=NULL; 113 char *final=NULL; 114 char* cur; 115 abac_list_foreach(abac_pl_constraints, cur, 116 if(cur) 117 if(first) { 118 final=abac_xstrdup(cur); 119 first=0; 120 } else { 121 tmp=final; 122 final=NULL; 123 int cnt=asprintf(&final,"%s,%s", tmp, cur); 124 } 125 ); 126 return final; 127 } 128 129 void abac_pl_add_constraints(char *constraint) 130 { 131 if(abac_pl_constraints == NULL) 132 abac_pl_init_constraints(); 133 char* nptr=abac_xstrdup(constraint); 134 abac_list_add(abac_pl_constraints, nptr); 135 } 136 137 138 /************************************************************************/ 139 void abac_pl_init_id_certs() 140 { 141 abac_pl_id_certs = abac_list_new(); 142 } 143 144 void abac_pl_free_id_certs() 145 { 146 if(abac_pl_id_certs==NULL) 147 return; 148 149 abac_id_cert_t *id; 150 abac_list_foreach(abac_pl_id_certs, id, 151 if(id) 152 free(id->principalname); 153 free(id->clause); 154 free(id); 155 ); 156 abac_list_free(abac_pl_id_certs); 157 abac_pl_id_certs = NULL; 158 } 159 160 int abac_pl_cnt_id_certs() 161 { 162 return abac_list_size(abac_pl_id_certs); 163 } 164 165 char *abac_pl_string_id_certs() 166 { 167 int first=1; 168 char *tmp=NULL; 169 abac_id_cert_t *cur; 170 abac_list_foreach(abac_pl_id_certs, cur, 171 if(cur) 172 if(first) { 173 tmp=abac_xstrdup(cur->clause); 174 first=0; 175 } else { 176 int cnt=asprintf(&tmp,"%s,%s", tmp, cur->clause); 177 } 178 ); 179 return tmp; 180 } 181 182 void abac_pl_add_id_certs(char *principalname, int type) 183 { 184 abac_id_cert_t *id_cert=NULL; 185 int found=0; 186 abac_id_cert_t *cur; 187 188 if(debug) { 189 printf("add_id_certs: adding --> (%s)\n", principalname); 190 } 191 192 if(abac_pl_id_certs == NULL) { 193 abac_pl_init_id_certs(); 194 } else { 195 abac_list_foreach(abac_pl_id_certs, cur, 196 if(cur) 197 if(strcmp(cur->principalname,principalname)==0) { 198 found=1; 199 break; 200 } 201 ); 202 } 203 204 if (found) { 205 return; 206 } else { 207 id_cert=abac_xmalloc(sizeof(abac_id_cert_t)); 208 id_cert->principalname=abac_xstrdup(principalname); 209 id_cert->type=type; 210 id_cert->clause=generate_pl_type_clause(principalname,type); 211 abac_list_add(abac_pl_id_certs, id_cert); 212 } 76 213 } 77 214 … … 104 241 } 105 242 106 if(debug && tmp) printf(" head_string: (%s)\n",tmp);243 if(debug && tmp) printf("generate_pl_head_string: (%s)\n",tmp); 107 244 if(cnt>0) 108 245 return tmp; … … 231 368 { 232 369 /*only, A.R <- B */ 370 if(debug) 371 printf("calling _build_constraint_rule_clause (%s)(%s)\n", head_string, tail_string); 233 372 char *tmp; 234 373 int idx=_get_next_cred_idx(); … … 452 591 abac_list_t *clauses=abac_list_new(); 453 592 454 int cnt=abac_ yy_cnt_yy_id_certs();593 int cnt=abac_pl_cnt_id_certs(); 455 594 if(cnt > 0) { /* string it up */ 456 id_clauses_string=abac_ yy_string_yy_id_certs();457 abac_ yy_free_yy_id_certs();595 id_clauses_string=abac_pl_string_id_certs(); 596 abac_pl_free_id_certs(); 458 597 } 459 598 460 599 /* make a loop here */ 461 cnt=abac_ yy_cnt_yy_constraints();600 cnt=abac_pl_cnt_constraints(); 462 601 if(cnt > 0) { 463 constraint_clauses_string=abac_ yy_string_yy_constraints();464 abac_ yy_free_yy_constraints();602 constraint_clauses_string=abac_pl_string_constraints(); 603 abac_pl_free_constraints(); 465 604 } 466 605 … … 539 678 if(typeid==NULL || strcmp(typeid,"NULL")==0) 540 679 panic("generate_pl_type_clause: can not have null typeid"); 680 if(debug) 681 printf("generate type clause, (%s)\n", principalname); 541 682 int cnt=asprintf(&tmp,"isType(%s,%s)", 542 683 principalname, typeid); -
libabac/abac_pl_yap.c
rd037f54 r440ba20 74 74 } 75 75 76 static void _show_yap_db(char *msg)76 void show_yap_db(const char *msg) 77 77 { 78 78 char lstr[]="listing"; … … 287 287 acme.buys_rocket <- coyote (coyote=prin, acme.buys_rocket=role) 288 288 ==> isMember(coyote,role(acme,buys_rocket), L) 289 290 acme.buys_rocket <- acme.preferred_customer -- NOT DONE YET*/289 acme.buys_rocket <- acme.preferred_customer -- NOT valid 290 */ 291 291 static abac_stack_t *_query_with_aspect(abac_pl_t *pl, abac_aspect_t* head, abac_aspect_t* tail) 292 292 { … … 295 295 296 296 if(debug) 297 _show_yap_db("DEBUG:calling within _query_with_aspect");297 show_yap_db("DEBUG:calling within _query_with_aspect"); 298 298 299 299 char *nm; … … 333 333 ret=_make_yap_query(prin_nm,nm,tmp); 334 334 return ret; 335 }336 337 /* this is only if the db is rather complete */338 static abac_stack_t *_dump_db(abac_pl_t *pl)339 {340 YAP_Term *eterm;341 YAP_Term arg[3];342 char tmp[5000];343 abac_stack_t *cred_list = abac_stack_new();344 345 if(USE("DUMP_DB"))346 _show_yap_db("DEBUG:calling within _dump_db");347 348 char *estring=NULL;349 YAP_Term *eterm1;350 YAP_Term *eterm2;351 asprintf(&estring,"_");352 /*353 arg[0]=YAP_ReadBuffer(estring,eterm1);354 arg[1]=YAP_ReadBuffer(estring,eterm2);355 */356 arg[0]=YAP_MkVarTerm();357 arg[1]=YAP_MkVarTerm();358 arg[2]=YAP_MkVarTerm();359 YAP_Atom f = YAP_LookupAtom("isMember");360 YAP_Functor func = YAP_MkFunctor(f, 3);361 YAP_Term goal=YAP_MkApplTerm(func, 3, arg);362 363 int rc =YAP_RunGoal( goal );364 if (rc) {365 printf("YAP dump succeed\n");366 YAP_WriteBuffer(arg[2], tmp, 5000,YAP_WRITE_HANDLE_VARS);367 if(debug) printf(" dump answer : %s\n", tmp);368 /* this is returned as ['string1','string2'] */369 _credentials_from_string(cred_list,tmp);370 while (YAP_RestartGoal()) {371 if(debug) printf("another dump success\n");372 YAP_WriteBuffer(arg[2], tmp, 5000,YAP_WRITE_HANDLE_VARS);373 if(debug) printf(" dump restart answer : %s\n", tmp);374 _credentials_from_string(cred_list,tmp);375 }376 } else {377 printf("YAP _dump_db query failed\n");378 /* YAP_Exit(1); */379 }380 return cred_list;381 }382 383 /* findall(X,isMember(_,_,X),L) */384 static abac_stack_t *_dump2_db(abac_pl_t *pl)385 {386 YAP_Term *eterm;387 YAP_Term arg[3];388 char tmp[5000];389 abac_stack_t *cred_list = abac_stack_new();390 391 if(debug)392 _show_yap_db("DEBUG:calling within _dump2_db");393 394 char *estring="isMember(_,_,X)";395 arg[0]=YAP_MkAtomTerm(YAP_LookupAtom("X"));396 arg[1]=YAP_ReadBuffer(estring,eterm);397 arg[2]=YAP_MkVarTerm();398 YAP_Atom f = YAP_LookupAtom("findall");399 YAP_Functor func = YAP_MkFunctor(f, 3);400 YAP_Term goal=YAP_MkApplTerm(func, 3, arg);401 402 int rc =YAP_RunGoal( goal );403 if (rc) {404 printf("YAP dump succeed\n");405 YAP_WriteBuffer(arg[2], tmp, 5000,YAP_WRITE_HANDLE_VARS);406 if(debug) printf(" dump answer : %s\n", tmp);407 /* this is returned as ['string1','string2'] */408 _credentials_from_string(cred_list,tmp);409 } else {410 printf("YAP _dump2_db query failed\n");411 /* YAP_Exit(1); */412 }413 return cred_list;414 335 } 415 336 -
libabac/abac_pl_yy.c
rd037f54 r440ba20 16 16 17 17 /* from abac_pl_gen.c */ 18 extern char *generate_pl_range_constraint(char *,char *,char *,char *);19 extern char *generate_pl_range_time_constraint(char *,char *,char *);20 18 extern abac_list_t *generate_pl_clauses(abac_aspect_t *, abac_aspect_t *); 21 extern char* generate_pl_constraint_clause(abac_aspect_t *, char *); 22 extern char *generate_pl_type_clause(char *, int); 23 /* from abac_pl_yap.c */ 24 extern char *abac_pl_add_range_constraint_clause(char *var, char *tmplist); 19 25 20 /* from rt2.y */ 26 21 extern void abac_yyinit(); … … 34 29 abac_aspect_t *abac_rule_tail_aspect=NULL; 35 30 36 /* to track id certs within a rule clause */37 typedef struct _abac_yy_id_cert_t {38 char *principalname;39 int type; /* keyidtype */40 char *clause;41 } abac_yy_id_cert_t;42 abac_list_t *abac_yy_id_certs = NULL;43 31 44 32 /* structure to hold the range information … … 55 43 } abac_yy_range_t; 56 44 57 /* to track role/oset constraint clauses used within a rule clause,58 collect them up in one place, these are for conjunction clauses */59 typedef struct _abac_yy_constraint_t {60 char *clause;61 } abac_yy_constraint_t;62 abac_list_t *abac_yy_constraints = NULL;63 64 45 /* local principal structure [keyid:USC] */ 65 46 struct _abac_yy_principal_t { … … 74 55 int is_anonymous; 75 56 char *name; 76 char *cond_str; 77 void *cond_ptr; // ptr to a saved abac_aspect_t 57 int isrange; 58 char *cond_str; // range string ??? not sure if this is possible 59 void *cond_ptr; // ptr to a saved abac_aspect_t or a list(item_t) 78 60 abac_yy_expression_t *cond_head_expr; 79 61 }; … … 92 74 int type; 93 75 char *name; 94 char *cond_str; 95 void *cond_ptr; // ptr to a saved abac_aspect_t 76 char *cond_str; // range string 77 void *cond_ptr; // ptr to a saved abac_aspect_t 96 78 abac_list_t *cond_range; 97 79 abac_yy_expression_t *cond_head_expr; // parking stub … … 186 168 { 187 169 if (abac_rule_clauses != NULL) { 188 char *cur; 189 if(abac_yy_id_certs) { 190 abac_list_foreach(abac_yy_id_certs, cur, 191 if(cur) free(cur); 192 ); 193 } 170 abac_pl_free_id_certs(); 194 171 abac_list_free(abac_rule_clauses); 195 172 } … … 213 190 214 191 /************************************************************************/ 215 void abac_yy_init_yy_id_certs()216 {217 abac_yy_id_certs = abac_list_new();218 }219 220 void abac_yy_free_yy_id_certs()221 {222 abac_yy_id_cert_t *id;223 abac_list_foreach(abac_yy_id_certs, id,224 if(id)225 free(id->principalname);226 free(id->clause);227 free(id);228 );229 abac_list_free(abac_yy_id_certs);230 abac_yy_id_certs = NULL;231 }232 233 int abac_yy_cnt_yy_id_certs()234 {235 return abac_list_size(abac_yy_id_certs);236 }237 238 char *abac_yy_string_yy_id_certs()239 {240 int first=1;241 char *tmp=NULL;242 abac_yy_id_cert_t *cur;243 abac_list_foreach(abac_yy_id_certs, cur,244 if(cur)245 if(first) {246 tmp=abac_xstrdup(cur->clause);247 first=0;248 } else {249 int cnt=asprintf(&tmp,"%s,%s", tmp, cur->clause);250 }251 );252 return tmp;253 }254 255 static void _add_yy_id_certs(char *principalname, int type)256 {257 abac_yy_id_cert_t *id_cert=NULL;258 259 if(debug) {260 printf("add_yy_id_certs: adding --> (%s)\n", principalname);261 }262 int found=0;263 abac_yy_id_cert_t *cur;264 abac_list_foreach(abac_yy_id_certs, cur,265 if(cur)266 if(strcmp(cur->principalname,principalname)==0) {267 found=1;268 break;269 }270 );271 272 if (found) {273 return;274 } else {275 id_cert=abac_xmalloc(sizeof(abac_yy_id_cert_t));276 id_cert->principalname=abac_xstrdup(principalname);277 id_cert->type=type;278 if(USE("ABAC_CN")) {279 id_cert->clause=generate_pl_type_clause(principalname,type);280 } else {281 int *tmp=NULL;282 asprintf(&tmp,"p%s",principalname);283 id_cert->clause=generate_pl_type_clause(tmp,type);284 free(tmp);285 }286 abac_list_add(abac_yy_id_certs, id_cert);287 }288 }289 290 /***********************************************************************/291 192 static void _free_yy_cond_range(abac_list_t *ptr) 292 193 { … … 459 360 void set_yy_term_data_type(abac_yy_term_data_t *ptr, char* typestr) 460 361 { 461 int type=abac_ term_verify_term_type(typestr);362 int type=abac_verify_term_type(typestr); 462 363 ptr->type=type; 463 364 } … … 470 371 bool is_yy_term_data_type_numeric(abac_yy_term_data_t *ptr) 471 372 { 472 if(ptr->type==abac_ term_verify_term_type("integer") ||473 ptr->type==abac_ term_verify_term_type("float"))373 if(ptr->type==abac_verify_term_type("integer") || 374 ptr->type==abac_verify_term_type("float")) 474 375 return 1; 475 376 return 0; … … 478 379 bool is_yy_term_data_type_time(abac_yy_term_data_t *ptr) 479 380 { 480 if(ptr->type==abac_ term_verify_term_type("time"))381 if(ptr->type==abac_verify_term_type("time")) 481 382 return 1; 482 383 return 0; … … 485 386 bool is_yy_term_data_type_alpha(abac_yy_term_data_t *ptr) 486 387 { 487 if(ptr->type==abac_ term_verify_term_type("string") ||488 ptr->type==abac_ term_verify_term_type("urn") ||489 ptr->type==abac_ term_verify_term_type("boolean"))388 if(ptr->type==abac_verify_term_type("string") || 389 ptr->type==abac_verify_term_type("urn") || 390 ptr->type==abac_verify_term_type("boolean")) 490 391 return 1; 491 392 return 0; … … 531 432 ptr->is_anonymous=0; 532 433 ptr->name=NULL; 434 ptr->isrange=0; 533 435 ptr->cond_str=NULL; 436 ptr->cond_ptr=NULL; 534 437 ptr->cond_head_expr=NULL; 535 438 return ptr; … … 539 442 { 540 443 using_this=1; 444 } 445 446 void set_yy_term_principal_isrange(abac_yy_term_principal_t *ptr, int isrange) 447 { 448 ptr->isrange=isrange; 541 449 } 542 450 … … 627 535 ptr->next=NULL; 628 536 ptr->bcnt=1; 629 return ptr;630 }631 632 /************************************************************************/633 void abac_yy_init_yy_constraints()634 {635 abac_yy_constraints = abac_list_new();636 }637 638 void abac_yy_free_yy_constraints()639 {640 abac_yy_constraint_t *cur;641 abac_list_foreach(abac_yy_constraints, cur,642 if(cur && cur->clause)643 free(cur->clause);644 free(cur);645 );646 abac_list_free(abac_yy_constraints);647 abac_yy_constraints=NULL;648 }649 650 int abac_yy_cnt_yy_constraints()651 {652 return abac_list_size(abac_yy_constraints);653 }654 655 char *abac_yy_string_yy_constraints()656 {657 int first=1;658 char *tmp=NULL;659 abac_yy_constraint_t *cur;660 abac_list_foreach(abac_yy_constraints, cur,661 if(cur && cur->clause)662 if(first) {663 tmp=abac_xstrdup(cur->clause);664 first=0;665 } else {666 int cnt=asprintf(&tmp,"%s,%s", tmp, cur->clause);667 }668 );669 return tmp;670 }671 672 abac_yy_constraint_t *abac_yy_add_yy_constraints(char *constraint)673 {674 abac_yy_constraint_t *ptr=675 (abac_yy_constraint_t *) abac_xmalloc(sizeof(abac_yy_constraint_t));676 ptr->clause=abac_xstrdup(constraint);677 abac_list_add(abac_yy_constraints, ptr);678 537 return ptr; 679 538 } … … 846 705 /***************************************************************************/ 847 706 /* add the oset condition to constraint list */ 848 char *make_yy_oset_constraint(abac_yy_term_data_t *ptr, char *tail_string)707 void make_yy_oset_constraint(abac_yy_term_data_t *ptr, char *tail_string) 849 708 { 850 709 abac_yy_expression_t *head_expr=get_yy_term_data_cond_head_expr(ptr); 851 710 if(head_expr) { 852 711 abac_aspect_t *head_aspect=validate_head(e_yy_OSET_TYPE,head_expr); 853 if(head_aspect == NULL) 854 goto error; 855 856 char *tmp=generate_pl_constraint_clause(head_aspect,tail_string); 857 set_yy_term_data_cond_str(ptr,tmp); 858 set_yy_term_data_cond_ptr(ptr,head_aspect); 859 abac_yy_add_yy_constraints(tmp); 860 return tmp; 712 if(head_aspect != NULL) { 713 if(debug) printf("make_yy_oset_constraint..\n"); 714 set_yy_term_data_cond_ptr(ptr,head_aspect); 715 } 861 716 } 862 863 error:864 return NULL;865 717 } 718 866 719 /* add the role condition to constraint list */ 867 char *make_yy_role_constraint(abac_yy_term_principal_t *ptr, char *tail_string)720 void make_yy_role_constraint(abac_yy_term_principal_t *ptr, char *tail_string) 868 721 { 869 722 abac_yy_expression_t *head_expr=get_yy_term_principal_cond_head_expr(ptr); 870 723 if(head_expr) { 871 724 abac_aspect_t *head_aspect=validate_head(e_yy_ROLE_TYPE,head_expr); 872 if(head_aspect == NULL) 873 goto error; 874 875 char *tmp=generate_pl_constraint_clause(head_aspect,tail_string); 876 set_yy_term_principal_cond_str(ptr,tmp); 877 set_yy_term_principal_cond_ptr(ptr,head_aspect); 878 abac_yy_add_yy_constraints(tmp); 879 if(debug) { 880 printf("make_yy_role_constraint, adding (%s) \n",tmp); 725 if(head_aspect != NULL) { 726 if(debug) printf("make_yy_role_constraint..\n"); 727 set_yy_term_principal_cond_ptr(ptr,head_aspect); 728 set_yy_term_principal_isrange(ptr,0); 881 729 } 882 return tmp;883 730 } 884 885 error:886 return NULL;887 731 } 888 732 889 733 890 734 /****************************************************************/ 891 /* add the range condition to constraint list */892 /* this is for integer and float only */893 void make_yy_range_numeric_constraint(abac_yy_term_data_t *ptr, char *var)894 {895 char *typestr=abac_termtype_string(ptr->type);896 abac_list_t *rlist=get_yy_term_data_cond_range(ptr);897 char *tmplist=NULL;898 char *tmp=NULL;899 int as_range=1; /* either , or ; */900 if(rlist) {901 char *rstring=_string_yy_cond_range(rlist);902 set_yy_term_data_cond_str(ptr,rstring);903 abac_yy_range_t *cur;904 905 /* a list of values -- in chars */906 abac_list_foreach(rlist, cur,907 int type=cur->type;908 char *val=cur->val;909 switch(type) {910 case e_yy_RANGE_MIN:911 tmp=generate_pl_range_constraint(typestr,var,val,">=");912 break;913 case e_yy_RANGE_MAX:914 tmp=generate_pl_range_constraint(typestr,var,val,"=<");915 break;916 case e_yy_RANGE_TARGET:917 tmp=generate_pl_range_constraint(NULL,var,val,"=");918 as_range=0;919 break;920 }921 /* ; is prolog's disjunction built in predicate */922 if(tmplist) {923 if(as_range)924 asprintf(&tmplist,"%s,%s",tmplist,tmp);925 else926 asprintf(&tmplist,"%s;%s",tmplist,tmp);927 } else {928 tmplist=tmp;929 }930 tmp=NULL;931 );932 asprintf(&tmplist,"(%s)",tmplist);933 abac_yy_add_yy_constraints(tmplist);934 }935 }936 937 /****************************************************************/938 /* this is for time only */939 void make_yy_range_time_constraint(abac_yy_term_data_t *ptr, char *var)940 {941 char *typestr=abac_termtype_string(ptr->type);942 abac_list_t *rlist=get_yy_term_data_cond_range(ptr);943 char *tmplist=NULL;944 char *tmp=NULL;945 char *ttmp=NULL;946 char *tlist=NULL;947 int as_range=1; /* either , or ; */948 if(rlist) {949 char *rstring=_string_yy_cond_range(rlist);950 set_yy_term_data_cond_str(ptr,rstring);951 abac_yy_range_t *cur;952 953 /* a list of values -- in chars */954 abac_list_foreach(rlist, cur,955 int type=cur->type;956 char *tval=cur->val;957 char *val=abac_term_to_time(tval);958 switch(type) {959 case e_yy_RANGE_MIN:960 ttmp=generate_pl_range_time_constraint(var,val,">");961 tmp=generate_pl_range_time_constraint(var,val,"=");962 asprintf(&tlist,"(%s;%s)",ttmp,tmp);963 tmp=tlist;964 break;965 case e_yy_RANGE_MAX:966 ttmp=generate_pl_range_time_constraint(var,val,"=");967 tmp=generate_pl_range_time_constraint(var,val,"<");968 asprintf(&tlist,"(%s;%s)",ttmp,tmp);969 tmp=tlist;970 break;971 case e_yy_RANGE_TARGET:972 tmp=generate_pl_range_time_constraint(var,val,"=");973 as_range=0;974 break;975 }976 free(val);977 /* ; is prolog's disjunction built in predicate */978 if(tmplist) {979 if(as_range)980 asprintf(&tmplist,"%s,%s",tmplist,tmp);981 else982 asprintf(&tmplist,"%s;%s",tmplist,tmp);983 } else {984 tmplist=tmp;985 }986 tmp=NULL;987 );988 989 asprintf(&tmplist,"(%s)",tmplist);990 /* generate a clause with above and add into db */991 tmp=abac_pl_add_range_constraint_clause(var,tmplist);992 abac_yy_add_yy_constraints(tmp);993 }994 }995 996 /****************************************************************/997 /* this is for string and urn only */998 void make_yy_range_string_constraint(abac_yy_term_data_t *ptr, char *var)999 {1000 char *typestr=abac_termtype_string(ptr->type);1001 abac_list_t *rlist=get_yy_term_data_cond_range(ptr);1002 char *tmplist=NULL;1003 char *tmp=NULL;1004 if(rlist) {1005 char *rstring=_string_yy_cond_range(rlist);1006 set_yy_term_data_cond_str(ptr,rstring);1007 abac_yy_range_t *cur;1008 1009 /* a list of values -- in chars */1010 abac_list_foreach(rlist, cur,1011 int type=cur->type;1012 char *val=cur->val;1013 switch(type) {1014 case e_yy_RANGE_MIN:1015 panic("make_yy_range_string_constraint, invalid range type - min");1016 break;1017 case e_yy_RANGE_MAX:1018 /* invalid range type */1019 panic("make_yy_range_string_constraint, invalid range type - max");1020 break;1021 case e_yy_RANGE_TARGET:1022 tmp=generate_pl_range_constraint(NULL,var,val,"=");1023 break;1024 }1025 /* ; is prolog's disjunction built in predicate */1026 if(tmplist)1027 asprintf(&tmplist,"%s;%s",tmplist,tmp);1028 else tmplist=tmp;1029 tmp=NULL;1030 );1031 asprintf(&tmplist,"(%s)",tmplist);1032 /* generate a clause with above and add into db */1033 tmp=abac_pl_add_range_constraint_clause(var,tmplist);1034 abac_yy_add_yy_constraints(tmp);1035 }1036 }1037 1038 void make_yy_range_constraint(abac_yy_term_data_t *ptr, char *var)1039 {1040 if(is_yy_term_data_type_numeric(ptr)) {1041 make_yy_range_numeric_constraint(ptr, var);1042 } else if (is_yy_term_data_type_alpha(ptr)) {1043 make_yy_range_string_constraint(ptr, var);1044 } else if (is_yy_term_data_type_time(ptr)) {1045 make_yy_range_time_constraint(ptr, var);1046 }1047 }1048 1049 1050 /************************************************************************/1051 1052 735 static void _aspect_add_terms(int linked, abac_aspect_t *aspect_ptr, 1053 736 abac_yy_term_t *terms) … … 1056 739 int type; 1057 740 int isnamed; 741 int isrange; 1058 742 char *name; 1059 743 char *cond; … … 1065 749 ptr=NULL; 1066 750 isnamed=0; 751 isrange=0; 1067 752 switch (curr->type) { 1068 753 case e_yy_DTERM_DATA: … … 1071 756 type=dptr->type; 1072 757 name=abac_xstrdup(dptr->name); 1073 if(dptr->cond_str) {758 if(dptr->cond_str) 1074 759 cond=abac_xstrdup(dptr->cond_str); 1075 ptr=dptr->cond_ptr;1076 }760 ptr=dptr->cond_ptr; 761 isrange=(dptr->cond_range!=NULL)?1:0; 1077 762 break; 1078 763 } … … 1080 765 { 1081 766 abac_yy_term_principal_t *pptr=curr->term.p_ptr; 1082 type=abac_ term_verify_term_type("principal");767 type=abac_verify_term_type("principal"); 1083 768 name=abac_xstrdup(pptr->name); 1084 if(pptr->cond_str) {769 if(pptr->cond_str) 1085 770 cond=abac_xstrdup(pptr->cond_str); 1086 ptr=pptr->cond_ptr;1087 }771 ptr=pptr->cond_ptr; 772 isrange=pptr->isrange; 1088 773 break; 1089 774 } … … 1098 783 case e_yy_DTERM_ANONYMOUS: 1099 784 { 1100 type=abac_ term_verify_term_type("anonymous");785 type=abac_verify_term_type("anonymous"); 1101 786 name=abac_xstrdup("_"); 1102 787 break; … … 1106 791 if(isnamed) 1107 792 param=abac_term_named_new(type,name); 1108 else param=abac_term_new(type,name, cond,ptr);793 else param=abac_term_new(type,name,isrange,cond,ptr); 1109 794 if (linked) 1110 795 abac_aspect_add_linked_param(aspect_ptr, param); … … 1140 825 1141 826 char *principalname=get_yy_principal_sha(principal); 1142 char *othername=get_yy_principal_name(principal);1143 827 char *name=ptr->name; 1144 828 abac_yy_term_t *terms=ptr->terms; … … 1158 842 _aspect_add_aspect_terms(aptr, terms); 1159 843 } 1160 _add_yy_id_certs(othername,get_yy_principal_type(principal));1161 844 return aptr; 1162 845 … … 1181 864 abac_yy_principal_t *principal=expr->principal; 1182 865 char *principalname=get_yy_principal_sha(principal); 1183 char *othername=get_yy_principal_name(principal);1184 866 1185 867 abac_aspect_t *ptr=NULL; … … 1187 869 ptr=abac_aspect_oset_principal_new(principalname); 1188 870 else ptr=abac_aspect_role_principal_new(principalname); 1189 _add_yy_id_certs(othername,get_yy_principal_type(principal));1190 871 if (ptr==NULL) 1191 872 goto error; … … 1208 889 char *cond=object->cond_str; 1209 890 void *ptr=object->cond_ptr; 1210 abac_term_t *term=abac_term_new(type,name,cond,ptr); 891 int isrange=(object->cond_range!=NULL)?1:0; 892 abac_term_t *term=abac_term_new(type,name,isrange,cond,ptr); 1211 893 abac_aspect_t *aptr=NULL; 1212 894 if(yytype==e_yy_OSET_TYPE) … … 1214 896 else 1215 897 goto error; /* can not be a role expression with obj */ 1216 1217 if(get_yy_term_data_is_variable(object))1218 _add_yy_id_certs(name,type);1219 1220 898 if (aptr==NULL) 1221 899 goto error; … … 1235 913 1236 914 char *principalname=get_yy_principal_sha(principal); 1237 char *othername=get_yy_principal_name(principal);1238 1239 915 char *name=eptr->name; 1240 916 abac_yy_term_t *terms=eptr->terms; … … 1251 927 _aspect_add_aspect_terms(ptr, terms); 1252 928 } 1253 1254 _add_yy_id_certs(othername,get_yy_principal_type(principal));1255 1256 929 return ptr; 1257 930 … … 1270 943 1271 944 char *principalname=get_yy_principal_sha(principal); 1272 char *othername=get_yy_principal_name(principal);1273 1274 945 char *name=eptr->name; 1275 946 abac_yy_term_t *terms=eptr->terms; … … 1293 964 _aspect_add_aspect_terms(ptr, terms); 1294 965 } 1295 1296 _add_yy_id_certs(othername,get_yy_principal_type(principal));1297 966 1298 967 return ptr; … … 1351 1020 } /* while */ 1352 1021 1022 preprocess_pl_head(head_oset); 1023 preprocess_pl_tail(tail_oset); 1024 1353 1025 /* XXX collect up type clauses, constraint clauses and 1354 1026 generate rule clauses */ … … 1381 1053 } 1382 1054 1055 /*****************************************************************************/ 1056 abac_list_t *validate_range(abac_list_t *ptr) 1057 { 1058 abac_list_t *nlist=abac_list_new(); 1059 1060 abac_item_t *nitem; 1061 abac_yy_range_t *cur; 1062 char *val; 1063 int type; 1064 abac_list_foreach(ptr, cur, 1065 if(cur) { 1066 type=cur->type; 1067 val=cur->val; 1068 if(type==e_yy_RANGE_MIN) nitem=abac_item_new("min",val); 1069 if(type==e_yy_RANGE_MAX) nitem=abac_item_new("max",val); 1070 if(type==e_yy_RANGE_TARGET) nitem=abac_item_new("target",val); 1071 abac_list_add(nlist,nitem); 1072 } 1073 ); 1074 return nlist; 1075 } 1076 1077 /****************************************************************/ 1078 void make_yy_range_constraint(abac_yy_term_data_t *ptr) 1079 { 1080 if(is_yy_term_data_type_numeric(ptr) || 1081 is_yy_term_data_type_alpha(ptr) || 1082 is_yy_term_data_type_time(ptr)) { 1083 abac_list_t *rlist=get_yy_term_data_cond_range(ptr); 1084 if(rlist) { 1085 abac_list_t *nlist=validate_range(rlist); 1086 set_yy_term_data_cond_ptr(ptr,nlist); 1087 } 1088 } 1089 } 1383 1090 /*****************************************************************************/ 1384 1091 /* build up the abac structure and also create the yap clause … … 1426 1133 } /* while */ 1427 1134 1135 preprocess_pl_head(head_role); 1136 preprocess_pl_tail(tail_role); 1137 1428 1138 /* collect up type clauses, constraint clauses and 1429 1139 generate the final rule clauses */ … … 1461 1171 abac_yyinit(); 1462 1172 abac_yy_init_rule_id_clauses(); 1463 abac_yy_init_yy_id_certs(); 1464 abac_yy_init_yy_constraints(); 1465 } 1466 1467 1173 } 1174 1175 -
libabac/abac_pl_yy.h
r8bd77b5 r440ba20 46 46 extern abac_list_t *make_yy_minmax_range(char *min, char *max); 47 47 extern abac_list_t *make_yy_min_range(char *min); 48 extern char *make_yy_oset_constraint(abac_yy_term_data_t *ptr, char *tail_string); 49 extern char *make_yy_oset_constraint(abac_yy_term_data_t *ptr, char *tail_string); 48 extern void make_yy_range_constraint(abac_yy_term_data_t *ptr); 49 extern void make_yy_oset_constraint(abac_yy_term_data_t *ptr, char *tail_string); 50 extern void make_yy_role_constraint(abac_yy_term_principal_t *ptr, char *tail_string); 50 51 extern abac_yy_principal_t *make_yy_principal(char *sha, char *cn, int type); 51 extern void make_yy_range_constraint(abac_yy_term_data_t *ptr, char *var);52 52 extern abac_yy_roleoset_t *make_yy_roleoset_role(char *name, abac_yy_term_t *terms); 53 53 extern abac_yy_roleoset_t *make_yy_roleoset_oset(char *name, abac_yy_term_t *terms); 54 extern char *make_yy_oset_constraint(abac_yy_term_data_t *ptr, char *tail_string);55 extern char *make_yy_role_constraint(abac_yy_term_principal_t *ptr, char *tail_string);56 54 extern abac_yy_term_data_t *make_yy_term_data(); 57 55 extern void set_yy_term_data_name(abac_yy_term_data_t *ptr, char *name); -
libabac/abac_term.c
rd037f54 r440ba20 18 18 static int debug=0; 19 19 20 /* string will contain either 21 the range literal (static constraint) 22 or 23 the oset/role prologized string (dynamic constraint) 24 union ptr will only be set if it is a dynamic 25 constraint */ 20 /* itemtype is 21 e_ITEM_MIN=1, 22 e_ITEM_MAX=2, 23 e_ITEM_TARGET=3, 24 [a..b], [a..], [..b], [a],[a,b],[many a] 25 */ 26 struct _abac_item_t { 27 int itemtype; 28 char *val; 29 }; 30 31 /* condtype is 32 e_COND_ROLE = 1, 33 e_COND_OSET = 2, 34 e_COND_RANGE = 3 35 vartype is one of termtype 36 string will contain either 37 the range literal (static constraint) 38 or 39 the oset/role prologized string (dynamic constraint) 40 it is set if this condition has been pre-processed for codegen 41 of_aspect ptr will only be set only if it is a dynamic 42 constraint 43 range_list is set only if needed 44 */ 26 45 struct _abac_condition_t { 27 int type; 46 int condtype; 47 int vartype; 28 48 char *string; 49 abac_list_t *range_list; 29 50 abac_aspect_t *of_aspect; 30 51 }; … … 33 54 idtype_t/name/p_name pair for the named principal term 34 55 */ 35 36 56 struct _abac_term_t { 37 57 int type; 38 58 char *name; 39 // e_TERM_PRINCIPAL isnamed40 59 int isnamed; 41 60 char *p_name; … … 49 68 }; 50 69 51 52 70 /******************************************************************/ 53 char *abac_condtype_ name(int i)71 char *abac_condtype_string(int i) 54 72 { 55 73 if(i>_condname_cnt) 56 panic("abac_condtype_ name: went out of range on condname");74 panic("abac_condtype_string: went out of range on condname"); 57 75 return (char *) _condname[i]; 58 76 } 59 60 abac_condition_t *abac_condition_new(int type,char* condstr,abac_aspect_t *cptr) 77 char *abac_termtype_string(int i) 78 { 79 if(i>_termname_cnt) 80 panic("abac_termtype_string: went out of range on termname"); 81 return (char *) _termname[i]; 82 } 83 84 int abac_verify_term_type(char *type) { 85 int i; 86 87 if (type == NULL) 88 panic("abac_verify_term_type: fail with NULL type\n"); 89 90 for (i = 1; i <= _termname_cnt ; i++) 91 if(strcmp(type,_termname[i])==0) 92 return i; 93 94 panic("abac_verify_term_type: fail with unfounded type\n"); 95 } 96 97 int abac_verify_item_type(char *type) { 98 int i; 99 100 if (type == NULL) 101 panic("abac_verify_item_type: fail with NULL type\n"); 102 103 for (i = 1; i <= _itemname_cnt ; i++) 104 if(strcmp(type,_itemname[i])==0) 105 return i; 106 panic("abac_verify_item_type: fail with unfounded type\n"); 107 } 108 109 char *abac_range_string(abac_list_t *ptr) 110 { 111 assert(ptr); 112 char *tmp=NULL; 113 char *min=NULL; 114 char *max=NULL; 115 char *val=NULL; 116 int type; 117 118 abac_item_t *cur; 119 assert(ptr); 120 abac_list_foreach(ptr, cur, 121 type=cur->itemtype; 122 switch (type) { 123 case e_ITEM_MIN: 124 min=abac_xstrdup(cur->val); 125 break; 126 case e_ITEM_MAX: 127 max=abac_xstrdup(cur->val); 128 break; 129 case e_ITEM_TARGET: 130 if(val) 131 asprintf(&val,"%s,%s",val,cur->val); 132 else val=abac_xstrdup(cur->val); 133 break; 134 } 135 ); 136 if(max && min) { 137 asprintf(&tmp,"[%s..%s]",min,max); 138 free(max); 139 free(min); 140 return tmp; 141 } 142 if(max) { 143 asprintf(&tmp,"[..%s]",max); 144 free(max); 145 return tmp; 146 } 147 if(min) { 148 asprintf(&tmp,"[%s..]",min); 149 free(min); 150 return tmp; 151 } 152 if(val) { 153 asprintf(&tmp,"[%s]",val); 154 free(val); 155 return tmp; 156 } 157 return NULL; 158 } 159 /******************************************************************/ 160 abac_item_t *abac_item_new(char *itype, char *val) 161 { 162 abac_item_t *nptr= 163 (abac_item_t *)abac_xmalloc(sizeof(abac_item_t)); 164 nptr->itemtype=abac_verify_item_type(itype); 165 nptr->val=abac_xstrdup(val); 166 return nptr; 167 } 168 169 void abac_item_free(abac_item_t *ptr) 170 { 171 assert(ptr); 172 assert(ptr->val); 173 free(ptr->val); 174 free(ptr); 175 } 176 177 abac_item_t *abac_item_dup(abac_item_t *ptr) 178 { 179 abac_item_t *nptr= 180 (abac_item_t *)abac_xmalloc(sizeof(abac_item_t)); 181 nptr->itemtype=ptr->itemtype; 182 nptr->val=abac_xstrdup(ptr->val); 183 return nptr; 184 } 185 186 int abac_item_type(abac_item_t *ptr) 187 { 188 return ptr->itemtype; 189 } 190 191 char *abac_item_val(abac_item_t *ptr) 192 { 193 return ptr->val; 194 } 195 196 /******************************************************************/ 197 static abac_condition_t *_abac_condition_new(int type, int vtype, 198 char* condstr,void *cptr) 61 199 { 62 200 if(debug) { 63 201 printf(" abac_condition_new: \n"); 64 printf(" type is %d(%s)\n", type, abac_condtype_name(type)); 202 printf(" condtype is %d(%s)\n", type, abac_condtype_string(type)); 203 printf(" vtype is %d(%s)\n", vtype, abac_termtype_string(type)); 65 204 printf(" condstr is (%s)\n", condstr); 66 205 if(cptr) printf(" yes on cptr\n"); … … 69 208 abac_condition_t *ptr= 70 209 (abac_condition_t *)abac_xmalloc(sizeof(abac_condition_t)); 71 ptr->type=type; 210 ptr->condtype=type; 211 ptr->vartype=vtype; 72 212 ptr->string=abac_xstrdup(condstr); 73 if(cptr) ptr->of_aspect=abac_aspect_dup(cptr); 74 else ptr->of_aspect=NULL; 213 ptr->of_aspect=NULL; 214 ptr->range_list=NULL; 215 if(type==e_COND_RANGE) { 216 ptr->range_list=(abac_list_t *)cptr; 217 } else { 218 if(cptr) ptr->of_aspect=abac_aspect_dup((abac_aspect_t *)cptr); 219 } 75 220 return ptr; 76 221 } … … 78 223 void abac_condition_free(abac_condition_t *ptr) 79 224 { 80 switch(ptr-> type) {225 switch(ptr->condtype) { 81 226 case e_COND_OSET: 82 227 case e_COND_ROLE: … … 88 233 } 89 234 if(ptr->string) free(ptr->string); 235 if(ptr->range_list != NULL) { 236 abac_item_t *cur; 237 abac_list_foreach(ptr->range_list, cur, 238 abac_item_free(cur); 239 ); 240 abac_list_free(ptr->range_list); 241 } 90 242 free(ptr); 91 243 } 92 244 93 abac_condition_t *abac_condition_from_string(char *string) 94 { 95 assert(string); 245 abac_aspect_t *abac_condition_of_aspect(abac_condition_t *ptr) 246 { 247 return ptr->of_aspect; 248 } 249 250 int abac_condition_is_range(abac_condition_t *ptr) 251 { 252 if(ptr->condtype==e_COND_RANGE) 253 return 1; 254 else return 0; 255 } 256 257 /* called from backend, intended as stub for range constraint */ 258 abac_condition_t *abac_condition_create(char *vtype) 259 { 96 260 abac_condition_t *nptr= 97 261 (abac_condition_t *)abac_xmalloc(sizeof(abac_condition_t)); 98 nptr->type=e_COND_RANGE; 99 nptr->string=abac_xstrdup(string); 262 nptr->condtype=e_COND_RANGE; 263 nptr->vartype=abac_verify_term_type(vtype); 264 nptr->string=NULL; 265 nptr->range_list=NULL; 100 266 nptr->of_aspect=NULL; 101 267 return nptr; 102 268 } 103 269 104 abac_condition_t *abac_condition_ from_aspect(abac_aspect_t *ptr)270 abac_condition_t *abac_condition_create_from_aspect(abac_aspect_t *ptr) 105 271 { 106 272 assert(ptr); … … 108 274 (abac_condition_t *)abac_xmalloc(sizeof(abac_condition_t)); 109 275 if(abac_aspect_is_role(ptr)) 110 nptr->type=e_COND_ROLE; 111 else nptr->type=e_COND_OSET; 276 nptr->condtype=e_COND_ROLE; 277 else nptr->condtype=e_COND_OSET; 278 nptr->vartype=e_TERM_PRINCIPAL; 112 279 nptr->string=NULL; 280 nptr->range_list=NULL; 113 281 nptr->of_aspect=abac_aspect_dup(ptr); 114 282 return nptr; … … 120 288 abac_condition_t *nptr= 121 289 (abac_condition_t *)abac_xmalloc(sizeof(abac_condition_t)); 122 nptr->type=ptr->type; 290 nptr->condtype=ptr->condtype; 291 nptr->vartype=ptr->vartype; 123 292 if(ptr->string) 124 293 nptr->string=abac_xstrdup(ptr->string); … … 127 296 nptr->of_aspect=abac_aspect_dup(ptr->of_aspect); 128 297 else nptr->of_aspect=NULL; 298 299 if(ptr->range_list!=NULL) { 300 nptr->range_list=abac_list_new(); 301 abac_item_t *cur; 302 abac_item_t *nitem; 303 abac_list_foreach(ptr->range_list, cur, 304 nitem=abac_item_dup(cur); 305 abac_list_add(nptr->range_list,nitem); 306 ); 307 } else { 308 nptr->range_list=NULL; 309 } 129 310 return nptr; 130 311 } 131 312 313 int abac_condition_vartype(abac_condition_t *ptr) 314 { 315 return ptr->vartype; 316 } 317 318 abac_list_t *abac_condition_range_list(abac_condition_t *ptr) 319 { 320 assert(ptr); 321 return ptr->range_list; 322 } 323 324 325 int abac_condition_add_range_item(abac_condition_t *ptr, char *vtype, char* itype, char* val) 326 { 327 if(ptr->vartype != abac_verify_term_type(vtype)) 328 panic("abac_condition_add_range_item: attempt to add range item that does not match with the constraint's type\n"); 329 abac_item_t *nitem=abac_item_new(itype,val); 330 if(ptr->range_list==NULL) 331 ptr->range_list=abac_list_new(); 332 abac_list_add(ptr->range_list,nitem); 333 } 334 132 335 char *abac_condition_string(abac_condition_t *ptr) 133 336 { 134 337 char *string=NULL; 135 switch(ptr-> type) {338 switch(ptr->condtype) { 136 339 case e_COND_OSET: 137 340 case e_COND_ROLE: 138 341 string=abac_aspect_string_with_condition(ptr->of_aspect); 342 return string; 139 343 break; 140 344 case e_COND_RANGE: 141 string=abac_xstrdup(ptr->string); 345 if(ptr->string != NULL) { 346 string=abac_xstrdup(ptr->string); 347 return string; 348 } 349 if(ptr->range_list != NULL) { 350 string=abac_range_string(ptr->range_list); 351 return string; 352 } 142 353 break; 143 354 } … … 148 359 { 149 360 char *string=NULL; 150 switch(ptr-> type) {361 switch(ptr->condtype) { 151 362 case e_COND_OSET: 152 363 case e_COND_ROLE: 153 364 string=abac_aspect_typed_string_with_condition(ptr->of_aspect); 365 return string; 154 366 break; 155 367 case e_COND_RANGE: 156 string=abac_xstrdup(ptr->string); 368 if(ptr->string != NULL) { 369 string=abac_xstrdup(ptr->string); 370 return string; 371 } 372 if(ptr->range_list != NULL) { 373 string=abac_range_string(ptr->range_list); 374 return string; 375 } 157 376 break; 158 377 } … … 160 379 } 161 380 381 int abac_condition_set_range_string(abac_condition_t *ptr) 382 { 383 char *string= abac_range_string(ptr->range_list); 384 ptr->string=string; 385 return 1; 386 } 387 388 int abac_condition_set_aspect_string(abac_condition_t *ptr, char *str) 389 { 390 ptr->string=abac_xstrdup(str); 391 return 1; 392 } 393 394 int abac_condition_set_aspect_ptr(abac_condition_t *ptr, abac_aspect_t *aptr) 395 { 396 ptr->of_aspect=abac_aspect_dup(aptr); 397 return 1; 398 } 399 400 void abac_condition_dump(abac_condition_t *ptr, char *offset) 401 { 402 printf("...constraint...\n"); 403 printf("%s condtype: %d(%s)\n", 404 offset, ptr->condtype,abac_condtype_string(ptr->condtype)); 405 printf("%s vartype: %d(%s)\n", 406 offset, ptr->vartype,abac_termtype_string(ptr->vartype)); 407 if(ptr->string) 408 printf("%s string: %s\n", offset, ptr->string); 409 else printf("%s string: --\n", offset); 410 if(ptr->range_list) 411 printf("%s range_list: %s\n", 412 offset, abac_range_string(ptr->range_list)); 413 else printf("%s range_list: --\n", offset); 414 if(ptr->of_aspect) { 415 char *tmp=NULL; 416 asprintf(&tmp," %s",offset); 417 abac_aspect_dump(ptr->of_aspect,tmp); 418 free(tmp); 419 } else printf("%s of_aspect: --\n", offset); 420 printf("................\n"); 421 } 422 162 423 /******************************************************************/ 424 int abac_term_isvar(abac_term_t *term) 425 { 426 if(isupper(term->name[0])) return 1; 427 else return 0; 428 } 163 429 164 430 int abac_term_isnamed(abac_term_t *term) … … 184 450 { 185 451 return term->constraint; 186 }187 188 char *abac_termtype_string(int i)189 {190 if(i>_termname_cnt)191 panic("abac_termtype_string: went out of range on termname");192 return (char *) _termname[i];193 452 } 194 453 … … 253 512 } 254 513 255 int abac_term_verify_term_type(char *type) { 256 int i; 257 258 if (type == NULL) 259 return 0; 260 261 for (i = 1; i <= _termname_cnt ; i++) 262 if(strcmp(type,_termname[i])==0) 263 return i; 514 bool abac_term_is_alpha(abac_term_t *term) 515 { 516 if(term->type == e_TERM_URN || 517 term->type == e_TERM_STRING || 518 term->type == e_TERM_BOOLEAN) 519 return 1; 520 return 0; 521 } 522 523 bool abac_term_is_numeric(abac_term_t *term) 524 { 525 if(term->type == e_TERM_INTEGER || 526 term->type == e_TERM_FLOAT) 527 return 1; 528 return 0; 529 } 530 531 bool abac_term_is_time(abac_term_t *term) 532 { 533 if(term->type == e_TERM_TIME) 534 return 1; 264 535 return 0; 265 536 } … … 275 546 } 276 547 277 /* called from yy */278 abac_term_t *abac_term_new(int type, char *name, char *cond, abac_aspect_t*cptr)548 /* called from yy, cptr is either abac_aspect_t or abac_list_t */ 549 abac_term_t *abac_term_new(int type, char *name, int isrange, char *cond, void *cptr) 279 550 { 280 551 if(debug) { … … 285 556 printf(" cond is %s\n", cond); 286 557 else printf(" no cond \n"); 287 if(cptr) 288 printf(" cptr is (%s)\n", abac_aspect_string_with_condition(cptr)); 289 else printf(" there is no cptr\n"); 558 printf(" isrange is %d\n", isrange); 559 if(cptr) { 560 if(isrange) printf(" cptr is (%s)\n", 561 abac_range_string((abac_list_t *)cptr)); 562 else 563 printf(" cptr is (%s)\n", 564 abac_aspect_string_with_condition((abac_aspect_t *)cptr)); 565 } else printf(" there is no cptr\n"); 290 566 } 291 567 abac_condition_t *constraint=NULL; 292 if (c ond) {293 if( type==e_TERM_PRINCIPAL) {294 constraint=abac_condition_new(e_COND_ROLE,cond,cptr);295 } else {296 if(cptr == NULL)297 constraint=abac_condition_new(e_COND_RANGE,cond,NULL);298 else299 constraint=abac_condition_new(e_COND_OSET,cond,cptr);568 if (cptr) { 569 if(isrange) { 570 constraint=_abac_condition_new(e_COND_RANGE,type,cond,cptr); 571 } else { 572 if(type==e_TERM_PRINCIPAL) 573 constraint=_abac_condition_new(e_COND_ROLE,type,cond,cptr); 574 else 575 constraint=_abac_condition_new(e_COND_OSET,type,cond,cptr); 300 576 } 301 577 } … … 414 690 abac_term_t *abac_term_add_constraint(abac_term_t *ptr, abac_condition_t *cond) 415 691 { 692 /* make sure the types are matching */ 693 if(abac_condition_vartype(cond) != abac_term_type(ptr)) { 694 panic("abac_term_add_constraint: mismatched constraint type with the dataterm\n"); 695 return NULL; 696 } 697 416 698 if(ptr->constraint) { 417 699 abac_condition_free(ptr->constraint); … … 467 749 468 750 /********************************************************************/ 751 abac_list_t *abac_param_list(abac_param_list_t *ptr) 752 { 753 assert(ptr); 754 return ptr->list; 755 } 756 757 void abac_param_dump(abac_param_list_t *ptr, char *offset) 758 { 759 printf("===params===\n"); 760 abac_term_t *cur; 761 abac_list_foreach(ptr->list, cur, 762 abac_term_dump(cur, offset); 763 ); 764 printf("============\n"); 765 } 766 469 767 abac_param_list_t *abac_param_list_new(abac_term_t *term) 470 768 { … … 595 893 } 596 894 895 597 896 void abac_terms_free(abac_term_t **terms) 598 897 { … … 605 904 free(terms); 606 905 } 906 907 void abac_term_dump(abac_term_t *ptr, char *offset) 908 { 909 printf("--- term---\n"); 910 printf("%s type : %s\n",offset, abac_term_type_name(ptr)); 911 printf("%s name : %s\n",offset, abac_term_name(ptr)); 912 printf("%s isnamed: %d\n",offset,ptr->isnamed); 913 if(ptr->p_name) 914 printf("%s p_name: %s\n",offset,ptr->p_name); 915 else printf("%s p_name: --\n",offset); 916 if(ptr->cn) 917 printf("%s cn: %s\n",offset,ptr->cn); 918 else printf("%s cn: --\n",offset); 919 if(ptr->constraint) { 920 char *tmp=NULL; 921 asprintf(&tmp," %s", offset); 922 abac_condition_dump(ptr->constraint,offset); 923 free(tmp); 924 } else printf("%s constraint: --\n",offset); 925 printf("-----------\n"); 926 } 927 -
libabac/abac_verifier.c
rd037f54 r440ba20 107 107 char *abac_idtype_string(int i) 108 108 { 109 if(i > _idtypename_cnt) 109 if(i > _idtypename_cnt) { 110 printf("bad idtypename idx %d\n", i); 110 111 panic("abac_idtype_string: went out of range on idtypename"); 111 return _idtypename[i]; 112 } 113 return (char*) _idtypename[i]; 112 114 } 113 115 … … 198 200 char *keyid=abac_id_keyid(a_id); 199 201 202 if(debug) { 203 printf("abac_verifier_add_id_credential, cn(%s),keyid(%s)\n", 204 cn, keyid); 205 } 206 200 207 // add the abac_id to the map of id credentials 201 208 id_cred = abac_xmalloc(sizeof(abac_id_credential_t)); … … 214 221 id_cred->hashkeyid, HASH_COUNT(id_creds)); 215 222 216 free(keyid);217 223 return id_cred; 218 224 } 219 225 220 226 /** 221 * Load an ID certificate.227 * Load an ID 222 228 */ 223 229 static int _load_id(abac_id_t **a_id,certificate_t *cert, abac_id_credential_t **id_cred_ret) { … … 257 263 HASH_FIND_STR(id_creds, keyid, id_cred); 258 264 if (id_cred != NULL) { 259 ret = ABAC_CERT_SUCCESS; 265 if(debug) printf("existing cert \n"); 266 ret = ABAC_CERT_EXISTS; 260 267 goto error; 261 268 } … … 269 276 270 277 // success, add a new abac_id 271 if(*a_id ==NULL) 272 *a_id = abac_id_keyid_new(keyid,cn,cert); 278 if(*a_id==NULL) { 279 *a_id=abac_id_keyid_new(keyid,cn,cert); 280 } 273 281 274 282 abac_id_credential_t *n_id_cred=abac_verifier_add_id_credential(*a_id); … … 351 359 352 360 int rc=_load_id(&id,cert,id_cred_ret); 361 if(rc==ABAC_CERT_EXISTS) { 362 if(debug) printf("abac_verifier_load_id_files: id already exists\n"); 363 return ABAC_CERT_SUCCESS; 364 } 365 353 366 /* try to load the private key if it is there */ 354 if( _exist(keyfilename)) {367 if((rc==ABAC_CERT_SUCCESS) && _exist(keyfilename)) { 355 368 if(debug) printf("loading... %s\n", keyfilename); 356 369 int keyrc=abac_id_load_privkey(id, keyfilename); -
libabac/rt2.y
rd037f54 r440ba20 288 288 if(is_yy_term_data_has_constraint(ptr)) { 289 289 char *tail_string=get_yy_term_data_name(ptr); 290 make_yy_range_constraint(ptr ,tail_string);290 make_yy_range_constraint(ptr); 291 291 make_yy_oset_constraint(ptr,tail_string); 292 292 } … … 307 307 set_yy_term_principal_name(ptr,tail_string); 308 308 set_yy_term_principal_cond_head_expr(ptr,expr); 309 char *string=make_yy_role_constraint(ptr,tail_string);309 make_yy_role_constraint(ptr,tail_string); 310 310 $$=ptr; 311 311 }
Note: See TracChangeset
for help on using the changeset viewer.
