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 
00053 #include "lcmaps_config.h"
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include <gssapi.h>
00058 
00059 /* LCMAPS includes */
00060 #include "pluginmanager/_lcmaps_pluginmanager.h"
00061 #include "pluginmanager/_lcmaps_log.h"
00062 #include "lcmaps_types.h"
00063 #include "lcmaps_utils.h"
00064 
00065 /******************************************************************************
00066                        Define module specific variables
00067 ******************************************************************************/
00068 static lcmaps_cred_id_t    lcmaps_cred; 
00069 static int                 lcmaps_initialized = 0; 
00071 /******************************************************************************
00072 Function:   lcmaps_init
00073 Description:
00074     Start PluginManager:
00075     read from LCMAPS config file, the plugins to be loaded
00076 
00077 Parameters:
00078     fp: file handle for logging (from gatekeeper)
00079 Returns:
00080     0: initialization succeeded
00081     1: initialization failed
00082 ******************************************************************************/
00098 int lcmaps_init(
00099         FILE* fp
00100 )
00101 {
00102     if (lcmaps_initialized)
00103     {
00104         if (lcmaps_log(0,"LCMAPS already initialized\n") != 0)
00105         {
00106             fprintf(stderr,"LCMAPS already initialized, but wrongly\n");
00107             goto fail_lcmaps_init;
00108         }
00109         return 0;
00110     }
00111 
00112     /* set logging file descriptor, for the moment the gatekeeper logfile */
00113 /*  if (lcmaps_log_open(NULL,fp,DO_USRLOG|DO_SYSLOG)) goto fail_lcmaps_init; */
00114     if (lcmaps_log_open(NULL,fp,DO_USRLOG)) goto fail_lcmaps_init;
00115     lcmaps_log_debug(0,"\n");
00116     lcmaps_log_time(LOG_NOTICE,"Initialization LCMAPS version %s\n",VERSION);
00117 
00118     /* Start PluginManager */
00119     if (startPluginManager()) {
00120         lcmaps_log(0,"lcmaps.mod-lcmaps_init() error: could not start plugin manager\n");
00121         goto fail_lcmaps_init;
00122     }
00123 
00124     /* success */
00125     lcmaps_initialized++;
00126     return 0;
00127 
00128  fail_lcmaps_init:
00129     return 1;
00130 
00131 }
00132 
00133 
00134 /******************************************************************************
00135 Function:   lcmaps_run
00136 Description:
00137     do the user mapping
00138 
00139 Parameters:
00140     request: JDL
00141     user_cred : user globus credential handle
00142 Returns:
00143     0: mapping succeeded
00144     1: mapping failed
00145 ******************************************************************************/
00161 #if ALLOW_EMPTY_CREDENTIALS
00162 int lcmaps_run(
00163         char * user_dn_tmp,
00164         gss_cred_id_t user_cred,
00165         lcmaps_request_t request
00166 )
00167 #else
00168 int lcmaps_run(
00169         gss_cred_id_t user_cred,
00170         lcmaps_request_t request
00171 )
00172 #endif
00173 {
00174     char *                        user_dn = NULL;
00175 
00176     if (lcmaps_initialized == 0)
00177     {
00178         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00179         goto fail_lcmaps_run;
00180     }
00181 
00182     /*
00183      * Create lcmaps credential (checks if dn can be extracted)
00184      */
00185     if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00186     {
00187         lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not create lcmaps credential, something wrong\n");
00188         lcmaps_log(0,"                                              : with user DN and user credential\n");
00189         goto fail_lcmaps_run;
00190     }
00191     user_dn = lcmaps_get_dn(lcmaps_cred);
00192     if (user_dn == NULL)
00193     {
00194         lcmaps_log(0, "lcmaps.mod-lcmaps_run() error: user DN empty\n");
00195         goto fail_lcmaps_run;
00196     }
00197 
00198     /* Run PluginManager */
00199     if (runPluginManager(request, lcmaps_cred)) {
00200         lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not run plugin manager\n");
00201         goto fail_lcmaps_run;
00202     }
00203 
00204     /* succes */
00205     lcmaps_release_cred(&lcmaps_cred);
00206     lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): succeeded\n");
00207     return 0;
00208 
00209  fail_lcmaps_run:
00210     lcmaps_release_cred(&lcmaps_cred);
00211     lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): failed\n");
00212     return 1;
00213 }
00214 
00215 /******************************************************************************
00216 Function:   lcmaps_run_without_credentials
00217 Description:
00218     do the user mapping without credentials, only the user DN
00219 
00220 Parameters:
00221     user_dn_tmp: user DN
00222 Returns:
00223     0: mapping succeeded
00224     1: mapping failed
00225 ******************************************************************************/
00239 int lcmaps_run_without_credentials(
00240         char * user_dn_tmp
00241 )
00242 {
00243     gss_cred_id_t user_cred  = GSS_C_NO_CREDENTIAL;
00244     lcmaps_request_t request = (lcmaps_request_t) NULL;
00245     char *           user_dn = NULL;
00246 
00247     if (lcmaps_initialized == 0)
00248     {
00249         fprintf(stderr,"LCMAPS has to be initialized first !\n");
00250         goto fail_lcmaps_run_without_credentials;
00251     }
00252 
00253     /*
00254      * Create lcmaps credential (checks if dn can be extracted)
00255      */
00256     if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00257     {
00258         lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not create lcmaps credential, something wrong\n");
00259         lcmaps_log(0,"                                              : with user DN and user credential\n");
00260         goto fail_lcmaps_run_without_credentials;
00261     }
00262     user_dn = lcmaps_get_dn(lcmaps_cred);
00263     if (user_dn == NULL)
00264     {
00265         lcmaps_log(0, "lcmaps.mod-lcmaps_run_without_credentials() error: user DN empty\n");
00266         goto fail_lcmaps_run_without_credentials;
00267     }
00268 
00269     /* Run PluginManager */
00270     if (runPluginManager(request, lcmaps_cred)) {
00271         lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not run plugin manager\n");
00272         goto fail_lcmaps_run_without_credentials;
00273     }
00274 
00275     /* succes */
00276     lcmaps_release_cred(&lcmaps_cred);
00277     lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): succeeded\n");
00278     return 0;
00279 
00280  fail_lcmaps_run_without_credentials:
00281     lcmaps_release_cred(&lcmaps_cred);
00282     lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): failed\n");
00283     return 1;
00284 }
00285 
00286 
00287 /******************************************************************************
00288 Function:   lcmaps_term
00289 Description:
00290     Terminate LCMAPS module: 
00291 
00292 Parameters:
00293 Returns:
00294     0: termination succeeded
00295     1: termination failed
00296 ******************************************************************************/
00308 int lcmaps_term()
00309 {
00310     lcmaps_log_time(0,"lcmaps.mod-lcmaps_term(): terminating\n");
00311     return stopPluginManager();
00312 }
00313 
00314 /******************************************************************************
00315 CVS Information:
00316     $Source: /cvs/fabric_mgt/gridification/lcmaps/src/lcmaps.c,v $
00317     $Date: 2003/07/16 12:53:28 $
00318     $Revision: 1.5 $
00319     $Author: martijn $
00320 ******************************************************************************/

Generated at Wed Jul 16 16:33:34 2003 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001