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