Standalone build of the gSoap plugin
authorDaniel Kouřil <kouril@ics.muni.cz>
Tue, 11 Jan 2005 13:55:45 +0000 (13:55 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Tue, 11 Jan 2005 13:55:45 +0000 (13:55 +0000)
- Removed all dependendcies on LB internals
- Added skeleton for simple client and server

org.glite.lb.server/src/glite_plugin/Makefile
org.glite.lb.server/src/glite_plugin/client.c [new file with mode: 0644]
org.glite.lb.server/src/glite_plugin/server.c [new file with mode: 0644]
org.glite.lb.server/src/glite_plugin/ws_plugin.c
org.glite.lb.server/src/glite_plugin/ws_plugin.h

index bc53cc8..2b0d8a8 100644 (file)
@@ -1,17 +1,22 @@
 GSSAPI_ROOT = /software/globus-3.2-pre
 FLAVOR = gcc32dbg
 GSOAP_ROOT = /software/gsoap-2.6
+ARES_ROOT =
 
-PLUGIN_OBJS = ws_plugin.o lb_gss.o
-
-CPPFLAGS = -DSTANDALONE_BUILD -D_GNU_SOURCE \
+CPPFLAGS = -DSTANDALONE_BUILD \
        -I$(GSSAPI_ROOT)/include/$(FLAVOR) -I$(GSSAPI_ROOT)/include \
        -I$(GSOAP_ROOT)/include
 CFLAGS = -Wall
+LDFLAGS = -L$(GSSAPI_ROOT)/lib -L$(GSOAP_ROOT)/lib
+LDLIBS = -lglobus_gssapi_gsi_$(FLAVOR) -lares
+
+PLUGIN_OBJS = ws_plugin.o lb_gss.o
+
+all: server
 
-all: client server
+server: $(PLUGIN_OBJS) server.o
 
-client: $(PLUGIN_OBJS)
+client: $(PLUGIN_OBJS) client.o
 
 clean:
-       $(RM) $(PLUGIN_OBJS) client server core 
+       $(RM) *.o client server core 
diff --git a/org.glite.lb.server/src/glite_plugin/client.c b/org.glite.lb.server/src/glite_plugin/client.c
new file mode 100644 (file)
index 0000000..5f3f9e2
--- /dev/null
@@ -0,0 +1,96 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <getopt.h>
+#include <stdsoap2.h>
+
+#include "ws_plugin.h"
+
+static struct option long_options[] = {
+       { "cert",    required_argument,      NULL,   'c' },
+       { "key",     required_argument,      NULL,   'k' },
+       { "CAdir",   required_argument,      NULL,   'd' },
+       { NULL, 0, NULL, 0 }
+};
+
+void
+usage(const char *me)
+{
+   fprintf(stderr,"usage: %s [option] hostname\n"
+          "\t-c, --cred\t certificate file\n"
+          "\t-k, --key\t private key file\n"
+          "\t-d, --CAdir\t trusted certificates directory\n"
+          , me);
+}
+
+int
+proto (edg_wll_GssConnection *con)
+{
+   return 0;
+}
+
+int
+doit(gss_cred_id_t cred, const char *hostname, short port)
+{
+   int ret;
+   struct timeval timeout = {10,0};
+   edg_wll_GssConnection con;
+   char *msg;
+   edg_wll_GssStatus gss_code;
+
+   ret = edg_wll_gss_connect(cred, hostname, port, &timeout, &con, &gss_code);
+   if (ret) {
+      edg_wll_gss_get_error(&gss_code, "Error connecting to server", &msg);
+      fprintf(stderr, "%s\n", msg);
+      free(msg);
+      return ret;
+   }
+
+   ret = proto(&con);
+
+   edg_wll_gss_close(&con, NULL);
+
+   return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+   char *cert, *key, *cadir;
+   const char *hostname = "localhost";
+   short port = 3322;
+   const char *name;
+   int ret, opt;
+   gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
+   edg_wll_GssStatus gss_code;
+   char *msg;
+   OM_uint32 min_stat;
+
+   cert = key = cadir = NULL;
+
+   name = strrchr(argv[0],'/');
+   if (name) name++; else name = argv[0];
+
+   while ((opt = getopt_long(argc, argv, "c:k:d:", long_options, NULL)) != EOF) {
+      switch (opt) {
+        case 'c': cert = optarg; break;
+        case 'k': key = optarg; break;
+        case 'd': cadir = optarg; break;
+        case '?':
+        default : usage(name); exit(1);
+      }
+   }
+
+   ret = edg_wll_gss_acquire_cred_gsi(cert, key, &cred, NULL, &gss_code);
+   if (ret) {
+      edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg);
+      fprintf(stderr, "%s\n", msg);
+      free(msg);
+      exit(1);
+   }
+
+   ret = doit(cred, hostname, port);
+
+   gss_release_cred(&min_stat, &cred);
+   return ret;
+}
diff --git a/org.glite.lb.server/src/glite_plugin/server.c b/org.glite.lb.server/src/glite_plugin/server.c
new file mode 100644 (file)
index 0000000..814d3cf
--- /dev/null
@@ -0,0 +1,116 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <getopt.h>
+#include <stdsoap2.h>
+
+#include "ws_plugin.h"
+
+static struct option long_options[] = {
+       { "cert",    required_argument,      NULL,   'c' },
+       { "key",     required_argument,      NULL,   'k' },
+       { "CAdir",   required_argument,      NULL,   'd' },
+       { NULL, 0, NULL, 0 }
+};
+
+void
+usage(const char *me)
+{
+   fprintf(stderr,"usage: %s [option]\n"
+          "\t-c, --cred\t certificate file\n"
+          "\t-k, --key\t private key file\n"
+          "\t-d, --CAdir\t trusted certificates directory\n"
+          , me);
+}
+
+int
+proto (edg_wll_GssConnection *con)
+{
+   return 0;
+}
+
+int
+doit(int socket, gss_cred_id_t cred)
+{
+   int ret;
+   struct timeval timeout = {10,0};
+   edg_wll_GssConnection con;
+   edg_wll_GssStatus gss_code;
+   char *msg;
+
+   ret = edg_wll_gss_accept(cred, socket, &timeout, &con, &gss_code);
+   if (ret) {
+      edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg);
+      fprintf(stderr, "%s\n", msg);
+      free(msg);
+      return ret;
+   }
+
+   ret = proto(&con);
+
+   edg_wll_gss_close(&con, &timeout);
+
+   return ret;
+}
+
+int
+main(int argc, char *argv[])
+{
+   const char *name;
+   int ret, opt;
+   int listener_fd;
+   int client_fd;
+   struct sockaddr_in client_addr;
+   int client_addr_len;
+   gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
+   char *cert, *key, *cadir;
+   edg_wll_GssStatus gss_code;
+   char *subject = NULL;
+   char *msg;
+   OM_uint32 min_stat;
+
+   cert = key = cadir = NULL;
+
+   name = strrchr(argv[0],'/');
+   if (name) name++; else name = argv[0];
+
+   while ((opt = getopt_long(argc, argv, "c:k:d:", long_options, NULL)) != EOF) {
+      switch (opt) {
+        case 'c': cert = optarg; break;
+        case 'k': key = optarg; break;
+        case 'd': cadir = optarg; break;
+        case '?':
+        default : usage(name); exit(1);
+      }
+   }
+
+   ret = edg_wll_gss_acquire_cred_gsi(cert, key, &cred, &subject, &gss_code);
+   if (ret) {
+      edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg);
+      fprintf(stderr, "%s\n", msg);
+      free(msg);
+      exit(1);
+   }
+
+   if (subject) {
+      printf("server running with certificate: %s\n", subject);
+      free(subject);
+   }
+
+   client_addr_len = sizeof(client_addr);
+   bzero((char *) &client_addr, client_addr_len);
+
+   while (1) {
+      client_fd = accept(listener_fd, (struct sockaddr *) &client_addr,
+                        &client_addr_len);
+      if (client_fd < 0) {
+        close(listener_fd);
+        perror("accept");
+        gss_release_cred(&min_stat, &cred);
+        exit(1);
+      }
+
+      ret = doit(client_fd, cred);
+      close(client_fd);
+   }
+}
index 12bb52b..2b8fa3e 100644 (file)
@@ -5,8 +5,7 @@
 #include <signal.h>
 #include <stdsoap2.h>
 
