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

Generated at Tue Sep 23 15:48:08 2003 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001