00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00080
00081
00082
00083 #include <stdio.h>
00084 #include <stdlib.h>
00085 #include <string.h>
00086 #include <pwd.h>
00087
00088 #include "lcmaps_config.h"
00089 #include "lcmaps_modules.h"
00090 #include "lcmaps_arguments.h"
00091 #include "lcmaps_cred_data.h"
00092 #include "lcmaps_gridlist.h"
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 static char *gridmapfile = NULL;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 int plugin_initialize(
00122 int argc,
00123 char ** argv
00124 )
00125 {
00126 char * logstr = "\tlcmaps_plugin_localaccount-plugin_initialize()";
00127 int i;
00128
00129 lcmaps_log_debug(2,"%s: passed arguments:\n",logstr);
00130 for (i=0; i < argc; i++)
00131 {
00132 lcmaps_log_debug(2,"%s: arg %d is %s\n", logstr, i, argv[i]);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 for (i = 1; i < argc; i++)
00144 {
00145 if ( ((strcmp(argv[i], "-gridmap") == 0) ||
00146 (strcmp(argv[i], "-GRIDMAP") == 0) ||
00147 (strcmp(argv[i], "-gridmapfile") == 0) ||
00148 (strcmp(argv[i], "-GRIDMAPFILE") == 0))
00149 && (i + 1 < argc))
00150 {
00151 if ((argv[i + 1] != NULL) && (strlen(argv[i + 1]) > 0))
00152 {
00153 gridmapfile = strdup(argv[i + 1]);
00154 }
00155 i++;
00156 }
00157 else
00158 {
00159 lcmaps_log(0,"%s: Error in initialization parameter: %s (failure)\n", logstr, argv[i]);
00160 return LCMAPS_MOD_FAIL;
00161 }
00162 }
00163
00164 return LCMAPS_MOD_SUCCESS;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 int plugin_introspect(
00178 int * argc,
00179 lcmaps_argument_t ** argv
00180 )
00181 {
00182 char * logstr = "\tlcmaps_plugin_localaccount-plugin_introspect()";
00183 static lcmaps_argument_t argList[] = {
00184 {"user_dn" , "char *" , 1, NULL},
00185 {NULL , NULL , -1, NULL}
00186 };
00187
00188 lcmaps_log_debug(1,"%s: introspecting\n", logstr);
00189
00190 *argv = argList;
00191 *argc = lcmaps_cntArgs(argList);
00192 lcmaps_log_debug(1,"%s: address first argument: 0x%x\n", logstr, argList);
00193
00194 return LCMAPS_MOD_SUCCESS;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 int plugin_run(
00210 int argc,
00211 lcmaps_argument_t * argv
00212 )
00213 {
00214 char * logstr = "\tlcmaps_plugin_localaccount-plugin_run()";
00215 char * dn = NULL;
00216 char * username = NULL;
00217 struct passwd *user_info = NULL;
00218 int i = 0;
00219 int cnt_sec_gid = 0;
00220 gid_t * sec_gid = NULL;
00221 int rc = 0;
00222
00223
00224
00225
00226 lcmaps_log_debug(1,"%s:\n", logstr);
00227
00228
00229
00230
00231 if ( ( dn = *(char **) lcmaps_getArgValue("user_dn", "char *", argc, argv) ) )
00232 lcmaps_log_debug(1,"%s: found dn: %s\n", logstr, dn);
00233 else
00234 lcmaps_log_debug(1,"%s: could not get value of dn !\n", logstr);
00235
00236
00237
00238
00239
00240
00241 if ((gridmapfile != NULL) && (strlen(gridmapfile) > 0))
00242 lcmaps_log_debug(1,"%s: gridmapfile is: %s\n", logstr, gridmapfile);
00243 else
00244 {
00245 if (gridmapfile) free(gridmapfile);
00246 gridmapfile = NULL;
00247 lcmaps_log_debug(1,"%s: No gridmapfile assigned, so function must find out for it self\n", logstr);
00248 }
00249
00250
00251
00252
00253
00254
00255 if ( (rc = lcmaps_gridlist(dn, &username, gridmapfile, MATCH_EXCLUDE|MATCH_NO_WILD_CHARS, ".", NULL)) == LCMAPS_MOD_SUCCESS)
00256 lcmaps_log_debug(1,"%s: found username: %s\n", logstr, username);
00257 else if (rc == LCMAPS_MOD_NOFILE)
00258 {
00259 lcmaps_log(0, "%s: Could not find the gridmapfile %s\n", logstr, gridmapfile);
00260 goto fail_localaccount;
00261 }
00262 else if (rc == LCMAPS_MOD_NOENTRY)
00263 {
00264 lcmaps_log_debug(1, "%s: No entry found for %s in %s\n", logstr, dn, gridmapfile);
00265 goto fail_localaccount;
00266 }
00267 else
00268 {
00269 lcmaps_log_debug(1,"%s: could not get value of username !\n", logstr);
00270 goto fail_localaccount;
00271 }
00272
00273
00274
00275
00276
00277
00278 if (username && (strlen(username) > 0))
00279 {
00280
00281 if ( ( user_info = getpwnam(username) ) )
00282 {
00283 lcmaps_log_debug(2,"%s: address user_info: %p\n", logstr, user_info);
00284 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));
00285 lcmaps_log_debug(2,"%s: password : %s\n", logstr, user_info->pw_passwd, &(user_info->pw_passwd));
00286 lcmaps_log_debug(2,"%s: user_id : %d, address uid: %p\n", logstr, user_info->pw_uid);
00287 lcmaps_log_debug(2,"%s: group_id : %d\n", logstr, user_info->pw_gid);
00288 lcmaps_log_debug(2,"%s: realname : %s\n", logstr, user_info->pw_gecos);
00289 lcmaps_log_debug(2,"%s: home dir : %s\n", logstr, user_info->pw_dir);
00290 lcmaps_log_debug(2,"%s: shellprg : %s\n", logstr, user_info->pw_shell);
00291
00292
00293
00294
00295 addCredentialData(DN, &dn);
00296 addCredentialData(UID, &(user_info->pw_uid));
00297 addCredentialData(PRI_GID, &(user_info->pw_gid));
00298
00299
00300
00301
00302 if (lcmaps_get_gidlist(username, &cnt_sec_gid, &sec_gid)==0)
00303 {
00304 for (i = 0; i < cnt_sec_gid; i++)
00305 {
00306 addCredentialData(SEC_GID, &(sec_gid[i]));
00307 }
00308 free(sec_gid);
00309 }
00310 }
00311 else
00312 {
00313 lcmaps_log(0,"%s: no user account found name \"%s\"\n", logstr,username);
00314 goto fail_localaccount;
00315 }
00316 }
00317 else
00318 {
00319 goto fail_localaccount;
00320 }
00321
00322
00323 success_localaccount:
00324 if (username) free(username);
00325 lcmaps_log_time(0,"%s: localaccount plugin succeeded\n", logstr);
00326 return LCMAPS_MOD_SUCCESS;
00327
00328 fail_localaccount:
00329 if (username) free(username);
00330 lcmaps_log_time(0,"%s: localaccount plugin failed\n", logstr);
00331 return LCMAPS_MOD_FAIL;
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 int plugin_terminate()
00345 {
00346 char * logstr = "\tlcmaps_plugin_localaccount-plugin_terminate()";
00347
00348 lcmaps_log_debug(1,"%s: terminating\n", logstr);
00349
00350 if (gridmapfile) free(gridmapfile);
00351
00352 return LCMAPS_MOD_SUCCESS;
00353 }
00354
00355
00356
00357
00358
00359
00360
00361