/[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 1211 by aramv, Tue Dec 1 17:01:19 2009 UTC revision 1212 by aramv, Wed Dec 2 14:13:38 2009 UTC
# Line 321  void add_policy(record_t* policy, rule_t Line 321  void add_policy(record_t* policy, rule_t
321    }    }
322    policies_list_last = new_policy;    policies_list_last = new_policy;
323    
324      /* start a new rules list */
325    rules_list = NULL;    rules_list = NULL;
326    
327    free(policy->string);    free(policy->string);
# Line 399  void link_rule_to_plugin(policy_t *polic Line 400  void link_rule_to_plugin(policy_t *polic
400  }  }
401    
402  /* iterates the policies and removes those that are not explicitly named in the passed array of strings */  /* iterates the policies and removes those that are not explicitly named in the passed array of strings */
403  policy_t* reduce_policy_tree(policy_t* policies, int number_of_policies, char* names_of_policies[]){  policy_t** reduce_policy_tree(policy_t** policies, int number_of_policies, char* names_of_policies[]){
404    int i, policy_should_be_removed;    int i, policy_should_be_removed;
405    policy_t *temp_policy = policies, *next_policy = NULL;    policy_t *temp_policy = NULL, *previous_policy = NULL;
406    
407    while(temp_policy){    for(temp_policy = *policies; temp_policy != NULL; previous_policy = temp_policy, temp_policy = temp_policy->next){
408      policy_should_be_removed = 1;      policy_should_be_removed = 1;
409      eef_log(LOG_DEBUG, "Checking policy: %s\n", (temp_policy)->name);      eef_log(LOG_DEBUG, "Checking policy: %s\n", (temp_policy)->name);
410      for(i = 0; i < number_of_policies; i++){      for(i = 0; i < number_of_policies; i++){
# Line 415  policy_t* reduce_policy_tree(policy_t* p Line 416  policy_t* reduce_policy_tree(policy_t* p
416        }        }
417      }      }
418    
     next_policy = temp_policy->next;  
   
419      if(policy_should_be_removed){      if(policy_should_be_removed){
420        eef_log(LOG_DEBUG, "Removing not-allowed policy: %s\n", temp_policy->name);        eef_log(LOG_DEBUG, "Removing not-allowed policy: %s\n", temp_policy->name);
       remove_policy_by_name(policies, temp_policy->name);  
     }  
421    
422      /* Move to next policy */        /* if the head node is deleted, overwrite it with the next node */
423      temp_policy = next_policy;        if(previous_policy == NULL){
424            *policies = temp_policy->next;
425          } else {
426            previous_policy->next = temp_policy->next;
427          }
428    
429          /* Clean policy fields */
430          eef_log(LOG_DEBUG, "Deleted policy: %s\n", temp_policy->name);
431          temp_policy->rules = clean_rules_list(temp_policy->rules);
432          free(temp_policy->name);
433          free(temp_policy);
434        }
435    }    }
436    
437    return policies;    return policies;
438  }  }
439    
# Line 492  void remove_policy(record_t* policy){ Line 501  void remove_policy(record_t* policy){
501        next_policy = temp_policy->next;        next_policy = temp_policy->next;
502    
503        /* Clean policy fields */        /* Clean policy fields */
504        clean_rules_list(temp_policy->rules);        temp_policy->rules = clean_rules_list(temp_policy->rules);
505        free(temp_policy->name);        free(temp_policy->name);
506        temp_policy->name = NULL;        temp_policy->name = NULL;
507        free(temp_policy);        free(temp_policy);
# Line 509  void remove_policy(record_t* policy){ Line 518  void remove_policy(record_t* policy){
518  }  }
519    
520  /*! Removes a policy from the list of policies */  /*! Removes a policy from the list of policies */
521  void remove_policy_by_name(policy_t* policies, char* policy){  policy_t* remove_policy_by_name(policy_t* policies, char* policy){
522    policy_t *temp_policy = policies, *next_policy = NULL;    policy_t *temp_policy = policies, *next_policy = NULL;
   eef_log(LOG_DEBUG, "Deleted policy: %s\n", policy);  
523    
524    while(temp_policy){    while(temp_policy){
525        printf("Iterating to %s\n", temp_policy->name);
526      next_policy = temp_policy->next;      next_policy = temp_policy->next;
527    
528      if(strcmp(temp_policy->name, policy) == 0){      if(strcmp(temp_policy->name, policy) == 0){
529        /* target policy was found */        /* target policy was found */
530    
531          /* if the head node is deleted, overwrite it with the next node */
532          if(temp_policy == policies){
533            policies = next_policy;
534          }
535    
536        /* Clean policy fields */        /* Clean policy fields */
537        clean_rules_list(temp_policy->rules);        temp_policy->rules = clean_rules_list(temp_policy->rules);
538          eef_log(LOG_DEBUG, "Deleted policy: %s\n", policy);
539        free(temp_policy->name);        free(temp_policy->name);
       temp_policy->name = NULL;  
540        free(temp_policy);        free(temp_policy);
541        temp_policy = NULL;        /*break;*/
542      }      }
543    
544      /* Move to next policy */      /* Move to next policy */
545      temp_policy = next_policy;      temp_policy = next_policy;
546    }    }
547    return;  
548      printf("Done removing %s, here is the list\n", policy);
549      print_policies(policies);
550      free(policy);
551      return policies;
552  }  }
553    
554  /*! converts a string to an array of strings by splitting it at each \t delimiter  /*! converts a string to an array of strings by splitting it at each \t delimiter
# Line 608  EES_RC clean_variables_list(){ Line 627  EES_RC clean_variables_list(){
627  }  }
628    
629  /*! Iterates the list of rule_t structures starting with the passed rule and tries to free them and their true/false branches */  /*! Iterates the list of rule_t structures starting with the passed rule and tries to free them and their true/false branches */
630  EES_RC clean_rules_list(rule_t* top_rule){  rule_t* clean_rules_list(rule_t* top_rule){
631    rule_t* temp_rule = top_rule;    rule_t* temp_rule = top_rule;
632    if(temp_rule){    if(temp_rule){
     /* Clean rules in true branch */  
   
     /* Clean rule state */  
633      free(temp_rule->state);      free(temp_rule->state);
     temp_rule->state = NULL;  
634    
635      clean_rules_list(temp_rule->true_branch);      clean_rules_list(temp_rule->true_branch);
636    
637      clean_rules_list(temp_rule->false_branch);      clean_rules_list(temp_rule->false_branch);
638    
     /* Clean rule struct */  
639      free(temp_rule);      free(temp_rule);
640      temp_rule = NULL;      temp_rule = NULL;
641    }    }
642    return EES_SUCCESS;    return top_rule;
643  }  }
644    
645  void free_args(int argc, char** argv){  void free_args(int argc, char** argv){
# Line 638  void free_args(int argc, char** argv){ Line 652  void free_args(int argc, char** argv){
652  }  }
653    
654  /*! Iterates the list of policy_t structures and tries to free them and their rules */  /*! Iterates the list of policy_t structures and tries to free them and their rules */
655  EES_RC clean_policies_list(){  EES_RC clean_policies_list(policy_t* policies){
656    policy_t *temp_policy = policies_list, *last_policy = NULL;    policy_t *temp_policy = policies, *last_policy = NULL;
657    while(temp_policy){    while(temp_policy){
658      /* Clean policy fields */      /* Clean policy fields */
659      clean_rules_list(temp_policy->rules);      temp_policy->rules = clean_rules_list(temp_policy->rules);
660      free(temp_policy->name);      free(temp_policy->name);
661      temp_policy->name = NULL;      temp_policy->name = NULL;
662    
# Line 656  EES_RC clean_policies_list(){ Line 670  EES_RC clean_policies_list(){
670  }  }
671    
672  /*! Terminates the parser and tries to free all used memory */  /*! Terminates the parser and tries to free all used memory */
673  EES_RC pdl_term(){  EES_RC pdl_term(policy_t* policies){
674    clean_variables_list();    clean_variables_list();
675    clean_policies_list();    clean_policies_list(policies);
676    free(_pdl_path);    free(_pdl_path);
677    _pdl_path = NULL;    _pdl_path = NULL;
678    

Legend:
Removed from v.1211  
changed lines
  Added in v.1212

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