00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00153
00154
00155
00156 #include <stdio.h>
00157 #include <stdlib.h>
00158 #include <string.h>
00159 #include <pwd.h>
00160 #include <ctype.h>
00161
00162 #include "lcmaps_config.h"
00163 #include "lcmaps_modules.h"
00164 #include "lcmaps_arguments.h"
00165 #include "lcmaps_cred_data.h"
00166 #include "lcmaps_gridlist.h"
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 static char *groupmapfile = NULL;
00181 static char *groupmapdir = NULL;
00182 static int mapall = 0;
00183 static int override_inconsistency = 0;
00184 static int mapmin = 0;
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 int plugin_initialize(
00198 int argc,
00199 char ** argv
00200 )
00201 {
00202 char * logstr = "\tlcmaps_plugin_voms_poolgroup-plugin_initialize()";
00203 int i, j;
00204
00205 lcmaps_log_debug(1,"%s: passed arguments:\n", logstr);
00206 for (i=0; i < argc; i++)
00207 {
00208 lcmaps_log_debug(2,"%s: arg %d is %s\n", logstr, i, argv[i]);
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 for (i = 1; i < argc; i++)
00219 {
00220 if ( ((strcmp(argv[i], "-groupmap") == 0) ||
00221 (strcmp(argv[i], "-GROUPMAP") == 0) ||
00222 (strcmp(argv[i], "-groupmapfile") == 0) ||
00223 (strcmp(argv[i], "-GROUPMAPFILE") == 0))
00224 && (i + 1 < argc))
00225 {
00226 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00227 {
00228 groupmapfile = strdup(argv[i + 1]);
00229 }
00230 i++;
00231 }
00232 else if ( ((strcmp(argv[i], "-groupmapdir") == 0) ||
00233 (strcmp(argv[i], "-GROUPMAPDIR") == 0))
00234 && (i + 1 < argc))
00235 {
00236 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00237 {
00238 groupmapdir = strdup(argv[i + 1]);
00239 }
00240 i++;
00241 }
00242 else if (strcmp(argv[i], "-mapall") == 0)
00243 {
00244 mapall = 1;
00245 }
00246 else if ( (strcmp(argv[i], "-override_inconsistency") == 0) ||
00247 (strcmp(argv[i], "-OVERRIDE_INCONSISTENCY") == 0))
00248 {
00249 override_inconsistency = 1;
00250 }
00251
00252 else if ((strcmp(argv[i], "-mapmin") == 0)
00253 && (i + 1 < argc))
00254 {
00255 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00256 {
00257
00258 for (j = 0; j < (strlen(argv[i + 1])); j++)
00259 {
00260 if (isdigit((argv[i + 1])[j]) == 0)
00261 {
00262 lcmaps_log(0,"%s: Error in initialization parameter: %s (%s is not a number)\n", logstr, argv[i], argv[i + 1]);
00263 return LCMAPS_MOD_FAIL;
00264 }
00265 }
00266
00267 mapmin = atoi(argv[i + 1]);
00268 }
00269 i++;
00270 }
00271
00272 else
00273 {
00274 lcmaps_log(0,"%s: Error in initialization parameter: %s (failure)\n", logstr,
00275 argv[i]);
00276 return LCMAPS_MOD_FAIL;
00277 }
00278 }
00279
00280 return LCMAPS_MOD_SUCCESS;
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 int plugin_introspect(
00294 int * argc,
00295 lcmaps_argument_t ** argv
00296 )
00297 {
00298 char * logstr = "\tlcmaps_plugin_voms_poolgroup-plugin_introspect()";
00299 static lcmaps_argument_t argList[] = {
00300 {"user_dn" , "char *" , 1, NULL},
00301 {NULL , NULL , -1, NULL}
00302 };
00303
00304 lcmaps_log_debug(1,"%s: introspecting\n", logstr);
00305
00306 *argv = argList;
00307 *argc = lcmaps_cntArgs(argList);
00308 lcmaps_log_debug(1,"%s: address first argument: 0x%x\n", logstr, argList);
00309
00310 return LCMAPS_MOD_SUCCESS;
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 int plugin_run(
00326 int argc,
00327 lcmaps_argument_t * argv
00328 )
00329 {
00330 char * logstr = "\tlcmaps_plugin_voms_poolgroup-plugin_run()";
00331 char * dn = NULL;
00332 char * groupname = NULL;
00333 struct group * group_info = NULL;
00334 int i = 0;
00335 char ** vo_cred_string_list = NULL;
00336 int cnt_vo_cred_string = 0;
00337 unsigned short matching_type = ((unsigned short)0x0000);
00338 int group_counter = 0;
00339 int rc = 0;
00340 lcmaps_vo_mapping_t * lcmaps_vo_mapping = NULL;
00341
00342
00343
00344
00345 lcmaps_log_debug(1,"%s:\n", logstr);
00346
00347
00348
00349
00350 if ( ( dn = *(char **) lcmaps_getArgValue("user_dn", "char *", argc, argv) ) )
00351 lcmaps_log_debug(1,"%s: found dn: %s\n", logstr, dn);
00352 else
00353 lcmaps_log_debug(1,"%s: could not get value of dn !\n", logstr);
00354
00355
00356
00357
00358
00359
00360 vo_cred_string_list = getCredentialData(LCMAPS_VO_CRED_STRING, &cnt_vo_cred_string);
00361 if (cnt_vo_cred_string == 0)
00362 {
00363 lcmaps_log(0,"%s: warning: no VOMS group info --> no mapping\n", logstr);
00364 goto success_voms_poolgroup;
00365 }
00366 else if (cnt_vo_cred_string < 0)
00367 {
00368 lcmaps_log(0,"%s: negative number of VOMS groups found ! (failure)\n", logstr);
00369 goto fail_voms_poolgroup;
00370 }
00371
00372
00373
00374
00375
00376 if ((groupmapfile != NULL) && (strlen(groupmapfile) > 0))
00377 lcmaps_log_debug(1,"%s: groupmapfile is: %s\n", logstr, groupmapfile);
00378 else
00379 {
00380 lcmaps_log(0,"%s: error finding the groupmapfile: %s\n", logstr, groupmapfile);
00381 lcmaps_log(0,"%s: (use the option \"-groupmapfile <groupmapfile>\")\n", logstr);
00382 goto fail_voms_poolgroup;
00383 }
00384
00385
00386
00387
00388 if (groupmapdir == NULL)
00389 {
00390 char * tmpptr=NULL;
00391 if ((tmpptr = getenv("GROUPMAPDIR")) == NULL)
00392 {
00393 lcmaps_log(0,"%s: GROUPMAPDIR unknown !\n", logstr);
00394 lcmaps_log(0,"%s: specify as option or set GROUPMAPDIR\n", logstr);
00395 goto fail_voms_poolgroup;
00396 }
00397 else
00398 {
00399 groupmapdir = strdup(tmpptr);
00400 }
00401 }
00402 if (strlen(groupmapdir) == 0)
00403 {
00404 lcmaps_log(0,"%s: cannot set MAPDIR (strlen(groupmapdir) == 0)\n", logstr);
00405 goto fail_voms_poolgroup;
00406 }
00407 lcmaps_log_debug(1,"%s: setting MAPDIR to %s\n", logstr, groupmapdir);
00408 if (setenv("MAPDIR", groupmapdir, 1))
00409 {
00410 lcmaps_log(0,"%s: cannot set MAPDIR\n", logstr);
00411 goto fail_voms_poolgroup;
00412 }
00413
00414
00415
00416
00417
00418
00419 matching_type = MATCH_INCLUDE|MATCH_WILD_CHARS;
00420
00421
00422 if (override_inconsistency)
00423 matching_type = matching_type|OVERRIDE_INCONSISTANCY;
00424
00425 for (i = 0; i < cnt_vo_cred_string; i++)
00426 {
00427 if ( (rc = lcmaps_gridlist(vo_cred_string_list[i], &groupname, groupmapfile, matching_type, ".", NULL)) == 0)
00428 {
00429 lcmaps_log_debug(1,"%s: found groupname: %s\n", logstr, groupname);
00430 group_counter++;
00431
00432 if (groupname && (strlen(groupname) > 0))
00433 {
00434 if ( ( group_info = getgrnam(groupname) ) )
00435 {
00436 if (i == 0)
00437 {
00438
00439 addCredentialData(PRI_GID, (void *) &(group_info->gr_gid));
00440 }
00441 else
00442 {
00443
00444 addCredentialData(SEC_GID, (void *) &(group_info->gr_gid));
00445 }
00446
00447
00448
00449
00450 lcmaps_vo_mapping=lcmaps_createVoMapping(
00451 vo_cred_string_list[i],
00452 groupname,
00453 group_info->gr_gid
00454 );
00455 if (! lcmaps_vo_mapping)
00456 {
00457 lcmaps_log(0,"%s: could not create VoMapping structure (failure)\n", logstr);
00458 goto fail_voms_poolgroup;
00459 }
00460
00461
00462 addCredentialData(LCMAPS_VO_CRED_MAPPING, (void *) lcmaps_vo_mapping);
00463 if ( lcmaps_deleteVoMapping(&lcmaps_vo_mapping) )
00464 {
00465 lcmaps_log(0,"%s: error while deleting VoMapping structure (failure)\n", logstr);
00466 goto fail_voms_poolgroup;
00467 }
00468 }
00469 else
00470 {
00471 lcmaps_log(0,"%s: no group id found for groupname = \"%s\"\n", logstr, groupname);
00472 goto fail_voms_poolgroup;
00473 }
00474 }
00475 else
00476 {
00477 lcmaps_log(0,"%s: error getting value of groupname (failure)!\n", logstr);
00478 goto fail_voms_poolgroup;
00479 }
00480 }
00481 else if (rc == LCMAPS_MOD_NOFILE)
00482 {
00483 lcmaps_log(0, "%s: Could not find the groupmapfile %s\n", logstr, groupmapfile);
00484 goto fail_voms_poolgroup;
00485 }
00486 else
00487 {
00488 lcmaps_log_debug(1,"%s: could not get value of groupname !\n", logstr);
00489 if (mapall)
00490 {
00491 lcmaps_log(0,"%s: no mapping for VO group %s\n", logstr,
00492 vo_cred_string_list[i]);
00493 goto fail_voms_poolgroup;
00494 }
00495 }
00496 }
00497
00498 if (group_counter < mapmin)
00499 {
00500 lcmaps_log(0,"%s: Not enough groups found. The minimum is set to %d. The plugin found %d\n", logstr, mapmin, group_counter);
00501 goto fail_voms_poolgroup;
00502 }
00503
00504
00505 success_voms_poolgroup:
00506 if (groupname) free(groupname);
00507 lcmaps_log_time(0,"%s: voms_poolgroup plugin succeeded\n", logstr);
00508 return LCMAPS_MOD_SUCCESS;
00509
00510 fail_voms_poolgroup:
00511 if (groupname) free(groupname);
00512 lcmaps_log_time(0,"%s: voms_poolgroup plugin failed\n", logstr);
00513 return LCMAPS_MOD_FAIL;
00514 }
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526 int plugin_terminate()
00527 {
00528 char * logstr = "\tlcmaps_plugin_voms_poolgroup-plugin_terminate()";
00529
00530 lcmaps_log_debug(1,"%s: terminating\n", logstr);
00531
00532 if (groupmapfile) free(groupmapfile);
00533 if (groupmapdir) free(groupmapdir);
00534
00535 return LCMAPS_MOD_SUCCESS;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544