00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00087 
00088 
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 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 static char *gridmapfile = NULL;
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
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 
00144 
00145 
00146 
00147     
00148 
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 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
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 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
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 
00232 
00233     lcmaps_log_debug(1,"%s:\n", logstr);
00234 
00235     
00236 
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 
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 
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 
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 
00301 
00302             addCredentialData(DN,  &dn);
00303             addCredentialData(UID, &(user_info->pw_uid));
00304             addCredentialData(PRI_GID, &(user_info->pw_gid));
00305 
00306             
00307 
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     {   
00326         goto fail_localaccount;
00327     }
00328 
00329     
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 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
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 
00364 
00365 
00366 
00367 
00368