00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00057 #include "lcmaps_config.h"
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 #include <string.h>
00061 #include <gssapi.h>
00062
00063
00064 #include "pluginmanager/_lcmaps_pluginmanager.h"
00065 #include "pluginmanager/_lcmaps_log.h"
00066 #include "lcmaps_types.h"
00067 #include "lcmaps_utils.h"
00068 #include "pluginmanager/_lcmaps_utils.h"
00069 #include "lcmaps_cred_data.h"
00070
00071
00072
00073
00074 static lcmaps_cred_id_t lcmaps_cred;
00075 static int lcmaps_initialized = 0;
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00104 int lcmaps_init(
00105 FILE* fp
00106 )
00107 {
00108 if (lcmaps_initialized)
00109 {
00110 if (lcmaps_log(0,"LCMAPS already initialized\n") != 0)
00111 {
00112 fprintf(stderr,"LCMAPS already initialized, but wrongly\n");
00113 goto fail_lcmaps_init;
00114 }
00115 return 0;
00116 }
00117
00118
00119
00120 if (lcmaps_log_open(NULL,fp,DO_USRLOG)) goto fail_lcmaps_init;
00121 lcmaps_log_debug(0,"\n");
00122 lcmaps_log_time(LOG_NOTICE,"Initialization LCMAPS version %s\n",VERSION);
00123
00124
00125 if (startPluginManager()) {
00126 lcmaps_log(0,"lcmaps.mod-lcmaps_init() error: could not start plugin manager\n");
00127 goto fail_lcmaps_init;
00128 }
00129
00130
00131 lcmaps_initialized++;
00132 return 0;
00133
00134 fail_lcmaps_init:
00135 return 1;
00136
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00167 #if ALLOW_EMPTY_CREDENTIALS
00168 int lcmaps_run(
00169 char * user_dn_tmp,
00170 gss_cred_id_t user_cred,
00171 lcmaps_request_t request
00172 )
00173 #else
00174 int lcmaps_run(
00175 gss_cred_id_t user_cred,
00176 lcmaps_request_t request
00177 )
00178 #endif
00179 {
00180 char * user_dn = NULL;
00181
00182 if (lcmaps_initialized == 0)
00183 {
00184 fprintf(stderr,"LCMAPS has to be initialized first !\n");
00185 goto fail_lcmaps_run;
00186 }
00187
00188
00189
00190
00191 if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00192 {
00193 lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not create lcmaps credential, something wrong\n");
00194 lcmaps_log(0," : with user DN and user credential\n");
00195 goto fail_lcmaps_run;
00196 }
00197 user_dn = lcmaps_get_dn(lcmaps_cred);
00198 if (user_dn == NULL)
00199 {
00200 lcmaps_log(0, "lcmaps.mod-lcmaps_run() error: user DN empty\n");
00201 goto fail_lcmaps_run;
00202 }
00203
00204
00205 if (runPluginManager(request, lcmaps_cred)) {
00206 lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not run plugin manager\n");
00207 goto fail_lcmaps_run;
00208 }
00209
00210
00211 lcmaps_release_cred(&lcmaps_cred);
00212 lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): succeeded\n");
00213 return 0;
00214
00215 fail_lcmaps_run:
00216 lcmaps_release_cred(&lcmaps_cred);
00217 lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): failed\n");
00218 return 1;
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00251 #if ALLOW_EMPTY_CREDENTIALS
00252 int lcmaps_run_and_return_username(
00253 char * user_dn_tmp,
00254 gss_cred_id_t user_cred,
00255 lcmaps_request_t request,
00256 char ** usernamep
00257 )
00258 #else
00259 int lcmaps_run_and_return_username(
00260 gss_cred_id_t user_cred,
00261 lcmaps_request_t request,
00262 char ** usernamep
00263 )
00264 #endif
00265 {
00266 uid_t * uid;
00267 int cntUid;
00268 struct passwd * user_info = NULL;
00269
00270 int retval = 0;
00271
00272 fprintf(stderr,"Using lcmaps_run_and_return_username interface of LCMAPS\n");
00273 if (usernamep == NULL)
00274 return 1;
00275
00276 *usernamep = NULL;
00277
00278 #if ALLOW_EMPTY_CREDENTIALS
00279 retval = lcmaps_run(user_dn_tmp, user_cred, request);
00280 #else
00281 retval = lcmaps_run(user_cred, request);
00282 #endif
00283 if (retval != 0)
00284 {
00285 fprintf(stderr,"LCMAPS failed to map the user credential\n");
00286 return 1;
00287 }
00288
00289
00290
00291
00292
00293
00294 uid = getCredentialData(UID, &cntUid);
00295 if (uid)
00296 {
00297 if ( (user_info = getpwuid(uid[0])) == NULL )
00298 {
00299 fprintf(stderr,"LCMAPS could not find the username related to uid: %d\n",uid[0]);
00300 return 1;
00301 }
00302 (*usernamep) = strdup(user_info->pw_name);
00303 }
00304 else
00305 {
00306 fprintf(stderr,"LCMAPS could not find any uid\n");
00307 return 1;
00308 }
00309
00310 return 0;
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00337 int lcmaps_run_without_credentials(
00338 char * user_dn_tmp
00339 )
00340 {
00341 gss_cred_id_t user_cred = GSS_C_NO_CREDENTIAL;
00342 lcmaps_request_t request = (lcmaps_request_t) NULL;
00343 char * user_dn = NULL;
00344
00345 if (lcmaps_initialized == 0)
00346 {
00347 fprintf(stderr,"LCMAPS has to be initialized first !\n");
00348 goto fail_lcmaps_run_without_credentials;
00349 }
00350
00351
00352
00353
00354 if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00355 {
00356 lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not create lcmaps credential, something wrong\n");
00357 lcmaps_log(0," : with user DN and user credential\n");
00358 goto fail_lcmaps_run_without_credentials;
00359 }
00360 user_dn = lcmaps_get_dn(lcmaps_cred);
00361 if (user_dn == NULL)
00362 {
00363 lcmaps_log(0, "lcmaps.mod-lcmaps_run_without_credentials() error: user DN empty\n");
00364 goto fail_lcmaps_run_without_credentials;
00365 }
00366
00367
00368 if (runPluginManager(request, lcmaps_cred)) {
00369 lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not run plugin manager\n");
00370 goto fail_lcmaps_run_without_credentials;
00371 }
00372
00373
00374 lcmaps_release_cred(&lcmaps_cred);
00375 lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): succeeded\n");
00376 return 0;
00377
00378 fail_lcmaps_run_without_credentials:
00379 lcmaps_release_cred(&lcmaps_cred);
00380 lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): failed\n");
00381 return 1;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00406 int lcmaps_term()
00407 {
00408 lcmaps_log_time(0,"lcmaps.mod-lcmaps_term(): terminating\n");
00409 return stopPluginManager();
00410 }
00411
00412
00413
00414
00415
00416
00417
00418