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

lcmaps.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 
00057 #include "lcmaps_config.h"
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 #include <string.h>
00061 #include <gssapi.h>
00062 
00063 /* LCMAPS includes */
00064 #include "pluginmanager/_lcmaps_pluginmanager.h"
00065 #include "pluginmanager/_lcmaps_log.h"
00066 #include "lcmaps_types.h"
00067 #include "lcmaps_utils.h"
00068 #include "pluginmanager/_lcmaps_utils.h"
00069 #include "lcmaps_cred_data.h"
00070 
00071 /******************************************************************************
00072                        Define module specific variables
00073 ******************************************************************************/
00074 static lcmaps_cred_id_t    lcmaps_cred; 
00075 static int                 lcmaps_initialized = 0; 
00077 /******************************************************************************
00078 Function:   lcmaps_init
00079 Description:
00080     Start PluginManager:
00081     read from LCMAPS config file, the plugins to be loaded
00082 
00083 Parameters:
00084     fp: file handle for logging (from gatekeeper)
00085 Returns:
00086     0: initialization succeeded
00087     1: initialization failed
00088 ******************************************************************************/
00104 int lcmaps_init(
00105         FILE* fp
00106 )
00107 {
00108     if (lcmaps_initialized)
00109     {
00110         if (lcmaps_log(0,"LCMAPS already initialized\n") != 0)
00111         {
00112             fprintf(stderr,"LCMAPS already initialized, but wrongly\n");
00113             goto fail_lcmaps_init;
00114         }
00115         return 0;
00116     }
00117 
00118     /* set logging file descriptor, for the moment the gatekeeper logfile */
00119 /*  if (lcmaps_log_open(NULL,fp,DO_USRLOG|DO_SYSLOG)) goto fail_lcmaps_init; */
00120     if (lcmaps_log_open(NULL,fp,DO_USRLOG)) goto fail_lcmaps_init;
00121     lcmaps_log_debug(0,"\n");
00122     lcmaps_log_time(LOG_NOTICE,"Initialization LCMAPS version %s\n",VERSION);
00123 
00124     /* Start PluginManager */
00125     if (startPluginManager()) {
00126         lcmaps_log(0,"lcmaps.mod-lcmaps_init() error: could not start plugin manager\n");
00127         goto fail_lcmaps_init;
00128     }
00129 
00130     /* success */
00131     lcmaps_initialized++;
00132     return 0;
00133 
00134  fail_lcmaps_init:
00135     return 1;
00136 
00137 }
00138 
00139 
00140 /******************************************************************************
00141 Function:   lcmaps_run
00142 Description:
00143     do the user mapping
00144 
00145 Parameters:
00146     request: JDL
00147     user_cred : user globus credential handle
00148 Returns:
00149     0: mapping succeeded
00150     1: mapping failed
00151 ******************************************************************************/
00167 #if ALLOW_EMPTY_CREDENTIALS
00168 int lcmaps_run(
00169         char * user_dn_tmp,
00170         gss_cred_id_t user_cred,
00171         lcmaps_request_t request
00172 )
00173 #else
00174 int lcmaps_run(
00175         gss_cred_id_t user_cred,
00176         lcmaps_request_t request
00177 )
00178 #endif
00179 {
00180     char *                        user_dn = NULL;
00181 
00182     if (lcmaps_initialized == 0)
00183     {
00184         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00185         goto fail_lcmaps_run;
00186     }
00187 
00188     /*
00189      * Create lcmaps credential (checks if dn can be extracted)
00190      */
00191     if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00192     {
00193         lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not create lcmaps credential, something wrong\n");
00194         lcmaps_log(0,"                                              : with user DN and user credential\n");
00195         goto fail_lcmaps_run;
00196     }
00197     user_dn = lcmaps_get_dn(lcmaps_cred);
00198     if (user_dn == NULL)
00199     {
00200         lcmaps_log(0, "lcmaps.mod-lcmaps_run() error: user DN empty\n");
00201         goto fail_lcmaps_run;
00202     }
00203 
00204     /* Run PluginManager */
00205     if (runPluginManager(request, lcmaps_cred)) {
00206         lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not run plugin manager\n");
00207         goto fail_lcmaps_run;
00208     }
00209 
00210     /* succes */
00211     lcmaps_release_cred(&lcmaps_cred);
00212     lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): succeeded\n");
00213     return 0;
00214 
00215  fail_lcmaps_run:
00216     lcmaps_release_cred(&lcmaps_cred);
00217     lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): failed\n");
00218     return 1;
00219 }
00220 
00221 /******************************************************************************
00222 Function:   lcmaps_run_and_return_username
00223 Description:
00224     do the user mapping and return user name (needed for e.g. GridFTP)
00225 
00226 Parameters:
00227     request: JDL
00228     user_cred : user globus credential handle
00229     usernamep : pointer to user name
00230 Returns:
00231     0: mapping succeeded
00232     1: mapping failed
00233 ******************************************************************************/
00251 #if ALLOW_EMPTY_CREDENTIALS
00252 int lcmaps_run_and_return_username(
00253         char * user_dn_tmp,
00254         gss_cred_id_t user_cred,
00255         lcmaps_request_t request,
00256         char ** usernamep
00257 )
00258 #else
00259 int lcmaps_run_and_return_username(
00260         gss_cred_id_t user_cred,
00261         lcmaps_request_t request,
00262         char ** usernamep
00263 )
00264 #endif
00265 {
00266     uid_t *          uid;
00267     int              cntUid;
00268     struct passwd *  user_info   = NULL;
00269 
00270     int retval = 0;
00271 
00272     fprintf(stderr,"Using lcmaps_run_and_return_username interface of LCMAPS\n");
00273     if (usernamep == NULL)
00274         return 1;
00275 
00276     *usernamep = NULL;
00277 
00278 #if ALLOW_EMPTY_CREDENTIALS
00279     retval = lcmaps_run(user_dn_tmp, user_cred, request);
00280 #else
00281     retval = lcmaps_run(user_cred, request);
00282 #endif
00283     if (retval != 0)
00284     {
00285         fprintf(stderr,"LCMAPS failed to map the user credential\n");
00286         return 1;
00287     }
00288     /*
00289      * Apparently lcmaps succeeded, so let's get the username from the credential repository
00290      * and return happily
00291      */
00292 
00293     /* Now try to get the userid drom the credential data */
00294     uid    = getCredentialData(UID,     &cntUid);
00295     if (uid)
00296     {
00297         if ( (user_info = getpwuid(uid[0])) == NULL )
00298         {
00299             fprintf(stderr,"LCMAPS could not find the username related to uid: %d\n",uid[0]);
00300             return 1;
00301         }
00302         (*usernamep) = strdup(user_info->pw_name);
00303     }
00304     else
00305     {
00306         fprintf(stderr,"LCMAPS could not find any uid\n");
00307         return 1;
00308     }
00309 
00310     return 0;
00311 }
00312 
00313 /******************************************************************************
00314 Function:   lcmaps_run_without_credentials
00315 Description:
00316     do the user mapping without credentials, only the user DN
00317 
00318 Parameters:
00319     user_dn_tmp: user DN
00320 Returns:
00321     0: mapping succeeded
00322     1: mapping failed
00323 ******************************************************************************/
00337 int lcmaps_run_without_credentials(
00338         char * user_dn_tmp
00339 )
00340 {
00341     gss_cred_id_t user_cred  = GSS_C_NO_CREDENTIAL;
00342     lcmaps_request_t request = (lcmaps_request_t) NULL;
00343     char *           user_dn = NULL;
00344 
00345     if (lcmaps_initialized == 0)
00346     {
00347         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00348         goto fail_lcmaps_run_without_credentials;
00349     }
00350 
00351     /*
00352      * Create lcmaps credential (checks if dn can be extracted)
00353      */
00354     if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00355     {
00356         lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not create lcmaps credential, something wrong\n");
00357         lcmaps_log(0,"                                              : with user DN and user credential\n");
00358         goto fail_lcmaps_run_without_credentials;
00359     }
00360     user_dn = lcmaps_get_dn(lcmaps_cred);
00361     if (user_dn == NULL)
00362     {
00363         lcmaps_log(0, "lcmaps.mod-lcmaps_run_without_credentials() error: user DN empty\n");
00364         goto fail_lcmaps_run_without_credentials;
00365     }
00366 
00367     /* Run PluginManager */
00368     if (runPluginManager(request, lcmaps_cred)) {
00369         lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not run plugin manager\n");
00370         goto fail_lcmaps_run_without_credentials;
00371     }
00372 
00373     /* succes */
00374     lcmaps_release_cred(&lcmaps_cred);
00375     lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): succeeded\n");
00376     return 0;
00377 
00378  fail_lcmaps_run_without_credentials:
00379     lcmaps_release_cred(&lcmaps_cred);
00380     lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): failed\n");
00381     return 1;
00382 }
00383 
00384 
00385 /******************************************************************************
00386 Function:   lcmaps_term
00387 Description:
00388     Terminate LCMAPS module: 
00389 
00390 Parameters:
00391 Returns:
00392     0: termination succeeded
00393     1: termination failed
00394 ******************************************************************************/
00406 int lcmaps_term()
00407 {
00408     lcmaps_log_time(0,"lcmaps.mod-lcmaps_term(): terminating\n");
00409     return stopPluginManager();
00410 }
00411 
00412 /******************************************************************************
00413 CVS Information:
00414     $Source: /cvs/fabric_mgt/gridification/lcmaps/src/lcmaps.c,v $
00415     $Date: 2004/03/04 16:34:33 $
00416     $Revision: 1.8 $
00417     $Author: martijn $
00418 ******************************************************************************/

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