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