From: reyk Date: Thu, 31 Jul 2014 14:18:38 +0000 (+0000) Subject: Allow to specify a non-default fastcgi socket. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=af5adad1612d8023e9fe6dca1ed31e52aa6b130a;p=openbsd Allow to specify a non-default fastcgi socket. --- diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c index 6130a0ba181..3d8a5e13c16 100644 --- a/usr.sbin/httpd/config.c +++ b/usr.sbin/httpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.9 2014/07/31 13:28:15 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.10 2014/07/31 14:18:38 reyk Exp $ */ /* * Copyright (c) 2011 - 2014 Reyk Floeter @@ -238,6 +238,14 @@ config_getserver_config(struct httpd *env, struct server *srv, if ((srv_conf->flags & f) == 0) srv_conf->flags |= srv->srv_conf.flags & f; + f = SRVFLAG_PATH|SRVFLAG_FCGI; + if ((srv_conf->flags & f) == SRVFLAG_FCGI) { + (void)strlcpy(srv_conf->path, + HTTPD_FCGI_SOCKET, + sizeof(srv_conf->path)); + srv_conf->flags |= SRVFLAG_PATH; + } + f = SRVFLAG_PATH; if ((srv_conf->flags & f) == 0) { (void)strlcpy(srv_conf->path, diff --git a/usr.sbin/httpd/httpd.conf.5 b/usr.sbin/httpd/httpd.conf.5 index 7cd03a8e84d..aa651a0f2a9 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.11 2014/07/31 09:34:57 reyk Exp $ +.\" $OpenBSD: httpd.conf.5,v 1.12 2014/07/31 14:18:38 reyk Exp $ .\" .\" Copyright (c) 2014 Reyk Floeter .\" @@ -128,8 +128,16 @@ 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 +.It Oo Ic no Oc Ic fastcgi Op Ar socket Enable FastCGI instead of serving files. +The +.Ar socket +is a local path name within the +.Xr chroot 2 +root directory of +.Nm httpd +and defaults to +.Pa /run/slowcgi.sock . .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 ae4b2b4cf0d..0b11fcf5f1b 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.h,v 1.22 2014/07/31 13:28:15 reyk Exp $ */ +/* $OpenBSD: httpd.h,v 1.23 2014/07/31 14:18:38 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -33,6 +33,7 @@ #define HTTPD_SERVERNAME "OpenBSD httpd" #define HTTPD_DOCROOT "/htdocs" #define HTTPD_INDEX "index.html" +#define HTTPD_FCGI_SOCKET "/run/slowcgi.sock" #define FD_RESERVE 5 #define SERVER_MAX_CLIENTS 1024 diff --git a/usr.sbin/httpd/parse.y b/usr.sbin/httpd/parse.y index 905c777f2ce..91e0197970f 100644 --- a/usr.sbin/httpd/parse.y +++ b/usr.sbin/httpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.12 2014/07/31 13:28:15 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.13 2014/07/31 14:18:38 reyk Exp $ */ /* * Copyright (c) 2007 - 2014 Reyk Floeter @@ -127,7 +127,7 @@ typedef struct { %} %token ALL AUTO DIRECTORY FCGI INDEX LISTEN LOCATION LOG NO ON PORT -%token PREFORK ROOT SERVER TYPES UPDATES VERBOSE +%token PREFORK ROOT SERVER SOCKET TYPES UPDATES VERBOSE %token ERROR INCLUDE %token STRING %token NUMBER @@ -284,6 +284,11 @@ serveroptsl : LISTEN ON STRING port { host_free(&al); } | ROOT STRING { + if (srv->srv_conf.flags & SRVFLAG_FCGI) { + yyerror("root conflicts with fastcgi"); + free($2); + YYERROR; + } if (strlcpy(srv->srv_conf.path, $2, sizeof(srv->srv_conf.path)) >= sizeof(srv->srv_conf.path)) { @@ -296,14 +301,7 @@ 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; - } + | fastcgi | LOCATION STRING { struct server *s; @@ -379,6 +377,41 @@ serveroptsl : LISTEN ON STRING port { } ; +fastcgi : 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; + } + | FCGI { + srv->srv_conf.flags &= ~SRVFLAG_NO_FCGI; + srv->srv_conf.flags |= SRVFLAG_FCGI; + } '{' fcgiflags_l '}' + | FCGI { + srv->srv_conf.flags &= ~SRVFLAG_NO_FCGI; + srv->srv_conf.flags |= SRVFLAG_FCGI; + } fcgiflags + ; + +fcgiflags_l : fcgiflags comma fcgiflags_l + | fcgiflags + ; + +fcgiflags : SOCKET STRING { + if (strlcpy(srv->srv_conf.path, $2, + sizeof(srv->srv_conf.path)) >= + sizeof(srv->srv_conf.path)) { + yyerror("fastcgi socket too long"); + free($2); + YYERROR; + } + free($2); + srv->srv_conf.flags |= SRVFLAG_PATH; + } + ; + dirflags_l : dirflags comma dirflags_l | dirflags ; @@ -555,6 +588,7 @@ lookup(char *s) { "prefork", PREFORK }, { "root", ROOT }, { "server", SERVER }, + { "socket", SOCKET }, { "types", TYPES }, { "updates", UPDATES } }; diff --git a/usr.sbin/httpd/server_fcgi.c b/usr.sbin/httpd/server_fcgi.c index 0e847f26cd3..79a21316006 100644 --- a/usr.sbin/httpd/server_fcgi.c +++ b/usr.sbin/httpd/server_fcgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server_fcgi.c,v 1.1 2014/07/31 09:23:53 florian Exp $ */ +/* $OpenBSD: server_fcgi.c,v 1.2 2014/07/31 14:18:38 reyk Exp $ */ /* * Copyright (c) 2014 Florian Obser @@ -105,7 +105,7 @@ server_fcgi(struct httpd *env, struct client *clt) bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; - len = strlcpy(sun.sun_path, "/run/slowcgi.sock", sizeof(sun.sun_path)); + len = strlcpy(sun.sun_path, srv_conf->path, sizeof(sun.sun_path)); if (len >= sizeof(sun.sun_path)) { errstr = "socket path to long"; goto fail;