00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00035 #include <stdlib.h>
00036 #include <string.h>
00037
00038 #include "_lcmaps_pluginmanager.h"
00039 #include "lcmaps_log.h"
00040 #include "evaluationmanager.h"
00041
00050 static lcmaps_db_entry_t* global_plugin_list = NULL;
00051
00052 int free_lcmaps_db_entry();
00053
00054
00063 int startEvaluationManager(const char* name)
00064 {
00065 if (pdl_init(name) < 0) {
00066 stopEvaluationManager();
00067 return -1;
00068 }
00069
00070
00071 yyparse();
00072
00073
00074
00075
00076
00077 if (yyparse_errors()) {
00078 stopEvaluationManager();
00079 return -1;
00080 }
00081
00082
00083
00084
00085
00086 if (check_policies_for_recursion())
00087 return -1;
00088
00089
00090
00091
00092
00093 reduce_policies();
00094
00095 return 0;
00096 }
00097
00098
00110 int getPluginNameAndArgs(lcmaps_db_entry_t** plugins)
00111 {
00112 const plugin_t* p_list, *tmp_p_list;
00113 lcmaps_db_entry_t* p=0;
00114 int path_length;
00115 char* path;
00116 BOOL string_too_long;
00117
00118 string_too_long = FALSE;
00119
00120
00121 if (global_plugin_list) {
00122 *plugins = global_plugin_list;
00123 return 0;
00124 }
00125
00126
00127 *plugins = 0;
00128
00129 if (!pdl_path()) {
00130 lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00131 return -1;
00132 }
00133
00134 path = strdup(pdl_path());
00135 path_length = strlen(path);
00136
00137 if (path[path_length-1] != '/') {
00138 path = (char *)realloc(path, path_length+2);
00139 path[path_length] = '/';
00140 path[path_length+1] = '\0';
00141
00142 path_length = strlen(path);
00143 }
00144
00145 p_list = get_plugins();
00146
00147 while (p_list) {
00148 if (!*plugins) {
00149 *plugins = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00150 p = *plugins;
00151 } else {
00152 p->next = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00153 p = p->next;
00154 }
00155
00156
00157 strncpy(p->pluginname, path, LCMAPS_MAXPATHLEN);
00158 strncpy(p->pluginname+path_length, p_list->name, LCMAPS_MAXPATHLEN-path_length);
00159
00160 if ((strlen(path) + strlen(p_list->name))>=LCMAPS_MAXPATHLEN) {
00161 lcmaps_log(1, "String too long to copy. Max length = %d\n", LCMAPS_MAXPATHLEN);
00162 string_too_long = TRUE;
00163 }
00164
00165 if (p_list->args) {
00166 strncpy(p->pluginargs, p_list->args, LCMAPS_MAXARGSTRING);
00167 if (strlen(p_list->args)>LCMAPS_MAXARGSTRING) {
00168 lcmaps_log(1, "String too long to copy. Max length = %d\n", LCMAPS_MAXARGSTRING);
00169 string_too_long = TRUE;
00170 }
00171 }
00172 else
00173 *p->pluginargs = '\0';
00174 p->next = 0;
00175
00176 tmp_p_list = p_list->next;
00177
00178 if (p_list->name) free(p_list->name);
00179 if (p_list->args) free(p_list->args);
00180 free((plugin_t*)p_list);
00181
00182 p_list = tmp_p_list;
00183
00184
00185 lcmaps_log_debug(1, "%s\n", p->pluginname);
00186 lcmaps_log_debug(1, "%s\n", p->pluginargs);
00187 }
00188
00189 free(path);
00190
00191 global_plugin_list = *plugins;
00192
00193 return string_too_long ? -1 : 0;
00194 }
00195
00196
00205 int runEvaluationManager(void)
00206 {
00207 const char* plugin_name;
00208 plugin_status_t result;
00209 policy_t* policy;
00210
00211 lcmaps_log_debug(1, "runEvaluationManager called\n");
00212
00213 result = EVALUATION_START;
00214 while ((plugin_name=pdl_next_plugin(result))) {
00215 result = (runPlugin(plugin_name) ? EVALUATION_FAILURE : EVALUATION_SUCCESS);
00216
00217 lcmaps_log_debug(1, "runEvaluationManager: running plugin: %s.\n", plugin_name);
00218 lcmaps_log_debug(1, " : result %s.\n", (result==EVALUATION_SUCCESS) ? "true" : "false");
00219
00220 free((char *)plugin_name);
00221 }
00222
00223 if (result==EVALUATION_START)
00224 lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00225
00226 return result==EVALUATION_SUCCESS ? 0 : 1;
00227 }
00228
00229
00240 int stopEvaluationManager(void)
00241 {
00242 lcmaps_log_debug(1, "stopEvaluationManager: cleaning up!\n");
00243
00244 free_resources();
00245
00246 free_lcmaps_db_entry();
00247
00248 return 0;
00249 }
00250
00251
00261 int free_lcmaps_db_entry()
00262 {
00263 lcmaps_db_entry_t* plugin = global_plugin_list;
00264
00265 while (plugin) {
00266 lcmaps_db_entry_t* tmp = plugin->next;
00267 free(plugin);
00268 plugin = tmp;
00269 }
00270
00271 global_plugin_list = NULL;
00272
00273 return 0;
00274 }