00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00032
00033
00034
00035 #include "lcmaps_config.h"
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039
00040 #if HAVE_MALLOC_H
00041 # include <malloc.h>
00042 #endif
00043
00044
00045 #if HAVE_DLFCN_H
00046 # include <dlfcn.h>
00047 #endif
00048
00049
00050 #include "lcmaps_types.h"
00051 #include "lcmaps_log.h"
00052 #include "lcmaps_arguments.h"
00053 #include "lcmaps_defines.h"
00054 #include "_lcmaps_utils.h"
00055 #include "_lcmaps_db_read.h"
00056 #include "_lcmaps_runvars.h"
00057 #include "_lcmaps_cred_data.h"
00058
00059 #include "../evaluationmanager/evaluationmanager.h"
00060
00061
00062
00063
00064
00065 #ifndef NUL
00066 #define NUL '\0'
00067 #endif
00068
00069
00070 #define MAXPROCS 4
00071 #define USE_EVALUATIONMANAGER 1
00072
00073
00074
00075
00076
00082 enum lcmaps_proctype_e
00083 {
00084 INITPROC,
00085 RUNPROC,
00086 TERMPROC,
00087 INTROPROC,
00088 ENDOFPROCS
00089 };
00090
00096 typedef int (*lcmaps_proc_t)();
00097
00108 typedef struct lcmaps_plugindl_s
00109 {
00110 void * handle;
00111 lcmaps_proc_t procs[MAXPROCS];
00112 char pluginname[LCMAPS_MAXPATHLEN+1];
00113 char pluginargs[LCMAPS_MAXARGSTRING+1];
00114 int init_argc;
00115 char * init_argv[LCMAPS_MAXARGS];
00116 int run_argc;
00117 lcmaps_argument_t * run_argv;
00118 struct lcmaps_plugindl_s * next;
00119 }
00120 lcmaps_plugindl_t;
00121
00122
00123
00124
00125 static lcmaps_plugindl_t * PluginInit(lcmaps_db_entry_t *, lcmaps_plugindl_t **);
00126 static lcmaps_proc_t get_procsymbol(void *, char *);
00127 static int print_lcmaps_plugin(int, lcmaps_plugindl_t *);
00128 static int parse_args_plugin(const char *, const char *, char **, int *);
00129 static int clean_plugin_list(lcmaps_plugindl_t **);
00130
00131
00132
00133
00134 static char * lcmaps_db_file_default = NULL;
00135 static char * lcmaps_dir = NULL;
00136 static lcmaps_plugindl_t * plugin_list = NULL;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00160 int startPluginManager(
00161 )
00162 {
00163 #if USE_EVALUATIONMANAGER
00164 lcmaps_db_entry_t * lcmaps_db_handle=NULL;
00165 #else
00166 lcmaps_db_entry_t ** lcmaps_db_handle=NULL;
00167 #endif
00168 lcmaps_db_entry_t * ihandle=NULL;
00169 lcmaps_plugindl_t * plugin_entry=NULL;
00170 lcmaps_plugindl_t * plugin_entry_cmp=NULL;
00171 char * lcmaps_db_file=NULL;
00172 int ientry;
00173
00174
00175 lcmaps_dir = getenv("LCMAPS_DIR");
00176 lcmaps_dir = (lcmaps_dir ? lcmaps_dir : getenv("LCMAPS_ETC_DIR") );
00177 lcmaps_dir = (lcmaps_dir ? lcmaps_dir : LCMAPS_ETC_HOME );
00178
00179 lcmaps_db_file_default = getenv("LCMAPS_DB_FILE");
00180 lcmaps_db_file_default = (lcmaps_db_file_default ? lcmaps_db_file_default : "lcmaps.db" );
00181
00182 lcmaps_db_file=lcmaps_genfilename(lcmaps_dir, lcmaps_db_file_default, NULL);
00183
00184 #if USE_EVALUATIONMANAGER
00185
00186
00187
00188 lcmaps_log_debug(2,"lcmaps.mod-startPluginManager(): doing startEvaluationManager(%s)\n",
00189 lcmaps_db_file);
00190 {
00191 int npol = 0;
00192 char * pol1 = NULL;
00193 if (startEvaluationManager(lcmaps_db_file, npol, &pol1 ) != 0)
00194 {
00195 lcmaps_log(0,"lcmaps.mod-startPluginManager(): startEvaluationManager(%s) failed\n",
00196 lcmaps_db_file);
00197 goto fail_startPluginManager;
00198 }
00199 }
00200 #endif
00201
00202
00203
00204
00205
00206 lcmaps_log_time(0,"lcmaps.mod-startPluginManager(): Reading LCMAPS database %s\n",
00207 lcmaps_db_file);
00208 #if USE_EVALUATIONMANAGER
00209 if (getPluginNameAndArgs(&lcmaps_db_handle) != 0)
00210 {
00211 lcmaps_log(0,"lcmaps.mod-startPluginManager(): Error fetching list of plugins from evaluation manager\n");
00212 goto fail_startPluginManager;
00213 }
00214 #else
00215 lcmaps_db_handle=lcmaps_db_read(lcmaps_db_file);
00216 #endif
00217
00218 if (lcmaps_db_handle == NULL)
00219 {
00220 #if USE_EVALUATIONMANAGER
00221 lcmaps_log_debug(1,"lcmaps.mod-startPluginManager(): Evaluation manager found no plugins\n");
00222 #else
00223 lcmaps_log_debug(1,"lcmaps.mod-startPluginManager(): no plugins found by lcmaps_db_read()\n");
00224 #endif
00225 goto fail_startPluginManager;
00226 }
00227
00228
00229
00230
00231
00232
00233 ientry=0;
00234 #if USE_EVALUATIONMANAGER
00235 ihandle=lcmaps_db_handle;
00236 #else
00237 ihandle=*lcmaps_db_handle;
00238 #endif
00239 while (ihandle)
00240 {
00241 if (strlen(ihandle->pluginname) > 0)
00242 {
00243 int plugin_count=0;
00244
00245 lcmaps_log_debug(1,"\n");
00246 lcmaps_log_debug(1,"lcmaps.mod-startPluginManager(): initializing plugin %s (db entry %d)\n",
00247 ihandle->pluginname, ientry);
00248 if ((plugin_entry=PluginInit(ihandle,&plugin_list)) == NULL)
00249 {
00250 lcmaps_log(0,"lcmaps.mod-startPluginManager(): error initializing plugin: %s\n",ihandle->pluginname);
00251 goto fail_startPluginManager;
00252 }
00253
00254
00255
00256
00257 plugin_entry_cmp=plugin_list;
00258 while (plugin_entry_cmp)
00259 {
00260 if ( (strncmp(plugin_entry_cmp->pluginname,
00261 plugin_entry->pluginname,
00262 LCMAPS_MAXPATHLEN) == 0)
00263 )
00264 plugin_count++;
00265 if (plugin_count > 1)
00266 {
00267 lcmaps_log(0,"lcmaps.mod-startPluginManager() error: plugin %s already registered as\n",
00268 plugin_entry->pluginname);
00269 goto fail_startPluginManager;
00270 }
00271 plugin_entry_cmp=plugin_entry_cmp->next;
00272 }
00273 }
00274 ientry++;
00275 ihandle=ihandle->next;
00276 }
00277
00278 plugin_entry=plugin_list;
00279 while (plugin_entry)
00280 {
00281 print_lcmaps_plugin(2,plugin_entry);
00282 lcmaps_log_debug(2,"\n");
00283 plugin_entry=plugin_entry->next;
00284 }
00285
00286
00287 #if USE_EVALUATIONMANAGER
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 #else
00299 if (lcmaps_db_clean())
00300 {
00301 lcmaps_log(0,"lcmaps.mod-startPluginManager() error: could not clean up plugin db structure\n");
00302 goto fail_startPluginManager;
00303 }
00304 lcmaps_log_debug(5,"lcmaps.mod-startPluginManager(): cleaned lcmaps_db list: %p\n",lcmaps_db_handle);
00305 #endif
00306
00307
00308 if (lcmaps_db_file) free(lcmaps_db_file);
00309 return 0;
00310
00311 fail_startPluginManager:
00312
00313 #if USE_EVALUATIONMANAGER
00314
00315
00316
00317
00318
00319 #else
00320 lcmaps_db_clean();
00321 #endif
00322 if (clean_plugin_list(&plugin_list)!=0)
00323 {
00324 lcmaps_log(0,"lcmaps.mod-startPluginManager() error: could not clean up plugin list\n");
00325 }
00326 if (lcmaps_db_file) free(lcmaps_db_file);
00327
00328 return 1;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00365 static lcmaps_plugindl_t * PluginInit(
00366 lcmaps_db_entry_t * db_handle,
00367 lcmaps_plugindl_t ** list
00368 )
00369 {
00370 char * name;
00371 char * pname=NULL;
00372 char * args=NULL;
00373 void * plugin_handle;
00374 lcmaps_proc_t plugin_procs[MAXPROCS];
00375 lcmaps_plugindl_t * pplugin=NULL;
00376 int i;
00377 int retval;
00378
00379 name = db_handle->pluginname;
00380 args = db_handle->pluginargs;
00381
00382
00383 pname = lcmaps_findfile(name);
00384 if (pname == NULL)
00385 {
00386 lcmaps_log(0,
00387 "lcmaps.mod-PluginInit(): plugin %s not found (arguments: %s)\n",
00388 name, args
00389 );
00390 goto fail_PluginInit;
00391 }
00392
00393
00394 plugin_handle=dlopen(pname,RTLD_NOW);
00395 if (!plugin_handle)
00396 {
00397 lcmaps_log(0,"lcmaps.mod-PluginInit(): dlopen error for %s:\n %s\n",
00398 pname,dlerror()
00399 );
00400 goto fail_PluginInit;
00401 }
00402
00403
00404 for (i=0; i < MAXPROCS; ++i)
00405 {
00406 switch (i)
00407 {
00408 case INITPROC:
00409 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_initialize");
00410 if (plugin_procs[i] == NULL)
00411 {
00412 lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00413 name);
00414 lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_initialize()\"\n");
00415 goto fail_PluginInit;
00416 }
00417 else
00418 {
00419 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_initialize()\"\n");
00420 }
00421 break;
00422 case RUNPROC:
00423 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_run");
00424 if (plugin_procs[i] == NULL)
00425 {
00426 lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00427 name);
00428 lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_run()\"\n");
00429 goto fail_PluginInit;
00430 }
00431 else
00432 {
00433 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_run()\"\n");
00434 }
00435 break;
00436 case TERMPROC:
00437 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_terminate");
00438 if (plugin_procs[i] == NULL)
00439 {
00440 lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00441 name);
00442 lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_terminate()\"\n");
00443 goto fail_PluginInit;
00444 }
00445 else
00446 {
00447 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_terminate()\"\n");
00448 }
00449 break;
00450 case INTROPROC:
00451 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_introspect");
00452 if (plugin_procs[i] == NULL)
00453 {
00454 lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00455 name);
00456 lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_introspect()\"\n");
00457 goto fail_PluginInit;
00458 }
00459 else
00460 {
00461 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_introspect()\"\n");
00462 }
00463 break;
00464 default:
00465
00466 plugin_procs[i]=NULL;
00467 break;
00468 }
00469 }
00470
00471 if (!*list)
00472 {
00473 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): creating first pluginlist entry\n");
00474 *list=pplugin=(lcmaps_plugindl_t *)malloc(sizeof(lcmaps_plugindl_t));
00475 }
00476 else
00477 {
00478 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): creating new pluginlist entry\n");
00479 pplugin=*list;
00480 while (pplugin->next) pplugin=pplugin->next;
00481 pplugin=pplugin->next=(lcmaps_plugindl_t *)malloc(sizeof(lcmaps_plugindl_t));
00482 }
00483 if (!pplugin)
00484 {
00485 lcmaps_log(0,"lcmaps.mod-PluginInit(): error creating new pluginlist entry\n");
00486 goto fail_PluginInit;
00487 }
00488
00489 pplugin->next=NULL;
00490 pplugin->handle=plugin_handle;
00491 pplugin->run_argc=0;
00492 pplugin->run_argv=NULL;
00493 for (i=0; i < MAXPROCS; ++i)
00494 pplugin->procs[i]=plugin_procs[i];
00495 if (pname != NULL)
00496 {
00497 strncpy(pplugin->pluginname,pname,LCMAPS_MAXPATHLEN);
00498 (pplugin->pluginname)[LCMAPS_MAXPATHLEN]=NUL;
00499 }
00500 else
00501 strncpy(pplugin->pluginname,"",LCMAPS_MAXPATHLEN);
00502
00503 if (args != NULL)
00504 {
00505 strncpy(pplugin->pluginargs,args,LCMAPS_MAXARGSTRING);
00506 (pplugin->pluginargs)[LCMAPS_MAXARGSTRING]=NUL;
00507 }
00508 else
00509 strncpy(pplugin->pluginargs,"",LCMAPS_MAXARGSTRING);
00510
00511
00512 if (parse_args_plugin(pname,args,pplugin->init_argv,&(pplugin->init_argc)) )
00513 {
00514 lcmaps_log(0,"lcmaps.mod-PluginInit(): Could not parse arguments for plugin module %s\n",
00515 pname);
00516 goto fail_PluginInit;
00517 }
00518 for (i=0; i < pplugin->init_argc; ++i)
00519 lcmaps_log_debug(4,"%s arg %d = %s\n",pname,i,(pplugin->init_argv)[i]);
00520
00521
00522
00523 retval=(*(pplugin->procs[INITPROC]))(pplugin->init_argc,pplugin->init_argv);
00524 if (retval != LCMAPS_MOD_SUCCESS )
00525 {
00526 lcmaps_log(0,"lcmaps.mod-PluginInit(): \"plugin_initialize()\" failed\n");
00527 goto fail_PluginInit;
00528 }
00529 else
00530 {
00531 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): \"plugin_initialize()\" succeeded\n");
00532 }
00533
00534
00535 retval=(*(pplugin->procs[INTROPROC]))(&(pplugin->run_argc),&(pplugin->run_argv));
00536 if (retval != LCMAPS_MOD_SUCCESS )
00537 {
00538 lcmaps_log(0,"lcmaps.mod-PluginInit(): \"plugin_introspect()\" failed\n");
00539 goto fail_PluginInit;
00540 }
00541 else
00542 {
00543 lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): \"plugin_introspect()\" succeeded\n");
00544 }
00545
00546
00547 if (pname) { free(pname); pname=NULL; }
00548
00549 return pplugin;
00550
00551 fail_PluginInit:
00552 if (pname) { free(pname); pname=NULL; }
00553 return NULL;
00554 }
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00588 static int parse_args_plugin(
00589 const char * name,
00590 const char * argstring,
00591 char ** xargv,
00592 int * xargc
00593 )
00594 {
00595 int len=0;
00596 int i;
00597 int rc;
00598
00599
00600 len=strlen(name);
00601 if ( (len > 0) && (len < LCMAPS_MAXPATHLEN) )
00602 {
00603 xargv[0]=(char *)malloc(len+1);
00604 if (xargv[0] != NULL)
00605 strncpy(xargv[0],name,len+1);
00606 else
00607 return 1;
00608 }
00609
00610 *xargc=LCMAPS_MAXARGS-1;
00611 if ( ( rc = lcmaps_tokenize(argstring, &xargv[1], xargc, " \t\n") ) )
00612 {
00613 lcmaps_log(0,"lcmaps.mod-parse_args_plugin(): something wrong parsing arguments of %s, rc=%d\n",
00614 name, rc);
00615 (*xargc)++;
00616 return 1;
00617 }
00618 (*xargc)++;
00619 lcmaps_log_debug(3,"lcmaps.mod-parse_args_plugin(): Found %d arguments:\n", *xargc);
00620 for (i=0; i < *xargc; i++)
00621 lcmaps_log_debug(3,"lcmaps.mod-parse_args_plugin(): %d --> %s\n", i, xargv[i]);
00622
00623 return 0;
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00649 static lcmaps_proc_t get_procsymbol(
00650 void * handle,
00651 char * symname
00652 )
00653 {
00654 lcmaps_proc_t symhandle;
00655 char *error;
00656
00657 symhandle=dlsym(handle,symname);
00658 if ((error = dlerror()) != NULL)
00659 {
00660 lcmaps_log(0,"lcmaps.mod-get_procsymbol(): dlsym error: %s",error);
00661 return NULL;
00662 }
00663 return symhandle;
00664 }
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00690 static int print_lcmaps_plugin(
00691 int debug_lvl,
00692 lcmaps_plugindl_t * plugin
00693 )
00694 {
00695 int i=0;
00696
00697 lcmaps_log_debug(debug_lvl,"\tplugin name : %s\n",plugin->pluginname);
00698 lcmaps_log_debug(debug_lvl,"\tplugin arguments : %s\n",plugin->pluginargs);
00699 lcmaps_log_debug(debug_lvl,"\tplugin address : x%x\n",plugin);
00700 lcmaps_log_debug(debug_lvl,"\tplugin size : %d\n",sizeof(lcmaps_plugindl_t));
00701 lcmaps_log_debug(debug_lvl,"\tplugin handle : x%x\n",plugin->handle);
00702 lcmaps_log_debug(debug_lvl,"\tplugin_initialize() : x%x\n",plugin->procs[INITPROC]);
00703 lcmaps_log_debug(debug_lvl,"\tplugin_run() : x%x\n",plugin->procs[RUNPROC]);
00704 lcmaps_log_debug(debug_lvl,"\tplugin_terminate() : x%x\n",plugin->procs[TERMPROC]);
00705 lcmaps_log_debug(debug_lvl,"\tplugin_introspect() : x%x\n",plugin->procs[INTROPROC]);
00706 lcmaps_log_debug(debug_lvl,"\tplugin init_argc : %d\n",plugin->init_argc);
00707 for (i=0; i < plugin->init_argc; i++)
00708 lcmaps_log_debug(debug_lvl,"\tplugin init_argv[%2d] : %s\n",i,(plugin->init_argv)[i]);
00709 lcmaps_log_debug(debug_lvl,"\tplugin run_argc : %d\n",plugin->run_argc);
00710 for (i=0; i < plugin->run_argc; i++)
00711 {
00712 char * argType=NULL;
00713
00714 argType=((plugin->run_argv)[i]).argType;
00715 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d] : x%x\n",i,(plugin->run_argv)+i);
00716 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], argName : %s\n",i,((plugin->run_argv)[i]).argName);
00717 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], argType : %s\n",i,((plugin->run_argv)[i]).argType);
00718 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], argInOut : %d\n",i,((plugin->run_argv)[i]).argInOut);
00719 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], value address : x%x\n",i,((plugin->run_argv)[i]).value);
00720 if (strcmp("char *",argType) == 0)
00721 {
00722 char ** pstring;
00723 if ( ((plugin->run_argv)[i]).value != NULL)
00724 {
00725 pstring = (char **) (((plugin->run_argv)[i]).value);
00726 pstring = (char **) lcmaps_getArgValue(
00727 ((plugin->run_argv)[i]).argName,
00728 ((plugin->run_argv)[i]).argType,
00729 plugin->run_argc,
00730 plugin->run_argv
00731 );
00732 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], char * value : %s\n",i,*pstring);
00733 }
00734 else
00735 {
00736 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], char * value : none yet\n",i);
00737 }
00738 }
00739 if (strcmp("int",argType) == 0)
00740 {
00741 int * pint;
00742 if ( ((plugin->run_argv)[i]).value != NULL)
00743 {
00744 pint = (int *) (((plugin->run_argv)[i]).value);
00745 pint = (int *) lcmaps_getArgValue(
00746 ((plugin->run_argv)[i]).argName,
00747 ((plugin->run_argv)[i]).argType,
00748 plugin->run_argc,
00749 plugin->run_argv
00750 );
00751 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], int value : %d\n",i,*pint);
00752 }
00753 else
00754 {
00755 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], int value : none yet\n",i);
00756 }
00757 }
00758 }
00759 lcmaps_log_debug(debug_lvl,"\tplugin next : x%x\n",plugin->next);
00760 if (plugin->next != NULL)
00761 lcmaps_log_debug(debug_lvl,"\tplugin_next : %s\n",(plugin->next)->pluginname);
00762 else
00763 lcmaps_log_debug(debug_lvl,"\tplugin_next : last plugin in list\n");
00764
00765 return 1;
00766 }
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00791 static int clean_plugin_list(
00792 lcmaps_plugindl_t ** list
00793 )
00794 {
00795 int rc;
00796 lcmaps_plugindl_t * plugin_entry=NULL;
00797
00798 plugin_entry=*list;
00799 while (plugin_entry)
00800 {
00801 lcmaps_plugindl_t * plugin_next;
00802 int i;
00803
00804 rc = plugin_entry->procs[TERMPROC]();
00805 if (rc != LCMAPS_MOD_SUCCESS)
00806 {
00807 lcmaps_log(0,"lcmaps.mod-clean_plugin_list(): failed to terminate plugin module %s\n",
00808 plugin_entry->pluginname);
00809 }
00810 lcmaps_log_debug(1, "lcmaps.mod-clean_plugin_list(): plugin module %s terminated\n",
00811 plugin_entry->pluginname);
00812 dlclose(plugin_entry->handle);
00813
00814 plugin_next=plugin_entry->next;
00815 for (i=0; i < plugin_entry->init_argc; i++)
00816 {
00817 if ((plugin_entry->init_argv)[i] != NULL)
00818 {
00819 lcmaps_log_debug(3,"Freeing %d - %s\n",i,(plugin_entry->init_argv)[i]);
00820 free((plugin_entry->init_argv)[i]);
00821 }
00822 }
00823 free(plugin_entry);
00824 plugin_entry=plugin_next;
00825 }
00826 *list=plugin_entry=NULL;
00827 return 0;
00828 }
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00866 int runPluginManager(
00867 lcmaps_request_t request,
00868 lcmaps_cred_id_t lcmaps_cred,
00869 int npols,
00870 char ** policynames
00871 )
00872 {
00873 lcmaps_plugindl_t * plugin_entry=NULL;
00874
00875
00876
00877
00878
00879
00880 lcmaps_log_debug(2,"lcmaps.mod-runPluginManager(): extract RunVars\n");
00881 if (lcmaps_extractRunVars(request, lcmaps_cred) != 0)
00882 {
00883 lcmaps_log(0,"lcmaps.mod-runPluginManager(): error in creating list of run variables\n");
00884 return 1;
00885 }
00886
00887 plugin_entry=plugin_list;
00888 while (plugin_entry)
00889 {
00890 void * pvalue=NULL;
00891 char * argName=NULL;
00892 char * argType=NULL;
00893 int iarg=0;
00894
00895 for (iarg=0; iarg < plugin_entry->run_argc; iarg++)
00896 {
00897 argName=(plugin_entry->run_argv+iarg)->argName;
00898 argType=(plugin_entry->run_argv+iarg)->argType;
00899 lcmaps_log_debug(2,
00900 "lcmaps.mod-runPluginManager(): Getting value of \"%s\" of type \"%s\" for plugin \"%s\"\n",
00901 argName, argType, plugin_entry->pluginname);
00902 if ((pvalue=lcmaps_getRunVars(argName, argType)) == NULL)
00903 {
00904 lcmaps_log(0,
00905 "lcmaps.mod-runPluginManager(): could not GET requested variable \"%s\" of type \"%s\" for plugin \"%s\"\n",
00906 argName, argType, plugin_entry->pluginname);
00907 return 1;
00908 }
00909 lcmaps_log_debug(2,
00910 "lcmaps.mod-runPluginManager(): Setting value of \"%s\" of type \"%s\" for plugin \"%s\", address: 0x%x\n",
00911 argName, argType, plugin_entry->pluginname, pvalue);
00912 if (lcmaps_setArgValue(argName, argType, pvalue, plugin_entry->run_argc, &(plugin_entry->run_argv)) != 0)
00913 {
00914 lcmaps_log(0,
00915 "lcmaps.mod-runPluginManager(): could not SET requested variable \"%s\" of type \"%s\" for plugin \"%s\"\n",
00916 argName, argType, plugin_entry->pluginname);
00917 return 1;
00918 }
00919 }
00920 plugin_entry=plugin_entry->next;
00921 }
00922
00923 #if USE_EVALUATIONMANAGER
00924 if (npols > 0)
00925 {
00926 int ipol = 0;
00927
00928 lcmaps_log_debug(1,"lcmaps.mod-runPluginManager(): Do runEvaluationManager with the following policies:\n");
00929 for (ipol = 0; ipol < npols; ipol ++)
00930 lcmaps_log_debug(1,"lcmaps.mod-runPluginManager(): %s\n", policynames[ipol]);
00931 }
00932 else
00933 lcmaps_log_debug(1,"lcmaps.mod-runPluginManager(): Do runEvaluationManager()\n");
00934 if (runEvaluationManager(npols, policynames) != 0)
00935 {
00936 lcmaps_log(0,"lcmaps.mod-runPluginManager(): Error running evaluation manager\n");
00937 return 1;
00938 }
00939 lcmaps_log_debug(1,"lcmaps.mod-runPluginManager(): runEvaluationManager() succeeded.\n");
00940 #else
00941
00942
00943
00944 plugin_entry=plugin_list;
00945 while (plugin_entry)
00946 {
00947 print_lcmaps_plugin(2,plugin_entry);
00948 lcmaps_log_debug(2,"\n");
00949 lcmaps_log(0,"lcmaps.mod-runPluginManager(): running %s\n",plugin_entry->pluginname);
00950 if (runPlugin(plugin_entry->pluginname)) {
00951 lcmaps_log(0,"lcmaps.mod-runPluginManager(): plugin %s failed\n",plugin_entry->pluginname);
00952 }
00953 plugin_entry=plugin_entry->next;
00954 }
00955 #endif
00956 return 0;
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00982 int resetCredentialData()
00983 {
00984 lcmaps_log_debug(1,"lcmaps.mod-resetCredentialData(): Called\n");
00985 return cleanCredentialData();
00986 }
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01014 int runPlugin(
01015 const char * pluginname
01016 )
01017 {
01018 lcmaps_plugindl_t * plugin_entry=NULL;
01019 int rc=1;
01020 int foundplugin=0;
01021
01022
01023
01024
01025
01026
01027 plugin_entry=plugin_list;
01028 while (plugin_entry)
01029 {
01030 lcmaps_log_debug(3,"lcmaps.mod-runPlugin(): looking for plugin %s\n",pluginname);
01031 if (strcmp(plugin_entry->pluginname,pluginname) == 0) {
01032 lcmaps_log_time(0,"lcmaps.mod-runPlugin(): found plugin %s\n",plugin_entry->pluginname);
01033 foundplugin++;
01034 break;
01035 }
01036 plugin_entry=plugin_entry->next;
01037 }
01038 if (!foundplugin) {
01039 lcmaps_log(0,"lcmaps.mod-runPlugin(): could not find plugin %s\n",pluginname);
01040 return 1;
01041 }
01042
01043
01044 lcmaps_log_time(0,"lcmaps.mod-runPlugin(): running plugin %s\n",plugin_entry->pluginname);
01045 rc = plugin_entry->procs[RUNPROC](plugin_entry->run_argc, plugin_entry->run_argv);
01046
01047 return rc;
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01070 int stopPluginManager(
01071 )
01072 {
01073 lcmaps_log_debug(1,"lcmaps.mod-stopPluginManager(): cleaning credential data\n");
01074 printCredData(1);
01075 if (cleanCredentialData()!=0)
01076 {
01077 lcmaps_log(0,"lcmaps.mod-stopPluginManager() error: could not clean credential data list\n");
01078 return 1;
01079 }
01080 if (clean_plugin_list(&plugin_list)!=0)
01081 {
01082 lcmaps_log(0,"lcmaps.mod-stopPluginManager() error: could not clean up plugin list\n");
01083 return 1;
01084 }
01085 #if USE_EVALUATIONMANAGER
01086 if (stopEvaluationManager() != 0)
01087 {
01088 lcmaps_log(0,"lcmaps.mod-stopPluginManager(): error in stopEvaluationManager()\n");
01089 return 1;
01090 }
01091 #endif
01092 return 0;
01093 }