diff options
author | Omar Polo <op@omarpolo.com> | 2021-04-28 12:43:17 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-04-28 12:43:17 +0000 |
commit | 9cc630aa63cfd22553912b5a1fc41a71776cb272 (patch) | |
tree | b1fa171477f23a869acdc374797a91ff638bdd78 | |
parent | e6ca8eb1561ade7484a0249ffd1234cdf94e2562 (diff) |
added ``env'' option to define environment vars for CGI scripts
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | ex.c | 5 | ||||
-rw-r--r-- | gmid.1 | 9 | ||||
-rw-r--r-- | gmid.c | 7 | ||||
-rw-r--r-- | gmid.h | 9 | ||||
-rw-r--r-- | lex.l | 1 | ||||
-rw-r--r-- | parse.y | 13 |
7 files changed, 44 insertions, 2 deletions
@@ -1,5 +1,7 @@ 2021-04-27 Omar Polo <op@omarpolo.com> + * parse.y (servopt): added ``env'' option to define environment vars for CGI scripts + * log.c (fatal): lower the log priority for fatal errors from CRIT to ERR 2021-04-25 Omar Polo <op@omarpolo.com> @@ -136,6 +136,7 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost) char *ex, *pwd; char iribuf[GEMINI_URL_LEN]; char path[PATH_MAX]; + struct envlist *e; close(p[0]); if (dup2(p[1], 1) == -1) @@ -200,6 +201,10 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost) setenv_time("TLS_CLIENT_NOT_AFTER", req->notafter); setenv_time("TLS_CLIENT_NOT_BEFORE", req->notbefore); + TAILQ_FOREACH(e, &vhost->env, envs) { + safe_setenv(e->name, e->value); + } + strlcpy(path, ex, sizeof(path)); pwd = dirname(path); @@ -241,6 +241,13 @@ is set to Handle all the requests for the current virtual host using the CGI script at .Pa path . +.It Ic env Ar name Ar value +Set the environment variable +.Ar name +to +.Ar value +when executing CGI scripts. +Can be provided more than once. .It Ic index Ar string Set the directory index file. If not specified, it defaults to @@ -270,7 +277,7 @@ A .Ic location section may include most of the server configuration rules except -.Ic cert , Ic key , Ic root , Ic location , +.Ic cert , Ic env , Ic key , Ic root , Ic location , .Ic entrypoint No and Ic cgi . .It Ic root Pa directory Specify the root directory for this server. @@ -244,6 +244,7 @@ free_config(void) { struct vhost *h, *th; struct location *l, *tl; + struct envlist *e, *te; int v; v = conf.verbose; @@ -266,6 +267,12 @@ free_config(void) free(l); } + TAILQ_FOREACH_SAFE(e, &h->env, envs, te) { + free(e->name); + free(e->value); + free(e); + } + TAILQ_REMOVE(&hosts, h, vhosts); free(h); } @@ -73,6 +73,13 @@ struct location { TAILQ_ENTRY(location) locations; }; +TAILQ_HEAD(envhead, envlist); +struct envlist { + char *name; + char *value; + TAILQ_ENTRY(envlist) envs; +}; + extern TAILQ_HEAD(vhosthead, vhost) hosts; struct vhost { const char *domain; @@ -89,6 +96,8 @@ struct vhost { * settings for the vhost, then follows the "real" location * rules as specified in the configuration. */ struct lochead locations; + + struct envhead env; }; struct etm { /* extension to mime */ @@ -60,6 +60,7 @@ chroot return TCHROOT; client return TCLIENT; default return TDEFAULT; entrypoint return TENTRYPOINT; +env return TENV; index return TINDEX; ipv6 return TIPV6; key return TKEY; @@ -59,7 +59,7 @@ void advance_loc(void); %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE %token TCHROOT TUSER TSERVER TPREFORK -%token TLOCATION TCERT TKEY TROOT TCGI TLANG TLOG TINDEX TAUTO +%token TLOCATION TCERT TKEY TROOT TCGI TENV TLANG TLOG TINDEX TAUTO %token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA %token TERR @@ -133,6 +133,17 @@ servopt : TCERT TSTRING { host->cert = ensure_absolute_path($2); } memmove($2, $2+1, strlen($2)); host->entrypoint = $2; } + | TENV TSTRING TSTRING { + struct envlist *e; + + e = xcalloc(1, sizeof(*e)); + e->name = $2; + e->value = $3; + if (TAILQ_EMPTY(&host->env)) + TAILQ_INSERT_HEAD(&host->env, e, envs); + else + TAILQ_INSERT_TAIL(&host->env, e, envs); + } | TKEY TSTRING { host->key = ensure_absolute_path($2); } | TROOT TSTRING { host->dir = ensure_absolute_path($2); } | locopt |