00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00129
00130
00131
00132 #include <stdio.h>
00133 #include <stdlib.h>
00134 #include <string.h>
00135 #include <pwd.h>
00136
00137 #include "lcmaps_config.h"
00138 #include "lcmaps_modules.h"
00139 #include "lcmaps_arguments.h"
00140 #include "lcmaps_cred_data.h"
00141 #include "lcmaps_gridlist.h"
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 static char *gridmapfile = NULL;
00156 static char *gridmapdir = NULL;
00157 static int override_inconsistency = 0;
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 int plugin_initialize(
00172 int argc,
00173 char ** argv
00174 )
00175 {
00176 char * logstr = "\tlcmaps_plugin_poolaccount-plugin_initialize()";
00177 int i;
00178
00179 lcmaps_log_debug(1,"%s: passed arguments:\n", logstr);
00180 for (i=0; i < argc; i++)
00181 {
00182 lcmaps_log_debug(2,"%s: arg %d is %s\n", logstr, i, argv[i]);
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 for (i = 1; i < argc; i++)
00194 {
00195 if ( ((strcmp(argv[i], "-gridmap") == 0) ||
00196 (strcmp(argv[i], "-GRIDMAP") == 0) ||
00197 (strcmp(argv[i], "-gridmapfile") == 0) ||
00198 (strcmp(argv[i], "-GRIDMAPFILE") == 0))
00199 && (i + 1 < argc))
00200 {
00201 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00202 {
00203 gridmapfile = strdup(argv[i + 1]);
00204 }
00205 i++;
00206 }
00207 else if ( ((strcmp(argv[i], "-gridmapdir") == 0) ||
00208 (strcmp(argv[i], "-GRIDMAPDIR") == 0))
00209 && (i + 1 < argc))
00210 {
00211 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00212 {
00213 gridmapdir = strdup(argv[i + 1]);
00214 }
00215 i++;
00216 }
00217 else if ( (strcmp(argv[i], "-override_inconsistency") == 0) ||
00218 (strcmp(argv[i], "-OVERRIDE_INCONSISTENCY") == 0))
00219 {
00220 override_inconsistency = 1;
00221 }
00222 else
00223 {
00224 lcmaps_log(0,"%s: Error in initialization parameter: %s (failure)\n", logstr,
00225 argv[i]);
00226 return LCMAPS_MOD_FAIL;
00227 }
00228 }
00229
00230 return LCMAPS_MOD_SUCCESS;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 int plugin_introspect(
00244 int * argc,
00245 lcmaps_argument_t ** argv
00246 )
00247 {
00248 char * logstr = "\tlcmaps_plugin_poolaccount-plugin_introspect()";
00249 static lcmaps_argument_t argList[] = {
00250 {"user_dn" , "char *" , 1, NULL},
00251 {NULL , NULL , -1, NULL}
00252 };
00253
00254 lcmaps_log_debug(1,"%s: introspecting\n", logstr);
00255
00256 *argv = argList;
00257 *argc = lcmaps_cntArgs(argList);
00258 lcmaps_log_debug(1,"%s: address first argument: 0x%x\n", logstr,argList);
00259
00260 return LCMAPS_MOD_SUCCESS;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 int plugin_run(
00276 int argc,
00277 lcmaps_argument_t * argv
00278 )
00279 {
00280 char * logstr = "\tlcmaps_plugin_poolaccount-plugin_run()";
00281 char * dn = NULL;
00282 char * username = NULL;
00283 struct passwd *user_info = NULL;
00284 int i = 0;
00285 int cnt_sec_gid = 0;
00286 gid_t * sec_gid = NULL;
00287 unsigned short matching_type = ((unsigned short)0x0000);
00288 int rc = 0;
00289
00290
00291
00292
00293 lcmaps_log_debug(1,"%s:\n", logstr);
00294
00295
00296
00297
00298 if ( ( dn = *(char **) lcmaps_getArgValue("user_dn", "char *", argc, argv) ) )
00299 lcmaps_log_debug(1,"%s: found dn: %s\n", logstr,dn);
00300 else
00301 lcmaps_log_debug(1,"%s: could not get value of dn !\n", logstr);
00302
00303
00304
00305
00306
00307
00308 if ((gridmapfile != NULL) && (strlen(gridmapfile) > 0))
00309 lcmaps_log_debug(1,"%s: gridmapfile is: %s\n", logstr, gridmapfile);
00310 else
00311 {
00312 if (gridmapfile) free(gridmapfile);
00313 gridmapfile = NULL;
00314 lcmaps_log_debug(1,"%s: No gridmapfile assigned, so function must find out for it self\n",
00315 logstr);
00316 }
00317
00318
00319
00320
00321 if (gridmapdir == NULL)
00322 {
00323 char * tmpptr=NULL;
00324 if ((tmpptr = getenv("GRIDMAPDIR")) == NULL)
00325 {
00326 lcmaps_log(0,"%s: GRIDMAPDIR unknown !\n", logstr);
00327 lcmaps_log(0,"%s: specify as option or set GRIDMAPDIR\n", logstr);
00328 goto fail_poolaccount;
00329 }
00330 else
00331 {
00332 gridmapdir = strdup(tmpptr);
00333 }
00334 }
00335 if (strlen(gridmapdir) == 0)
00336 {
00337 lcmaps_log(0,"%s: cannot set MAPDIR (strlen(gridmapdir) == 0)\n", logstr);
00338 goto fail_poolaccount;
00339 }
00340 lcmaps_log_debug(1,"%s: setting MAPDIR to %s\n", logstr, gridmapdir);
00341 if (setenv("MAPDIR", gridmapdir, 1))
00342 {
00343 lcmaps_log(0,"%s: cannot set MAPDIR\n", logstr);
00344 goto fail_poolaccount;
00345 }
00346
00347
00348
00349
00350 matching_type = MATCH_INCLUDE|MATCH_NO_WILD_CHARS;
00351
00352
00353 if (override_inconsistency)
00354 matching_type = matching_type|OVERRIDE_INCONSISTANCY;
00355
00356 if ( (rc = lcmaps_gridlist(dn, &username, gridmapfile, matching_type, ".", NULL)) == LCMAPS_MOD_SUCCESS)
00357 lcmaps_log_debug(1,"%s: found username: %s\n", logstr, username);
00358 else if (rc == LCMAPS_MOD_NOFILE)
00359 {
00360 lcmaps_log(0, "%s: Could not find the gridmapfile %s\n", logstr, gridmapfile);
00361 goto fail_poolaccount;
00362 }
00363 else if (rc == LCMAPS_MOD_NOENTRY)
00364 {
00365 lcmaps_log_debug(1, "%s: No entry found for %s in %s\n", logstr, dn, gridmapfile);
00366 goto fail_poolaccount;
00367 }
00368 else
00369 {
00370 lcmaps_log_debug(1,"%s: could not get value of username !\n", logstr);
00371 goto fail_poolaccount;
00372 }
00373
00374
00375
00376
00377
00378 if (username && (strlen(username) > 0))
00379 {
00380
00381 if ( ( user_info = getpwnam(username) ) )
00382 {
00383 char * encoded_dn = NULL;
00384
00385 lcmaps_log_debug(2,"%s: address user_info: %p\n", logstr, user_info);
00386 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));
00387 lcmaps_log_debug(2,"%s: password : %s\n", logstr, user_info->pw_passwd, &(user_info->pw_passwd));
00388 lcmaps_log_debug(2,"%s: user_id : %d, address uid: %p\n", logstr, user_info->pw_uid, &(user_info->pw_uid));
00389 lcmaps_log_debug(2,"%s: group_id : %d\n", logstr, user_info->pw_gid);
00390 lcmaps_log_debug(2,"%s: realname : %s\n", logstr, user_info->pw_gecos);
00391 lcmaps_log_debug(2,"%s: home dir : %s\n", logstr, user_info->pw_dir);
00392 lcmaps_log_debug(2,"%s: shellprg : %s\n", logstr, user_info->pw_shell);
00393
00394
00395
00396
00397 addCredentialData(DN, &dn);
00398 addCredentialData(UID, &(user_info->pw_uid));
00399 addCredentialData(PRI_GID, &(user_info->pw_gid));
00400
00401
00402
00403
00404 if (lcmaps_get_gidlist(username, &cnt_sec_gid, &sec_gid)==0)
00405 {
00406 for (i = 0; i < cnt_sec_gid; i++)
00407 {
00408 addCredentialData(SEC_GID, &(sec_gid[i]));
00409 }
00410 free(sec_gid);
00411 }
00412
00413
00414 encoded_dn = gridmapdir_urlencode(dn);
00415 lcmaps_log_a_string_debug(3, "\tlcmaps_plugin_poolaccount-plugin_run(): found encoded DN: %s\n", encoded_dn);
00416 addCredentialData(POOL_INDEX, &encoded_dn);
00417 if (encoded_dn)
00418 {
00419 free(encoded_dn);
00420 encoded_dn = NULL;
00421 }
00422 }
00423 else
00424 {
00425 lcmaps_log(0,"%s: no user account found name \"%s\"\n", logstr, username);
00426 goto fail_poolaccount;
00427 }
00428 }
00429 else
00430 {
00431 goto fail_poolaccount;
00432 }
00433
00434
00435 success_poolaccount:
00436 if (username) free(username);
00437 lcmaps_log_time(0,"%s: poolaccount plugin succeeded\n", logstr);
00438 return LCMAPS_MOD_SUCCESS;
00439
00440 fail_poolaccount:
00441 if (username) free(username);
00442 lcmaps_log_time(0,"%s: poolaccount plugin failed\n", logstr);
00443 return LCMAPS_MOD_FAIL;
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 int plugin_terminate()
00457 {
00458 char * logstr = "\tlcmaps_plugin_poolaccount-plugin_terminate()";
00459 lcmaps_log_debug(1,"%s: terminating\n", logstr);
00460
00461 if (gridmapfile) free(gridmapfile);
00462 if (gridmapdir) free(gridmapdir);
00463
00464 return LCMAPS_MOD_SUCCESS;
00465 }
00466
00467
00468
00469
00470
00471
00472
00473