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

lcmaps_voms_localgroup.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 
00109 /*****************************************************************************
00110                             Include header files
00111 ******************************************************************************/
00112 #include <stdio.h>
00113 #include <stdlib.h>
00114 #include <string.h>
00115 #include <pwd.h>
00116 #include <ctype.h>
00117 
00118 #include "lcmaps_config.h"
00119 #include "lcmaps_modules.h"
00120 #include "lcmaps_arguments.h"
00121 #include "lcmaps_cred_data.h"
00122 #include "lcmaps_gridlist.h"
00123 
00124 /******************************************************************************
00125                                 Definitions
00126 ******************************************************************************/
00127 
00128 /******************************************************************************
00129                           Module specific prototypes
00130 ******************************************************************************/
00131 
00132 /******************************************************************************
00133                        Define module specific variables
00134 ******************************************************************************/
00135 
00136 static char *groupmapfile = NULL;
00137 static int   mapall       = 0;
00138 static int   mapmin       = 0;
00139 
00140 /******************************************************************************
00141 Function:   plugin_initialize
00142 Description:
00143     Initialize plugin
00144 Parameters:
00145     argc, argv
00146     argv[0]: the name of the plugin
00147 Returns:
00148     LCMAPS_MOD_SUCCESS : succes
00149     LCMAPS_MOD_FAIL    : failure
00150     LCMAPS_MOD_NOFILE  : db file not found (will halt LCMAPS initialization)
00151 ******************************************************************************/
00152 int plugin_initialize(
00153         int argc,
00154         char ** argv
00155 )
00156 {
00157     char * logstr = "\tlcmaps_plugin_voms_localgroup-plugin_initialize()";
00158     int i, j;
00159 
00160     lcmaps_log_debug(1,"%s: passed arguments:\n", logstr);
00161     for (i=0; i < argc; i++)
00162     {
00163        lcmaps_log_debug(2,"%s: arg %d is %s\n", logstr, i, argv[i]);
00164     }
00165 
00166     /*
00167      * the first will be the thing to edit/select (groupmap(file))
00168      */
00169 
00170     /*
00171      * Parse arguments, argv[0] = name of plugin, so start with i = 1
00172      */
00173     for (i = 1; i < argc; i++)
00174     {
00175         if ( ((strcmp(argv[i], "-groupmap") == 0) ||
00176               (strcmp(argv[i], "-GROUPMAP") == 0) ||
00177               (strcmp(argv[i], "-groupmapfile") == 0) ||
00178               (strcmp(argv[i], "-GROUPMAPFILE") == 0))
00179              && (i + 1 < argc))
00180         {
00181             if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00182             {
00183                  groupmapfile = strdup(argv[i + 1]);
00184             }
00185             i++;
00186         }
00187         else if (strcmp(argv[i], "-mapall") == 0)
00188         {
00189              mapall = 1;
00190         }
00191         else if ((strcmp(argv[i], "-mapmin") == 0)
00192                  && (i + 1 < argc))
00193         {
00194             if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00195             {
00196                  /* check parameter integrety */
00197                  for (j = 0; j < (strlen(argv[i + 1])); j++)
00198                  {
00199                      if (isdigit((argv[i + 1])[j]) == 0)
00200                      {
00201                          lcmaps_log(0,"%s: Error in initialization parameter: %s (%s is not a number)\n", logstr, argv[i], argv[i + 1]);
00202                          return LCMAPS_MOD_FAIL;
00203                      }
00204                  }
00205  
00206                  mapmin = atoi(argv[i + 1]);
00207             }
00208             i++;
00209         }
00210         else
00211         {
00212             lcmaps_log(0,"%s: Error in initialization parameter: %s (failure)\n", logstr,
00213                        argv[i]);
00214             return LCMAPS_MOD_FAIL;
00215         }
00216     }
00217 
00218     return LCMAPS_MOD_SUCCESS;
00219 } 
00220 
00221 /******************************************************************************
00222 Function:   plugin_introspect
00223 Description:
00224     return list of required arguments
00225 Parameters:
00226 
00227 Returns:
00228     LCMAPS_MOD_SUCCESS : succes
00229     LCMAPS_MOD_FAIL    : failure
00230 ******************************************************************************/
00231 int plugin_introspect(
00232         int * argc,
00233         lcmaps_argument_t ** argv
00234 )
00235 {
00236     char *                   logstr = "\tlcmaps_plugin_voms_localgroup-plugin_introspect()";
00237     static lcmaps_argument_t argList[] = {
00238         {"user_dn"      ,       "char *"        , 1,   NULL},
00239         {NULL           ,       NULL            , -1,   NULL}
00240     };
00241 
00242     lcmaps_log_debug(1,"%s: introspecting\n", logstr);
00243 
00244     *argv = argList;
00245     *argc = lcmaps_cntArgs(argList);
00246     lcmaps_log_debug(1,"%s: address first argument: 0x%x\n", logstr,argList);
00247 
00248     return LCMAPS_MOD_SUCCESS;
00249 }
00250 
00251 
00252 /******************************************************************************
00253 Function:   plugin_run
00254 Description:
00255     Gather credentials for LCMAPS
00256 Parameters:
00257     argc: number of arguments
00258     argv: list of arguments
00259 Returns:
00260     LCMAPS_MOD_SUCCESS: authorization succeeded
00261     LCMAPS_MOD_FAIL   : authorization failed
00262 ******************************************************************************/
00263 int plugin_run(
00264         int argc,
00265         lcmaps_argument_t * argv
00266 )
00267 {
00268     char *           logstr = "\tlcmaps_plugin_voms_localgroup-plugin_run()";
00269     char *           dn                  = NULL; 
00270     char *           groupname           = NULL;
00271     struct group *   group_info          = NULL;
00272     int              i                   = 0;
00273     char **          vo_cred_string_list = NULL;
00274     int              cnt_vo_cred_string  = 0;
00275     int              group_counter       = 0;
00276     int              rc                  = 0;
00277     
00278     /*
00279      * The beginning
00280      */
00281     lcmaps_log_debug(1,"%s:\n", logstr);
00282 
00283     /*
00284      * Try to get the ordered values:
00285      */
00286     if ( (dn = *(char **) lcmaps_getArgValue("user_dn", "char *", argc, argv) ) )
00287         lcmaps_log_debug(1,"%s: found dn: %s\n", logstr,dn);
00288     else
00289         lcmaps_log_debug(1,"%s: could not get value of dn !\n", logstr);
00290 
00291     /*
00292      * Get the VO user information.
00293      * We cannot order it by lcmaps_argument_t, but have to use the getCredentialData() function
00294      * since it was stored there by a plugin (lcmaps_voms.mod)
00295      */
00296     vo_cred_string_list = getCredentialData(LCMAPS_VO_CRED_STRING, &cnt_vo_cred_string);
00297     if (cnt_vo_cred_string == 0)
00298     {
00299         lcmaps_log(0,"%s: warning: no VOMS group info --> no mapping\n", logstr);
00300         goto success_voms_localgroup;
00301     }
00302     else if (cnt_vo_cred_string < 0)
00303     {
00304         lcmaps_log(0,"%s: negative number of VOMS groups found ! (failure)\n", logstr);
00305         goto fail_voms_localgroup;
00306     }
00307 
00308     /*
00309      * Check the groupmapfile
00310      */
00311 
00312     if ((groupmapfile != NULL) && (strlen(groupmapfile) > 0))
00313         lcmaps_log_debug(1,"%s: groupmapfile is: %s\n", logstr, groupmapfile);
00314     else
00315     {
00316         lcmaps_log(0,"%s: error finding the groupmapfile: %s\n", logstr, groupmapfile);
00317         lcmaps_log(0,"%s: (use the option \"-groupmapfile <groupmapfile>\")\n", logstr);
00318         goto fail_voms_localgroup;
00319     }
00320 
00321     /*
00322      * Try to find the unix groups from the VO info in the groupmapfile
00323      * The first group (if found) should become the primary group
00324      */
00325     for (i = 0; i < cnt_vo_cred_string; i++)
00326     {
00327         if ( (rc = lcmaps_gridlist(vo_cred_string_list[i], &groupname, groupmapfile, MATCH_EXCLUDE|MATCH_WILD_CHARS, ".", NULL) ) == 0)
00328         {
00329             lcmaps_log_debug(1,"%s: found groupname: %s\n", logstr, groupname);
00330             group_counter++;   
00331 
00332             if (groupname && (strlen(groupname) > 0))
00333             {
00334                 if ( ( group_info = getgrnam(groupname) ) )
00335                 {
00336                     if (i == 0)
00337                     {
00338                         /* First VO group */
00339                         addCredentialData(PRI_GID, (void *) &(group_info->gr_gid));
00340                     }
00341                     else
00342                     {
00343                         /* Other VO groups */
00344                         addCredentialData(SEC_GID, (void *) &(group_info->gr_gid));
00345                     }
00346                 }
00347                 else
00348                 {
00349                     lcmaps_log(0,"%s: no group id found for groupname = \"%s\"\n", logstr, groupname);
00350                     goto fail_voms_localgroup;
00351                 }
00352             }
00353             else
00354             {
00355                 lcmaps_log(0,"%s: error getting value of groupname (failure)!\n", logstr);
00356                 goto fail_voms_localgroup;
00357             }
00358         }
00359         else if (rc == LCMAPS_MOD_NOFILE)
00360         {
00361             lcmaps_log(0, "%s: Could not find the groupmapfile %s\n", logstr, groupmapfile);
00362             goto fail_voms_localgroup;
00363         }
00364         else
00365         {
00366             lcmaps_log_debug(1,"%s: could not get value of groupname !\n", logstr);
00367             if (mapall)
00368             {
00369                 lcmaps_log(0,"%s: no mapping for VO group %s\n", logstr,
00370                            vo_cred_string_list[i]);
00371                 goto fail_voms_localgroup;
00372             }
00373         }
00374     }
00375 
00376     if (group_counter < mapmin)
00377     {
00378         lcmaps_log(0,"%s: Not enough groups found. The minimum is set to %d. The plugin found %d\n", logstr, mapmin, group_counter);
00379         goto fail_voms_localgroup;
00380     }
00381 
00382     /* success */
00383  success_voms_localgroup:
00384     if (groupname) free(groupname);
00385     lcmaps_log_time(0,"%s: voms_localgroup plugin succeeded\n", logstr);
00386     return LCMAPS_MOD_SUCCESS;
00387 
00388  fail_voms_localgroup:
00389     if (groupname) free(groupname);
00390     lcmaps_log_time(0,"%s: voms_localgroup plugin failed\n", logstr);
00391     return LCMAPS_MOD_FAIL;
00392 }
00393 
00394 /******************************************************************************
00395 Function:   plugin_terminate
00396 Description:
00397     Terminate plugin
00398 Parameters:
00399 
00400 Returns:
00401     LCMAPS_MOD_SUCCESS : succes
00402     LCMAPS_MOD_FAIL    : failure
00403 ******************************************************************************/
00404 int plugin_terminate()
00405 {
00406     char *           logstr = "\tlcmaps_plugin_voms_localgroup-plugin_terminate()";
00407 
00408     lcmaps_log_debug(1,"%s: terminating\n", logstr);
00409 
00410     if (groupmapfile) free(groupmapfile);
00411 
00412     return LCMAPS_MOD_SUCCESS;
00413 }
00414 
00415 /******************************************************************************
00416 CVS Information:
00417     $Source: /cvs/fabric_mgt/gridification/lcmaps/modules/voms/lcmaps_voms_localgroup.c,v $
00418     $Date: 2003/08/15 13:06:32 $
00419     $Revision: 1.13 $
00420     $Author: martijn $
00421 ******************************************************************************/

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