00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00053 #include "lcmaps_config.h"
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include <gssapi.h>
00058
00059
00060 #include "pluginmanager/_lcmaps_pluginmanager.h"
00061 #include "pluginmanager/_lcmaps_log.h"
00062 #include "lcmaps_types.h"
00063 #include "lcmaps_utils.h"
00064
00065
00066
00067
00068 static lcmaps_cred_id_t lcmaps_cred;
00069 static int lcmaps_initialized = 0;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00098 int lcmaps_init(
00099 FILE* fp
00100 )
00101 {
00102 if (lcmaps_initialized)
00103 {
00104 if (lcmaps_log(0,"LCMAPS already initialized\n") != 0)
00105 {
00106 fprintf(stderr,"LCMAPS already initialized, but wrongly\n");
00107 goto fail_lcmaps_init;
00108 }
00109 return 0;
00110 }
00111
00112
00113
00114 if (lcmaps_log_open(NULL,fp,DO_USRLOG)) goto fail_lcmaps_init;
00115 lcmaps_log_debug(0,"\n");
00116 lcmaps_log_time(LOG_NOTICE,"Initialization LCMAPS version %s\n",VERSION);
00117
00118
00119 if (startPluginManager()) {
00120 lcmaps_log(0,"lcmaps.mod-lcmaps_init() error: could not start plugin manager\n");
00121 goto fail_lcmaps_init;
00122 }
00123
00124
00125 lcmaps_initialized++;
00126 return 0;
00127
00128 fail_lcmaps_init:
00129 return 1;
00130
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00161 #if ALLOW_EMPTY_CREDENTIALS
00162 int lcmaps_run(
00163 char * user_dn_tmp,
00164 gss_cred_id_t user_cred,
00165 lcmaps_request_t request
00166 )
00167 #else
00168 int lcmaps_run(
00169 gss_cred_id_t user_cred,
00170 lcmaps_request_t request
00171 )
00172 #endif
00173 {
00174 char * user_dn = NULL;
00175
00176 if (lcmaps_initialized == 0)
00177 {
00178 fprintf(stderr,"LCMAPS has to be initialized first !\n");
00179 goto fail_lcmaps_run;
00180 }
00181
00182
00183
00184
00185 if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00186 {
00187 lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not create lcmaps credential, something wrong\n");
00188 lcmaps_log(0," : with user DN and user credential\n");
00189 goto fail_lcmaps_run;
00190 }
00191 user_dn = lcmaps_get_dn(lcmaps_cred);
00192 if (user_dn == NULL)
00193 {
00194 lcmaps_log(0, "lcmaps.mod-lcmaps_run() error: user DN empty\n");
00195 goto fail_lcmaps_run;
00196 }
00197
00198
00199 if (runPluginManager(request, lcmaps_cred)) {
00200 lcmaps_log(0,"lcmaps.mod-lcmaps_run() error: could not run plugin manager\n");
00201 goto fail_lcmaps_run;
00202 }
00203
00204
00205 lcmaps_release_cred(&lcmaps_cred);
00206 lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): succeeded\n");
00207 return 0;
00208
00209 fail_lcmaps_run:
00210 lcmaps_release_cred(&lcmaps_cred);
00211 lcmaps_log_time(0,"lcmaps.mod-lcmaps_run(): failed\n");
00212 return 1;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00239 int lcmaps_run_without_credentials(
00240 char * user_dn_tmp
00241 )
00242 {
00243 gss_cred_id_t user_cred = GSS_C_NO_CREDENTIAL;
00244 lcmaps_request_t request = (lcmaps_request_t) NULL;
00245 char * user_dn = NULL;
00246
00247 if (lcmaps_initialized == 0)
00248 {
00249 fprintf(stderr,"LCMAPS has to be initialized first !\n");
00250 goto fail_lcmaps_run_without_credentials;
00251 }
00252
00253
00254
00255
00256 if ( lcmaps_fill_cred(user_dn_tmp, user_cred, &lcmaps_cred) != 0)
00257 {
00258 lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not create lcmaps credential, something wrong\n");
00259 lcmaps_log(0," : with user DN and user credential\n");
00260 goto fail_lcmaps_run_without_credentials;
00261 }
00262 user_dn = lcmaps_get_dn(lcmaps_cred);
00263 if (user_dn == NULL)
00264 {
00265 lcmaps_log(0, "lcmaps.mod-lcmaps_run_without_credentials() error: user DN empty\n");
00266 goto fail_lcmaps_run_without_credentials;
00267 }
00268
00269
00270 if (runPluginManager(request, lcmaps_cred)) {
00271 lcmaps_log(0,"lcmaps.mod-lcmaps_run_without_credentials() error: could not run plugin manager\n");
00272 goto fail_lcmaps_run_without_credentials;
00273 }
00274
00275
00276 lcmaps_release_cred(&lcmaps_cred);
00277 lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): succeeded\n");
00278 return 0;
00279
00280 fail_lcmaps_run_without_credentials:
00281 lcmaps_release_cred(&lcmaps_cred);
00282 lcmaps_log_debug(0,"lcmaps.mod-lcmaps_run_without_credentials(): failed\n");
00283 return 1;
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00308 int lcmaps_term()
00309 {
00310 lcmaps_log_time(0,"lcmaps.mod-lcmaps_term(): terminating\n");
00311 return stopPluginManager();
00312 }
00313
00314
00315
00316
00317
00318
00319
00320