Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

lcmaps_pluginmanager.c

Go to the documentation of this file.
00001 /*                                                                                                            
00002  * Copyright (c) 2001 EU DataGrid.                                                                             
00003  * For license conditions see http://www.eu-datagrid.org/license.html                                          
00004  *
00005  * Copyright (c) 2001, 2002 by 
00006  *     Martijn Steenbakkers <martijn@nikhef.nl>,
00007  *     David Groep <davidg@nikhef.nl>,
00008  *     NIKHEF Amsterdam, the Netherlands
00009  */
00010 
00024 /*****************************************************************************
00025                             Include header files
00026 ******************************************************************************/
00027 #include "lcmaps_config.h"
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 #if HAVE_MALLOC_H
00033 #    include <malloc.h>
00034 #endif
00035 
00036 /* Programming interface to dynamic linking loader */
00037 #if HAVE_DLFCN_H
00038 #    include <dlfcn.h>
00039 #endif
00040 
00041 #include <gssapi.h>
00042 
00043 /* LCMAPS includes */
00044 #include "lcmaps_types.h"
00045 #include "lcmaps_log.h"
00046 #include "lcmaps_arguments.h"
00047 #include "lcmaps_defines.h"
00048 #include "_lcmaps_utils.h"
00049 #include "_lcmaps_db_read.h"
00050 #include "_lcmaps_runvars.h"
00051 #include "_lcmaps_cred_data.h"
00052 /* interface to evaluationmanager */
00053 #include "../evaluationmanager/evaluationmanager.h"
00054 
00055 /******************************************************************************
00056                              Define constants
00057 ******************************************************************************/
00058 
00059 #ifndef NUL
00060 #define NUL '\0' 
00061 #endif
00062 
00063 /* LCMAPS authorization module definitions */
00064 #define MAXPROCS    4 
00065 #define USE_EVALUATIONMANAGER 1
00066 
00067 
00068 /******************************************************************************
00069                                Type definitions
00070 ******************************************************************************/
00076 enum lcmaps_proctype_e
00077 {
00078     INITPROC,  
00079     RUNPROC,   
00080     TERMPROC,  
00081     INTROPROC, 
00082     ENDOFPROCS /*< this is the last enumeration value */
00083 };
00084 
00090 typedef int (*lcmaps_proc_t)();
00091 
00102 typedef struct lcmaps_plugindl_s
00103 {
00104     void *                      handle;                            
00105     lcmaps_proc_t               procs[MAXPROCS];                   
00106     char                        pluginname[LCMAPS_MAXPATHLEN+1];   
00107     char                        pluginargs[LCMAPS_MAXARGSTRING+1]; 
00108     int                         init_argc;                         
00109     char *                      init_argv[LCMAPS_MAXARGS];         
00110     int                         run_argc;                          
00111     lcmaps_argument_t *         run_argv;                          
00112     struct lcmaps_plugindl_s *  next;                              
00113 }
00114 lcmaps_plugindl_t;
00115 
00116 /******************************************************************************
00117                           Module specific prototypes
00118 ******************************************************************************/
00119 static lcmaps_plugindl_t * PluginInit(lcmaps_db_entry_t *, lcmaps_plugindl_t **);
00120 static lcmaps_proc_t       get_procsymbol(void *, char *);
00121 static int                 print_lcmaps_plugin(int, lcmaps_plugindl_t *);
00122 static int                 parse_args_plugin(const char *, const char *, char **, int *);
00123 static int                 clean_plugin_list(lcmaps_plugindl_t **);
00124 
00125 /******************************************************************************
00126                        Define module specific variables
00127 ******************************************************************************/
00128 static char *              lcmaps_db_file_default = NULL; 
00129 static char *              lcmaps_dir             = NULL; 
00130 static lcmaps_plugindl_t * plugin_list            = NULL; 
00132 /******************************************************************************
00133 Function:   startPluginManager
00134 Description:
00135     Start PluginManager module:
00136     read from LCMAPS config file, the plugins to be loaded
00137     Start evaluation manager (get policy)
00138 
00139 Parameters:
00140 Returns:
00141     0: succes
00142     1: failure
00143 ******************************************************************************/
00154 int startPluginManager(
00155 )
00156 {
00157 #if USE_EVALUATIONMANAGER
00158     lcmaps_db_entry_t *   lcmaps_db_handle=NULL;
00159 #else
00160     lcmaps_db_entry_t **  lcmaps_db_handle=NULL;
00161 #endif
00162     lcmaps_db_entry_t *   ihandle=NULL;
00163     lcmaps_plugindl_t *   plugin_entry=NULL;
00164     lcmaps_plugindl_t *   plugin_entry_cmp=NULL;
00165     char *                lcmaps_db_file=NULL;
00166     int                   ientry;
00167 
00168     /* get LCMAPS (database) home directory and set lcmaps_db_file */
00169     lcmaps_dir = getenv("LCMAPS_DIR");
00170     lcmaps_dir = (lcmaps_dir ? lcmaps_dir : LCMAPS_ETC_HOME );
00171     lcmaps_db_file_default = getenv("LCMAPS_DB_FILE");
00172     lcmaps_db_file_default = (lcmaps_db_file_default ? lcmaps_db_file_default : "lcmaps.db" );
00173 
00174     lcmaps_db_file=lcmaps_genfilename(lcmaps_dir, lcmaps_db_file_default, NULL);
00175 
00176 #if USE_EVALUATIONMANAGER
00177     /* To be done:
00178      * Start evaluation manager (evaluates the  LCMAPS policy database)
00179      */
00180     lcmaps_log_debug(2,"lcmaps.mod-startPluginManager(): doing startEvaluationManager(%s)\n",
00181             lcmaps_db_file);
00182     if (startEvaluationManager(lcmaps_db_file) != 0)
00183     {
00184         lcmaps_log(0,"lcmaps.mod-startPluginManager(): startEvaluationManager(%s) failed\n",
00185                 lcmaps_db_file);
00186         goto fail_startPluginManager;
00187     }
00188 #endif
00189 
00190     /* 
00191      * retrieve PLUGIN MODULE info from evaluation manager and store
00192      * the info in a lcmaps_db structure
00193      */
00194     lcmaps_log_time(0,"lcmaps.mod-startPluginManager(): Reading LCMAPS database %s\n",
00195             lcmaps_db_file);
00196 #if USE_EVALUATIONMANAGER
00197     if (getPluginNameAndArgs(&lcmaps_db_handle) != 0)
00198     {
00199         lcmaps_log(0,"lcmaps.mod-startPluginManager(): Error fetching list of plugins from evaluation manager\n");
00200         goto fail_startPluginManager;
00201     }
00202 #else
00203     lcmaps_db_handle=lcmaps_db_read(lcmaps_db_file);
00204 #endif
00205 
00206     if (lcmaps_db_handle == NULL)
00207     {
00208 #if USE_EVALUATIONMANAGER
00209         lcmaps_log_debug(1,"lcmaps.mod-startPluginManager(): Evaluation manager found no plugins\n");
00210 #else
00211         lcmaps_log_debug(1,"lcmaps.mod-startPluginManager(): no plugins found by lcmaps_db_read()\n");
00212 #endif
00213         goto fail_startPluginManager;
00214     }
00215 
00216     /*
00217      * init the PLUGIN AUTHORIZATION MODULES (PluginInit)
00218      * - open plugins and check the symbols plugin_init and confirm_authorization
00219      * - run plugin_init
00220      */
00221     ientry=0;
00222 #if USE_EVALUATIONMANAGER
00223     ihandle=lcmaps_db_handle;
00224 #else
00225     ihandle=*lcmaps_db_handle;
00226 #endif
00227     while (ihandle)
00228     {
00229         if (strlen(ihandle->pluginname) > 0)
00230         {
00231             int plugin_count=0;
00232 
00233             lcmaps_log_debug(1,"\n");
00234             lcmaps_log_debug(1,"lcmaps.mod-startPluginManager(): initializing plugin %s (db entry %d)\n",
00235                      ihandle->pluginname, ientry);
00236             if ((plugin_entry=PluginInit(ihandle,&plugin_list)) == NULL)
00237             {
00238                 lcmaps_log(0,"lcmaps.mod-startPluginManager(): error initializing plugin: %s\n",ihandle->pluginname);
00239                 goto fail_startPluginManager;
00240             }
00241             /* 
00242              * Check if plugin module is already registered as standard authorization module,
00243              * by comparing the complete path names of the plugin and modules
00244              */
00245             plugin_entry_cmp=plugin_list;
00246             while (plugin_entry_cmp)
00247             {
00248                 if ( (strncmp(plugin_entry_cmp->pluginname,
00249                               plugin_entry->pluginname,
00250                               LCMAPS_MAXPATHLEN) == 0)
00251                    )
00252                     plugin_count++;
00253                 if (plugin_count > 1)
00254                 {
00255                     lcmaps_log(0,"lcmaps.mod-startPluginManager() error: plugin %s already registered as\n",
00256                              plugin_entry->pluginname);
00257                     goto fail_startPluginManager;
00258                 }
00259                 plugin_entry_cmp=plugin_entry_cmp->next;
00260             }
00261         }
00262         ientry++;
00263         ihandle=ihandle->next;
00264     }
00265 
00266     plugin_entry=plugin_list;
00267     while (plugin_entry)
00268     {
00269         print_lcmaps_plugin(2,plugin_entry);
00270         lcmaps_log_debug(2,"\n");
00271         plugin_entry=plugin_entry->next;
00272     }
00273 
00274     /* clean PLUGIN authorization module database structure */
00275 #if USE_EVALUATIONMANAGER
00276     /*
00277      * Do not clean lcmaps_db_entry_t structure since it is managed by the evaluation manager
00278      * and will be taken care of in stopEvaluationManager
00279      */
00280 //    if (lcmaps_db_clean_list(&lcmaps_db_handle))
00281 //    {
00282 //        lcmaps_log(0,"lcmaps.mod-startPluginManager() error: could not clean up plugin db structure\n");
00283 //        goto fail_startPluginManager;
00284 //    }
00285 //    lcmaps_log_debug(5,"lcmaps.mod-startPluginManager(): cleaned lcmaps_db list: %p\n",lcmaps_db_handle);
00286 #else
00287     if (lcmaps_db_clean())
00288     {
00289         lcmaps_log(0,"lcmaps.mod-startPluginManager() error: could not clean up plugin db structure\n");
00290         goto fail_startPluginManager;
00291     }
00292     lcmaps_log_debug(5,"lcmaps.mod-startPluginManager(): cleaned lcmaps_db list: %p\n",lcmaps_db_handle);
00293 #endif
00294 
00295     /* success */
00296     if (lcmaps_db_file) free(lcmaps_db_file);
00297     return 0;
00298 
00299  fail_startPluginManager:
00300     /* failure */
00301 #if USE_EVALUATIONMANAGER
00302     /*
00303      * Do not clean lcmaps_db_entry_t structure since it is managed by the evaluation manager
00304      * and will be taken care of in stopEvaluationManager
00305      */
00306 /*    lcmaps_db_clean_list(&lcmaps_db_handle); */
00307 #else
00308     lcmaps_db_clean();
00309 #endif
00310     if (clean_plugin_list(&plugin_list)!=0)
00311     {
00312         lcmaps_log(0,"lcmaps.mod-startPluginManager() error: could not clean up plugin list\n");
00313     }
00314     if (lcmaps_db_file) free(lcmaps_db_file);
00315 
00316     return 1;
00317 }
00318 
00319 
00320 /******************************************************************************
00321 Function:   PluginInit
00322 Description:
00323     Initialize the plugin
00324     - Create entry in (plugin)list
00325     - Open plugins and check the symbols plugin_init and confirm_authorization
00326     - run plugin_init
00327 
00328 Parameters:
00329     db_handle: handle to LCMAPS db (containing pluginname and pluginargs)
00330     list:      pointer to list to which (plugin) module has to be added
00331 Returns:
00332     pointer to plugin structure
00333     NULL: could not initialize plugin
00334 ******************************************************************************/
00353 static lcmaps_plugindl_t * PluginInit(
00354         lcmaps_db_entry_t * db_handle,
00355         lcmaps_plugindl_t ** list
00356 )
00357 {
00358     char *                 name;
00359     char *                 pname=NULL;
00360     char *                 args=NULL;
00361     void *                 plugin_handle;
00362     lcmaps_proc_t          plugin_procs[MAXPROCS];
00363     lcmaps_plugindl_t *    pplugin=NULL;
00364     int                    i;
00365     int                    retval;
00366 
00367     name = db_handle->pluginname;
00368     args = db_handle->pluginargs;
00369 
00370     /* Find plugin module */
00371     pname = lcmaps_findfile(name);
00372     if (pname == NULL)
00373     {
00374         lcmaps_log(0,
00375             "lcmaps.mod-PluginInit(): plugin %s not found (arguments: %s)\n",
00376             name, args
00377         );
00378         goto fail_PluginInit;
00379     }
00380 
00381 
00382     /* Try a dlopen() */
00383     plugin_handle=dlopen(pname,RTLD_NOW);
00384     if (!plugin_handle)
00385     {
00386         lcmaps_log(0,"lcmaps.mod-PluginInit(): dlopen error for %s:\n    %s\n",
00387             pname,dlerror()
00388         );
00389         goto fail_PluginInit;
00390     }
00391 
00392     /* Check symbols */
00393     for (i=0; i < MAXPROCS; ++i)
00394     {
00395         switch (i)
00396         {
00397             case INITPROC:
00398                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_initialize");
00399                 if (plugin_procs[i] == NULL)
00400                 {
00401                     lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00402                         name);
00403                     lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_initialize()\"\n");
00404                     goto fail_PluginInit;
00405                 }
00406                 else
00407                 {
00408                     lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_initialize()\"\n");
00409                 }
00410                 break;
00411             case RUNPROC:
00412                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_run");
00413                 if (plugin_procs[i] == NULL)
00414                 {
00415                     lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00416                         name);
00417                     lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_run()\"\n");
00418                     goto fail_PluginInit;
00419                 }
00420                 else
00421                 {
00422                     lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_run()\"\n");
00423                 }
00424                 break;
00425             case TERMPROC:
00426                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_terminate");
00427                 if (plugin_procs[i] == NULL)
00428                 {
00429                     lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00430                         name);
00431                     lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_terminate()\"\n");
00432                     goto fail_PluginInit;
00433                 }
00434                 else
00435                 {
00436                     lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_terminate()\"\n");
00437                 }
00438                 break;
00439             case INTROPROC:
00440                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_introspect");
00441                 if (plugin_procs[i] == NULL)
00442                 {
00443                     lcmaps_log(0,"lcmaps.mod-PluginInit(): plugin %s not compliant\n",
00444                         name);
00445                     lcmaps_log(0,"lcmaps.mod-PluginInit(): missing function \"plugin_introspect()\"\n");
00446                     goto fail_PluginInit;
00447                 }
00448                 else
00449                 {
00450                     lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): found \"plugin_introspect()\"\n");
00451                 }
00452                 break;
00453             default:
00454                 /* do nothing */
00455                 plugin_procs[i]=NULL;
00456                 break;
00457         }
00458     }
00459     /* Make a new entry at end of plugin list */
00460     if (!*list)
00461     {
00462         lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): creating first pluginlist entry\n");
00463         *list=pplugin=(lcmaps_plugindl_t *)malloc(sizeof(lcmaps_plugindl_t));
00464     }
00465     else
00466     {
00467         lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): creating new pluginlist entry\n");
00468         pplugin=*list;
00469         while (pplugin->next) pplugin=pplugin->next;
00470         pplugin=pplugin->next=(lcmaps_plugindl_t *)malloc(sizeof(lcmaps_plugindl_t));
00471     }
00472     if (!pplugin)
00473     {
00474         lcmaps_log(0,"lcmaps.mod-PluginInit(): error creating new pluginlist entry\n");
00475         goto fail_PluginInit;
00476     }
00477     /* Set plugin list elements */
00478     pplugin->next=NULL;
00479     pplugin->handle=plugin_handle;
00480     pplugin->run_argc=0;
00481     pplugin->run_argv=NULL;
00482     for (i=0; i < MAXPROCS; ++i)
00483         pplugin->procs[i]=plugin_procs[i];
00484     if (pname != NULL)
00485     {
00486         strncpy(pplugin->pluginname,pname,LCMAPS_MAXPATHLEN);
00487         (pplugin->pluginname)[LCMAPS_MAXPATHLEN]=NUL;
00488     }
00489     else
00490         strncpy(pplugin->pluginname,"",LCMAPS_MAXPATHLEN);
00491 
00492     if (args != NULL)
00493     {
00494         strncpy(pplugin->pluginargs,args,LCMAPS_MAXARGSTRING);
00495         (pplugin->pluginargs)[LCMAPS_MAXARGSTRING]=NUL;
00496     }
00497     else
00498         strncpy(pplugin->pluginargs,"",LCMAPS_MAXARGSTRING);
00499 
00500     /* Parse options */
00501     if (parse_args_plugin(pname,args,pplugin->init_argv,&(pplugin->init_argc)) )
00502     {
00503         lcmaps_log(0,"lcmaps.mod-PluginInit(): Could not parse arguments for plugin module %s\n",
00504         pname);
00505         goto fail_PluginInit;
00506     }
00507     for (i=0; i < pplugin->init_argc; ++i)
00508         lcmaps_log_debug(4,"%s arg %d = %s\n",pname,i,(pplugin->init_argv)[i]);
00509 
00510 
00511     /* Run plugin_initialize() */
00512     retval=(*(pplugin->procs[INITPROC]))(pplugin->init_argc,pplugin->init_argv);
00513     if (retval != LCMAPS_MOD_SUCCESS )
00514     {
00515         lcmaps_log(0,"lcmaps.mod-PluginInit(): \"plugin_initialize()\" failed\n");
00516         goto fail_PluginInit;
00517     }
00518     else
00519     {
00520         lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): \"plugin_initialize()\" succeeded\n");
00521     }
00522 
00523     /* Run plugin_introspect() */
00524     retval=(*(pplugin->procs[INTROPROC]))(&(pplugin->run_argc),&(pplugin->run_argv));
00525     if (retval != LCMAPS_MOD_SUCCESS )
00526     {
00527         lcmaps_log(0,"lcmaps.mod-PluginInit(): \"plugin_introspect()\" failed\n");
00528         goto fail_PluginInit;
00529     }
00530     else
00531     {
00532         lcmaps_log_debug(2,"lcmaps.mod-PluginInit(): \"plugin_introspect()\" succeeded\n");
00533     }
00534 
00535     /* free stuff */
00536     if (pname) { free(pname); pname=NULL; }
00537 
00538     return pplugin;
00539 
00540  fail_PluginInit:
00541     if (pname) { free(pname); pname=NULL; }
00542     return NULL;
00543 }
00544 
00545 /******************************************************************************
00546 Function:   parse_args_plugin()
00547 Description:
00548     Parse the argument string of the plugin and create xargv and xargc
00549 
00550 Parameters:
00551     name: name of the plugin (goes into argv[0])
00552     argstring: string containing the arguments
00553     xargv: array of argument strings (has to be freed later)
00554     xargc: number of arguments
00555 Returns:
00556     0 on succes
00557     1 on failure
00558 ******************************************************************************/
00577 static int parse_args_plugin(
00578         const char * name,
00579         const char * argstring,
00580         char ** xargv,
00581         int * xargc
00582 )
00583 {
00584     int len=0;
00585     int i;
00586     int rc;
00587 
00588     /* set modulename */
00589     len=strlen(name);
00590     if ( (len > 0) && (len < LCMAPS_MAXPATHLEN) )
00591     {
00592         xargv[0]=(char *)malloc(len+1);
00593         if (xargv[0] != NULL)
00594             strncpy(xargv[0],name,len+1);
00595         else
00596             return 1;
00597     }
00598 
00599     *xargc=LCMAPS_MAXARGS-1;
00600     if ( ( rc = lcmaps_tokenize(argstring, &xargv[1], xargc, " \t\n") ) )
00601     {
00602         lcmaps_log(0,"lcmaps.mod-parse_args_plugin(): something wrong parsing arguments of %s, rc=%d\n",
00603                  name, rc);
00604         (*xargc)++;
00605         return 1;
00606     }
00607     (*xargc)++; /* increase by one for xargv[0] */
00608     lcmaps_log_debug(3,"lcmaps.mod-parse_args_plugin(): Found %d arguments:\n", *xargc);
00609     for (i=0; i < *xargc; i++)
00610         lcmaps_log_debug(3,"lcmaps.mod-parse_args_plugin(): %d --> %s\n", i, xargv[i]);
00611 
00612     return 0;
00613 }
00614 
00615 /******************************************************************************
00616 Function:   get_procsymbol
00617 Description:
00618     get procedure symbol from dlopen-ed library
00619 
00620 Parameters:
00621     handle:  handle of dynamic library
00622     symname: name of procedure symbol
00623 Returns:
00624     handle to procedure symbol
00625     NULL: Could not get symbol
00626 ******************************************************************************/
00638 static lcmaps_proc_t get_procsymbol(
00639         void * handle,
00640         char * symname
00641 )
00642 {
00643     lcmaps_proc_t symhandle;
00644     char *error;
00645 
00646     symhandle=dlsym(handle,symname);
00647     if ((error = dlerror()) != NULL)
00648     {
00649         lcmaps_log(0,"lcmaps.mod-get_procsymbol(): dlsym error: %s",error);
00650         return NULL;
00651     }
00652     return symhandle;
00653 }
00654 
00655 /******************************************************************************
00656 Function:   print_lcmaps_plugin
00657 Description:
00658     print the lcmaps_plugindl_t structure
00659 
00660 Parameters:
00661     debug_lvl: debugging level
00662     plugin:    plugin structure
00663 Returns:
00664     1: succes
00665     0: failure
00666 ******************************************************************************/
00679 static int print_lcmaps_plugin(
00680         int debug_lvl,
00681         lcmaps_plugindl_t * plugin
00682 )
00683 {
00684     int i=0;
00685 
00686     lcmaps_log_debug(debug_lvl,"\tplugin name                         : %s\n",plugin->pluginname);
00687     lcmaps_log_debug(debug_lvl,"\tplugin arguments                    : %s\n",plugin->pluginargs);
00688     lcmaps_log_debug(debug_lvl,"\tplugin address                      : x%x\n",plugin);
00689     lcmaps_log_debug(debug_lvl,"\tplugin size                         : %d\n",sizeof(lcmaps_plugindl_t));
00690     lcmaps_log_debug(debug_lvl,"\tplugin handle                       : x%x\n",plugin->handle);
00691     lcmaps_log_debug(debug_lvl,"\tplugin_initialize()                 : x%x\n",plugin->procs[INITPROC]);
00692     lcmaps_log_debug(debug_lvl,"\tplugin_run()                        : x%x\n",plugin->procs[RUNPROC]);
00693     lcmaps_log_debug(debug_lvl,"\tplugin_terminate()                  : x%x\n",plugin->procs[TERMPROC]);
00694     lcmaps_log_debug(debug_lvl,"\tplugin_introspect()                 : x%x\n",plugin->procs[INTROPROC]);
00695     lcmaps_log_debug(debug_lvl,"\tplugin init_argc                    : %d\n",plugin->init_argc);
00696     for (i=0; i < plugin->init_argc; i++)
00697         lcmaps_log_debug(debug_lvl,"\tplugin init_argv[%2d]                : %s\n",i,(plugin->init_argv)[i]);
00698     lcmaps_log_debug(debug_lvl,"\tplugin run_argc                     : %d\n",plugin->run_argc);
00699     for (i=0; i < plugin->run_argc; i++)
00700     {
00701         char * argType=NULL;
00702 
00703         argType=((plugin->run_argv)[i]).argType;
00704         lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d]                 : x%x\n",i,(plugin->run_argv)+i);
00705         lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], argName        : %s\n",i,((plugin->run_argv)[i]).argName);
00706         lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], argType        : %s\n",i,((plugin->run_argv)[i]).argType);
00707         lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], argInOut       : %d\n",i,((plugin->run_argv)[i]).argInOut);
00708         lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], value address  : x%x\n",i,((plugin->run_argv)[i]).value);
00709         if (strcmp("char *",argType) == 0)
00710         {
00711             char ** pstring;
00712             if ( ((plugin->run_argv)[i]).value != NULL)
00713             {
00714                 pstring = (char **) (((plugin->run_argv)[i]).value);
00715                 pstring = (char **) lcmaps_getArgValue(
00716                         ((plugin->run_argv)[i]).argName,
00717                         ((plugin->run_argv)[i]).argType,
00718                         plugin->run_argc,
00719                         plugin->run_argv
00720                 );
00721                 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], char * value   : %s\n",i,*pstring);
00722             }
00723             else
00724             {
00725                 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], char * value   : none yet\n",i);
00726             }
00727         }
00728         if (strcmp("int",argType) == 0)
00729         {
00730             int * pint;
00731             if ( ((plugin->run_argv)[i]).value != NULL)
00732             {
00733                 pint = (int *) (((plugin->run_argv)[i]).value);
00734                 pint = (int *) lcmaps_getArgValue(
00735                         ((plugin->run_argv)[i]).argName,
00736                         ((plugin->run_argv)[i]).argType,
00737                         plugin->run_argc,
00738                         plugin->run_argv
00739                 );
00740                 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], int value      : %d\n",i,*pint);
00741             }
00742             else
00743             {
00744                 lcmaps_log_debug(debug_lvl,"\tplugin run_argv[%2d], int value      : none yet\n",i);
00745             }
00746         }
00747     }
00748     lcmaps_log_debug(debug_lvl,"\tplugin next                         : x%x\n",plugin->next);
00749     if (plugin->next != NULL)
00750         lcmaps_log_debug(debug_lvl,"\tplugin_next                         : %s\n",(plugin->next)->pluginname);
00751     else
00752         lcmaps_log_debug(debug_lvl,"\tplugin_next                         : last plugin in list\n");
00753 
00754     return 1;
00755 }
00756 
00757 /******************************************************************************
00758 Function:   clean_plugin_list
00759 Description:
00760     clean (free) the list of plugins and call the plugin termination functions
00761 
00762 Parameters:
00763     list:      pointer to list of plugins which has to be freeed.
00764 
00765 Returns:
00766     1: succes
00767     0: failure
00768 ******************************************************************************/
00780 static int clean_plugin_list(
00781         lcmaps_plugindl_t ** list
00782 )
00783 {
00784     int                           rc;
00785     lcmaps_plugindl_t *             plugin_entry=NULL;
00786 
00787     plugin_entry=*list;
00788     while (plugin_entry)
00789     {
00790         lcmaps_plugindl_t * plugin_next;
00791         int               i;
00792 
00793         rc = plugin_entry->procs[TERMPROC]();
00794         if (rc != LCMAPS_MOD_SUCCESS)
00795         {
00796             lcmaps_log(0,"lcmaps.mod-clean_plugin_list(): failed to terminate plugin module %s\n",
00797                     plugin_entry->pluginname);
00798         }
00799         lcmaps_log_debug(1, "lcmaps.mod-clean_plugin_list(): plugin module %s terminated\n",
00800                 plugin_entry->pluginname);
00801         dlclose(plugin_entry->handle);
00802 
00803         plugin_next=plugin_entry->next;
00804         for (i=0; i < plugin_entry->init_argc; i++)
00805         {
00806             if ((plugin_entry->init_argv)[i] != NULL)
00807             {
00808                 lcmaps_log_debug(3,"Freeing %d - %s\n",i,(plugin_entry->init_argv)[i]);
00809                 free((plugin_entry->init_argv)[i]);
00810             }
00811         }
00812         free(plugin_entry);
00813         plugin_entry=plugin_next;
00814     }
00815     *list=plugin_entry=NULL;
00816     return 0;
00817 }
00818 
00819 /******************************************************************************
00820 Function:   runPluginManager
00821 Description:
00822     Run PluginManager:
00823     Contact Evaluation Manager --> runs plugins
00824 
00825 Parameters:
00826     request:   RSL request
00827     lcmaps_cred: user credential
00828 Returns:
00829     0: user mapping succeeded
00830     1: user mapping failed
00831 ******************************************************************************/
00848 int runPluginManager(
00849         lcmaps_request_t request,
00850         lcmaps_cred_id_t lcmaps_cred
00851 )
00852 {
00853     lcmaps_plugindl_t * plugin_entry=NULL;
00854 
00855     /* To be done:
00856      * Take the run_argv array (of lcmaps_argument_t) and make a match on name and on type with the
00857      * lcmaps_variable[] list (created from request and lcmaps_cred)
00858      * make an array of void pointers to arguments --> fill in the lcmaps_plugindl_t structure
00859      */
00860     lcmaps_log_debug(2,"lcmaps.mod-runPluginManager(): extract RunVars\n");
00861     if (lcmaps_extractRunVars(request, lcmaps_cred) != 0)
00862     {
00863         lcmaps_log(0,"lcmaps.mod-runPluginManager(): error in creating list of run variables\n");
00864         return 1;
00865     }
00866 
00867     plugin_entry=plugin_list;
00868     while (plugin_entry)
00869     {
00870         void * pvalue=NULL;
00871         char * argName=NULL;
00872         char * argType=NULL;
00873         int iarg=0;
00874 
00875         for (iarg=0; iarg < plugin_entry->run_argc; iarg++)
00876         {
00877             argName=(plugin_entry->run_argv+iarg)->argName;
00878             argType=(plugin_entry->run_argv+iarg)->argType;
00879             lcmaps_log_debug(2,
00880                 "lcmaps.mod-runPluginManager(): Getting value of \"%s\" of type \"%s\" for plugin \"%s\"\n",
00881                 argName, argType, plugin_entry->pluginname);
00882             if ((pvalue=lcmaps_getRunVars(argName, argType)) == NULL)
00883             {
00884                 lcmaps_log(0,
00885                     "lcmaps.mod-runPluginManager(): could not GET requested variable \"%s\" of type \"%s\" for plugin \"%s\"\n",
00886                     argName, argType, plugin_entry->pluginname);
00887                 return 1;
00888             }
00889             lcmaps_log_debug(2,
00890                 "lcmaps.mod-runPluginManager(): Setting value of \"%s\" of type \"%s\" for plugin \"%s\", address: 0x%x\n",
00891                 argName, argType, plugin_entry->pluginname, pvalue);
00892             if (lcmaps_setArgValue(argName, argType, pvalue, plugin_entry->run_argc, &(plugin_entry->run_argv)) != 0)
00893             {
00894                 lcmaps_log(0,
00895                     "lcmaps.mod-runPluginManager(): could not SET requested variable \"%s\" of type \"%s\" for plugin \"%s\"\n",
00896                     argName, argType, plugin_entry->pluginname);
00897                 return 1;
00898             }
00899         }
00900         plugin_entry=plugin_entry->next;
00901     }
00902 
00903 #if USE_EVALUATIONMANAGER
00904     /* To be done:
00905      * Run evaluation manager
00906      */
00907     lcmaps_log_debug(1,"lcmaps.mod-runPluginManager(): Do runEvaluationManager()\n");
00908     if (runEvaluationManager() != 0)
00909     {
00910         lcmaps_log(0,"lcmaps.mod-runPluginManager(): Error running evaluation manager\n");
00911         return 1;
00912     }
00913     lcmaps_log_debug(1,"lcmaps.mod-runPluginManager(): runEvaluationManager() succeeded.\n");
00914 #else
00915     /* The following will be taken over by the evaluation manager
00916      * It will call runPluginManager() directly and evaluate its return values
00917      */
00918     plugin_entry=plugin_list;
00919     while (plugin_entry)
00920     {
00921         print_lcmaps_plugin(2,plugin_entry);
00922         lcmaps_log_debug(2,"\n");
00923         lcmaps_log(0,"lcmaps.mod-runPluginManager(): running %s\n",plugin_entry->pluginname);
00924         if (runPlugin(plugin_entry->pluginname)) {
00925             lcmaps_log(0,"lcmaps.mod-runPluginManager(): plugin %s failed\n",plugin_entry->pluginname);
00926         }
00927         plugin_entry=plugin_entry->next;
00928     }
00929 #endif
00930     return 0;
00931 }
00932 
00933 /******************************************************************************
00934 Function:   runPlugin
00935 Description:
00936     Run a plugin for the Evaluation Manager
00937     the result (succes or not will be passed to the Evaluation Manager)
00938 
00939 Parameters:
00940     pluginname: the name of the plugin module
00941 Returns:
00942     0: plugin run succeeded
00943     1: plugin run failed
00944 ******************************************************************************/
00959 int runPlugin(
00960         const char * pluginname
00961 )
00962 {
00963     lcmaps_plugindl_t * plugin_entry=NULL;
00964     int rc=1;
00965     int foundplugin=0;
00966 
00967     /* To be done:
00968      * Search for the right plugin in lcmaps_plugindl_t structure
00969      * Run this plugin
00970      */
00971 
00972     plugin_entry=plugin_list;
00973     while (plugin_entry)
00974     {
00975         lcmaps_log_debug(3,"lcmaps.mod-runPlugin(): looking for plugin %s\n",pluginname);
00976         if (strcmp(plugin_entry->pluginname,pluginname) == 0) {
00977             lcmaps_log_time(0,"lcmaps.mod-runPlugin(): found plugin %s\n",plugin_entry->pluginname);
00978             foundplugin++;
00979             break;
00980         }
00981         plugin_entry=plugin_entry->next;
00982     }
00983     if (!foundplugin) {
00984         lcmaps_log(0,"lcmaps.mod-runPlugin(): could not find plugin %s\n",pluginname);
00985         return 1;
00986     }
00987 
00988     /* Actually run the plugin */
00989     lcmaps_log_time(0,"lcmaps.mod-runPlugin(): running plugin %s\n",plugin_entry->pluginname);
00990     rc = plugin_entry->procs[RUNPROC](plugin_entry->run_argc, plugin_entry->run_argv);
00991 
00992     return rc;
00993 }
00994 
00995 /******************************************************************************
00996 Function:   stopPluginManager
00997 Description:
00998     Terminate PluginManager module.
00999 
01000 Parameters:
01001 Returns:
01002     0: termination succeeded
01003     1: termination failed
01004 ******************************************************************************/
01015 int stopPluginManager(
01016 )
01017 {
01018     lcmaps_log_debug(1,"lcmaps.mod-stopPluginManager(): cleaning credential data\n");
01019     printCredData();
01020     if (cleanCredentialData()!=0)
01021     {
01022         lcmaps_log(0,"lcmaps.mod-stopPluginManager() error: could not clean credential data list\n");
01023         return 1;
01024     }
01025     if (clean_plugin_list(&plugin_list)!=0)
01026     {
01027         lcmaps_log(0,"lcmaps.mod-stopPluginManager() error: could not clean up plugin list\n");
01028         return 1;
01029     }
01030 #if USE_EVALUATIONMANAGER
01031     if (stopEvaluationManager() != 0)
01032     {
01033         lcmaps_log(0,"lcmaps.mod-stopPluginManager(): error in stopEvaluationManager()\n");
01034         return 1;
01035     }
01036 #endif
01037     return 0;
01038 }

Generated at Tue Sep 23 15:48:08 2003 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001