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

Generated at Thu Mar 4 17:39:03 2004 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001