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

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