/[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 1144 by aramv, Wed Nov 18 17:05:33 2009 UTC revision 1145 by aramv, Thu Nov 19 14:40:54 2009 UTC
# Line 29  policy_t*                   policies_lis Line 29  policy_t*                   policies_lis
29  policy_t*                   policies_list_last;  policy_t*                   policies_list_last;
30  policy_t*                   current_policy;  policy_t*                   current_policy;
31    
 eef_plugindl_t*             plugin_tree;  
   
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      eef_plugindl_t* temp_plugin = NULL;
35    config_file_s = config_file_name;    config_file_s = config_file_name;
36    
37    if((config_file_fp = fopen(config_file_s,"r")) != NULL){    if((config_file_fp = fopen(config_file_s,"r")) != NULL){
38      yyin = config_file_fp;      yyin = config_file_fp;
39      yyparse();      yyparse();
40      print_policies();      /*print_policies();*/
41      if(add_plugins() == EES_SUCCESS){      if(add_plugins() == EES_SUCCESS){
42        /* this is a callout to the plugin manager, which calls dlopen(), dlsym() and the plugin's initialize function */        /* this is a callout to the plugin manager, which calls dlopen(), dlsym() and the plugin's initialize function */
43        if(initialize_plugins() == EES_SUCCESS){        if(initialize_plugins() == EES_SUCCESS){
44          build_plugin_tree(policies_list);          temp_plugin = build_plugin_tree(policies_list);
45            print_plugin_tree_recursive(temp_plugin, 0);
46    
47          return EES_SUCCESS;          return EES_SUCCESS;
48        } else {        } else {
49          eef_log(LOG_ERR, "Failed to initialize plug-ins from policy config file %s\n", config_file_s);          eef_log(LOG_ERR, "Failed to initialize plug-ins from policy config file %s\n", config_file_s);
# Line 55  EES_RC pdl_init(const char* config_file_ Line 57  EES_RC pdl_init(const char* config_file_
57    return EES_FAILURE;    return EES_FAILURE;
58  }  }
59    
60    /* TODO fix this */
61    /* builds a tree of eef_plugindl_t structs, which hold pointers to initialized plugins retrieved from the plugin manager */
62    eef_plugindl_t* build_plugin_tree(policy_t* policies){
63      policy_t        *temp_policy        = policies;
64      eef_plugindl_t  *temp_plugin_rule   = NULL , *temp_plugin_rule_last = NULL, *plugin_tree  = NULL, *plugin_tree_last = NULL, *temp_plugin_node = NULL;
65      rule_t          *temp_rule          = NULL;
66      /*plugin_tree = calloc(1,sizeof(eef_plugindl_t));*/
67      char**    argv;
68      int       argc;
69    
70      while(temp_policy){
71        temp_rule = temp_policy->rules;
72        eef_log(LOG_DEBUG, "Policy: %s\n", temp_policy->name);
73        while(temp_rule){
74          argv = _var_to_argv(get_variable_by_name(temp_rule->state)->value, &argc);
75          temp_plugin_node = get_plugin(argv[0]);
76          free_args(argc, argv);
77          if(temp_plugin_rule){
78            temp_plugin_rule_last->next = temp_plugin_node;
79          } else {
80            temp_plugin_rule = temp_plugin_node;
81          }
82          temp_plugin_rule_last = temp_plugin_node;
83    
84          eef_log(LOG_DEBUG, "  | Rule %s\n", temp_rule->state);
85          /*eef_log(LOG_DEBUG, "ARGV[0]: %s\n", argv[0]);*/
86          eef_log(LOG_DEBUG, "  -------------------------\n");
87    
88          if(temp_plugin_rule_last){
89            if(temp_rule->true_branch){
90              eef_log(LOG_DEBUG, "   True branch:  %s\n", temp_rule->true_branch->state);
91              argv = _var_to_argv(get_variable_by_name(temp_rule->true_branch->state)->value, &argc);
92              /*eef_log(LOG_DEBUG, "ARGV[0]: %s\n", argv[0]);*/
93              temp_plugin_rule_last->true_branch = get_plugin(argv[0]);
94              free_args(argc, argv);
95            }
96    
97            if(temp_rule->false_branch){
98              eef_log(LOG_DEBUG, "   False branch: %s\n", temp_rule->false_branch->state);
99              argv = _var_to_argv(get_variable_by_name(temp_rule->false_branch->state)->value, &argc);
100              /*eef_log(LOG_DEBUG, "ARGV[0]: %s\n", argv[0]);*/
101              temp_plugin_rule_last->false_branch = get_plugin(argv[0]);
102              free_args(argc, argv);
103            }
104          }
105    
106          eef_log(LOG_DEBUG, "\n");
107    
108          /* iterate to next rule */
109          temp_rule = temp_rule->next;
110        }
111    
112        /* iterate to next policy */
113        temp_policy = temp_policy->next;
114    
115        /* append to the end of the list */
116        if(plugin_tree){
117          plugin_tree_last->next = temp_plugin_rule;
118        } else {
119          plugin_tree = temp_plugin_rule;
120        }
121        plugin_tree_last = temp_plugin_rule;
122    
123      }
124      return plugin_tree;
125    }
126    
127    void free_args(int argc, char** argv){
128      for(; argc > 0; argc--){
129        free(argv[argc-1]);
130      }
131      free(argv);
132    }
133    
134    void print_plugin_tree_recursive(eef_plugindl_t* plugin_tree, int depth){
135      int depth_cache;
136      int num_policy = 1;
137    
138      while(plugin_tree){
139        if(depth==0){
140          printf("Policy %i\n", num_policy);
141        }
142    
143        for(depth_cache = depth; depth_cache > 0; depth_cache--){
144          printf("  ");
145        }
146        printf("| Rule %s\n", plugin_tree->pluginname);
147        for(depth_cache = depth; depth_cache > 0; depth_cache--){
148          printf("  ");
149        }
150        printf("-------------------------\n");
151        if(plugin_tree->true_branch){
152          printf("True: \n");
153          print_plugin_tree_recursive(plugin_tree->true_branch, depth+1);
154        }
155        if(plugin_tree->false_branch){
156          printf("False: \n");
157          print_plugin_tree_recursive(plugin_tree->false_branch, depth+1);
158        }
159        printf("\n");
160    
161        if(depth==0){
162          num_policy++;
163          /* only iterate top level plugins as only they can be considered policies - that is, they have branches */
164          if(plugin_tree->next){
165            if(!plugin_tree->next->true_branch || !plugin_tree->next->false_branch){
166              plugin_tree = NULL;
167            } else {
168              plugin_tree = plugin_tree->next;
169            }
170          }
171        } else {
172          /* prevent recursive printing of everything below top level plugins */
173          plugin_tree = NULL;
174        }
175      }
176    
177    }
178    
179  /*! sets the path to modules directory */  /*! sets the path to modules directory */
180  void set_pdl_path(record_t* path){  void set_pdl_path(record_t* path){
181    size_t path_size = 0;    size_t path_size = 0;
# Line 290  void add_policy(record_t* policy, rule_t Line 411  void add_policy(record_t* policy, rule_t
411    free(policy);    free(policy);
412  }  }
413    
 /* TODO fix this */  
 /* builds a tree of eef_plugindl_t structs, which hold pointers to initialized plugins retrieved from the plugin manager */  
 eef_plugindl_t* build_plugin_tree(policy_t* policies){  
   policy_t        *temp_policy  = policies;  
   eef_plugindl_t  *temp_plugin  = plugin_tree, *temp_plugin_true = NULL, *temp_plugin_false = NULL;  
   rule_t          *temp_rule    = NULL;  
   
   while(temp_policy){  
     if((temp_plugin = calloc(1,sizeof(eef_plugindl_t)))){  
       temp_rule = temp_policy->rules;  
       eef_log(LOG_DEBUG, "Policy: %s\n", temp_policy->name);  
       while(temp_rule){  
         eef_log(LOG_DEBUG, "  | Rule %s\n", temp_rule->state);  
         eef_log(LOG_DEBUG, "  -------------------------\n");  
         temp_plugin = get_plugin(get_variable_by_name(temp_rule->state)->value);  
   
         if(temp_rule->true_branch){  
           eef_log(LOG_DEBUG, "   True branch:  %s\n", temp_rule->true_branch->state);  
           temp_plugin_true = get_plugin(get_variable_by_name(temp_rule->true_branch->state)->value);  
           if(temp_plugin_true){  
             temp_plugin->true_branch = temp_plugin_true;  
           }  
         }  
         if(temp_rule->false_branch){  
           eef_log(LOG_DEBUG, "   False branch: %s\n", temp_rule->false_branch->state);  
           temp_plugin_false = get_plugin(get_variable_by_name(temp_rule->false_branch->state)->value);  
           if(temp_plugin_false){  
             temp_plugin->false_branch = temp_plugin_false;  
           }  
         }  
         eef_log(LOG_DEBUG, "\n");  
         temp_rule = temp_rule->next;  
       }  
       temp_policy = temp_policy->next;  
       temp_plugin = temp_plugin->next;  
     }  
   }  
   return temp_plugin;  
 }  
   
414    
415  void print_policies(){  void print_policies(){
416    rule_t*   temp_rule = NULL;    rule_t*   temp_rule = NULL;

Legend:
Removed from v.1144  
changed lines
  Added in v.1145

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