/[pdpsoft]/trunk/grid-mw-security/ees/src/eval_man/pdl.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/src/eval_man/pdl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1201 by aramv, Mon Nov 30 14:59:01 2009 UTC revision 1202 by aramv, Mon Nov 30 17:14:03 2009 UTC
# Line 31  policy_t*                   current_poli Line 31  policy_t*                   current_poli
31    
32  /*! initializes the parsing of the configuration file */  /*! initializes the parsing of the configuration file */
33  EES_RC pdl_init(const char* config_file_name){  EES_RC pdl_init(const char* config_file_name){
34    config_file_s = config_file_name;  config_file_s = config_file_name;
35    
36    if((config_file_fp = fopen(config_file_s,"r")) != NULL){    if((config_file_fp = fopen(config_file_s,"r")) != NULL){
37      yyin = config_file_fp;      yyin = config_file_fp;
38      yyparse();      yyparse();
39      if(add_prepared_plugins() == EES_SUCCESS){      if(add_prepared_plugins() == EES_SUCCESS){
       print_policies(policies_list);  
40        return EES_SUCCESS;        return EES_SUCCESS;
41      } else {      } else {
42        eef_log(LOG_ERR, "Failed to load plug-ins from policy config file %s\n", config_file_s);        eef_log(LOG_ERR, "Failed to load plug-ins from policy config file %s\n", config_file_s);
# Line 119  rule_t* add_rule(record_t* state, record Line 118  rule_t* add_rule(record_t* state, record
118    var_t  *temp_var = NULL;    var_t  *temp_var = NULL;
119    char *unknown_var_format_string = "Unknown variable %s at line %i in config file %s";    char *unknown_var_format_string = "Unknown variable %s at line %i in config file %s";
120    
121    if((new_rule = get_rule(rules_list, state->string))){    if((new_rule = get_left_hand_rule(rules_list, state->string))){
122      eef_log(LOG_WARNING, "State %s at line %i is already in use at line %i.\n", state->string, state->lineno, new_rule->lineno);      eef_log(LOG_WARNING, "State %s at line %i is already in use at line %i.\n", state->string, state->lineno, new_rule->lineno);
123    } else {    } else {
124      /*find variables for rule */      /*find variables for rule */
# Line 142  rule_t* add_rule(record_t* state, record Line 141  rule_t* add_rule(record_t* state, record
141              eef_log(LOG_ERR, unknown_var_format_string, false_branch->string, false_branch->lineno, config_file_s);              eef_log(LOG_ERR, unknown_var_format_string, false_branch->string, false_branch->lineno, config_file_s);
142              return NULL;              return NULL;
143            }            }
144            if(!(new_false_branch = get_rule(rules_list, false_branch->string))){            if((new_false_branch = get_rule(rules_list, false_branch->string))){
145                new_rule->false_branch = new_false_branch;
146              } else {
147              if((new_false_branch = calloc(1, sizeof(rule_t)))){              if((new_false_branch = calloc(1, sizeof(rule_t)))){
148                new_false_branch->state = strdup(false_branch->string);                new_false_branch->state = strdup(false_branch->string);
149                new_false_branch->lineno = false_branch->lineno;                new_false_branch->lineno = false_branch->lineno;
150                  new_rule->false_branch = new_false_branch;
151              }              }
152            }            }
           new_rule->false_branch = new_false_branch;  
153          }          }
154    
155          if(true_branch){          if(true_branch){
# Line 158  rule_t* add_rule(record_t* state, record Line 159  rule_t* add_rule(record_t* state, record
159              eef_log(LOG_ERR, unknown_var_format_string, true_branch->string, true_branch->lineno, config_file_s);              eef_log(LOG_ERR, unknown_var_format_string, true_branch->string, true_branch->lineno, config_file_s);
160              return NULL;              return NULL;
161            }            }
162            if(!(new_true_branch = get_rule(rules_list, true_branch->string))){            if((new_true_branch = get_rule(rules_list, true_branch->string))){
163                new_rule->true_branch = new_true_branch;
164              } else {
165              if((new_true_branch = calloc(1, sizeof(rule_t)))){              if((new_true_branch = calloc(1, sizeof(rule_t)))){
166                new_true_branch->state = strdup(true_branch->string);                new_true_branch->state = strdup(true_branch->string);
167                new_true_branch->lineno = true_branch->lineno;                new_true_branch->lineno = true_branch->lineno;
168                  new_rule->true_branch = new_true_branch;
169              }              }
170              
171            }            }
           new_rule->true_branch = new_true_branch;  
172          }          }
173    
174          /* check for recursion */          /* check for recursion */
# Line 179  rule_t* add_rule(record_t* state, record Line 183  rule_t* add_rule(record_t* state, record
183              rules_list = new_rule;              rules_list = new_rule;
184            }            }
185            rules_list_last = new_rule;            rules_list_last = new_rule;
186    
187            eef_log(LOG_DEBUG, "Added a new rule: %s\n", new_rule->state);            eef_log(LOG_DEBUG, "Added a new rule: %s\n", new_rule->state);
188            if(new_rule->true_branch){            if(new_rule->true_branch){
189              printf("New true branch %s\n", new_rule->true_branch->state);              printf("New true branch %s\n", new_rule->true_branch->state);
# Line 267  rule_t* get_rule(rule_t* temp_rule, cons Line 272  rule_t* get_rule(rule_t* temp_rule, cons
272    }    }
273    
274    /* iterate while the rule isn't associated with the given state */    /* iterate while the rule isn't associated with the given state */
275    while(temp_rule && strcmp(name, temp_rule->state)){    while(temp_rule){
276      if(strcmp(name, temp_rule->true_branch->state)){      if(!strcmp(name, temp_rule->true_branch->state)){
277        return temp_rule->true_branch;        return temp_rule->true_branch;
278      }      }
279      if(strcmp(name, temp_rule->false_branch->state)){      if(!strcmp(name, temp_rule->false_branch->state)){
280        return temp_rule->false_branch;        return temp_rule->false_branch;
281      }      }
282        if(!strcmp(name, temp_rule->state)){
283          return temp_rule;
284        }
285      temp_rule = temp_rule->next;      temp_rule = temp_rule->next;
286    }    }
287    return temp_rule;    return NULL;
288    }
289    
290    rule_t* get_left_hand_rule(rule_t* temp_rule, const char* name){
291      if(!temp_rule || !name){
292        return NULL;
293      }
294    
295      /* iterate while the rule isn't associated with the given state */
296      while(temp_rule){
297        if(!strcmp(name, temp_rule->state)){
298          return temp_rule;
299        }
300        temp_rule = temp_rule->next;
301      }
302      return NULL;
303  }  }
304    
305  EES_RC link_dead_end_rules_in_policy(policy_t* policy){  EES_RC link_dead_end_rules_in_policy(policy_t* policy){
306    policy_t *temp_policy = policy;    policy_t *temp_policy = policy;
   rule_t  *temp_rule = NULL, *true_rule = NULL, *false_rule = NULL;  
307    while(temp_policy){    while(temp_policy){
308      temp_rule = temp_policy->rules;      link_dead_end_rules(temp_policy, temp_policy->rules);
309      while(temp_rule){      temp_policy = temp_policy->next;
310        if(true_rule = get_rule(policy->rules, temp_rule->true_branch)){    }
311          temp_rule->true_branch = true_rule;  }
312          printf("Linking temp_rule->true_branch: %s to %s\n", temp_rule->state, true_rule->state);  
313    void link_dead_end_rules(policy_t* policy, rule_t* rule){
314      rule_t *temp_rule, *true_rule = NULL, *false_rule = NULL;
315      if(temp_rule = get_rule(policy->rules, rule->state)){
316        if(rule->true_branch){
317          if(true_rule = get_rule(policy->rules, rule->true_branch->state)){
318            printf("Linking temp_rule->true_branch: %s to %s\n", rule->state, true_rule->state);
319            rule = temp_rule;
320            rule->true_branch = true_rule;
321            link_dead_end_rules(policy, rule->true_branch);
322          } else {
323            printf("Err: True branch not found\n");
324        }        }
325        if((false_rule = get_rule(policy->rules, temp_rule->false_branch))){      }
326          temp_rule->false_branch = false_rule;      if(rule->false_branch){
327          if((false_rule = get_rule(policy->rules, rule->false_branch->state))){
328            printf("Linking temp_rule->false_branch: %s to %s\n", rule->state, false_rule->state);
329            rule = temp_rule;
330            rule->false_branch = false_rule;
331            link_dead_end_rules(policy, rule->false_branch);
332          } else {
333            printf("Err: False branch not found\n");
334        }        }
       temp_rule = temp_rule->next;  
335      }      }
     temp_policy = temp_policy->next;  
336    }    }
337  }  }
338    
# Line 337  void print_policies(policy_t* policies){ Line 375  void print_policies(policy_t* policies){
375    
376  /* prints the list of rules */  /* prints the list of rules */
377  void print_rules(rule_t* rules){  void print_rules(rule_t* rules){
378    rule_t*   temp_rule = rules;    if(rules){
379    while(temp_rule){      eef_log(LOG_DEBUG, "  | Rule %s\n", rules->state);
     eef_log(LOG_DEBUG, "  | Rule %s\n", temp_rule->state);  
380      eef_log(LOG_DEBUG, "  -------------------------\n");      eef_log(LOG_DEBUG, "  -------------------------\n");
381      /*TODO could recurse here */      print_rules(rules->true_branch);
382      temp_rule = temp_rule->next;      print_rules(rules->false_branch);
383    }    }
384    return;    return;
385  }  }
# Line 355  EES_RC link_rules_to_plugins(policy_t* p Line 392  EES_RC link_rules_to_plugins(policy_t* p
392    while(temp_policy){    while(temp_policy){
393      temp_rule = temp_policy->rules;      temp_rule = temp_policy->rules;
394      while(temp_rule){      while(temp_rule){
395        link_rule_to_plugin(temp_rule);        link_rule_to_plugin(temp_policy, temp_rule);
396        temp_rule = temp_rule->next;        temp_rule = temp_rule->next;
397      }      }
398      temp_policy = temp_policy->next;      temp_policy = temp_policy->next;
# Line 363  EES_RC link_rules_to_plugins(policy_t* p Line 400  EES_RC link_rules_to_plugins(policy_t* p
400    return EES_SUCCESS;    return EES_SUCCESS;
401  }  }
402    
403  void link_rule_to_plugin(rule_t* rule){  void link_rule_to_plugin(policy_t *policy, rule_t *rule){
404    var_t    *temp_var    = NULL;    var_t    *temp_var    = NULL;
405    char**    argv;    char**    argv;
406    int       argc;    int       argc;
# Line 386  void link_rule_to_plugin(rule_t* rule){ Line 423  void link_rule_to_plugin(rule_t* rule){
423        }        }
424        free_args(argc, argv);        free_args(argc, argv);
425      }      }
426        /*if(rule->true_branch){*/
427        /*rule->true_branch = get_rule(policy->rules, rule->true_branch->state);*/
428        /*}*/
429        /*if(rule->false_branch){*/
430        /*rule->false_branch = get_rule(policy->rules, rule->false_branch->state);*/
431        /*}*/
432        link_rule_to_plugin(policy, rule->true_branch);
433        link_rule_to_plugin(policy, rule->false_branch);
434    }    }
435    return;    return;
436  }  }
# Line 591  EES_RC clean_variables_list(){ Line 636  EES_RC clean_variables_list(){
636  EES_RC clean_rules_list(rule_t* top_rule){  EES_RC clean_rules_list(rule_t* top_rule){
637    rule_t* temp_rule = top_rule;    rule_t* temp_rule = top_rule;
638    rule_t* last_rule;    rule_t* last_rule;
639    while(temp_rule){    if(temp_rule){
640      /* Clean rules in true branch */      /* Clean rules in true branch */
641    
642        /* Clean rule state */
643        free(temp_rule->state);
644    
645        /**//* Move to next rule */
646        /*clean_rules_list(temp_rule->true_branch);*/
647        /*clean_rules_list(temp_rule->false_branch);*/
648    
649      if(temp_rule->true_branch){      if(temp_rule->true_branch){
650        clean_rules_list(temp_rule->true_branch);        clean_rules_list(temp_rule->true_branch);
651      }      }
# Line 602  EES_RC clean_rules_list(rule_t* top_rule Line 655  EES_RC clean_rules_list(rule_t* top_rule
655        clean_rules_list(temp_rule->false_branch);        clean_rules_list(temp_rule->false_branch);
656      }      }
657    
     /* Clean rule state */  
     free(temp_rule->state);  
   
     /* Move to next rule */  
     last_rule = temp_rule;  
     temp_rule = temp_rule->next;  
   
658      /* Clean rule struct */      /* Clean rule struct */
659      free(last_rule);      free(temp_rule);
660    }    }
661    return EES_SUCCESS;    return EES_SUCCESS;
662  }  }

Legend:
Removed from v.1201  
changed lines
  Added in v.1202

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28