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(int argc, char *argv[])
00206 {
00207 const char* plugin_name;
00208 plugin_status_t result;
00209 policy_t* policy;
00210 int policy_seen;
00211
00212 lcmaps_log_debug(1, "runEvaluationManager called\n");
00213
00214 policy_seen = 0;
00215
00216 result = EVALUATION_START;
00217 while ((plugin_name=pdl_next_plugin(result))) {
00218
00219
00220
00221
00222 if (argc) {
00223 int i;
00224 int found = 0;
00225 policy = get_current_policy();
00226
00227
00228
00229
00230 for (i=0; policy, i<argc; ++i) {
00231 if (strcmp(policy->name, argv[i])==0) {
00232 found = 1;
00233 break;
00234 }
00235 }
00236
00237 if (found) {
00238
00239
00240
00241
00242
00243
00244 policy_seen = 1;
00245 } else {
00246 if (plugin_name) free((char *)plugin_name);
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 if (policy_seen)
00261 break;
00262 else {
00263
00264
00265
00266
00267 result = EVALUATION_FAILURE;
00268 continue;
00269 }
00270 }
00271 }
00272
00273 result = (runPlugin(plugin_name) ? EVALUATION_FAILURE : EVALUATION_SUCCESS);
00274
00275 lcmaps_log_debug(1, "runEvaluationManager: running plugin: %s.\n", plugin_name);
00276 lcmaps_log_debug(1, " : result %s.\n", (result==EVALUATION_SUCCESS) ? "true" : "false");
00277
00278 if (plugin_name) free((char *)plugin_name);
00279 }
00280
00281 if (result==EVALUATION_START)
00282 lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00283
00284 return result==EVALUATION_SUCCESS ? 0 : 1;
00285 }
00286
00287
00298 int stopEvaluationManager(void)
00299 {
00300 lcmaps_log_debug(1, "stopEvaluationManager: cleaning up!\n");
00301
00302 free_resources();
00303
00304 free_lcmaps_db_entry();
00305
00306 return 0;
00307 }
00308
00309
00319 int free_lcmaps_db_entry()
00320 {
00321 lcmaps_db_entry_t* plugin = global_plugin_list;
00322
00323 while (plugin) {
00324 lcmaps_db_entry_t* tmp = plugin->next;
00325 free(plugin);
00326 plugin = tmp;
00327 }
00328
00329 global_plugin_list = NULL;
00330
00331 return 0;
00332 }