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

lcmaps_localaccount.c

Go to the documentation of this file.
00001 /*                                                                                                            
00002  * Copyright (c) Members of the EGEE Collaboration. 2004.
00003  * See http://eu-egee.org/partners/ for details on the copyright holders.
00004  * For license conditions see the license file or
00005  * http://eu-egee.org/license.html
00006  */
00007 
00008 /*
00009  * Copyright (c) 2001 EU DataGrid.
00010  * For license conditions see http://www.eu-datagrid.org/license.html
00011  *
00012  * Copyright (c) 2001, 2002 by
00013  *     Martijn Steenbakkers <martijn@nikhef.nl>,
00014  *     David Groep <davidg@nikhef.nl>,
00015  *     NIKHEF Amsterdam, the Netherlands
00016  */
00017 
00087 /*****************************************************************************
00088                             Include header files
00089 ******************************************************************************/
00090 #include <stdio.h>
00091 #include <stdlib.h>
00092 #include <string.h>
00093 #include <pwd.h>
00094 
00095 #include "lcmaps_config.h"
00096 #include "lcmaps_modules.h"
00097 #include "lcmaps_arguments.h"
00098 #include "lcmaps_cred_data.h"
00099 #include "lcmaps_gridlist.h"
00100 
00101 /******************************************************************************
00102                                 Definitions
00103 ******************************************************************************/
00104 
00105 /******************************************************************************
00106                           Module specific prototypes
00107 ******************************************************************************/
00108 
00109 /******************************************************************************
00110                        Define module specific variables
00111 ******************************************************************************/
00112 
00113 static char *gridmapfile = NULL;
00114 
00115 
00116 /******************************************************************************
00117 Function:   plugin_initialize
00118 Description:
00119     Initialize plugin
00120 Parameters:
00121     argc, argv
00122     argv[0]: the name of the plugin
00123 Returns:
00124     LCMAPS_MOD_SUCCESS : succes
00125     LCMAPS_MOD_FAIL    : failure
00126     LCMAPS_MOD_NOFILE  : db file not found (will halt LCMAPS initialization)
00127 ******************************************************************************/
00128 int plugin_initialize(
00129         int argc,
00130         char ** argv
00131 )
00132 {
00133     char * logstr = "\tlcmaps_plugin_localaccount-plugin_initialize()";
00134     int i;
00135 
00136     lcmaps_log_debug(2,"%s: passed arguments:\n",logstr);
00137     for (i=0; i < argc; i++)
00138     {
00139        lcmaps_log_debug(2,"%s: arg %d is %s\n", logstr, i, argv[i]);
00140     }
00141 
00142     /*
00143      * the first will be the thing to edit/select (gridmap(file))
00144      * the second will be the path && filename of the gridmapfile
00145      */
00146 
00147     /*
00148      * Parse arguments, argv[0] = name of plugin, so start with i = 1
00149      */
00150     for (i = 1; i < argc; i++)
00151     {
00152         if ( ((strcmp(argv[i], "-gridmap") == 0) ||
00153               (strcmp(argv[i], "-GRIDMAP") == 0) ||
00154               (strcmp(argv[i], "-gridmapfile") == 0) ||
00155               (strcmp(argv[i], "-GRIDMAPFILE") == 0))
00156              && (i + 1 < argc))
00157         {
00158             if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00159             {
00160                  gridmapfile = strdup(argv[i + 1]);
00161             }
00162             i++;
00163         }
00164         else
00165         {
00166             lcmaps_log(0,"%s: Error in initialization parameter: %s (failure)\n", logstr, argv[i]);
00167             return LCMAPS_MOD_FAIL;
00168         }
00169     }
00170 
00171     return LCMAPS_MOD_SUCCESS;
00172 } 
00173 
00174 /******************************************************************************
00175 Function:   plugin_introspect
00176 Description:
00177     return list of required arguments
00178 Parameters:
00179 
00180 Returns:
00181     LCMAPS_MOD_SUCCESS : succes
00182     LCMAPS_MOD_FAIL    : failure
00183 ******************************************************************************/
00184 int plugin_introspect(
00185         int * argc,
00186         lcmaps_argument_t ** argv
00187 )
00188 {
00189     char * logstr = "\tlcmaps_plugin_localaccount-plugin_introspect()";
00190     static lcmaps_argument_t argList[] = {
00191         {"user_dn"      ,       "char *"        , 1,   NULL},
00192         {NULL           ,       NULL            , -1,   NULL}
00193     };
00194 
00195     lcmaps_log_debug(1,"%s: introspecting\n", logstr);
00196 
00197     *argv = argList;
00198     *argc = lcmaps_cntArgs(argList);
00199     lcmaps_log_debug(1,"%s: address first argument: 0x%x\n", logstr, argList);
00200 
00201     return LCMAPS_MOD_SUCCESS;
00202 }
00203 
00204 
00205 /******************************************************************************
00206 Function:   plugin_run
00207 Description:
00208     Gather credentials for LCMAPS
00209 Parameters:
00210     argc: number of arguments
00211     argv: list of arguments
00212 Returns:
00213     LCMAPS_MOD_SUCCESS: authorization succeeded
00214     LCMAPS_MOD_FAIL   : authorization failed
00215 ******************************************************************************/
00216 int plugin_run(
00217         int argc,
00218         lcmaps_argument_t * argv
00219 )
00220 {
00221     char *              logstr = "\tlcmaps_plugin_localaccount-plugin_run()";
00222     char *              dn          = NULL; 
00223     char *              username    = NULL;
00224     struct passwd       *user_info  = NULL;
00225     int                 i           = 0;
00226     int                 cnt_sec_gid = 0;
00227     gid_t *             sec_gid     = NULL;
00228     int                 rc          = 0;
00229      
00230     /*
00231      * The beginning
00232      */
00233     lcmaps_log_debug(1,"%s:\n", logstr);
00234 
00235     /*
00236      * Try to get the ordered values:
00237      */
00238     if ( ( dn = *(char **) lcmaps_getArgValue("user_dn", "char *", argc, argv) ) )
00239         lcmaps_log_debug(1,"%s: found dn: %s\n", logstr, dn);
00240     else
00241         lcmaps_log_debug(1,"%s: could not get value of dn !\n", logstr);
00242 
00243 
00244     /*
00245      * Check the gridmapfile
00246      */
00247 
00248     if ((gridmapfile != NULL) && (strlen(gridmapfile) > 0))
00249         lcmaps_log_debug(1,"%s: gridmapfile is: %s\n", logstr, gridmapfile);
00250     else
00251     {
00252         if (gridmapfile) free(gridmapfile);
00253         gridmapfile = NULL;
00254         lcmaps_log_debug(1,"%s: No gridmapfile assigned, so function must find out for it self\n", logstr);
00255     }
00256 
00257     /*
00258      * Try to find the dn in the gridmapfile
00259      */
00260 
00261 
00262     if ( (rc = lcmaps_gridlist(dn, &username, gridmapfile, MATCH_EXCLUDE|MATCH_NO_WILD_CHARS, ".", NULL)) == LCMAPS_MOD_SUCCESS)
00263         lcmaps_log_debug(1,"%s: found username: %s\n", logstr, username);
00264     else if (rc == LCMAPS_MOD_NOFILE)
00265     {
00266         lcmaps_log(0, "%s: Could not find the gridmapfile %s\n", logstr, gridmapfile);
00267         goto fail_localaccount;
00268     }
00269     else if (rc == LCMAPS_MOD_NOENTRY)
00270     {
00271         lcmaps_log_debug(1, "%s: No entry found for %s in %s\n", logstr, dn, gridmapfile);
00272         goto fail_localaccount;
00273     }
00274     else
00275     {
00276         lcmaps_log_debug(1,"%s: could not get value of username !\n", logstr);
00277         goto fail_localaccount;
00278     }
00279 
00280     /*
00281      * Get userid to pwd_t structure
00282      */
00283 
00284 
00285     if (username && (strlen(username) > 0))
00286     {
00287 
00288         if ( ( user_info = getpwnam(username) ) )
00289         {
00290             lcmaps_log_debug(2,"%s: address user_info: %p\n", logstr, user_info);
00291             lcmaps_log_debug(2,"%s: username : %s, char ptr: %p, address char ptr: %p\n", logstr, user_info->pw_name, user_info->pw_name, &(user_info->pw_name));
00292             lcmaps_log_debug(2,"%s: password : %s\n", logstr, user_info->pw_passwd);
00293             lcmaps_log_debug(2,"%s: user_id  : %d, address uid: %p\n", logstr, user_info->pw_uid, &(user_info->pw_uid));
00294             lcmaps_log_debug(2,"%s: group_id : %d\n", logstr, user_info->pw_gid);
00295             lcmaps_log_debug(2,"%s: realname : %s\n", logstr, user_info->pw_gecos);
00296             lcmaps_log_debug(2,"%s: home dir : %s\n", logstr, user_info->pw_dir);
00297             lcmaps_log_debug(2,"%s: shellprg : %s\n", logstr, user_info->pw_shell);
00298 
00299             /* 
00300              * Add this credential data to the credential data repository in the plugin manager
00301              */
00302             addCredentialData(DN,  &dn);
00303             addCredentialData(UID, &(user_info->pw_uid));
00304             addCredentialData(PRI_GID, &(user_info->pw_gid));
00305 
00306             /*
00307              * Retrieve secondary group id's
00308              */
00309             if (lcmaps_get_gidlist(username, &cnt_sec_gid, &sec_gid)==0)
00310             {
00311                 for (i = 0; i < cnt_sec_gid; i++)
00312                 {
00313                     addCredentialData(SEC_GID, &(sec_gid[i]));
00314                 }
00315                 free(sec_gid);
00316             }
00317         }
00318         else
00319         {
00320             lcmaps_log(0,"%s: no user account found name \"%s\"\n", logstr,username);
00321             goto fail_localaccount;
00322         }
00323     }
00324     else
00325     {   // error (msg is already given)
00326         goto fail_localaccount;
00327     }
00328 
00329     /* succes */
00330  success_localaccount:
00331     if (username) free(username);
00332     lcmaps_log_time(0,"%s: localaccount plugin succeeded\n", logstr);
00333     return LCMAPS_MOD_SUCCESS;
00334 
00335  fail_localaccount:
00336     if (username) free(username);
00337     lcmaps_log_time(0,"%s: localaccount plugin failed\n", logstr);
00338     return LCMAPS_MOD_FAIL;
00339 }
00340 
00341 /******************************************************************************
00342 Function:   plugin_terminate
00343 Description:
00344     Terminate plugin
00345 Parameters:
00346 
00347 Returns:
00348     LCMAPS_MOD_SUCCESS : succes
00349     LCMAPS_MOD_FAIL    : failure
00350 ******************************************************************************/
00351 int plugin_terminate()
00352 {
00353     char *              logstr = "\tlcmaps_plugin_localaccount-plugin_terminate()";
00354 
00355     lcmaps_log_debug(1,"%s: terminating\n", logstr);
00356 
00357     if (gridmapfile) free(gridmapfile);
00358 
00359     return LCMAPS_MOD_SUCCESS;
00360 }
00361 
00362 /******************************************************************************
00363 CVS Information:
00364     $Source: /cvs/jra1mw/org.glite.security.lcmaps-plugins-basic/src/localaccount/lcmaps_localaccount.c,v $
00365     $Date: 2005/02/27 01:30:41 $
00366     $Revision: 1.4 $
00367     $Author: msteenba $
00368 ******************************************************************************/

Generated on Sun May 29 21:22:10 2005 for lcmaps by doxygen 1.3.5