+ /* Get the context from the request. If the context is NULL or
+ * there is no outstanding request (no nonce set), just forward
+ * all of the buckets as-is, because the client isn't gssweb
+ */
+ if ((NULL == (conn_ctx = gss_retrieve_conn_ctx(r))) ||
+ (0 == conn_ctx->nonce)) {
+ for (bkt_in = APR_BRIGADE_FIRST(brig_in);
+ bkt_in != APR_BRIGADE_SENTINEL(brig_in);
+ bkt_in = APR_BUCKET_NEXT(bkt_in))
+ {
+ if (NULL == (brig_out = apr_brigade_create(r->pool, c->bucket_alloc))) {
+ apr_brigade_cleanup(brig_in);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ apr_bucket_copy(bkt_in, &bkt_out);
+ APR_BRIGADE_INSERT_TAIL(brig_out, bkt_out);
+ ap_pass_brigade(f->next, brig_out);
+ }
+ gss_log(APLOG_MARK, APLOG_ERR, 0, r, "gssweb_authenticate_filter: Failed to find valid context");
+ apr_brigade_cleanup(brig_in);
+ return OK;
+ }
+
+ c_type = apr_table_get(r->headers_in, "Content-Type");
+ c_len = apr_table_get(r->headers_in, "Content-Length");
+ /* clear content-length and MD5 checksum */
+ apr_table_unset(r->headers_out, "Content-Length");
+ apr_table_unset(r->headers_out, "Content-MD5");
+ gss_log(APLOG_MARK, APLOG_DEBUG, 0, r, "gssweb_authenticate_filter: Received Content-Type: %s, Content-Length: %d", c_type, c_len);
+
+ /* If this is the first call for a response, send opening JSON block */
+ if (GSS_FILT_NEW == conn_ctx->filter_stat) {
+ gss_log(APLOG_MARK, APLOG_DEBUG, 0, r, "gssweb_authenticate_filter: First filter call for response");
+ if (NULL == (brig_out = apr_brigade_create(r->pool, c->bucket_alloc))) {
+ conn_ctx->filter_stat = GSS_FILT_ERROR;
+ gss_log(APLOG_MARK, APLOG_ERR, 0, r, "gssweb_authenticate_filter: Unable to allocate output brigade (opening)");
+ apr_brigade_cleanup(brig_in);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ /* Encode the output token */
+ len = apr_base64_encode_len(conn_ctx->output_token.length);
+ if (NULL == (stoken = apr_bucket_alloc(len+1, c->bucket_alloc))) {
+ gss_log(APLOG_MARK, APLOG_ERR, 0, r, "gssweb_authenticate_filter: Unable to allocate space for encoded output token");
+ apr_brigade_cleanup(brig_in);
+ apr_brigade_cleanup(brig_out);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ apr_base64_encode_binary(stoken, conn_ctx->output_token.value, conn_ctx->output_token.length);
+
+ if (NULL == (data = apr_bucket_alloc(len+1024, c->bucket_alloc))) {
+ gss_log(APLOG_MARK, APLOG_ERR, 0, r, "gssweb_authenticate_filter: Unable to allocate space for opening JSON block");
+ apr_brigade_cleanup(brig_in);
+ apr_brigade_cleanup(brig_out);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }