00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00066 #ifndef LCMAPS_C
00067 #define LCMAPS_C
00068 
00069 #include "lcmaps_config.h"
00070 #include <stdio.h>
00071 #include <stdlib.h>
00072 #include <string.h>
00073 #ifdef LCMAPS_GSI_MODE
00074 #   include <gssapi.h>
00075 #endif
00076 
00077 
00078 #include "lcmaps_types.h"
00079 #include "lcmaps_utils.h"
00080 #include "lcmaps_cred_data.h"
00081 #include "_lcmaps_utils.h"
00082 #include "_lcmaps_pluginmanager.h"
00083 #include "_lcmaps_log.h"
00084 #include "_lcmaps_credential.h"
00085 
00086 
00087 
00088 
00089 static lcmaps_cred_id_t    lcmaps_cred; 
00090 static int                 lcmaps_initialized = 0; 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 int lcmaps_init_and_logfile(
00111         char * logfile,
00112         FILE* fp,
00113         unsigned short logtype
00114 )
00115 {
00116     if (lcmaps_initialized)
00117     {
00118         if (lcmaps_log(0,"LCMAPS already initialized\n") != 0)
00119         {
00120             fprintf(stderr,"LCMAPS already initialized, but wrongly\n");
00121             goto fail_lcmaps_init_and_logfile;
00122         }
00123         return 0;
00124     }
00125 
00126     
00127     if (lcmaps_log_open(logfile,fp,logtype))
00128         goto fail_lcmaps_init_and_logfile;
00129     lcmaps_log_debug(0,"\n");
00130     lcmaps_log_time(LOG_DEBUG,"Initialization LCMAPS version %s\n",VERSION);
00131 
00132     
00133     if (startPluginManager()) {
00134         lcmaps_log(0,"lcmaps.mod-lcmaps_init() error: could not start plugin manager\n");
00135         goto fail_lcmaps_init_and_logfile;
00136     }
00137 
00138     
00139     lcmaps_initialized++;
00140     return 0;
00141 
00142  fail_lcmaps_init_and_logfile:
00143     return 1;
00144 
00145 }
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 int lcmaps_init_and_log(
00163         FILE* fp,
00164         unsigned short logtype
00165 )
00166 {
00167     return lcmaps_init_and_logfile(NULL, fp, logtype);
00168 }
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 int lcmaps_init(
00184         FILE* fp
00185 )
00186 {
00187     
00188     
00189     if (fp)
00190     {
00191         return lcmaps_init_and_log(fp,DO_USRLOG);
00192     }
00193     else
00194     {
00195         return lcmaps_init_and_log(NULL,DO_SYSLOG);
00196     }
00197 }
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 int lcmaps_term()
00210 {
00211     lcmaps_log_time(LOG_DEBUG,"Termination LCMAPS\n");
00212     lcmaps_log_time(0,"lcmaps.mod-lcmaps_term(): terminating\n");
00213     if (stopPluginManager() != 0)
00214         return 1;
00215     if (lcmaps_log_close() != 0)
00216         return 1;
00217     if (lcmaps_initialized > 0)
00218         lcmaps_initialized--;
00219     return 0;
00220 }
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 int lcmaps_run_without_credentials_and_return_username(
00245         char * user_dn_tmp,
00246         lcmaps_request_t request,
00247         char ** usernamep,
00248         int npols,
00249         char ** policynames
00250 )
00251 {
00252     char *            user_dn     = NULL;
00253     uid_t *           uid;
00254     int               cntUid;
00255     struct passwd *   user_info   = NULL;
00256     char *            logstr = "lcmaps.mod-lcmaps_run_without_credentials_and_return_username()";
00257     int               rc          = 0;
00258 
00259 
00260     if (lcmaps_initialized == 0)
00261     {
00262         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00263         goto fail_lcmaps_run_without_credentials_and_return_username;
00264     }
00265     lcmaps_log_time(LOG_NOTICE,"LCMAPS credential mapping request\n");
00266     
00267     lcmaps_log_debug(1, "Using \"lcmaps_run_without_credentials_and_return_username\" interface of LCMAPS\n");
00268     if (usernamep == NULL)
00269         goto fail_lcmaps_run_without_credentials_and_return_username;
00270     *usernamep = NULL;
00271 
00272     
00273 
00274 
00275 
00276     if ((rc = lcmaps_credential_init(&lcmaps_cred)) != 0)
00277     {
00278         if (rc == -1)
00279         {
00280             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00281             goto fail_lcmaps_run_without_credentials_and_return_username;
00282         }
00283         else
00284         {
00285             lcmaps_log(0, "%s error: in initializing lcmaps_cred\n", logstr);
00286             goto fail_lcmaps_run_without_credentials_and_return_username;
00287         }
00288     }
00289     if (lcmaps_credential_store_dn(user_dn_tmp, &lcmaps_cred) != 0)
00290     {
00291         lcmaps_log(0, "%s error: storing dn in lcmaps_cred\n");
00292         goto fail_lcmaps_run_without_credentials_and_return_username;
00293     }
00294     user_dn = lcmaps_credential_get_dn(lcmaps_cred);
00295     if (user_dn == NULL)
00296     {
00297         lcmaps_log(0, "lcmaps.mod-lcmaps_run_without_credentials_and_return_username() error: user DN empty\n");
00298         goto fail_lcmaps_run_without_credentials_and_return_username;
00299     }
00300 
00301     
00302     if (runPluginManager(request, lcmaps_cred, npols, policynames)) {
00303         lcmaps_log(0, "%s error: could not run plugin manager\n");
00304         goto fail_lcmaps_run_without_credentials_and_return_username;
00305     }
00306 
00307     
00308     uid    = getCredentialData(UID,     &cntUid);
00309     if (uid)
00310     {
00311         if ( (user_info = getpwuid(uid[0])) == NULL )
00312         {
00313             fprintf(stderr,"LCMAPS could not find the username related to uid: %d\n",uid[0]);
00314             return 1;
00315         }
00316         (*usernamep) = strdup(user_info->pw_name);
00317     }
00318     else
00319     {
00320         fprintf(stderr,"LCMAPS could not find any uid\n");
00321         return 1;
00322     }
00323 
00324     
00325     lcmaps_release_cred(&lcmaps_cred);
00326     lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials_and_return_username(): succeeded\n");
00327     return 0;
00328 
00329  fail_lcmaps_run_without_credentials_and_return_username:
00330     lcmaps_release_cred(&lcmaps_cred);
00331     lcmaps_log_debug(0, "%s: failed\n", logstr);
00332     return 1;
00333 }
00334 
00335 
00336 
00337 
00338 
00339 
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 int lcmaps_run_with_fqans_and_return_account(
00365         char *            user_dn,
00366         char **           fqan_list,
00367         int               nfqan,
00368         lcmaps_request_t  request,
00369         int               npols,
00370         char **           policynames,
00371         uid_t *           puid,
00372         gid_t **          ppgid_list,
00373         int *             pnpgid,
00374         gid_t **          psgid_list,
00375         int *             pnsgid,
00376         char **           poolindexp
00377 )
00378 {
00379     char *   logstr         = "lcmaps.mod-lcmaps_run_with_fqans_and_return_account()";
00380     int      rc             = 0;
00381     uid_t *  uid            = NULL;
00382     int      cntUid         = -1;
00383     gid_t *  priGid         = NULL;
00384     int      cntPriGid      = -1;
00385     gid_t *  secGid         = NULL;
00386     int      cntSecGid      = -1;
00387     char **  poolindex_list = NULL;
00388     char *   poolindex      = NULL;
00389     int      cntpoolindex   = 0;
00390 
00391     if (lcmaps_initialized == 0)
00392     {
00393         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00394         goto fail_lcmaps_run_with_fqans_and_return_account;
00395     }
00396     lcmaps_log_time(LOG_NOTICE,"LCMAPS credential mapping request\n");
00397 
00398     lcmaps_log_debug(1, "Using \"lcmaps_run_with_fqans_and_return_account\" interface of LCMAPS\n");
00399     
00400 
00401 
00402 
00403     if ((rc = lcmaps_credential_init(&lcmaps_cred)) != 0)
00404     {
00405         if (rc == -1)
00406         {
00407             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00408             goto fail_lcmaps_run_with_fqans_and_return_account;
00409         }
00410         else
00411         {
00412             lcmaps_log(0, "%s error: in initializing lcmaps_cred\n", logstr);
00413             goto fail_lcmaps_run_with_fqans_and_return_account;
00414         }
00415     }
00416     if (lcmaps_credential_store_dn(user_dn, &lcmaps_cred) != 0)
00417     {
00418         lcmaps_log(0, "%s error: storing dn in lcmaps_cred\n");
00419         goto fail_lcmaps_run_with_fqans_and_return_account;
00420     }
00421     if ((rc = lcmaps_credential_store_fqan_list(nfqan, fqan_list, &lcmaps_cred)) != 0)
00422     {
00423         if (rc == -1)
00424         {
00425             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00426             goto fail_lcmaps_run_with_fqans_and_return_account;
00427         }
00428         else if (rc == 1)
00429         {
00430             lcmaps_log(0, "%s error: while storing a malformed fqan list\n", logstr);
00431             goto fail_lcmaps_run_with_fqans_and_return_account;
00432         }
00433         else if (rc == 2)
00434         {
00435             lcmaps_log(0, "%s error: Malloc error while storing fqan list!\n", logstr);
00436             goto fail_lcmaps_run_with_fqans_and_return_account;
00437         }
00438         else
00439         {
00440             lcmaps_log(0, "%s error: storing fqan list\n", logstr);
00441             goto fail_lcmaps_run_with_fqans_and_return_account;
00442         }
00443     }
00444 
00445     
00446     if (runPluginManager(request, lcmaps_cred, npols, policynames)) {
00447         lcmaps_log(0, "%s error: could not run plugin manager\n", logstr);
00448         goto fail_lcmaps_run_with_fqans_and_return_account;
00449     }
00450 
00451     
00452     
00453     uid              = (uid_t *) getCredentialData(UID,     &cntUid);
00454     if (uid == NULL)
00455     {
00456         lcmaps_log(0, "%s error: LCMAPS could not find any uid\n", logstr);
00457         goto fail_lcmaps_run_with_fqans_and_return_account;
00458     }
00459     else if (cntUid != 1)
00460     {
00461         lcmaps_log(0, "%s error: LCMAPS found %d uids, only 1 allowed\n", logstr, cntUid);
00462         goto fail_lcmaps_run_with_fqans_and_return_account;
00463     }
00464     else
00465     {
00466         *puid = uid[0];
00467     }
00468     
00469     priGid           = (gid_t *) getCredentialData(PRI_GID, &cntPriGid);
00470     if (priGid == NULL)
00471     {
00472         lcmaps_log(0, "%s error: LCMAPS could not find any gid, at least one required!\n", logstr);
00473         goto fail_lcmaps_run_with_fqans_and_return_account;
00474     }
00475     else
00476     {
00477         *pnpgid = cntPriGid;
00478         *ppgid_list = priGid;
00479     }
00480     
00481     secGid           = (gid_t *) getCredentialData(SEC_GID, &cntSecGid);
00482     if (secGid == NULL)
00483     {
00484         lcmaps_log_debug(1, "%s: LCMAPS found no secondary groups\n", logstr);
00485     }
00486     else
00487     {
00488         *pnsgid = cntSecGid;
00489         *psgid_list = secGid;
00490     }
00491     
00492     poolindex_list = (char **) getCredentialData(POOL_INDEX, &cntpoolindex);
00493     if (poolindex_list && (cntpoolindex > 0))
00494     {
00495         poolindex = (char *)(*(poolindex_list));
00496         lcmaps_log_debug(3, "%s: found %d poolindeces starting at address = %p\n",
00497             logstr, cntpoolindex, poolindex);
00498         
00499 
00500 
00501 
00502         lcmaps_log_a_string_debug(3,
00503             "lcmaps.mod-lcmaps_run_with_fqans_and_return_account(): found this poolindex %s\n",
00504             poolindex);
00505         *poolindexp = poolindex;
00506     }
00507     else
00508     {
00509         lcmaps_log(0, "%s: LCMAPS could not find the poolindex\n", logstr);
00510         goto fail_lcmaps_run_with_fqans_and_return_account;
00511     }
00512 
00513     
00514     lcmaps_release_cred(&lcmaps_cred);
00515     lcmaps_log_time(0, "%s: succeeded\n", logstr);
00516     return 0;
00517 
00518  fail_lcmaps_run_with_fqans_and_return_account:
00519     lcmaps_release_cred(&lcmaps_cred);
00520     lcmaps_log_time(0, "%s: failed\n", logstr);
00521     return 1;
00522 }
00523 
00524 
00525 
00526 
00527 
00528 #ifdef LCMAPS_GSI_MODE
00529 
00530 
00531 
00532 
00533 
00534 
00535 
00536 
00537 
00538 
00539 
00540 
00541 
00542 
00543 
00544 #if ALLOW_EMPTY_CREDENTIALS
00545 int lcmaps_run(
00546         char * user_dn_tmp,
00547         gss_cred_id_t user_cred,
00548         lcmaps_request_t request
00549 )
00550 #else
00551 int lcmaps_run(
00552         gss_cred_id_t user_cred,
00553         lcmaps_request_t request
00554 )
00555 #endif
00556 {
00557     char *  user_dn = NULL;
00558     char *  logstr = "lcmaps.mod-lcmaps_run()";
00559     int     rc = 0;
00560 
00561     if (lcmaps_initialized == 0)
00562     {
00563         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00564         goto fail_lcmaps_run;
00565     }
00566     lcmaps_log_time(LOG_NOTICE,"LCMAPS credential mapping request\n");
00567 
00568     
00569 
00570 
00571 
00572     if ((rc = lcmaps_credential_init(&lcmaps_cred)) != 0)
00573     {
00574         if (rc == -1)
00575         {
00576             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00577             goto fail_lcmaps_run;
00578         }
00579         else
00580         {
00581             lcmaps_log(0, "%s error: in initializing lcmaps_cred\n", logstr);
00582             goto fail_lcmaps_run;
00583         }
00584     }
00585 #if ALLOW_EMPTY_CREDENTIALS
00586     if (lcmaps_credential_store_dn(user_dn_tmp, &lcmaps_cred) != 0)
00587     {
00588         lcmaps_log(0, "%s error: storing dn in lcmaps_cred\n");
00589         goto fail_lcmaps_run;
00590     }
00591 #endif
00592     if ((rc = lcmaps_credential_store_gss_cred_id_t(user_cred, &lcmaps_cred)) != 0)
00593     {
00594         if (rc == -1)
00595         {
00596             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00597             goto fail_lcmaps_run;
00598         }
00599         else if (rc == 1)
00600         {
00601             lcmaps_log(0, "%s error: cannot retrieve dn while storing gss_credential\n", logstr);
00602             goto fail_lcmaps_run;
00603         }
00604         else if (rc == 2)
00605         {
00606             lcmaps_log(0, "%s: No FQANs found while storing gss_credential (non fatal)\n", logstr);
00607         }
00608         else if (rc == 3)
00609         {
00610             lcmaps_log(0, "%s error: Retrieving VOMS FQANs while storing gss_credential\n", logstr);
00611             goto fail_lcmaps_run;
00612         }
00613         else
00614         {
00615             lcmaps_log(0, "%s error: storing gss_credential\n", logstr);
00616             goto fail_lcmaps_run;
00617         }
00618     }
00619     user_dn = lcmaps_credential_get_dn(lcmaps_cred);
00620     if (user_dn == NULL)
00621     {
00622         lcmaps_log(0, "%s error: user DN empty\n", logstr);
00623         goto fail_lcmaps_run;
00624     }
00625 
00626     
00627     if (runPluginManager(request, lcmaps_cred, 0, NULL)) {
00628         lcmaps_log(0, "%s error: could not run plugin manager\n", logstr);
00629         goto fail_lcmaps_run;
00630     }
00631 
00632     
00633     lcmaps_release_cred(&lcmaps_cred);
00634     lcmaps_log_time(0, "%s: succeeded\n", logstr);
00635     return 0;
00636 
00637  fail_lcmaps_run:
00638     lcmaps_release_cred(&lcmaps_cred);
00639     lcmaps_log_time(0, "%s: failed\n", logstr);
00640     return 1;
00641 }
00642 
00643 
00644 
00645 
00646 
00647 
00648 
00649 
00650 
00651 
00652 
00653 
00654 
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 #if ALLOW_EMPTY_CREDENTIALS
00664 int lcmaps_run_and_return_username(
00665         char * user_dn_tmp,
00666         gss_cred_id_t user_cred,
00667         lcmaps_request_t request,
00668         char ** usernamep,
00669         int npols,
00670         char ** policynames
00671 )
00672 #else
00673 int lcmaps_run_and_return_username(
00674         gss_cred_id_t user_cred,
00675         lcmaps_request_t request,
00676         char ** usernamep,
00677         int npols,
00678         char ** policynames
00679 )
00680 #endif
00681 {
00682     char *  logstr  = "lcmaps.mod-lcmaps_run_and_return_username()";
00683     char *  user_dn = NULL;
00684     int     rc      = 0;
00685 
00686     uid_t *          uid;
00687     int              cntUid;
00688     struct passwd *  user_info   = NULL;
00689 
00690     if (lcmaps_initialized == 0)
00691     {
00692         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00693         goto fail_lcmaps_run_and_return_username;
00694     }
00695     lcmaps_log_time(LOG_NOTICE,"LCMAPS credential mapping request\n");
00696 
00697     lcmaps_log_debug(1, "Using lcmaps_run_and_return_username interface of LCMAPS\n");
00698     if (usernamep == NULL)
00699         goto fail_lcmaps_run_and_return_username;
00700 
00701     *usernamep = NULL;
00702 
00703     
00704 
00705 
00706 
00707     if ((rc = lcmaps_credential_init(&lcmaps_cred)) != 0)
00708     {
00709         if (rc == -1)
00710         {
00711             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00712             goto fail_lcmaps_run_and_return_username;
00713         }
00714         else
00715         {
00716             lcmaps_log(0, "%s error: in initializing lcmaps_cred\n", logstr);
00717             goto fail_lcmaps_run_and_return_username;
00718         }
00719     }
00720 #if ALLOW_EMPTY_CREDENTIALS
00721     if (lcmaps_credential_store_dn(user_dn_tmp, &lcmaps_cred) != 0)
00722     {
00723         lcmaps_log(0, "%s error: storing dn in lcmaps_cred\n");
00724         goto fail_lcmaps_run_and_return_username;
00725     }
00726 #endif
00727     if ((rc = lcmaps_credential_store_gss_cred_id_t(user_cred, &lcmaps_cred)) != 0)
00728     {
00729         if (rc == -1)
00730         {
00731             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00732             goto fail_lcmaps_run_and_return_username;
00733         }
00734         else if (rc == 1)
00735         {
00736             lcmaps_log(0, "%s error: cannot retrieve dn while storing gss_credential\n", logstr);
00737             goto fail_lcmaps_run_and_return_username;
00738         }
00739         else if (rc == 2)
00740         {
00741             lcmaps_log(0, "%s: No FQANs found while storing gss_credential (non fatal)\n", logstr);
00742         }
00743         else if (rc == 3)
00744         {
00745             lcmaps_log(0, "%s error: Retrieving VOMS FQANs while storing gss_credential\n", logstr);
00746             goto fail_lcmaps_run_and_return_username;
00747         }
00748         else
00749         {
00750             lcmaps_log(0, "%s error: storing gss_credential\n", logstr);
00751             goto fail_lcmaps_run_and_return_username;
00752         }
00753     }
00754     user_dn = lcmaps_credential_get_dn(lcmaps_cred);
00755     if (user_dn == NULL)
00756     {
00757         lcmaps_log(0, "%s error: user DN empty\n", logstr);
00758         goto fail_lcmaps_run_and_return_username;
00759     }
00760 
00761     
00762     if (runPluginManager(request, lcmaps_cred, npols, policynames)) {
00763         lcmaps_log(0,"%s error: could not run plugin manager\n", logstr);
00764         goto fail_lcmaps_run_and_return_username;
00765     }
00766 
00767     
00768 
00769 
00770 
00771 
00772     
00773     uid    = getCredentialData(UID,     &cntUid);
00774     if (uid)
00775     {
00776         if ( (user_info = getpwuid(uid[0])) == NULL )
00777         {
00778             fprintf(stderr,"LCMAPS could not find the username related to uid: %d\n",uid[0]);
00779             return 1;
00780         }
00781         (*usernamep) = strdup(user_info->pw_name);
00782     }
00783     else
00784     {
00785         fprintf(stderr,"LCMAPS could not find any uid\n");
00786         return 1;
00787     }
00788 
00789     
00790     lcmaps_release_cred(&lcmaps_cred);
00791     lcmaps_log_time(0,"%s: succeeded\n", logstr);
00792     return 0;
00793 
00794  fail_lcmaps_run_and_return_username:
00795     lcmaps_release_cred(&lcmaps_cred);
00796     lcmaps_log_time(0,"%s: failed\n", logstr);
00797     return 1;
00798 }
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806 
00807 
00808 
00809 
00810 
00811 
00812 
00813 
00814 
00815 
00816 
00817 
00818 
00819 
00820 
00821 
00822 #if ALLOW_EMPTY_CREDENTIALS
00823 int lcmaps_run_and_return_poolindex(
00824         char * user_dn_tmp,
00825         gss_cred_id_t user_cred,
00826         lcmaps_request_t request,
00827         char ** poolindexp,
00828         int npols,
00829         char ** policynames
00830 )
00831 #else
00832 int lcmaps_run_and_return_poolindex(
00833         gss_cred_id_t user_cred,
00834         lcmaps_request_t request,
00835         char ** poolindexp,
00836         int npols,
00837         char ** policynames
00838 )
00839 #endif
00840 {
00841     char *           user_dn      = NULL;
00842     char *           poolindex    = NULL;
00843     char **          tmpptr       = NULL;
00844     int              cntpoolindex = -1;
00845     char *           logstr       = "lcmaps.mod-lcmaps_run_and_return_poolindex()";
00846     int              rc           = 0;
00847 
00848     if (lcmaps_initialized == 0)
00849     {
00850         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00851         goto fail_lcmaps_run_and_return_poolindex;
00852     }
00853     lcmaps_log_time(LOG_NOTICE,"LCMAPS credential mapping request\n");
00854 
00855     lcmaps_log_debug(1, "Using lcmaps_run_and_return_poolindex interface of LCMAPS\n");
00856     if (poolindexp == NULL)
00857         goto fail_lcmaps_run_and_return_poolindex;
00858 
00859     *poolindexp = NULL;
00860 
00861     
00862 
00863 
00864 
00865     if ((rc = lcmaps_credential_init(&lcmaps_cred)) != 0)
00866     {
00867         if (rc == -1)
00868         {
00869             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00870             goto fail_lcmaps_run_and_return_poolindex;
00871         }
00872         else
00873         {
00874             lcmaps_log(0, "%s error: in initializing lcmaps_cred\n", logstr);
00875             goto fail_lcmaps_run_and_return_poolindex;
00876         }
00877     }
00878 #if ALLOW_EMPTY_CREDENTIALS
00879     if (lcmaps_credential_store_dn(user_dn_tmp, &lcmaps_cred) != 0)
00880     {
00881         lcmaps_log(0, "%s error: storing dn in lcmaps_cred\n");
00882         goto fail_lcmaps_run_and_return_poolindex;
00883     }
00884 #endif
00885     if ((rc = lcmaps_credential_store_gss_cred_id_t(user_cred, &lcmaps_cred)) != 0)
00886     {
00887         if (rc == -1)
00888         {
00889             lcmaps_log(0, "%s error: lcmaps_cred does not exist\n", logstr);
00890             goto fail_lcmaps_run_and_return_poolindex;
00891         }
00892         else if (rc == 1)
00893         {
00894             lcmaps_log(0, "%s error: cannot retrieve dn while storing gss_credential\n", logstr);
00895             goto fail_lcmaps_run_and_return_poolindex;
00896         }
00897         else if (rc == 2)
00898         {
00899             lcmaps_log(0, "%s: No FQANs found while storing gss_credential (non fatal)\n", logstr);
00900         }
00901         else if (rc == 3)
00902         {
00903             lcmaps_log(0, "%s error: Retrieving VOMS FQANs while storing gss_credential\n", logstr);
00904             goto fail_lcmaps_run_and_return_poolindex;
00905         }
00906         else
00907         {
00908             lcmaps_log(0, "%s error: storing gss_credential\n", logstr);
00909             goto fail_lcmaps_run_and_return_poolindex;
00910         }
00911     }
00912     user_dn = lcmaps_credential_get_dn(lcmaps_cred);
00913     if (user_dn == NULL)
00914     {
00915         lcmaps_log(0, "%s error: user DN empty\n", logstr);
00916         goto fail_lcmaps_run_and_return_poolindex;
00917     }
00918 
00919     
00920     if (runPluginManager(request, lcmaps_cred, npols, policynames)) {
00921         lcmaps_log(0,"%s error: could not run plugin manager\n", logstr);
00922         goto fail_lcmaps_run_and_return_poolindex;
00923     }
00924 
00925     
00926 
00927 
00928 
00929     tmpptr = (char **) getCredentialData(POOL_INDEX, &cntpoolindex);
00930     if (tmpptr && (cntpoolindex > 0))
00931     {
00932         poolindex = (char *)(*(tmpptr));
00933         lcmaps_log_debug(3,
00934             "%s: found %d poolindeces at address = %p\n",
00935             logstr, cntpoolindex, poolindex);
00936         
00937 
00938 
00939 
00940         lcmaps_log_a_string_debug(3,
00941             "lcmaps.mod-lcmaps_run_and_return_poolindex(): found this poolindex %s\n",
00942             poolindex);
00943         *poolindexp = strdup(poolindex);
00944     }
00945     else
00946     {
00947         lcmaps_log(0, "%s: LCMAPS could not find the poolindex\n", logstr);
00948         goto fail_lcmaps_run_and_return_poolindex;
00949     }
00950 
00951     
00952     lcmaps_release_cred(&lcmaps_cred);
00953     lcmaps_log_time(0,"%s: succeeded\n", logstr);
00954     return 0;
00955 
00956  fail_lcmaps_run_and_return_poolindex:
00957     lcmaps_release_cred(&lcmaps_cred);
00958     lcmaps_log_time(0, "%s: failed\n", logstr);
00959     return 1;
00960 }
00961 #endif 
00962 
00963 
00964 
00965 
00966 #endif 
00967 
00968 
00969 
00970 
00971 
00972 
00973 
00974