Sorry again, I'm trying now with with patch as an attachment -
when I did it the first time I think it wasn't accepted by the
list.

On Fri, Nov 13, 2015 at 05:22:22PM +0100, Bret Lambert wrote:
> tech@ accepts attachments; don't make this harder for us than
> it needs to be, please.
> 
> On Fri, Nov 13, 2015 at 05:06:47PM +0100, Stanislaw Adaszewski wrote:
> > Excuse me, the indentation was removed because message wasn't plain text.
> > 
> > Patch: http://pastebin.com/XnZLEPEk
> > 
> > httpd.conf: http://pastebin.com/gGp3NqCD
> > 
> > rewr.php: http://pastebin.com/prA1NJXC
> > 
? httpd
? httpd_url_rewrite.patch
? parse.c
? y.tab.h
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.73
diff -u -p -u -r1.73 parse.y
--- parse.y     19 Jul 2015 05:17:27 -0000      1.73
+++ parse.y     13 Nov 2015 08:29:10 -0000
@@ -907,7 +907,7 @@ filter              : block RETURN NUMBER optstring 
 
                        if ($4 != NULL) {
                                /* Only for 3xx redirection headers */
-                               if ($3 < 300 || $3 > 399) {
+                               if ($3 != 200 && ($3 < 300 || $3 > 399)) {
                                        yyerror("invalid return code for "
                                            "location URI");
                                        free($4);
Index: server_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.96
diff -u -p -u -r1.96 server_http.c
--- server_http.c       31 Jul 2015 00:10:51 -0000      1.96
+++ server_http.c       13 Nov 2015 08:29:10 -0000
@@ -1054,6 +1054,7 @@ server_response(struct httpd *httpd, str
        int                      portval = -1, ret;
        char                    *hostval;
        const char              *errstr = NULL;
+       char                    buf[IBUF_READ_SIZE];
 
        /* Canonicalize the request path */
        if (desc->http_path == NULL ||
@@ -1154,11 +1155,44 @@ server_response(struct httpd *httpd, str
        resp->http_method = desc->http_method;
        if ((resp->http_version = strdup(desc->http_version)) == NULL)
                goto fail;
+               
+#ifdef DEBUG
+       DPRINTF("%s: http_path: %s, http_path_alias: %s\n", __func__, 
desc->http_path, desc->http_path_alias);
+#endif
 
        /* Now search for the location */
        srv_conf = server_getlocation(clt, desc->http_path);
 
-       if (srv_conf->flags & SRVFLAG_BLOCK) {
+
+       if ((srv_conf->flags & SRVFLAG_BLOCK) && srv_conf->return_code == 200) {
+#ifdef DEBUG
+               DPRINTF("%s: Rewrite from: %s to %s\n", __func__, 
desc->http_path, srv_conf->return_uri);
+#endif
+               if (desc->http_path != NULL) {
+                       free(desc->http_path);
+                       desc->http_path = NULL;
+               }
+               if (server_expand_http(clt, srv_conf->return_uri, buf, 
sizeof(buf)) == NULL) {
+                       server_abort_http(clt, 500, strerror(errno));
+                       return (-1);
+               }
+               desc->http_path = strdup(buf);
+               if (desc->http_path == NULL) {
+                       server_abort_http(clt, 500, strerror(errno));
+               }
+               desc->http_query = strchr(desc->http_path, '?');
+               if (desc->http_query != NULL) {
+                       *desc->http_query++ = '\0';
+                       desc->http_query = strdup(desc->http_query);
+                       if (desc->http_query == NULL) {
+                               server_abort_http(clt, 500, strerror(errno));
+                       }
+               }
+               srv_conf = server_getlocation(clt, desc->http_path); // again
+       }
+
+
+       if ((srv_conf->flags & SRVFLAG_BLOCK) && srv_conf->return_code != 200) {
                server_abort_http(clt, srv_conf->return_code,
                    srv_conf->return_uri);
                return (-1);

Reply via email to