Various patches for WS interface in glite 3.0. Fixes bug #26811.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 31 May 2007 16:00:57 +0000 (16:00 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 31 May 2007 16:00:57 +0000 (16:00 +0000)
org.glite.security.gsoap-plugin/src/glite_gsplugin.c
org.glite.security.gsoap-plugin/src/glite_gss.c

index d7a9891..8b4d9f0 100644 (file)
@@ -27,6 +27,7 @@ static int glite_gsplugin_send(struct soap *, const char *, size_t);
 static int glite_gsplugin_connect(struct soap *, const char *, const char *, int);
 static int glite_gsplugin_close(struct soap *);
 static int glite_gsplugin_accept(struct soap *, int, struct sockaddr *, int *);
+static int glite_gsplugin_posthdr(struct soap *soap, const char *key, const char *val);
 
 
 int
@@ -147,7 +148,7 @@ glite_gsplugin(struct soap *soap, struct soap_plugin *p, void *arg)
        soap->faccept           = glite_gsplugin_accept;
        soap->fsend                     = glite_gsplugin_send;
        soap->frecv                     = glite_gsplugin_recv;
-
+       soap->fposthdr          = glite_gsplugin_posthdr;
 
        return SOAP_OK;
 }
@@ -238,6 +239,7 @@ glite_gsplugin_connect(
                goto err;
        }
 
+       return 0;
 
 err:
        pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_connect() error!\n"));
@@ -413,3 +415,34 @@ glite_gsplugin_send(struct soap *soap, const char *buf, size_t bufsz)
        return SOAP_OK;
 }
 
+
+static int http_send_header(struct soap *soap, const char *s) {
+       const char *t;
+
+       do {
+               t = strchr(s, '\n'); /* disallow \n in HTTP headers */
+               if (!t) t = s + strlen(s);
+               if (soap_send_raw(soap, s, t - s)) return soap->error;
+               s = t + 1;
+       } while (*t);
+
+       return SOAP_OK;
+}
+
+
+static int glite_gsplugin_posthdr(struct soap *soap, const char *key, const char *val) {
+       if (key) {
+               if (strcmp(key, "Status") == 0) {
+                       snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "HTTP/%s", soap->http_version);
+                       if (http_send_header(soap, soap->tmpbuf)) return soap->error;
+                       if (val && (soap_send_raw(soap, " ", 1) || http_send_header(soap, val)))
+                               return soap->error;
+               } else {
+                       if (http_send_header(soap, key)) return soap->error;
+                       if (val && (soap_send_raw(soap, ": ", 2) || http_send_header(soap, val)))
+                               return soap->error;
+               }
+       }
+
+       return soap_send_raw(soap, "\r\n", 2);
+}
index b2e4d31..8617f1e 100644 (file)
@@ -366,8 +366,12 @@ recv_token(int sock, void **token, size_t *token_length, struct timeval *to)
            goto end;
         }
       }
-      if (count == 0 && tl == 0 && errno == 0)
-        return EDG_WLL_GSS_ERROR_EOF; 
+
+      if (count==0) {
+         if (tl==0) 
+            return EDG_WLL_GSS_ERROR_EOF;
+         else goto end;
+      }
       tmp=realloc(t, tl + count);
       if (tmp == NULL) {
         errno = ENOMEM;
@@ -614,6 +618,7 @@ edg_wll_gss_connect(gss_cred_id_t cred, char const *hostname, int port,
    int retry = _EXPIRED_ALERT_RETRY_COUNT;
 
    maj_stat = min_stat = min_stat2 = req_flags = 0;
+   memset(connection, 0, sizeof(*connection));
 
    /* GSI specific */
    req_flags = GSS_C_GLOBUS_SSL_COMPATIBLE;
@@ -708,7 +713,6 @@ edg_wll_gss_connect(gss_cred_id_t cred, char const *hostname, int port,
 
    } while (retry);
 
-   memset(connection, 0, sizeof(*connection));
    connection->sock = sock;
    connection->context = context;
    servername = NULL;
@@ -742,6 +746,7 @@ edg_wll_gss_accept(gss_cred_id_t cred, int sock, struct timeval *timeout,
    int ret;
 
    maj_stat = min_stat = min_stat2 = 0;
+   memset(connection, 0, sizeof(*connection));
 
    /* GSI specific */
    ret_flags = GSS_C_GLOBUS_SSL_COMPATIBLE;
@@ -786,7 +791,6 @@ edg_wll_gss_accept(gss_cred_id_t cred, int sock, struct timeval *timeout,
       goto end;
    }
 
-   memset(connection, 0, sizeof(*connection));
    connection->sock = sock;
    connection->context = context;
    memset(&output_token, 0, sizeof(output_token.value));
@@ -867,6 +871,7 @@ edg_wll_gss_read(edg_wll_GssConnection *connection, void *buf, size_t bufsize,
         /* XXX cleanup */
         return ret;
 
+
       maj_stat = gss_unwrap(&min_stat, connection->context, &input_token,
                            &output_token, NULL, NULL);
       gss_release_buffer(&min_stat, &input_token);