00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00056 
00057 
00058 
00059 #include "lcas_config.h"
00060 #include <stdio.h>
00061 #include <stdlib.h>
00062 #include <string.h>
00063 
00064 #if HAVE_MALLOC_H
00065 #    include <malloc.h>
00066 #endif
00067 
00068 
00069 #if HAVE_DLFCN_H
00070 #    include <dlfcn.h>
00071 #endif
00072 
00073 #include <gssapi.h>
00074 
00075 
00076 #include "lcas_types.h"
00077 #include "_lcas_utils.h"
00078 #include "_lcas_defines.h"
00079 #include "_lcas_log.h"
00080 #include "_lcas_db_read.h"
00081 
00082 
00083 
00084 
00085 
00086 
00087 #ifndef NUL
00088 #define NUL '\0' 
00089 #endif
00090 
00091 
00092 #define MAXAUTHMODS 3 
00093 #define MAXPROCS    3 
00095 
00096 
00097 
00098 #define FAILED_LCAS_USERALLOW   1 
00100 #define FAILED_LCAS_USERBAN     2 
00102 #define FAILED_LCAS_CLOCKCHECK  3 
00104 #define FAILED_LCAS_OTHER       4 
00105 #define FAILED_LCAS_PLUGIN      5 
00108 #ifndef APIMAJORVERSION
00109 #    define APIMAJORVERSION -1
00110 #endif
00111 #ifndef APIMINORVERSION
00112 #    define APIMINORVERSION -1
00113 #endif
00114 #ifndef APIPATCHVERSION
00115 #    define APIPATCHVERSION -1
00116 #endif
00117 
00118 
00119 
00120 
00126 enum lcas_proctype_e
00127 {
00128     INITPROC, 
00129     AUTHPROC, 
00130     TERMPROC, 
00131     ENDOFPROCS 
00132 };
00133 
00139 typedef int (*lcas_proc_t)();
00140 
00151 typedef struct lcas_plugindl_s
00152 {
00153     void *                    handle; 
00154     lcas_proc_t               procs[MAXPROCS]; 
00155     char                      pluginname[LCAS_MAXPATHLEN+1]; 
00156     char                      pluginargs[LCAS_MAXARGSTRING+1]; 
00157     int                       argc; 
00158     char *                    argv[LCAS_MAXARGS]; 
00159     struct lcas_plugindl_s *  next; 
00160 }
00161 lcas_plugindl_t;
00162 
00163 
00164 
00165 
00166 static lcas_plugindl_t * PluginInit(lcas_db_entry_t *, lcas_plugindl_t **);
00167 static lcas_proc_t       get_procsymbol(void *, char *);
00168 static int               print_lcas_plugin(int, lcas_plugindl_t *);
00169 static int               parse_args_plugin(const char *, const char *, char **, int *);
00170 static int               clean_plugin_list(lcas_plugindl_t **);
00171 
00172 
00173 
00174 
00175 static lcas_cred_id_t    lcas_cred; 
00176 static int               lcas_initialized = 0; 
00177 static char *            lcas_db_file_default = NULL; 
00178 static char *            lcas_dir         = NULL; 
00179 static lcas_plugindl_t * plugin_list      = NULL; 
00180 static lcas_plugindl_t * authmod_list     = NULL; 
00181 static char *            authmods[MAXAUTHMODS][2] = {
00182                              {(char *) NULL, (char *) NULL},
00183                              {(char *) NULL, (char *) NULL},
00184                              {(char *) NULL, (char *) NULL}
00185 }; 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 int getMajorVersionNumber() { return (int)(APIMAJORVERSION); }
00196 int getMinorVersionNumber() { return (int)(APIMINORVERSION); }
00197 int getPatchVersionNumber() { return (int)(APIPATCHVERSION); }
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 int lcas_init_and_logfile(
00223         char * logfile,
00224         FILE* fp,
00225         unsigned short logtype
00226 )
00227 {
00228     lcas_db_entry_t **  lcas_db_handle=NULL;
00229     lcas_db_entry_t **  lcas_mod_handle=NULL;
00230     lcas_db_entry_t *   lcas_mod_db=NULL;
00231     lcas_db_entry_t     lcas_mod_entry;
00232     lcas_db_entry_t *   ihandle=NULL;
00233     lcas_plugindl_t *   plugin_entry=NULL;
00234     lcas_plugindl_t *   authmod_entry=NULL;
00235     char *              lcas_db_file=NULL;
00236     int                 ientry;
00237     int                 i;
00238 
00239     if (lcas_initialized)
00240     {
00241         if (lcas_log(0,"LCAS already initialized\n") != 0)
00242         {
00243             fprintf(stderr,"LCAS already initialized, but wrongly\n");
00244             goto fail_lcas_init_and_logfile;
00245         }
00246         return 0;
00247     }
00248 
00249     
00250     if (lcas_log_open(logfile,fp,logtype))
00251         goto fail_lcas_init_and_logfile;
00252     lcas_log_debug(0,"\n");
00253     lcas_log_time(LOG_DEBUG,"Initialization LCAS version %s\n",VERSION);
00254 
00255     
00256     lcas_dir = getenv("LCAS_DIR");
00257     lcas_dir = (lcas_dir ? lcas_dir : getenv("LCAS_ETC_DIR") );
00258     lcas_dir = (lcas_dir ? lcas_dir : LCAS_ETC_HOME );
00259 
00260     lcas_db_file_default = getenv("LCAS_DB_FILE");
00261     lcas_db_file_default = (lcas_db_file_default ? lcas_db_file_default : "lcas.db" );
00262 
00263     lcas_db_file=lcas_genfilename(lcas_dir, lcas_db_file_default, NULL);
00264 
00265     
00266 
00267 
00268 
00269 
00270     
00271     lcas_mod_entry.next=NULL;
00272     lcas_mod_handle=&lcas_mod_db;
00273     for (i=0; i < MAXAUTHMODS; ++i)
00274     {
00275         if (authmods[i][0] == NULL) break; 
00276         *(lcas_mod_entry.pluginname)=NUL;
00277         *(lcas_mod_entry.pluginargs)=NUL;
00278         if (authmods[i][0] != NULL)
00279         {
00280             strncpy(lcas_mod_entry.pluginname,authmods[i][0],LCAS_MAXPATHLEN);
00281             (lcas_mod_entry.pluginname)[LCAS_MAXPATHLEN]=NUL;
00282         }
00283         if (authmods[i][1] != NULL)
00284         {
00285             strncpy(lcas_mod_entry.pluginargs,authmods[i][1],LCAS_MAXARGSTRING);
00286             (lcas_mod_entry.pluginargs)[LCAS_MAXARGSTRING]=NUL;
00287         }
00288         lcas_log_debug(1,"lcas.mod-lcas_init(): creating db structure for authorization module %s\n",
00289                  authmods[i][0]);
00290         if (lcas_db_fill_entry(lcas_mod_handle, &lcas_mod_entry) == NULL)
00291         {
00292             lcas_log(0,"lcas.mod-lcas_init() error: Cannot create standard authorization module (%d-%s) db structure\n",
00293                     i,authmods[i][0]);
00294             goto fail_lcas_init_and_logfile;
00295         }
00296     }
00297 
00298     
00299 
00300 
00301 
00302 
00303     ientry=0;
00304     ihandle=*lcas_mod_handle;
00305     while (ihandle)
00306     {
00307         if (strlen(ihandle->pluginname) > 0)
00308         {
00309             lcas_log_debug(1,"lcas.mod-lcas_init(): initializing standard module %s (db entry %d)\n",
00310                      ihandle->pluginname, ientry);
00311             if ((authmod_entry=PluginInit(ihandle,&authmod_list)) == NULL)
00312             {
00313                 lcas_log(0,"lcas.mod-lcas_init(): error initializing standard module : %s\n",
00314                          ihandle->pluginname);
00315                 goto fail_lcas_init_and_logfile;
00316             }
00317         }
00318         ientry++;
00319         ihandle=ihandle->next;
00320     }
00321 
00322     
00323 
00324 
00325 
00326     lcas_log_debug(0,"lcas.mod-lcas_init(): Reading LCAS database %s\n",
00327             lcas_db_file);
00328     lcas_db_handle=lcas_db_read(lcas_db_file);
00329     if (lcas_db_handle == NULL)
00330     {
00331         lcas_log(0,"lcas.mod-lcas_init(): Failed to read LCAS database %s\n",
00332                  lcas_db_file);
00333         goto fail_lcas_init_and_logfile;
00334     }
00335     
00336 
00337 
00338 
00339 
00340     ientry=0;
00341     ihandle=*lcas_db_handle;
00342     while (ihandle)
00343     {
00344         if (strlen(ihandle->pluginname) > 0)
00345         {
00346             lcas_log_debug(1,"lcas.mod-lcas_init(): initializing plugin %s (db entry %d)\n",
00347                      ihandle->pluginname, ientry);
00348             if ((plugin_entry=PluginInit(ihandle,&plugin_list)) == NULL)
00349             {
00350                 lcas_log(0,"lcas.mod-lcas_init(): error initializing plugin: %s\n",ihandle->pluginname);
00351                 goto fail_lcas_init_and_logfile;
00352             }
00353             
00354 
00355 
00356 
00357             authmod_entry=authmod_list;
00358             while (authmod_entry)
00359             {
00360                 if ( (strncmp(authmod_entry->pluginname,
00361                               plugin_entry->pluginname,
00362                               LCAS_MAXPATHLEN) == 0)
00363                    )
00364                 {
00365                     lcas_log(0,"lcas.mod-lcas_init() error: plugin %s already registered as\n",
00366                              plugin_entry->pluginname);
00367                     lcas_log(0,"    standard authorization module\n");
00368                     goto fail_lcas_init_and_logfile;
00369                 }
00370                 authmod_entry=authmod_entry->next;
00371             }
00372             
00373         }
00374         ientry++;
00375         ihandle=ihandle->next;
00376     }
00377 
00378     authmod_entry=authmod_list;
00379     while (authmod_entry)
00380     {
00381         print_lcas_plugin(2,authmod_entry);
00382         lcas_log_debug(2,"\n");
00383         authmod_entry=authmod_entry->next;
00384     }
00385 
00386     plugin_entry=plugin_list;
00387     while (plugin_entry)
00388     {
00389         print_lcas_plugin(2,plugin_entry);
00390         lcas_log_debug(2,"\n");
00391         plugin_entry=plugin_entry->next;
00392     }
00393 
00394     
00395     if(lcas_db_clean_list(&lcas_mod_db))
00396     {
00397         lcas_log(0,"lcas.mod-lcas_init() error: could not clean up authmod db structure\n");
00398         goto fail_lcas_init_and_logfile;
00399     }
00400     
00401     if (lcas_db_clean())
00402     {
00403         lcas_log(0,"lcas.mod-lcas_init() error: could not clean up plugin db structure\n");
00404         goto fail_lcas_init_and_logfile;
00405     }
00406 
00407     
00408     if (lcas_db_file) free(lcas_db_file);
00409     lcas_initialized++;
00410     return 0;
00411 
00412  fail_lcas_init_and_logfile:
00413     
00414     lcas_db_clean_list(&lcas_mod_db);
00415     lcas_db_clean();
00416     if (clean_plugin_list(&plugin_list)!=0)
00417     {
00418         lcas_log(0,"lmas.mod-lcas_init() error: could not clean up plugin list\n");
00419     }
00420     if (lcas_db_file) free(lcas_db_file);
00421 
00422     return 1;
00423 }
00424 
00425 
00426 
00427 
00428 
00429 
00430 
00431 
00432 
00433 
00434 
00435 
00436 
00437 
00438 
00439 
00440 
00441 
00442 
00443 int lcas_init_and_log(
00444         FILE* fp,
00445         unsigned short logtype
00446 )
00447 {
00448     return lcas_init_and_logfile(NULL, fp, logtype);
00449 }
00450 
00451 
00452 
00453 
00454 
00455 
00456 
00457 
00458 
00459 
00460 
00461 
00462 
00463 
00464 
00465 int lcas_init(
00466         FILE* fp
00467 )
00468 {
00469     
00470     
00471     if (fp)
00472     {
00473         return lcas_init_and_log(fp,DO_USRLOG);
00474     }
00475     else
00476     {
00477         return lcas_init_and_log(NULL,DO_SYSLOG);
00478     }
00479 }
00480 
00481 
00482 
00483 
00484 
00485 
00486 
00487 
00488 
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 
00515 static lcas_plugindl_t * PluginInit(
00516         lcas_db_entry_t * db_handle,
00517         lcas_plugindl_t ** list
00518 )
00519 {
00520     char *                 name;
00521 #if 0
00522     char *                 names[5]={NULL,NULL,NULL,NULL,NULL};
00523 #endif
00524     char *                 pname=NULL;
00525     char *                 args=NULL;
00526 #if 0
00527     char *                 db;
00528     char *                 dbs[5]={NULL,NULL,NULL,NULL,NULL};
00529     char *                 pdb=NULL;
00530 #endif
00531     void *                 plugin_handle;
00532     lcas_proc_t            plugin_procs[MAXPROCS];
00533     lcas_plugindl_t *      pplugin=NULL;
00534     int                    i;
00535     int                    retval;
00536 
00537     name = db_handle->pluginname;
00538 #if 0
00539     db = db_handle->pluginargs;
00540 #endif
00541     args = db_handle->pluginargs;
00542 
00543     
00544 #if 0
00545     names[0]=lcas_genfilename(NULL,name,NULL);
00546     names[1]=lcas_genfilename("modules",name,NULL);
00547     names[2]=lcas_genfilename(LCAS_MOD_HOME,name,NULL);
00548     names[3]=lcas_genfilename(LCAS_LIB_HOME,name,NULL);
00549     names[4]=lcas_genfilename(LCAS_ETC_HOME,name,NULL);
00550     pname=lcas_getfexist(5,names[0],
00551                       names[1],names[2],
00552                       names[3],names[4]
00553           );
00554 #endif
00555     pname = lcas_findfile(name);
00556     if (pname == NULL)
00557     {
00558         lcas_log(0,
00559             "lcas.mod-PluginInit(): plugin %s not found\n",
00560             name
00561         );
00562         goto fail_PluginInit;
00563     }
00564 
00565 #if 0
00566     
00567     if (strlen(db) > 0)
00568     {
00569         dbs[0]=lcas_genfilename(NULL,db,NULL);
00570         dbs[1]=lcas_genfilename("modules",db,NULL);
00571         dbs[2]=lcas_genfilename(LCAS_ETC_HOME,db,NULL);
00572         dbs[3]=lcas_genfilename(LCAS_MOD_HOME,db,NULL);
00573         dbs[4]=lcas_genfilename(LCAS_LIB_HOME,db,NULL);
00574         pdb=lcas_getfexist(5,dbs[0],
00575                         dbs[1],dbs[2],
00576                         dbs[3],dbs[4]
00577             );
00578     }
00579 #endif
00580 
00581     
00582     plugin_handle=dlopen(pname,RTLD_NOW);
00583 
00584     if (!plugin_handle)
00585     {
00586         lcas_log(0,"lcas.mod-PluginInit(): dlopen error for %s:\n    %s\n",
00587             pname,dlerror()
00588         );
00589         goto fail_PluginInit;
00590     }
00591 
00592     
00593     for (i=0; i < MAXPROCS; ++i)
00594     {
00595         switch (i)
00596         {
00597             case INITPROC:
00598                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_initialize");
00599                 if (plugin_procs[i] == NULL)
00600                 {
00601                     lcas_log(0,"lcas.mod-PluginInit(): plugin %s not compliant\n",
00602                         name);
00603                     lcas_log(0,"lcas.mod-PluginInit(): missing function \"plugin_initialize()\"\n");
00604                     goto fail_PluginInit;
00605                 }
00606                 else
00607                 {
00608                     lcas_log_debug(2,"lcas.mod-PluginInit(): found \"plugin_initialize()\"\n");
00609                 }
00610                 break;
00611             case AUTHPROC:
00612                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_confirm_authorization");
00613                 if (plugin_procs[i] == NULL)
00614                 {
00615                     lcas_log(0,"lcas.mod-PluginInit(): plugin %s not compliant\n",
00616                         name);
00617                     lcas_log(0,"lcas.mod-PluginInit(): missing function \"plugin_confirm_authorization()\"\n");
00618                     goto fail_PluginInit;
00619                 }
00620                 else
00621                 {
00622                     lcas_log_debug(2,"lcas.mod-PluginInit(): found \"plugin_confirm_authorization()\"\n");
00623                 }
00624                 break;
00625             case TERMPROC:
00626                 plugin_procs[i]=get_procsymbol(plugin_handle,"plugin_terminate");
00627                 if (plugin_procs[i] == NULL)
00628                 {
00629                     lcas_log(0,"lcas.mod-PluginInit(): plugin %s not compliant\n",
00630                         name);
00631                     lcas_log(0,"lcas.mod-PluginInit(): missing function \"plugin_terminate()\"\n");
00632                     goto fail_PluginInit;
00633                 }
00634                 else
00635                 {
00636                     lcas_log_debug(2,"lcas.mod-PluginInit(): found \"plugin_terminate()\"\n");
00637                 }
00638                 break;
00639             default:
00640                 
00641                 plugin_procs[i]=NULL;
00642                 break;
00643         }
00644     }
00645     
00646     if (!*list)
00647     {
00648         lcas_log_debug(2,"lcas.mod-PluginInit(): creating first pluginlist entry\n");
00649         *list=pplugin=(lcas_plugindl_t *)malloc(sizeof(lcas_plugindl_t));
00650     }
00651     else
00652     {
00653         lcas_log_debug(2,"lcas.mod-PluginInit(): creating new pluginlist entry\n");
00654         pplugin=*list;
00655         while (pplugin->next) pplugin=pplugin->next;
00656         pplugin=pplugin->next=(lcas_plugindl_t *)malloc(sizeof(lcas_plugindl_t));
00657     }
00658     if (!pplugin)
00659     {
00660         lcas_log(0,"lcas.mod-PluginInit(): error creating new pluginlist entry\n");
00661         goto fail_PluginInit;
00662     }
00663     
00664     pplugin->next=NULL;
00665     pplugin->handle=plugin_handle;
00666     for (i=0; i < MAXPROCS; ++i)
00667         pplugin->procs[i]=plugin_procs[i];
00668     if (pname != NULL)
00669     {
00670         strncpy(pplugin->pluginname,pname,LCAS_MAXPATHLEN);
00671         (pplugin->pluginname)[LCAS_MAXPATHLEN]=NUL;
00672     }
00673     else
00674         strncpy(pplugin->pluginname,"",LCAS_MAXPATHLEN);
00675 
00676     if (args != NULL)
00677     {
00678         strncpy(pplugin->pluginargs,args,LCAS_MAXARGSTRING);
00679         (pplugin->pluginargs)[LCAS_MAXARGSTRING]=NUL;
00680     }
00681     else
00682         strncpy(pplugin->pluginargs,"",LCAS_MAXARGSTRING);
00683 
00684     
00685     if (parse_args_plugin(pname,args,pplugin->argv,&(pplugin->argc)) )
00686     {
00687         lcas_log(0,"lcas.mod-PluginInit(): Could not parse arguments for plugin module %s\n",
00688         pname);
00689         goto fail_PluginInit;
00690     }
00691     for (i=0; i < pplugin->argc; ++i)
00692         lcas_log_debug(4,"%s arg %d = %s\n",pname,i,(pplugin->argv)[i]);
00693 
00694 
00695     
00696 #if 0
00697     retval=(*(pplugin->procs[INITPROC]))(pplugin->pluginargs);
00698 #endif
00699     retval=(*(pplugin->procs[INITPROC]))(pplugin->argc,pplugin->argv);
00700     if (retval != LCAS_MOD_SUCCESS )
00701     {
00702         lcas_log(0,"lcas.mod-PluginInit(): \"plugin_initialize()\" failed\n");
00703         goto fail_PluginInit;
00704     }
00705     else
00706     {
00707         lcas_log_debug(2,"lcas.mod-PluginInit(): \"plugin_initialize()\" succeeded\n");
00708     }
00709 
00710 
00711     
00712     if (pname) { free(pname); pname=NULL; }
00713 #if 0
00714     for (i=0; i < 5; ++i)
00715     {
00716         if (names[i]) free(names[i]);
00717         if (dbs[i]) free(dbs[i]);
00718     }
00719 #endif
00720 
00721     return pplugin;
00722 
00723  fail_PluginInit:
00724     if (pname) { free(pname); pname=NULL; }
00725 #if 0
00726     for (i=0; i < 5; ++i)
00727     {
00728         if (names[i]) free(names[i]);
00729         if (dbs[i]) free(dbs[i]);
00730     }
00731 #endif
00732     return NULL;
00733 }
00734 
00735 
00736 
00737 
00738 
00739 
00740 
00741 
00742 
00743 
00744 
00745 
00746 
00747 
00748 
00767 static int parse_args_plugin(
00768         const char * name,
00769         const char * argstring,
00770         char ** xargv,
00771         int * xargc
00772 )
00773 {
00774     int len=0;
00775     int i;
00776     int rc;
00777 
00778     
00779     len=strlen(name);
00780     if ( (len > 0) && (len < LCAS_MAXPATHLEN) )
00781     {
00782         xargv[0]=(char *)malloc(len+1);
00783         if (xargv[0] != NULL)
00784             strncpy(xargv[0],name,len+1);
00785         else
00786             return 1;
00787     }
00788 
00789     *xargc=LCAS_MAXARGS-1;
00790     if ( (rc=lcas_tokenize(argstring, &xargv[1], xargc, " \t\n")) )
00791     {
00792         lcas_log(0,"lcas.mod-parse_args_plugin(): something wrong parsing arguments of %s, rc=%d\n",
00793                  name, rc);
00794         (*xargc)++;
00795         return 1;
00796     }
00797     (*xargc)++; 
00798     lcas_log_debug(3,"lcas.mod-parse_args_plugin(): Found %d arguments:\n", *xargc);
00799     for (i=0; i < *xargc; i++)
00800         lcas_log_debug(3,"lcas.mod-parse_args_plugin(): %d --> %s\n", i, xargv[i]);
00801 
00802     return 0;
00803 }
00804 
00805 
00806 
00807 
00808 
00809 
00810 
00811 
00812 
00813 
00814 
00815 
00816 
00828 static lcas_proc_t get_procsymbol(
00829         void * handle,
00830         char * symname
00831 )
00832 {
00833     lcas_proc_t symhandle;
00834     char *error;
00835 
00836     symhandle=dlsym(handle,symname);
00837     if ((error = dlerror()) != NULL)
00838     {
00839         lcas_log(0,"lcas.mod-get_procsymbol(): dlsym error: %s",error);
00840         return NULL;
00841     }
00842     return symhandle;
00843 }
00844 
00845 
00846 
00847 
00848 
00849 
00850 
00851 
00852 
00853 
00854 
00855 
00856 
00868 static int clean_plugin_list(
00869         lcas_plugindl_t ** list
00870 )
00871 {
00872     int                           rc;
00873     lcas_plugindl_t *             plugin_entry=NULL;
00874 
00875     plugin_entry=*list;
00876     while (plugin_entry)
00877     {
00878         lcas_plugindl_t * plugin_next;
00879         int               i;
00880 
00881         rc = plugin_entry->procs[TERMPROC]();
00882         if (rc != LCAS_MOD_SUCCESS)
00883         {
00884             lcas_log(0,"lcas.mod-clean_plugin_list(): failed to terminate plugin module %s\n",
00885                     plugin_entry->pluginname);
00886         }
00887         lcas_log_debug(1, "lcas.mod-clean_plugin_list(): plugin module %s terminated\n",
00888                 plugin_entry->pluginname);
00889         dlclose(plugin_entry->handle);
00890 
00891         plugin_next=plugin_entry->next;
00892         for (i=0; i < plugin_entry->argc; i++)
00893         {
00894             if ((plugin_entry->argv)[i] != NULL)
00895             {
00896                 lcas_log_debug(3,"Freeing %d - %s\n",i,(plugin_entry->argv)[i]);
00897                 free((plugin_entry->argv)[i]);
00898             }
00899         }
00900         free(plugin_entry);
00901         plugin_entry=plugin_next;
00902     }
00903     *list=plugin_entry=NULL;
00904     return 0;
00905 }
00906 
00907 
00908 
00909 
00910 
00911 
00912 
00913 
00914 
00915 
00916 
00917 
00918 
00931 static int print_lcas_plugin(
00932         int debug_lvl,
00933         lcas_plugindl_t * plugin
00934 )
00935 {
00936     int i=0;
00937 
00938     lcas_log_debug(debug_lvl,"\tplugin name                   : %s\n",plugin->pluginname);
00939     lcas_log_debug(debug_lvl,"\tplugin arguments              : %s\n",plugin->pluginargs);
00940     lcas_log_debug(debug_lvl,"\tplugin address                : %x\n",plugin);
00941     lcas_log_debug(debug_lvl,"\tplugin size                   : %d\n",sizeof(lcas_plugindl_t));
00942     lcas_log_debug(debug_lvl,"\tplugin handle                 : %x\n",plugin->handle);
00943     lcas_log_debug(debug_lvl,"\tplugin_initialize()           : %x\n",plugin->procs[INITPROC]);
00944     lcas_log_debug(debug_lvl,"\tplugin_confirm_authorization(): %x\n",plugin->procs[AUTHPROC]);
00945     lcas_log_debug(debug_lvl,"\tplugin_terminate()            : %x\n",plugin->procs[TERMPROC]);
00946     lcas_log_debug(debug_lvl,"\tplugin argc                   : %d\n",plugin->argc);
00947     for (i=0; i < plugin->argc; i++)
00948         lcas_log_debug(debug_lvl,"\tplugin argv[%2d]               : %s\n",i,(plugin->argv)[i]);
00949     lcas_log_debug(debug_lvl,"\tplugin next                   : %x\n",plugin->next);
00950     if (plugin->next != NULL)
00951         lcas_log_debug(debug_lvl,"\tplugin_next                   : %s\n",(plugin->next)->pluginname);
00952     else
00953         lcas_log_debug(debug_lvl,"\tplugin_next                   : last plugin in list\n");
00954 
00955     return 1;
00956 }
00957 
00958 
00959 
00960 
00961 
00962 
00963 
00964 
00965 
00966 
00967 
00968 
00969 
00970 #if ALLOW_EMPTY_CREDENTIALS
00971 int lcas_get_fabric_authorization(
00972         char * user_dn_tmp,
00973         gss_cred_id_t user_cred,
00974         lcas_request_t request
00975 )
00976 #else
00977 int lcas_get_fabric_authorization(
00978         gss_cred_id_t user_cred,
00979         lcas_request_t request
00980 )
00981 #endif
00982 {
00983     char *                        user_dn = NULL;
00984     int                           rc;
00985     int                           retval;
00986     int                           lcas_authorized=0;
00987 
00988     lcas_plugindl_t *             plugin_entry;
00989     lcas_plugindl_t *             authmod_entry;
00990 
00991 
00992     
00993     lcas_authorized=0;
00994 
00995     if (lcas_initialized == 0)
00996     {
00997         fprintf(stderr,"LCAS has to be initialized first !\n");
00998         retval = FAILED_LCAS_OTHER;
00999         goto fail_lcas_get_fabric_authorization;
01000     }
01001     lcas_log_debug(0,"\n");
01002     lcas_log_time(LOG_NOTICE,"LCAS authorization request\n");
01003 
01004     
01005 
01006 
01007     if ( lcas_fill_cred(user_dn_tmp, user_cred, &lcas_cred) != 0)
01008     {
01009         lcas_log(0,"lcas.mod-lcas_get_fabric_authorization() error: could not create lcas credential, something wrong\n");
01010         lcas_log(0,"                                              : with user DN and user credential\n");
01011         retval = FAILED_LCAS_OTHER;
01012         goto fail_lcas_get_fabric_authorization;
01013     }
01014     user_dn = lcas_get_dn(lcas_cred);
01015     if (user_dn == NULL)
01016     {
01017         lcas_log(0, "lcas.mod-lcas_get_fabric_authorization() error: user DN empty\n");
01018         retval = FAILED_LCAS_OTHER;
01019         goto fail_lcas_get_fabric_authorization;
01020     }
01021 
01022     lcas_log_debug(0, "lcas.mod-lcas_get_fabric_authorization(): user is %s\n", user_dn);
01023 
01024     
01025 
01026 
01027     authmod_entry=authmod_list;
01028     while (authmod_entry)
01029     {
01030         rc = authmod_entry->procs[AUTHPROC](request, lcas_cred);
01031         if (rc != LCAS_MOD_SUCCESS)
01032         {
01033             lcas_log_debug(0,"lcas.mod-lcas_get_fabric_authorization(): authorization failed for standard module %s\n",
01034                     authmod_entry->pluginname);
01035             retval = FAILED_LCAS_PLUGIN;
01036             goto fail_lcas_get_fabric_authorization;
01037         }
01038         lcas_log_debug(0, "lcas.mod-lcas_get_fabric_authorization(): authorization granted by standard module %s\n",
01039                 authmod_entry->pluginname);
01040         lcas_authorized++;
01041 
01042         authmod_entry=authmod_entry->next;
01043     }
01044 
01045     
01046 
01047 
01048     plugin_entry=plugin_list;
01049     while (plugin_entry)
01050     {
01051         rc = plugin_entry->procs[AUTHPROC](request, lcas_cred);
01052         if (rc != LCAS_MOD_SUCCESS)
01053         {
01054             lcas_log_debug(0,"lcas.mod-lcas_get_fabric_authorization(): authorization failed for plugin %s\n",
01055                     plugin_entry->pluginname);
01056             retval = FAILED_LCAS_PLUGIN;
01057             goto fail_lcas_get_fabric_authorization;
01058         }
01059         lcas_log_debug(0, "lcas.mod-lcas_get_fabric_authorization(): authorization granted by plugin %s\n",
01060                 plugin_entry->pluginname);
01061         lcas_authorized++;
01062 
01063         plugin_entry=plugin_entry->next;
01064     }
01065 
01066     
01067 
01068 
01069 
01070 
01071 
01072     
01073 
01074 
01075     if ( !(lcas_authorized > 0) )
01076     {
01077         lcas_log_debug(0,"lcas.mod-lcas_get_fabric_authorization(): No authorization modules were called (check lcas db file)\n");
01078         retval = FAILED_LCAS_OTHER;
01079         goto fail_lcas_get_fabric_authorization;
01080     }
01081     else
01082         lcas_log_debug(2,"lcas.mod-lcas_get_fabric_authorization(): %d modules authorized you\n",lcas_authorized);
01083 
01084     
01085     lcas_release_cred(&lcas_cred);
01086     lcas_log_debug(0,"lcas.mod-lcas_get_fabric_authorization(): succeeded\n");
01087     return 0;
01088 
01089  fail_lcas_get_fabric_authorization:
01090     
01091     lcas_release_cred(&lcas_cred);
01092     lcas_log_debug(0,"lcas.mod-lcas_get_fabric_authorization(): failed\n");
01093     return retval;
01094 }
01095 
01096 
01097 
01098 
01099 
01100 
01101 
01102 
01103 
01104 
01105 
01106 int lcas_term()
01107 {
01108     int                           rc;
01109     lcas_plugindl_t *             plugin_entry;
01110     lcas_plugindl_t *             authmod_entry;
01111 
01112     lcas_log_debug(0,"\n");
01113     lcas_log_time(LOG_DEBUG,"Termination LCAS\n");
01114     
01115 
01116 
01117 
01118     authmod_entry=authmod_list;
01119     while (authmod_entry)
01120     {
01121         lcas_plugindl_t * authmod_next;
01122         int               i;
01123 
01124         rc = authmod_entry->procs[TERMPROC]();
01125         if (rc != LCAS_MOD_SUCCESS)
01126         {
01127             lcas_log(0,"lcas.mod-lcas_term(): failed to terminate standard module %s\n",
01128                     authmod_entry->pluginname);
01129             return 1;
01130         }
01131         lcas_log_debug(1, "lcas.mod-lcas_term(): standard module %s terminated\n",
01132                 authmod_entry->pluginname);
01133 
01134         authmod_next=authmod_entry->next;
01135         for (i=0; i < authmod_entry->argc; i++)
01136         {
01137             if ((authmod_entry->argv)[i] != NULL)
01138             {
01139                 lcas_log_debug(3,"Freeing %d - %s\n",i,(authmod_entry->argv)[i]);
01140                 free((authmod_entry->argv)[i]);
01141             }
01142         }
01143         free(authmod_entry);
01144         authmod_entry=authmod_next;
01145     }
01146     authmod_list=authmod_entry=NULL;
01147 
01148     
01149 
01150 
01151 
01152     plugin_entry=plugin_list;
01153     while (plugin_entry)
01154     {
01155         lcas_plugindl_t * plugin_next;
01156         int               i;
01157 
01158         rc = plugin_entry->procs[TERMPROC]();
01159         if (rc != LCAS_MOD_SUCCESS)
01160         {
01161             lcas_log(0,"lcas.mod-lcas_term(): failed to terminate plugin module %s\n",
01162                     plugin_entry->pluginname);
01163             return 1;
01164         }
01165         lcas_log_debug(1, "lcas.mod-lcas_term(): plugin module %s terminated\n",
01166                 plugin_entry->pluginname);
01167 
01168         plugin_next=plugin_entry->next;
01169         for (i=0; i < plugin_entry->argc; i++)
01170         {
01171             if ((plugin_entry->argv)[i] != NULL)
01172             {
01173                 lcas_log_debug(3,"Freeing %d - %s\n",i,(plugin_entry->argv)[i]);
01174                 free((plugin_entry->argv)[i]);
01175             }
01176         }
01177         free(plugin_entry);
01178         plugin_entry=plugin_next;
01179     }
01180     plugin_list=plugin_entry=NULL;
01181 
01182     
01183     if (lcas_log_close() != 0)
01184         return 1;
01185 
01186     lcas_initialized=0;
01187     return 0;
01188 }
01189 
01190 
01191 
01192 
01193 
01194 
01195 
01196