00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00097
00098
00099
00100 #include <stdio.h>
00101 #include <stdlib.h>
00102 #include <string.h>
00103 #include <pwd.h>
00104
00105 #include "lcmaps_config.h"
00106 #include "lcmaps_modules.h"
00107 #include "lcmaps_arguments.h"
00108 #include "lcmaps_cred_data.h"
00109 #include "lcmaps_gridlist.h"
00110
00111
00112
00113
00114 #define LCMAPS_MAXGIDBUFFER 256
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 static char *gridmapfile = NULL;
00125 static int use_voms_gid = 0;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 int plugin_initialize(
00140 int argc,
00141 char ** argv
00142 )
00143 {
00144 char * logstr = "\tlcmaps_plugin_voms_localaccount-plugin_initialize()";
00145 int i;
00146
00147 lcmaps_log_debug(1,"%s: passed arguments:\n", logstr);
00148 for (i=0; i < argc; i++)
00149 {
00150 lcmaps_log_debug(2,"%s: arg %d is %s\n", logstr, i, argv[i]);
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 for (i = 1; i < argc; i++)
00162 {
00163 if ( ((strcmp(argv[i], "-gridmap") == 0) ||
00164 (strcmp(argv[i], "-GRIDMAP") == 0) ||
00165 (strcmp(argv[i], "-gridmapfile") == 0) ||
00166 (strcmp(argv[i], "-GRIDMAPFILE") == 0))
00167 && (i + 1 < argc))
00168 {
00169 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00170 {
00171 gridmapfile = strdup(argv[i + 1]);
00172 }
00173 i++;
00174 }
00175 else if (strcmp(argv[i], "-use_voms_gid") == 0)
00176 {
00177 use_voms_gid = 1;
00178 }
00179 else
00180 {
00181 lcmaps_log(0,"%s: Error in initialization parameter: %s (failure)\n", logstr,
00182 argv[i]);
00183 return LCMAPS_MOD_FAIL;
00184 }
00185 }
00186 return LCMAPS_MOD_SUCCESS;
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 int plugin_introspect(
00200 int * argc,
00201 lcmaps_argument_t ** argv
00202 )
00203 {
00204 char * logstr = "\tlcmaps_plugin_voms_localaccount-plugin_introspect()";
00205 static lcmaps_argument_t argList[] = {
00206 {"user_dn" , "char *" , 1, NULL},
00207 {NULL , NULL , -1, NULL}
00208 };
00209
00210 lcmaps_log_debug(1,"%s: introspecting\n", logstr);
00211
00212 *argv = argList;
00213 *argc = lcmaps_cntArgs(argList);
00214 lcmaps_log_debug(1,"%s: address first argument: 0x%x\n", logstr, argList);
00215
00216 return LCMAPS_MOD_SUCCESS;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 int plugin_run(
00232 int argc,
00233 lcmaps_argument_t * argv
00234 )
00235 {
00236 char * logstr = "\tlcmaps_plugin_voms_localaccount-plugin_run()";
00237 char * dn = NULL;
00238 char * username = NULL;
00239 struct passwd *user_info = NULL;
00240 int i = 0;
00241 int cnt_sec_gid = 0;
00242 gid_t * sec_gid = NULL;
00243 char ** vo_cred_string_list = NULL;
00244 int cnt_vo_cred_string = 0;
00245 int found = 0;
00246 unsigned short matching_type = ((unsigned short)0x0000);
00247 int rc = 0;
00248
00249
00250
00251
00252 lcmaps_log_debug(1,"%s:\n", logstr);
00253
00254
00255
00256
00257 if ( ( dn = *(char **) lcmaps_getArgValue("user_dn", "char *", argc, argv) ) )
00258 lcmaps_log_debug(1,"%s: found dn: %s\n", logstr, dn);
00259 else
00260 lcmaps_log_debug(1,"%s: could not get value of dn !\n", logstr);
00261
00262
00263
00264
00265
00266
00267 if ((gridmapfile != NULL) && (strlen(gridmapfile) > 0))
00268 lcmaps_log_debug(1,"%s: gridmapfile is: %s\n", logstr, gridmapfile);
00269 else
00270 {
00271 if (gridmapfile) free(gridmapfile);
00272 gridmapfile = NULL;
00273 lcmaps_log_debug(1,"%s: No gridmapfile assigned, so function must find out for it self\n", logstr);
00274 }
00275
00276
00277
00278
00279
00280
00281
00282 vo_cred_string_list = getCredentialData(LCMAPS_VO_CRED_STRING, &cnt_vo_cred_string);
00283 if (cnt_vo_cred_string == 0)
00284 {
00285 lcmaps_log(0,"%s: warning: no VOMS group info --> no mapping\n", logstr);
00286 goto success_voms_localaccount;
00287 }
00288 else if (cnt_vo_cred_string < 0)
00289 {
00290 lcmaps_log(0,"%s: negative number of VOMS groups found ! (failure)\n", logstr);
00291 goto fail_voms_localaccount;
00292 }
00293
00294
00295
00296
00297
00298
00299 found = 0;
00300
00301 matching_type = MATCH_EXCLUDE|MATCH_WILD_CHARS;
00302
00303 for (i = 0; i < cnt_vo_cred_string; i++)
00304 {
00305 if ( (rc = lcmaps_gridlist(vo_cred_string_list[i], &username, gridmapfile, matching_type, ".", NULL)) == 0)
00306 {
00307 found = 1;
00308 lcmaps_log_debug(1,"%s: found username: %s\n", logstr, username);
00309 break;
00310 }
00311 else if (rc == LCMAPS_MOD_NOFILE)
00312 {
00313 lcmaps_log(0, "%s: Could not find the gridmapfile %s\n", logstr, gridmapfile);
00314 goto fail_voms_localaccount;
00315 }
00316 else
00317 {
00318 lcmaps_log_debug(1, "%s: no localaccount available for group (%s) in %s\n", logstr, vo_cred_string_list[i], gridmapfile);
00319 }
00320 }
00321 if (found != 1)
00322 {
00323 lcmaps_log(0, "%s: Could not find a VOMS localaccount in %s (failure)\n", logstr, gridmapfile);
00324 goto fail_voms_localaccount;
00325 }
00326
00327
00328
00329
00330
00331 if (username && (strlen(username) > 0))
00332 {
00333
00334 if ( ( user_info = getpwnam(username) ) )
00335 {
00336 lcmaps_log_debug(2,"%s: address user_info: %p\n", logstr, user_info);
00337 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));
00338 lcmaps_log_debug(2,"%s: password : %s\n", logstr, user_info->pw_passwd, &(user_info->pw_passwd));
00339 lcmaps_log_debug(2,"%s: user_id : %d, address uid: %p\n", logstr, user_info->pw_uid, &(user_info->pw_uid));
00340 lcmaps_log_debug(2,"%s: group_id : %d\n", logstr, user_info->pw_gid);
00341 lcmaps_log_debug(2,"%s: realname : %s\n", logstr, user_info->pw_gecos);
00342 lcmaps_log_debug(2,"%s: home dir : %s\n", logstr, user_info->pw_dir);
00343 lcmaps_log_debug(2,"%s: shellprg : %s\n", logstr, user_info->pw_shell);
00344
00345
00346
00347
00348 addCredentialData(DN, &dn);
00349 addCredentialData(UID, &(user_info->pw_uid));
00350 if (use_voms_gid == 0)
00351 {
00352 lcmaps_log_debug(1,"%s: adding primary GID (%d) from local account to CredentialData\n",
00353 logstr, user_info->pw_gid);
00354 addCredentialData(PRI_GID, &(user_info->pw_gid));
00355
00356
00357
00358 if (lcmaps_get_gidlist(username, &cnt_sec_gid, &sec_gid)==0)
00359 {
00360 for (i = 0; i < cnt_sec_gid; i++)
00361 {
00362 addCredentialData(SEC_GID, &(sec_gid[i]));
00363 }
00364 free(sec_gid);
00365 }
00366 }
00367 }
00368 else
00369 {
00370 lcmaps_log(0,"%s: no user account found named \"%s\"\n", logstr, username);
00371 goto fail_voms_localaccount;
00372 }
00373 }
00374 else
00375 {
00376 goto fail_voms_localaccount;
00377 }
00378
00379
00380 success_voms_localaccount:
00381 if (username) free(username);
00382 lcmaps_log_time(0,"%s: voms_localaccount plugin succeeded\n", logstr);
00383 return LCMAPS_MOD_SUCCESS;
00384
00385 fail_voms_localaccount:
00386 if (username) free(username);
00387 lcmaps_log_time(0,"%s: voms_localaccount plugin failed\n", logstr);
00388 return LCMAPS_MOD_FAIL;
00389 }
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 int plugin_terminate()
00402 {
00403 char * logstr = "\tlcmaps_plugin_voms_localaccount-plugin_terminate()";
00404
00405 lcmaps_log_debug(1,"%s: terminating\n", logstr);
00406
00407 if (gridmapfile) free(gridmapfile);
00408
00409 return LCMAPS_MOD_SUCCESS;
00410 }
00411
00412
00413
00414
00415
00416
00417
00418