-#include "glite/lb/lb_gss.h"
-#include "glite/lb/context-int.h"
+#include "lb_gss.h"
 
 #ifdef PLUGIN_TEST
 extern int edg_wll_open(edg_wll_Context);
@@ -14,8 +13,6 @@ extern int edg_wll_open(edg_wll_Context);
 
 #include "ws_plugin.h"
 
-#include "LoggingAndBookkeeping.nsmap"
-
 #ifdef WS_PLUGIN_DEBUG
 #  define pdprintf(s)  printf s
 #else
@@ -47,6 +44,8 @@ int edg_wll_ws_plugin(struct soap *soap, struct soap_plugin *p, void *arg)
        soap->fsend             = edg_wll_ws_send;
        soap->frecv             = edg_wll_ws_recv;
 
+       /* XXX globus_module_activate(GLOBUS_COMMON_MODULE); */
+
        return SOAP_OK;
 }
 
@@ -79,21 +78,23 @@ static void edg_wll_ws_delete(struct soap *soap, struct soap_plugin *p)
 
 size_t edg_wll_ws_recv(struct soap *soap, char *buf, size_t bufsz)
 {
-       edg_wll_Context         ctx = (edg_wll_Context)soap_lookup_plugin(soap, plugin_id);
+       edg_wll_ws_Context      ctx = (edg_wll_ws_Context)soap_lookup_plugin(soap, plugin_id);
        edg_wll_GssStatus       gss_code;
        int                                     len;
 
 
-       edg_wll_ResetError(ctx);
-       if ( ctx->connPool[ctx->connToUse].gss.context == GSS_C_NO_CONTEXT )
+       if (ctx->error_msg)
+               free(ctx->error_msg);
+       ctx->error_msg = NULL;
+
+       if ( ctx->connection->context == GSS_C_NO_CONTEXT )
        {
-               edg_wll_SetError(ctx, ENOTCONN, NULL);
                soap->errnum = ENOTCONN;
+               /* XXX edg_wll_ws_send() returns SOAP_EOF on errors */
                return 0;
        }
        
-       len = edg_wll_gss_read(&ctx->connPool[ctx->connToUse].gss,
-                                       buf, bufsz, &ctx->p_tmp_timeout, &gss_code);
+       len = edg_wll_gss_read(ctx->connection, buf, bufsz, ctx->timeout, &gss_code);
 
        switch ( len )
        {
@@ -101,22 +102,21 @@ size_t edg_wll_ws_recv(struct soap *soap, char *buf, size_t bufsz)
                break;
 
        case EDG_WLL_GSS_ERROR_GSS:
-               edg_wll_SetErrorGss(ctx, "receving WS request", &gss_code);
+               edg_wll_gss_get_error(&gss_code, "receving WS request",
+                                     &ctx->error_msg);
                soap->errnum = ENOTCONN;
                return 0;
 
        case EDG_WLL_GSS_ERROR_ERRNO:
-               edg_wll_SetError(ctx, errno, "edg_wll_gss_read()");
+               ctx->error_msg = strdup("edg_wll_gss_read()");
                soap->errnum = errno;
                return 0;
 
        case EDG_WLL_GSS_ERROR_TIMEOUT:
-               edg_wll_SetError(ctx, ETIMEDOUT, NULL);
                soap->errnum = ETIMEDOUT;
                return 0;
 
        case EDG_WLL_GSS_ERROR_EOF:
-               edg_wll_SetError(ctx, ENOTCONN, NULL);
                soap->errnum = ENOTCONN;
                return 0;
 
@@ -129,18 +129,14 @@ size_t edg_wll_ws_recv(struct soap *soap, char *buf, size_t bufsz)
 
 static int edg_wll_ws_send(struct soap *soap, const char *buf, size_t bufsz)
 {
-       edg_wll_Context         ctx = (edg_wll_Context) soap_lookup_plugin(soap, plugin_id);
+       edg_wll_ws_Context      ctx = (edg_wll_ws_Context) soap_lookup_plugin(soap, plugin_id);
        edg_wll_GssStatus       gss_code;
        struct sigaction        sa, osa;
        size_t                  total = 0;
        int                     ret;
 
-
-       edg_wll_ResetError(ctx);
-
-       if ( ctx->connPool[ctx->connToUse].gss.context == GSS_C_NO_CONTEXT )
+       if ( ctx->connection->context == GSS_C_NO_CONTEXT )
        {
-               edg_wll_SetError(ctx, ENOTCONN, NULL);
                soap->errnum = ENOTCONN;
                return SOAP_EOF;
        }
@@ -150,9 +146,9 @@ static int edg_wll_ws_send(struct soap *soap, const char *buf, size_t bufsz)
        sa.sa_handler = SIG_IGN;
        sigaction(SIGPIPE, &sa, &osa);
 
-       ret = edg_wll_gss_write_full(&ctx->connPool[ctx->connToUse].gss,
+       ret = edg_wll_gss_write_full(ctx->connection,
                                (void*)buf, bufsz,
-                               &ctx->p_tmp_timeout,
+                               ctx->timeout,
                                &total, &gss_code);
 
        sigaction(SIGPIPE, &osa, NULL);
@@ -164,19 +160,19 @@ static int edg_wll_ws_send(struct soap *soap, const char *buf, size_t bufsz)
                break;
 
        case EDG_WLL_GSS_ERROR_TIMEOUT:
-               edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_ws_send()");
+               ctx->error_msg = strdup("edg_wll_ws_send()");
                soap->errnum = ETIMEDOUT;
                return SOAP_EOF;
 
        case EDG_WLL_GSS_ERROR_ERRNO:
                if ( errno == EPIPE )
                {
-                       edg_wll_SetError(ctx, ENOTCONN, "edg_wll_ws_send()");
+                       ctx->error_msg = strdup("edg_wll_ws_send()");
                        soap->errnum = ENOTCONN;
                }
                else
                {
-                       edg_wll_SetError(ctx, errno, "edg_wll_ws_send()");
+                       ctx->error_msg = strdup("edg_wll_ws_send()");
                        soap->errnum = errno;
                }
                return SOAP_EOF;
@@ -184,7 +180,7 @@ static int edg_wll_ws_send(struct soap *soap, const char *buf, size_t bufsz)
        case EDG_WLL_GSS_ERROR_GSS:
        case EDG_WLL_GSS_ERROR_EOF:
        default:
-               edg_wll_SetError(ctx, ENOTCONN, "edg_wll_ws_send()");
+               ctx->error_msg = strdup("edg_wll_ws_send()");
                soap->errnum = ENOTCONN;
                return SOAP_EOF;
        }
index 1b1d6be..5ecd596 100644 (file)
@@ -3,8 +3,18 @@
 
 /* /cvs/jra1mw/org.glite.lb.server/src/ws_plugin.h,v 1.2 2004/10/14 14:27:30 jskrabal */
 
+#include "lb_gss.h"
+
 #define PLUGIN_ID              "GLITE_WS_PLUGIN"
 
+typedef struct _edg_wll_ws_Context {
+       edg_wll_GssConnection *connection;
+       struct timeval *timeout;
+       char *error_msg;
+} _edg_wll_ws_Context;
+
+typedef _edg_wll_ws_Context * edg_wll_ws_Context;
+
 int edg_wll_ws_plugin(struct soap *, struct soap_plugin *, void *);
 
 #endif /* __EDG_WORKLOAD_LOGGING_LBSERVER_WS_PLUGIN_H__ */