Allow to specify a non-default fastcgi socket.
authorreyk <reyk@openbsd.org>
Thu, 31 Jul 2014 14:18:38 +0000 (14:18 +0000)
committerreyk <reyk@openbsd.org>
Thu, 31 Jul 2014 14:18:38 +0000 (14:18 +0000)
usr.sbin/httpd/config.c
usr.sbin/httpd/httpd.conf.5
usr.sbin/httpd/httpd.h
usr.sbin/httpd/parse.y
usr.sbin/httpd/server_fcgi.c

index 6130a0b..3d8a5e1 100644 (file)
@@ -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 <reyk@openbsd.org>
@@ -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,
index 7cd03a8..aa651a0 100644 (file)
@@ -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 <reyk@openbsd.org>
 .\"
@@ -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 { ... }
index ae4b2b4..0b11fcf 100644 (file)
@@ -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 <reyk@openbsd.org>
@@ -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
index 905c777..91e0197 100644 (file)
@@ -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 <reyk@openbsd.org>
@@ -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 <v.string>      STRING
 %token  <v.number>     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 }
        };
index 0e847f2..79a2131 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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;