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