00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00029 #include "lcmaps_config.h"
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033
00034 #if HAVE_MALLOC_H
00035 #include <malloc.h>
00036 #endif
00037
00038 #include <gssapi.h>
00039 #include "globus_gss_assist.h"
00040
00041
00042 #if HAVE_DLFCN_H
00043 #include <dlfcn.h>
00044 #endif
00045
00046 #if LINKED_LCMAPS
00047 #include "lcmaps.h"
00048 #endif
00049
00050 static void failure(short failure_type, char *s);
00051 static void notice(int, char *s);
00052
00053 #define FAILED_AUTHORIZATION 1
00054 #define FAILED_SERVICELOOKUP 2
00055 #define FAILED_SERVER 3
00056 #define FAILED_NOLOGIN 4
00057 #define FAILED_AUTHENTICATION 5
00058 #define FAILED_PING 6
00059
00060 static char tmpbuf[1024];
00061 #define notice2(i,a,b) {sprintf(tmpbuf, a,b); notice(i,tmpbuf);}
00062 #define notice3(i,a,b,c) {sprintf(tmpbuf, a,b,c); notice(i,tmpbuf);}
00063 #define notice4(i,a,b,c,d) {sprintf(tmpbuf, a,b,c,d); notice(i,tmpbuf);}
00064 #define failure2(t,a,b) {sprintf(tmpbuf, a,b); failure(t,tmpbuf);}
00065 #define failure3(t,a,b,c) {sprintf(tmpbuf, a,b,c); failure(t,tmpbuf);}
00066 #define failure4(t,a,b,c,d) {sprintf(tmpbuf, a,b,c,d); failure(t,tmpbuf);}
00067
00068 static char * lcmapsmod_name= NULL;
00069 static gss_cred_id_t delegated_cred_handle = GSS_C_NO_CREDENTIAL;
00070 static FILE * usrlog_fp=NULL;
00071
00072 int main()
00073 {
00074 char * lcmaps_request="Test lcmaps_request";
00075 char * client_name="/O=dutchgrid/O=users/O=nikhef/CN=Martijn Steenbakkers";
00076 int retval=0;
00077
00078 usrlog_fp=stderr;
00079
00080
00081 {
00082 OM_uint32 major_status;
00083 OM_uint32 minor_status;
00084 char * proxyname = "/home/gridtest/cvs/fabric_mgt/gridification/lcmaps/modules/voms/x509up_u500";
00085
00086 setenv("X509_USER_PROXY",proxyname,1);
00087 major_status = globus_gss_assist_acquire_cred(&minor_status,
00088 GSS_C_INITIATE,
00089 &delegated_cred_handle);
00090
00091 if (major_status != GSS_S_COMPLETE)
00092 {
00093 globus_gss_assist_display_status(stderr,
00094 "Some failure message here",
00095 major_status,
00096 minor_status,
00097 0);
00098 return 1;
00099 }
00100 }
00101
00102 #if LINKED_LCMAPS
00103 {
00104 int retval;
00105
00106 notice(0,"Using linked in version of LCMAPS");
00107
00108 retval=lcmaps_init(usrlog_fp);
00109 if (retval)
00110 {
00111 failure(FAILED_SERVER, "LCMAPS initialization failure.");
00112 }
00113 #if ALLOW_EMPTY_CREDENTIALS
00114 retval=lcmaps_run(client_name,delegated_cred_handle, lcmaps_request);
00115 #else
00116 retval=lcmaps_run(delegated_cred_handle, lcmaps_request);
00117 #endif
00118 if (retval)
00119 {
00120 failure(FAILED_AUTHORIZATION, "LCMAPS failed authorization.");
00121 }
00122 retval=lcmaps_term();
00123 if (retval)
00124 {
00125 failure(FAILED_SERVER, "LCMAPS termination failure.");
00126 }
00127 }
00128 #else
00129 lcmapsmod_name="/opt/edg/lib/lcmaps/lcmaps.mod";
00130 {
00131 void *handle;
00132 char *error;
00133 int retval;
00134 int (*LcmapsInit)(FILE *);
00135 int (*LcmapsTerm)();
00136 #if ALLOW_EMPTY_CREDENTIALS
00137 int (*LcmapsRun)(char*, gss_cred_id_t, char*);
00138 notice(0,"temporarily ALLOW empty credentials");
00139 #else
00140 int (*LcmapsRun)(gss_cred_id_t, char*);
00141 #endif
00142
00143 notice2(0,"lcmapsmod_name = %s",lcmapsmod_name);
00144 handle = dlopen(lcmapsmod_name,RTLD_LAZY|RTLD_GLOBAL);
00145 if (!handle)
00146 {
00147 notice2(0,"dlopen error: %s",dlerror());
00148 failure2(FAILED_SERVER,"Cannot open LCMAPS module of %s",lcmapsmod_name);
00149 }
00150 else
00151 {
00152
00153 LcmapsInit=dlsym(handle,"lcmaps_init");
00154 if ((error = dlerror()) != NULL)
00155 {
00156 notice2(0,"dlsym error: %s",error);
00157 dlclose(handle);
00158 failure(FAILED_SERVER,"LCMAPS module not compliant.");
00159 }
00160 LcmapsRun=dlsym(handle,"lcmaps_run");
00161 if ((error = dlerror()) != NULL)
00162 {
00163 notice2(0,"dlsym error: %s",error);
00164 dlclose(handle);
00165 failure(FAILED_SERVER,"LCMAPS module not compliant.");
00166 }
00167 LcmapsTerm=dlsym(handle,"lcmaps_term");
00168 if ((error = dlerror()) != NULL)
00169 {
00170 notice2(0,"dlsym error: %s",error);
00171 dlclose(handle);
00172 failure(FAILED_SERVER,"LCMAPS module not compliant.");
00173 }
00174
00175
00176 retval=(*LcmapsInit)(usrlog_fp);
00177 if (retval)
00178 {
00179 dlclose(handle);
00180 failure(FAILED_SERVER, "LCMAPS initialization failure.");
00181 }
00182 #if ALLOW_EMPTY_CREDENTIALS
00183 retval=(*LcmapsRun)(client_name, delegated_cred_handle, lcmaps_request);
00184 #else
00185 retval=(*LcmapsRun)(delegated_cred_handle, lcmaps_request);
00186 #endif
00187 if (retval)
00188 {
00189 if ((*LcmapsTerm)())
00190 {
00191 dlclose(handle);
00192 failure(FAILED_SERVER, "LCMAPS termination failure.");
00193 }
00194 dlclose(handle);
00195 failure(FAILED_NOLOGIN, "LCMAPS failed user mapping.");
00196 }
00197 retval=(*LcmapsTerm)();
00198 if (retval)
00199 {
00200 dlclose(handle);
00201 failure(FAILED_SERVER, "LCMAPS termination failure.");
00202 }
00203 dlclose(handle);
00204 }
00205 }
00206 #endif
00207 fprintf(usrlog_fp,"return value= %d\n",retval);
00208 return 0;
00209 }
00210
00211
00212
00213
00214
00215
00216 static void
00217 notice(int prty, char * s)
00218 {
00219 {
00220 fprintf(usrlog_fp, "Notice: %d: %s\n", prty, s);
00221 }
00222 }
00223
00224
00225
00226
00227
00228
00229
00230 static void
00231 failure(short failure_type, char * s)
00232 {
00233 fprintf(stderr,"Failure: %s\n", s);
00234 {
00235 fprintf(usrlog_fp, "Failure: %s\n", s);
00236 }
00237 exit(1);
00238 }
00239
00240
00241
00242
00243
00244
00245