From 435dc7cdb664bd7ae3de23127b6601b662f24f0b Mon Sep 17 00:00:00 2001 From: reyk Date: Thu, 31 Jul 2014 09:34:57 +0000 Subject: [PATCH] Add a configuration variable "fastcgi" to enable it per server or location. --- usr.sbin/httpd/config.c | 6 +++++- usr.sbin/httpd/httpd.conf.5 | 6 ++++-- usr.sbin/httpd/httpd.h | 7 +++++-- usr.sbin/httpd/parse.y | 15 ++++++++++++--- usr.sbin/httpd/server_http.c | 17 ++++++++--------- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c index 44cd419565f..cc8060f313c 100644 --- a/usr.sbin/httpd/config.c +++ b/usr.sbin/httpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.7 2014/07/30 13:49:48 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.8 2014/07/31 09:34:57 reyk Exp $ */ /* * Copyright (c) 2011 - 2014 Reyk Floeter @@ -245,6 +245,10 @@ config_getserver_config(struct httpd *env, struct server *srv, sizeof(srv_conf->docroot)); } + f = SRVFLAG_FCGI|SRVFLAG_NO_FCGI; + if ((srv_conf->flags & f) == 0) + srv_conf->flags |= srv->srv_conf.flags & f; + DPRINTF("%s: %s %d received location \"%s\", parent \"%s\"", __func__, ps->ps_title[privsep_process], ps->ps_instance, srv_conf->location, srv->srv_conf.name); diff --git a/usr.sbin/httpd/httpd.conf.5 b/usr.sbin/httpd/httpd.conf.5 index 9c056da7485..7cd03a8e84d 100644 --- a/usr.sbin/httpd/httpd.conf.5 +++ b/usr.sbin/httpd/httpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: httpd.conf.5,v 1.10 2014/07/30 10:05:14 reyk Exp $ +.\" $OpenBSD: httpd.conf.5,v 1.11 2014/07/31 09:34:57 reyk Exp $ .\" .\" Copyright (c) 2014 Reyk Floeter .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: July 30 2014 $ +.Dd $Mdocdate: July 31 2014 $ .Dt HTTPD.CONF 5 .Os .Sh NAME @@ -128,6 +128,8 @@ If not specified, it defaults to Disable the directory index. .Nm httpd will neither display nor generate a directory index. +.It Oo Ic no Oc Ic fastcgi +Enable FastCGI instead of serving files. .It Ic listen on Ar address Ic port Ar number Set the listen address and port. .It Ic location Ar path { ... } diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h index 852a93fd596..66c047ca64b 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.h,v 1.20 2014/07/31 09:23:53 florian Exp $ */ +/* $OpenBSD: httpd.h,v 1.21 2014/07/31 09:34:57 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -279,9 +279,12 @@ SPLAY_HEAD(client_tree, client); #define SRVFLAG_NO_AUTO_INDEX 0x08 #define SRVFLAG_DOCROOT 0x10 #define SRVFLAG_LOCATION 0x20 +#define SRVFLAG_FCGI 0x40 +#define SRVFLAG_NO_FCGI 0x80 #define SRVFLAG_BITS \ - "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX\05LOCATION" + "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX" \ + "\05LOCATION\06FCGI\07NO_FCGI" #define TCPFLAG_NODELAY 0x01 #define TCPFLAG_NNODELAY 0x02 diff --git a/usr.sbin/httpd/parse.y b/usr.sbin/httpd/parse.y index 3947f710cd5..253664b98f8 100644 --- a/usr.sbin/httpd/parse.y +++ b/usr.sbin/httpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.10 2014/07/30 13:49:48 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.11 2014/07/31 09:34:57 reyk Exp $ */ /* * Copyright (c) 2007 - 2014 Reyk Floeter @@ -126,8 +126,8 @@ typedef struct { %} -%token ALL AUTO DIRECTORY INDEX LISTEN LOCATION LOG NO ON PORT PREFORK ROOT -%token SERVER TYPES UPDATES VERBOSE +%token ALL AUTO DIRECTORY FCGI INDEX LISTEN LOCATION LOG NO ON PORT +%token PREFORK ROOT SERVER TYPES UPDATES VERBOSE %token ERROR INCLUDE %token STRING %token NUMBER @@ -296,6 +296,14 @@ serveroptsl : LISTEN ON STRING port { } | DIRECTORY dirflags | DIRECTORY '{' dirflags_l '}' + | NO FCGI { + srv->srv_conf.flags &= ~SRVFLAG_FCGI; + srv->srv_conf.flags |= SRVFLAG_NO_FCGI; + } + | FCGI { + srv->srv_conf.flags &= ~SRVFLAG_NO_FCGI; + srv->srv_conf.flags |= SRVFLAG_FCGI; + } | LOCATION STRING { struct server *s; @@ -535,6 +543,7 @@ lookup(char *s) { "all", ALL }, { "auto", AUTO }, { "directory", DIRECTORY }, + { "fastcgi", FCGI }, { "include", INCLUDE }, { "index", INDEX }, { "listen", LISTEN }, diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c index da60d15ab99..3eff410c891 100644 --- a/usr.sbin/httpd/server_http.c +++ b/usr.sbin/httpd/server_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server_http.c,v 1.22 2014/07/31 09:23:53 florian Exp $ */ +/* $OpenBSD: server_http.c,v 1.23 2014/07/31 09:34:57 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -748,18 +748,17 @@ server_response(struct httpd *httpd, struct client *clt) fnmatch(location->location, desc->http_path, FNM_CASEFOLD) == 0) { /* Replace host configuration */ - clt->clt_srv_conf = location; - srv_conf = NULL; + clt->clt_srv_conf = srv_conf = location; break; } } - if (strlen(desc->http_path) > strlen("/cgi-bin/") && - strncmp("/cgi-bin/", desc->http_path, strlen("/cgi-bin/")) == 0) { - if ((ret = server_fcgi(httpd, clt)) == -1) - return (-1); - } else if ((ret = server_file(httpd, clt)) == -1) - return (-1); + if (srv_conf->flags & SRVFLAG_FCGI) + ret = server_fcgi(httpd, clt); + else + ret = server_file(httpd, clt); + if (ret == -1) + return (ret); server_reset_http(clt); -- 2.20.1