Blame


1 15902770 2021-01-15 op %{
2 15902770 2021-01-15 op
3 15902770 2021-01-15 op /*
4 e2f167af 2021-01-02 op * Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
5 c39be742 2021-07-09 op * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
6 c39be742 2021-07-09 op * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
7 c39be742 2021-07-09 op * Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
8 c39be742 2021-07-09 op * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
9 c39be742 2021-07-09 op * Copyright (c) 2001 Markus Friedl. All rights reserved.
10 c39be742 2021-07-09 op * Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
11 c39be742 2021-07-09 op * Copyright (c) 2001 Theo de Raadt. All rights reserved.
12 15902770 2021-01-15 op *
13 15902770 2021-01-15 op * Permission to use, copy, modify, and distribute this software for any
14 15902770 2021-01-15 op * purpose with or without fee is hereby granted, provided that the above
15 15902770 2021-01-15 op * copyright notice and this permission notice appear in all copies.
16 15902770 2021-01-15 op *
17 15902770 2021-01-15 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18 15902770 2021-01-15 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
19 15902770 2021-01-15 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20 15902770 2021-01-15 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 15902770 2021-01-15 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22 15902770 2021-01-15 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23 15902770 2021-01-15 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 15902770 2021-01-15 op */
25 1f1f3810 2022-02-03 op
26 1f1f3810 2022-02-03 op #include "gmid.h"
27 15902770 2021-01-15 op
28 74f0778b 2021-06-16 op #include <ctype.h>
29 002a84a1 2021-02-10 op #include <errno.h>
30 6abda252 2021-02-06 op #include <stdarg.h>
31 15902770 2021-01-15 op #include <stdio.h>
32 74f0778b 2021-06-16 op #include <stdlib.h>
33 32693ee6 2021-01-28 op #include <string.h>
34 15902770 2021-01-15 op
35 c39be742 2021-07-09 op TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
36 c39be742 2021-07-09 op static struct file {
37 c39be742 2021-07-09 op TAILQ_ENTRY(file) entry;
38 c39be742 2021-07-09 op FILE *stream;
39 c39be742 2021-07-09 op char *name;
40 c39be742 2021-07-09 op size_t ungetpos;
41 c39be742 2021-07-09 op size_t ungetsize;
42 c39be742 2021-07-09 op u_char *ungetbuf;
43 c39be742 2021-07-09 op int eof_reached;
44 c39be742 2021-07-09 op int lineno;
45 c39be742 2021-07-09 op int errors;
46 c39be742 2021-07-09 op } *file, *topfile;
47 74f0778b 2021-06-16 op
48 c39be742 2021-07-09 op struct file *pushfile(const char *, int);
49 c39be742 2021-07-09 op int popfile(void);
50 c39be742 2021-07-09 op int yyparse(void);
51 c39be742 2021-07-09 op int yylex(void);
52 c39be742 2021-07-09 op void yyerror(const char *, ...)
53 c39be742 2021-07-09 op __attribute__((__format__ (printf, 1, 2)))
54 c39be742 2021-07-09 op __attribute__((__nonnull__ (1)));
55 f3966209 2021-07-13 op void yywarn(const char *, ...)
56 f3966209 2021-07-13 op __attribute__((__format__ (printf, 1, 2)))
57 f3966209 2021-07-13 op __attribute__((__nonnull__ (1)));
58 c39be742 2021-07-09 op int kw_cmp(const void *, const void *);
59 c39be742 2021-07-09 op int lookup(char *);
60 c39be742 2021-07-09 op int igetc(void);
61 c39be742 2021-07-09 op int lgetc(int);
62 c39be742 2021-07-09 op void lungetc(int);
63 c39be742 2021-07-09 op int findeol(void);
64 ef129b08 2021-06-16 op
65 15902770 2021-01-15 op /*
66 15902770 2021-01-15 op * #define YYDEBUG 1
67 15902770 2021-01-15 op * int yydebug = 1;
68 15902770 2021-01-15 op */
69 15902770 2021-01-15 op
70 3b21cca3 2021-06-29 op TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
71 3b21cca3 2021-06-29 op struct sym {
72 3b21cca3 2021-06-29 op TAILQ_ENTRY(sym) entry;
73 3b21cca3 2021-06-29 op int used;
74 3b21cca3 2021-06-29 op int persist;
75 3b21cca3 2021-06-29 op char *name;
76 3b21cca3 2021-06-29 op char *val;
77 3b21cca3 2021-06-29 op };
78 3b21cca3 2021-06-29 op
79 c39be742 2021-07-09 op int symset(const char *, const char *, int);
80 c39be742 2021-07-09 op char *symget(const char *);
81 15902770 2021-01-15 op
82 c39be742 2021-07-09 op struct vhost *new_vhost(void);
83 c39be742 2021-07-09 op struct location *new_location(void);
84 b7967bc1 2021-01-02 op struct proxy *new_proxy(void);
85 e17642a7 2021-02-01 op char *ensure_absolute_path(char*);
86 6abda252 2021-02-06 op int check_block_code(int);
87 6abda252 2021-02-06 op char *check_block_fmt(char*);
88 6abda252 2021-02-06 op int check_strip_no(int);
89 391825e3 2021-07-09 op int check_port_num(int);
90 a709ddf5 2021-02-07 op int check_prefork_num(int);
91 49b73ba1 2021-02-10 op void advance_loc(void);
92 b7967bc1 2021-01-02 op void advance_proxy(void);
93 b7967bc1 2021-01-02 op void parsehp(char *, char **, const char **, const char *);
94 c705ecb1 2021-05-03 op void only_once(const void*, const char*);
95 8ad1c570 2021-05-09 op void only_oncei(int, const char*);
96 8ad1c570 2021-05-09 op int fastcgi_conf(char *, char *, char *);
97 2025e96d 2022-09-10 op void add_param(char *, char *);
98 13ed2fb6 2021-01-27 op
99 c39be742 2021-07-09 op static struct vhost *host;
100 c39be742 2021-07-09 op static struct location *loc;
101 b7967bc1 2021-01-02 op static struct proxy *proxy;
102 ee219d70 2022-02-26 op static char *current_media;
103 c39be742 2021-07-09 op static int errors;
104 c39be742 2021-07-09 op
105 c39be742 2021-07-09 op typedef struct {
106 c39be742 2021-07-09 op union {
107 c39be742 2021-07-09 op char *string;
108 c39be742 2021-07-09 op int number;
109 c39be742 2021-07-09 op } v;
110 c39be742 2021-07-09 op int lineno;
111 c39be742 2021-07-09 op } YYSTYPE;
112 c39be742 2021-07-09 op
113 15902770 2021-01-15 op %}
114 15902770 2021-01-15 op
115 15902770 2021-01-15 op /* for bison: */
116 15902770 2021-01-15 op /* %define parse.error verbose */
117 15902770 2021-01-15 op
118 c74c7030 2021-07-19 op %token ALIAS AUTO
119 c74c7030 2021-07-19 op %token BLOCK
120 d29a2ee2 2022-09-06 op %token CA CERT CHROOT CLIENT
121 c74c7030 2021-07-19 op %token DEFAULT
122 b7967bc1 2021-01-02 op %token FASTCGI FOR_HOST
123 c74c7030 2021-07-19 op %token INCLUDE INDEX IPV6
124 c74c7030 2021-07-19 op %token KEY
125 c74c7030 2021-07-19 op %token LANG LOCATION LOG
126 ff05125e 2021-10-15 op %token OCSP OFF ON
127 b7967bc1 2021-01-02 op %token PARAM PORT PREFORK PROTO PROTOCOLS PROXY
128 72b033ef 2021-12-29 op %token RELAY_TO REQUIRE RETURN ROOT
129 1cdea97b 2022-01-30 op %token SERVER SNI SPAWN STRIP
130 ee219d70 2022-02-26 op %token TCP TOEXT TYPE TYPES
131 593e412b 2021-01-01 op %token USE_TLS USER
132 5128c0b0 2021-01-01 op %token VERIFYNAME
133 d06d6f4b 2021-04-29 op
134 c39be742 2021-07-09 op %token ERROR
135 7252049d 2021-06-29 op
136 c39be742 2021-07-09 op %token <v.string> STRING
137 c39be742 2021-07-09 op %token <v.number> NUM
138 15902770 2021-01-15 op
139 c39be742 2021-07-09 op %type <v.number> bool
140 ee219d70 2022-02-26 op %type <v.string> string numberstring
141 98f52178 2021-06-29 op
142 15902770 2021-01-15 op %%
143 15902770 2021-01-15 op
144 6b86655a 2021-06-29 op conf : /* empty */
145 c39be742 2021-07-09 op | conf include '\n'
146 c39be742 2021-07-09 op | conf '\n'
147 c39be742 2021-07-09 op | conf varset '\n'
148 c39be742 2021-07-09 op | conf option '\n'
149 c39be742 2021-07-09 op | conf vhost '\n'
150 ee219d70 2022-02-26 op | conf types '\n'
151 c39be742 2021-07-09 op | conf error '\n' { file->errors++; }
152 3b21cca3 2021-06-29 op ;
153 3b21cca3 2021-06-29 op
154 c39be742 2021-07-09 op include : INCLUDE STRING {
155 c39be742 2021-07-09 op struct file *nfile;
156 c39be742 2021-07-09 op
157 c39be742 2021-07-09 op if ((nfile = pushfile($2, 0)) == NULL) {
158 c39be742 2021-07-09 op yyerror("failed to include file %s", $2);
159 c39be742 2021-07-09 op free($2);
160 c39be742 2021-07-09 op YYERROR;
161 c39be742 2021-07-09 op }
162 c39be742 2021-07-09 op free($2);
163 c39be742 2021-07-09 op
164 c39be742 2021-07-09 op file = nfile;
165 c39be742 2021-07-09 op lungetc('\n');
166 c39be742 2021-07-09 op }
167 c39be742 2021-07-09 op ;
168 c39be742 2021-07-09 op
169 c74c7030 2021-07-19 op bool : ON { $$ = 1; }
170 c74c7030 2021-07-19 op | OFF { $$ = 0; }
171 c39be742 2021-07-09 op ;
172 c39be742 2021-07-09 op
173 c39be742 2021-07-09 op string : string STRING {
174 98f52178 2021-06-29 op if (asprintf(&$$, "%s%s", $1, $2) == -1) {
175 98f52178 2021-06-29 op free($1);
176 98f52178 2021-06-29 op free($2);
177 98f52178 2021-06-29 op yyerror("string: asprintf: %s", strerror(errno));
178 98f52178 2021-06-29 op YYERROR;
179 98f52178 2021-06-29 op }
180 98f52178 2021-06-29 op free($1);
181 98f52178 2021-06-29 op free($2);
182 98f52178 2021-06-29 op }
183 c39be742 2021-07-09 op | STRING
184 98f52178 2021-06-29 op ;
185 98f52178 2021-06-29 op
186 ee219d70 2022-02-26 op numberstring : NUM {
187 ee219d70 2022-02-26 op char *s;
188 ee219d70 2022-02-26 op if (asprintf(&s, "%d", $1) == -1) {
189 ee219d70 2022-02-26 op yyerror("asprintf: number");
190 ee219d70 2022-02-26 op YYERROR;
191 ee219d70 2022-02-26 op }
192 ee219d70 2022-02-26 op $$ = s;
193 ee219d70 2022-02-26 op }
194 ee219d70 2022-02-26 op | STRING
195 ee219d70 2022-02-26 op ;
196 ee219d70 2022-02-26 op
197 c39be742 2021-07-09 op varset : STRING '=' string {
198 3b21cca3 2021-06-29 op char *s = $1;
199 3b21cca3 2021-06-29 op while (*s++) {
200 c39be742 2021-07-09 op if (isspace((unsigned char)*s)) {
201 3b21cca3 2021-06-29 op yyerror("macro name cannot contain "
202 3b21cca3 2021-06-29 op "whitespaces");
203 3b21cca3 2021-06-29 op free($1);
204 3b21cca3 2021-06-29 op free($3);
205 3b21cca3 2021-06-29 op YYERROR;
206 3b21cca3 2021-06-29 op }
207 3b21cca3 2021-06-29 op }
208 3b21cca3 2021-06-29 op symset($1, $3, 0);
209 3b21cca3 2021-06-29 op free($1);
210 3b21cca3 2021-06-29 op free($3);
211 3b21cca3 2021-06-29 op }
212 15902770 2021-01-15 op ;
213 15902770 2021-01-15 op
214 7277bb7d 2022-09-10 op option : CHROOT string {
215 7277bb7d 2022-09-10 op if (strlcpy(conf.chroot, $2, sizeof(conf.chroot)) >=
216 7277bb7d 2022-09-10 op sizeof(conf.chroot))
217 7277bb7d 2022-09-10 op yyerror("chroot path too long");
218 7277bb7d 2022-09-10 op free($2);
219 7277bb7d 2022-09-10 op }
220 c74c7030 2021-07-19 op | IPV6 bool { conf.ipv6 = $2; }
221 c74c7030 2021-07-19 op | PORT NUM { conf.port = check_port_num($2); }
222 c74c7030 2021-07-19 op | PREFORK NUM { conf.prefork = check_prefork_num($2); }
223 c74c7030 2021-07-19 op | PROTOCOLS string {
224 5bc3c98e 2021-01-15 op if (tls_config_parse_protocols(&conf.protos, $2) == -1)
225 002a84a1 2021-02-10 op yyerror("invalid protocols string \"%s\"", $2);
226 3c4b712b 2021-01-01 op free($2);
227 5bc3c98e 2021-01-15 op }
228 7277bb7d 2022-09-10 op | USER string {
229 7277bb7d 2022-09-10 op if (strlcpy(conf.user, $2, sizeof(conf.user)) >=
230 7277bb7d 2022-09-10 op sizeof(conf.user))
231 7277bb7d 2022-09-10 op yyerror("user name too long");
232 7277bb7d 2022-09-10 op free($2);
233 7277bb7d 2022-09-10 op }
234 15902770 2021-01-15 op ;
235 15902770 2021-01-15 op
236 c74c7030 2021-07-19 op vhost : SERVER string {
237 b8e64ccd 2021-03-31 op host = new_vhost();
238 b8e64ccd 2021-03-31 op TAILQ_INSERT_HEAD(&hosts, host, vhosts);
239 b8e64ccd 2021-03-31 op
240 b8e64ccd 2021-03-31 op loc = new_location();
241 b8e64ccd 2021-03-31 op TAILQ_INSERT_HEAD(&host->locations, loc, locations);
242 b8e64ccd 2021-03-31 op
243 b7967bc1 2021-01-02 op TAILQ_INIT(&host->proxies);
244 b7967bc1 2021-01-02 op
245 b8e64ccd 2021-03-31 op loc->match = xstrdup("*");
246 15902770 2021-01-15 op host->domain = $2;
247 15902770 2021-01-15 op
248 cbeee4ca 2021-01-28 op if (strstr($2, "xn--") != NULL) {
249 f3966209 2021-07-13 op yywarn("\"%s\" looks like punycode: you "
250 f3966209 2021-07-13 op "should use the decoded hostname", $2);
251 cbeee4ca 2021-01-28 op }
252 b7967bc1 2021-01-02 op } '{' optnl servbody '}' {
253 fdea6aa0 2021-04-30 op if (host->cert == NULL || host->key == NULL)
254 002a84a1 2021-02-10 op yyerror("invalid vhost definition: %s", $2);
255 15902770 2021-01-15 op }
256 f3966209 2021-07-13 op | error '}' { yyerror("bad server directive"); }
257 15902770 2021-01-15 op ;
258 15902770 2021-01-15 op
259 b7967bc1 2021-01-02 op servbody : /* empty */
260 b7967bc1 2021-01-02 op | servbody servopt optnl
261 b7967bc1 2021-01-02 op | servbody location optnl
262 b7967bc1 2021-01-02 op | servbody proxy optnl
263 15902770 2021-01-15 op ;
264 15902770 2021-01-15 op
265 c74c7030 2021-07-19 op servopt : ALIAS string {
266 cc8c2901 2021-04-29 op struct alist *a;
267 cc8c2901 2021-04-29 op
268 cc8c2901 2021-04-29 op a = xcalloc(1, sizeof(*a));
269 cc8c2901 2021-04-29 op a->alias = $2;
270 cc8c2901 2021-04-29 op if (TAILQ_EMPTY(&host->aliases))
271 cc8c2901 2021-04-29 op TAILQ_INSERT_HEAD(&host->aliases, a, aliases);
272 cc8c2901 2021-04-29 op else
273 cc8c2901 2021-04-29 op TAILQ_INSERT_TAIL(&host->aliases, a, aliases);
274 cc8c2901 2021-04-29 op }
275 c74c7030 2021-07-19 op | CERT string {
276 c705ecb1 2021-05-03 op only_once(host->cert, "cert");
277 c705ecb1 2021-05-03 op host->cert = ensure_absolute_path($2);
278 9cc630aa 2021-04-28 op }
279 c74c7030 2021-07-19 op | KEY string {
280 c705ecb1 2021-05-03 op only_once(host->key, "key");
281 c705ecb1 2021-05-03 op host->key = ensure_absolute_path($2);
282 c92b802b 2021-06-11 op }
283 ff05125e 2021-10-15 op | OCSP string {
284 ff05125e 2021-10-15 op only_once(host->ocsp, "ocsp");
285 ff05125e 2021-10-15 op host->ocsp = ensure_absolute_path($2);
286 ff05125e 2021-10-15 op }
287 c74c7030 2021-07-19 op | PARAM string '=' string {
288 2025e96d 2022-09-10 op add_param($2, $4);
289 c705ecb1 2021-05-03 op }
290 c8b74339 2021-01-24 op | locopt
291 c8b74339 2021-01-24 op ;
292 7bdcc91e 2021-01-01 op
293 b7967bc1 2021-01-02 op proxy : PROXY { advance_proxy(); }
294 b7967bc1 2021-01-02 op proxy_matches '{' optnl proxy_opts '}' {
295 b7967bc1 2021-01-02 op if (proxy->host == NULL)
296 b7967bc1 2021-01-02 op yyerror("invalid proxy block: missing `relay-to' option");
297 b7967bc1 2021-01-02 op
298 b7967bc1 2021-01-02 op if ((proxy->cert == NULL && proxy->key != NULL) ||
299 b7967bc1 2021-01-02 op (proxy->cert != NULL && proxy->key == NULL))
300 b7967bc1 2021-01-02 op yyerror("invalid proxy block: missing cert or key");
301 b7967bc1 2021-01-02 op }
302 b7967bc1 2021-01-02 op ;
303 b7967bc1 2021-01-02 op
304 b7967bc1 2021-01-02 op proxy_matches : /* empty */
305 b7967bc1 2021-01-02 op | proxy_matches proxy_match
306 b7967bc1 2021-01-02 op ;
307 b7967bc1 2021-01-02 op
308 b7967bc1 2021-01-02 op proxy_match : PROTO string {
309 b7967bc1 2021-01-02 op only_once(proxy->match_proto, "proxy proto");
310 b7967bc1 2021-01-02 op free(proxy->match_proto);
311 b7967bc1 2021-01-02 op proxy->match_proto = $2;
312 b7967bc1 2021-01-02 op }
313 b7967bc1 2021-01-02 op | FOR_HOST string {
314 b7967bc1 2021-01-02 op only_once(proxy->match_host, "proxy for-host");
315 b7967bc1 2021-01-02 op free(proxy->match_host);
316 b7967bc1 2021-01-02 op parsehp($2, &proxy->match_host, &proxy->match_port, "10965");
317 b7967bc1 2021-01-02 op }
318 7bdcc91e 2021-01-01 op ;
319 7bdcc91e 2021-01-01 op
320 7bdcc91e 2021-01-01 op proxy_opts : /* empty */
321 7bdcc91e 2021-01-01 op | proxy_opts proxy_opt optnl
322 7bdcc91e 2021-01-01 op ;
323 7bdcc91e 2021-01-01 op
324 7bdcc91e 2021-01-01 op proxy_opt : CERT string {
325 b7967bc1 2021-01-02 op only_once(proxy->cert, "proxy cert");
326 b7967bc1 2021-01-02 op tls_unload_file(proxy->cert, proxy->certlen);
327 7bdcc91e 2021-01-01 op ensure_absolute_path($2);
328 b7967bc1 2021-01-02 op proxy->cert = tls_load_file($2, &proxy->certlen, NULL);
329 b7967bc1 2021-01-02 op if (proxy->cert == NULL)
330 7bdcc91e 2021-01-01 op yyerror("can't load cert %s", $2);
331 3c4b712b 2021-01-01 op free($2);
332 7bdcc91e 2021-01-01 op }
333 7bdcc91e 2021-01-01 op | KEY string {
334 b7967bc1 2021-01-02 op only_once(proxy->key, "proxy key");
335 b7967bc1 2021-01-02 op tls_unload_file(proxy->key, proxy->keylen);
336 7bdcc91e 2021-01-01 op ensure_absolute_path($2);
337 b7967bc1 2021-01-02 op proxy->key = tls_load_file($2, &proxy->keylen, NULL);
338 b7967bc1 2021-01-02 op if (proxy->key == NULL)
339 7bdcc91e 2021-01-01 op yyerror("can't load key %s", $2);
340 3c4b712b 2021-01-01 op free($2);
341 c7c8ef44 2021-01-01 op }
342 c7c8ef44 2021-01-01 op | PROTOCOLS string {
343 b7967bc1 2021-01-02 op if (tls_config_parse_protocols(&proxy->protocols, $2) == -1)
344 c7c8ef44 2021-01-01 op yyerror("invalid protocols string \"%s\"", $2);
345 3c4b712b 2021-01-01 op free($2);
346 7bdcc91e 2021-01-01 op }
347 7bdcc91e 2021-01-01 op | RELAY_TO string {
348 b7967bc1 2021-01-02 op only_once(proxy->host, "proxy relay-to");
349 b7967bc1 2021-01-02 op free(proxy->host);
350 b7967bc1 2021-01-02 op parsehp($2, &proxy->host, &proxy->port, "1965");
351 593e412b 2021-01-01 op }
352 ba94a608 2022-01-04 op | REQUIRE CLIENT CA string {
353 ba94a608 2022-01-04 op only_once(proxy->reqca, "require client ca");
354 ba94a608 2022-01-04 op ensure_absolute_path($4);
355 ba94a608 2022-01-04 op if ((proxy->reqca = load_ca($4)) == NULL)
356 ba94a608 2022-01-04 op yyerror("couldn't load ca cert: %s", $4);
357 ba94a608 2022-01-04 op free($4);
358 1cdea97b 2022-01-30 op }
359 1cdea97b 2022-01-30 op | SNI string {
360 1cdea97b 2022-01-30 op only_once(proxy->sni, "proxy sni");
361 1cdea97b 2022-01-30 op free(proxy->sni);
362 1cdea97b 2022-01-30 op proxy->sni = $2;
363 ba94a608 2022-01-04 op }
364 593e412b 2021-01-01 op | USE_TLS bool {
365 b7967bc1 2021-01-02 op proxy->notls = !$2;
366 7bdcc91e 2021-01-01 op }
367 5128c0b0 2021-01-01 op | VERIFYNAME bool {
368 b7967bc1 2021-01-02 op proxy->noverifyname = !$2;
369 5128c0b0 2021-01-01 op }
370 7bdcc91e 2021-01-01 op ;
371 7bdcc91e 2021-01-01 op
372 c74c7030 2021-07-19 op location : LOCATION { advance_loc(); } string '{' optnl locopts '}' {
373 49b73ba1 2021-02-10 op /* drop the starting '/' if any */
374 49b73ba1 2021-02-10 op if (*$3 == '/')
375 49b73ba1 2021-02-10 op memmove($3, $3+1, strlen($3));
376 49b73ba1 2021-02-10 op loc->match = $3;
377 6119e13e 2021-01-19 op }
378 c8b74339 2021-01-24 op | error '}'
379 c8b74339 2021-01-24 op ;
380 c8b74339 2021-01-24 op
381 c8b74339 2021-01-24 op locopts : /* empty */
382 c39be742 2021-07-09 op | locopts locopt optnl
383 c8b74339 2021-01-24 op ;
384 c8b74339 2021-01-24 op
385 c74c7030 2021-07-19 op locopt : AUTO INDEX bool { loc->auto_index = $3 ? 1 : -1; }
386 c74c7030 2021-07-19 op | BLOCK RETURN NUM string {
387 c705ecb1 2021-05-03 op only_once(loc->block_fmt, "block");
388 6abda252 2021-02-06 op loc->block_fmt = check_block_fmt($4);
389 6abda252 2021-02-06 op loc->block_code = check_block_code($3);
390 6abda252 2021-02-06 op }
391 c74c7030 2021-07-19 op | BLOCK RETURN NUM {
392 c705ecb1 2021-05-03 op only_once(loc->block_fmt, "block");
393 6abda252 2021-02-06 op loc->block_fmt = xstrdup("temporary failure");
394 6abda252 2021-02-06 op loc->block_code = check_block_code($3);
395 6abda252 2021-02-06 op if ($3 >= 30 && $3 < 40)
396 6abda252 2021-02-06 op yyerror("missing `meta' for block return %d", $3);
397 6abda252 2021-02-06 op }
398 c74c7030 2021-07-19 op | BLOCK {
399 c705ecb1 2021-05-03 op only_once(loc->block_fmt, "block");
400 6abda252 2021-02-06 op loc->block_fmt = xstrdup("temporary failure");
401 6abda252 2021-02-06 op loc->block_code = 40;
402 6abda252 2021-02-06 op }
403 c74c7030 2021-07-19 op | DEFAULT TYPE string {
404 c705ecb1 2021-05-03 op only_once(loc->default_mime, "default type");
405 eb59f87e 2021-02-09 op loc->default_mime = $3;
406 eb59f87e 2021-02-09 op }
407 abc8801d 2021-07-19 op | FASTCGI fastcgi
408 c74c7030 2021-07-19 op | INDEX string {
409 c705ecb1 2021-05-03 op only_once(loc->index, "index");
410 eb59f87e 2021-02-09 op loc->index = $2;
411 eb59f87e 2021-02-09 op }
412 c74c7030 2021-07-19 op | LANG string {
413 c705ecb1 2021-05-03 op only_once(loc->lang, "lang");
414 eb59f87e 2021-02-09 op loc->lang = $2;
415 eb59f87e 2021-02-09 op }
416 c74c7030 2021-07-19 op | LOG bool { loc->disable_log = !$2; }
417 da2185f3 2021-01-01 op | REQUIRE CLIENT CA string {
418 da2185f3 2021-01-01 op only_once(loc->reqca, "require client ca");
419 da2185f3 2021-01-01 op ensure_absolute_path($4);
420 da2185f3 2021-01-01 op if ((loc->reqca = load_ca($4)) == NULL)
421 da2185f3 2021-01-01 op yyerror("couldn't load ca cert: %s", $4);
422 da2185f3 2021-01-01 op free($4);
423 da2185f3 2021-01-01 op }
424 da2185f3 2021-01-01 op | ROOT string {
425 da2185f3 2021-01-01 op only_once(loc->dir, "root");
426 da2185f3 2021-01-01 op loc->dir = ensure_absolute_path($2);
427 da2185f3 2021-01-01 op }
428 da2185f3 2021-01-01 op | STRIP NUM { loc->strip = check_strip_no($2); }
429 da2185f3 2021-01-01 op ;
430 da2185f3 2021-01-01 op
431 c74c7030 2021-07-19 op fastcgi : SPAWN string {
432 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
433 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf(NULL, NULL, $2);
434 0d047efc 2021-05-24 op }
435 98f52178 2021-06-29 op | string {
436 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
437 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($1, NULL, NULL);
438 0d047efc 2021-05-24 op }
439 c74c7030 2021-07-19 op | TCP string PORT NUM {
440 0d047efc 2021-05-24 op char *c;
441 762b9b99 2021-07-09 op if (asprintf(&c, "%d", $4) == -1)
442 0d047efc 2021-05-24 op err(1, "asprintf");
443 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
444 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($2, c, NULL);
445 0d047efc 2021-05-24 op }
446 c74c7030 2021-07-19 op | TCP string {
447 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
448 0d047efc 2021-05-24 op loc->fcgi = fastcgi_conf($2, xstrdup("9000"), NULL);
449 0d047efc 2021-05-24 op }
450 c74c7030 2021-07-19 op | TCP string PORT string {
451 0d047efc 2021-05-24 op only_oncei(loc->fcgi, "fastcgi");
452 762b9b99 2021-07-09 op loc->fcgi = fastcgi_conf($2, $4, NULL);
453 0d047efc 2021-05-24 op }
454 ee219d70 2022-02-26 op ;
455 ee219d70 2022-02-26 op
456 cd5826b8 2022-09-10 op types : TYPES '{' optnl mediaopts_l '}' ;
457 0d047efc 2021-05-24 op
458 ee219d70 2022-02-26 op mediaopts_l : mediaopts_l mediaoptsl nl
459 ee219d70 2022-02-26 op | mediaoptsl nl
460 ee219d70 2022-02-26 op ;
461 ee219d70 2022-02-26 op
462 aa9543b9 2022-09-10 op mediaoptsl : STRING {
463 aa9543b9 2022-09-10 op free(current_media);
464 aa9543b9 2022-09-10 op current_media = $1;
465 aa9543b9 2022-09-10 op } medianames_l optsemicolon
466 ee219d70 2022-02-26 op | include
467 ee219d70 2022-02-26 op ;
468 ee219d70 2022-02-26 op
469 ee219d70 2022-02-26 op medianames_l : medianames_l medianamesl
470 ee219d70 2022-02-26 op | medianamesl
471 ee219d70 2022-02-26 op ;
472 ee219d70 2022-02-26 op
473 d8d170aa 2022-04-08 op medianamesl : numberstring {
474 d8d170aa 2022-04-08 op if (add_mime(&conf.mime, current_media, $1) == -1)
475 d8d170aa 2022-04-08 op err(1, "add_mime");
476 aa9543b9 2022-09-10 op free($1);
477 d8d170aa 2022-04-08 op }
478 ee219d70 2022-02-26 op ;
479 ee219d70 2022-02-26 op
480 ee219d70 2022-02-26 op nl : '\n' optnl
481 ee219d70 2022-02-26 op ;
482 ee219d70 2022-02-26 op
483 c39be742 2021-07-09 op optnl : '\n' optnl /* zero or more newlines */
484 67f49405 2021-07-09 op | ';' optnl /* semicolons too */
485 c39be742 2021-07-09 op | /*empty*/
486 c39be742 2021-07-09 op ;
487 fdea6aa0 2021-04-30 op
488 ee219d70 2022-02-26 op optsemicolon : ';'
489 ee219d70 2022-02-26 op |
490 ee219d70 2022-02-26 op ;
491 ee219d70 2022-02-26 op
492 c39be742 2021-07-09 op %%
493 b8e64ccd 2021-03-31 op
494 e5d82d94 2022-03-19 op static const struct keyword {
495 74f0778b 2021-06-16 op const char *word;
496 74f0778b 2021-06-16 op int token;
497 74f0778b 2021-06-16 op } keywords[] = {
498 d93c8191 2021-07-09 op /* these MUST be sorted */
499 c74c7030 2021-07-19 op {"alias", ALIAS},
500 c74c7030 2021-07-19 op {"auto", AUTO},
501 c74c7030 2021-07-19 op {"block", BLOCK},
502 c74c7030 2021-07-19 op {"ca", CA},
503 c74c7030 2021-07-19 op {"cert", CERT},
504 c74c7030 2021-07-19 op {"chroot", CHROOT},
505 c74c7030 2021-07-19 op {"client", CLIENT},
506 c74c7030 2021-07-19 op {"default", DEFAULT},
507 abc8801d 2021-07-19 op {"fastcgi", FASTCGI},
508 b7967bc1 2021-01-02 op {"for-host", FOR_HOST},
509 88971f9a 2022-02-26 op {"include", INCLUDE},
510 c74c7030 2021-07-19 op {"index", INDEX},
511 c74c7030 2021-07-19 op {"ipv6", IPV6},
512 c74c7030 2021-07-19 op {"key", KEY},
513 c74c7030 2021-07-19 op {"lang", LANG},
514 c74c7030 2021-07-19 op {"location", LOCATION},
515 c74c7030 2021-07-19 op {"log", LOG},
516 ff05125e 2021-10-15 op {"ocsp", OCSP},
517 c74c7030 2021-07-19 op {"off", OFF},
518 c74c7030 2021-07-19 op {"on", ON},
519 c74c7030 2021-07-19 op {"param", PARAM},
520 c74c7030 2021-07-19 op {"port", PORT},
521 c74c7030 2021-07-19 op {"prefork", PREFORK},
522 b7967bc1 2021-01-02 op {"proto", PROTO},
523 c74c7030 2021-07-19 op {"protocols", PROTOCOLS},
524 72b033ef 2021-12-29 op {"proxy", PROXY},
525 72b033ef 2021-12-29 op {"relay-to", RELAY_TO},
526 c74c7030 2021-07-19 op {"require", REQUIRE},
527 c74c7030 2021-07-19 op {"return", RETURN},
528 c74c7030 2021-07-19 op {"root", ROOT},
529 c74c7030 2021-07-19 op {"server", SERVER},
530 1cdea97b 2022-01-30 op {"sni", SNI},
531 c74c7030 2021-07-19 op {"spawn", SPAWN},
532 c74c7030 2021-07-19 op {"strip", STRIP},
533 c74c7030 2021-07-19 op {"tcp", TCP},
534 c74c7030 2021-07-19 op {"to-ext", TOEXT},
535 c74c7030 2021-07-19 op {"type", TYPE},
536 ee219d70 2022-02-26 op {"types", TYPES},
537 593e412b 2021-01-01 op {"use-tls", USE_TLS},
538 c74c7030 2021-07-19 op {"user", USER},
539 5128c0b0 2021-01-01 op {"verifyname", VERIFYNAME},
540 74f0778b 2021-06-16 op };
541 74f0778b 2021-06-16 op
542 c39be742 2021-07-09 op void
543 c39be742 2021-07-09 op yyerror(const char *msg, ...)
544 c39be742 2021-07-09 op {
545 c39be742 2021-07-09 op va_list ap;
546 c39be742 2021-07-09 op
547 c39be742 2021-07-09 op file->errors++;
548 c39be742 2021-07-09 op
549 c39be742 2021-07-09 op va_start(ap, msg);
550 f3966209 2021-07-13 op fprintf(stderr, "%s:%d error: ", config_path, yylval.lineno);
551 f3966209 2021-07-13 op vfprintf(stderr, msg, ap);
552 f3966209 2021-07-13 op fprintf(stderr, "\n");
553 f3966209 2021-07-13 op va_end(ap);
554 f3966209 2021-07-13 op }
555 f3966209 2021-07-13 op
556 f3966209 2021-07-13 op void
557 f3966209 2021-07-13 op yywarn(const char *msg, ...)
558 f3966209 2021-07-13 op {
559 f3966209 2021-07-13 op va_list ap;
560 f3966209 2021-07-13 op
561 f3966209 2021-07-13 op va_start(ap, msg);
562 f3966209 2021-07-13 op fprintf(stderr, "%s:%d warning: ", config_path, yylval.lineno);
563 c39be742 2021-07-09 op vfprintf(stderr, msg, ap);
564 c39be742 2021-07-09 op fprintf(stderr, "\n");
565 c39be742 2021-07-09 op va_end(ap);
566 c39be742 2021-07-09 op }
567 c39be742 2021-07-09 op
568 d93c8191 2021-07-09 op int
569 d93c8191 2021-07-09 op kw_cmp(const void *k, const void *e)
570 d93c8191 2021-07-09 op {
571 d93c8191 2021-07-09 op return strcmp(k, ((struct keyword *)e)->word);
572 d93c8191 2021-07-09 op }
573 d93c8191 2021-07-09 op
574 c39be742 2021-07-09 op int
575 c39be742 2021-07-09 op lookup(char *s)
576 74f0778b 2021-06-16 op {
577 c39be742 2021-07-09 op const struct keyword *p;
578 74f0778b 2021-06-16 op
579 c39be742 2021-07-09 op p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
580 c39be742 2021-07-09 op sizeof(keywords[0]), kw_cmp);
581 74f0778b 2021-06-16 op
582 c39be742 2021-07-09 op if (p)
583 c39be742 2021-07-09 op return p->token;
584 c39be742 2021-07-09 op else
585 c39be742 2021-07-09 op return STRING;
586 c39be742 2021-07-09 op }
587 c39be742 2021-07-09 op
588 c39be742 2021-07-09 op #define START_EXPAND 1
589 c39be742 2021-07-09 op #define DONE_EXPAND 2
590 c39be742 2021-07-09 op
591 c39be742 2021-07-09 op static int expanding;
592 c39be742 2021-07-09 op
593 c39be742 2021-07-09 op int
594 c39be742 2021-07-09 op igetc(void)
595 c39be742 2021-07-09 op {
596 c39be742 2021-07-09 op int c;
597 c39be742 2021-07-09 op
598 c39be742 2021-07-09 op while (1) {
599 c39be742 2021-07-09 op if (file->ungetpos > 0)
600 c39be742 2021-07-09 op c = file->ungetbuf[--file->ungetpos];
601 c39be742 2021-07-09 op else
602 c39be742 2021-07-09 op c = getc(file->stream);
603 c39be742 2021-07-09 op
604 c39be742 2021-07-09 op if (c == START_EXPAND)
605 c39be742 2021-07-09 op expanding = 1;
606 c39be742 2021-07-09 op else if (c == DONE_EXPAND)
607 c39be742 2021-07-09 op expanding = 0;
608 c39be742 2021-07-09 op else
609 c39be742 2021-07-09 op break;
610 74f0778b 2021-06-16 op }
611 c39be742 2021-07-09 op return c;
612 c39be742 2021-07-09 op }
613 74f0778b 2021-06-16 op
614 c39be742 2021-07-09 op int
615 c39be742 2021-07-09 op lgetc(int quotec)
616 c39be742 2021-07-09 op {
617 c39be742 2021-07-09 op int c, next;
618 c39be742 2021-07-09 op
619 c39be742 2021-07-09 op if (quotec) {
620 c39be742 2021-07-09 op if ((c = igetc()) == EOF) {
621 c39be742 2021-07-09 op yyerror("reached end of file while parsing "
622 c39be742 2021-07-09 op "quoted string");
623 c39be742 2021-07-09 op if (file == topfile || popfile() == EOF)
624 c39be742 2021-07-09 op return EOF;
625 c39be742 2021-07-09 op return quotec;
626 c39be742 2021-07-09 op }
627 74f0778b 2021-06-16 op return c;
628 74f0778b 2021-06-16 op }
629 74f0778b 2021-06-16 op
630 c39be742 2021-07-09 op while ((c = igetc()) == '\\') {
631 c39be742 2021-07-09 op next = igetc();
632 c39be742 2021-07-09 op if (next != '\n') {
633 c39be742 2021-07-09 op c = next;
634 74f0778b 2021-06-16 op break;
635 c39be742 2021-07-09 op }
636 c39be742 2021-07-09 op yylval.lineno = file->lineno;
637 c39be742 2021-07-09 op file->lineno++;
638 c39be742 2021-07-09 op }
639 3b21cca3 2021-06-29 op
640 c39be742 2021-07-09 op if (c == EOF) {
641 c39be742 2021-07-09 op /*
642 c39be742 2021-07-09 op * Fake EOL when hit EOF for the first time. This gets line
643 c39be742 2021-07-09 op * count right if last line in included file is syntactically
644 c39be742 2021-07-09 op * invalid and has no newline.
645 c39be742 2021-07-09 op */
646 c39be742 2021-07-09 op if (file->eof_reached == 0) {
647 c39be742 2021-07-09 op file->eof_reached = 1;
648 c39be742 2021-07-09 op return '\n';
649 c39be742 2021-07-09 op }
650 c39be742 2021-07-09 op while (c == EOF) {
651 c39be742 2021-07-09 op if (file == topfile || popfile() == EOF)
652 c39be742 2021-07-09 op return EOF;
653 c39be742 2021-07-09 op c = igetc();
654 c39be742 2021-07-09 op }
655 c39be742 2021-07-09 op }
656 c39be742 2021-07-09 op return c;
657 c39be742 2021-07-09 op }
658 c39be742 2021-07-09 op
659 c39be742 2021-07-09 op void
660 c39be742 2021-07-09 op lungetc(int c)
661 c39be742 2021-07-09 op {
662 c39be742 2021-07-09 op if (c == EOF)
663 c39be742 2021-07-09 op return;
664 c39be742 2021-07-09 op
665 c39be742 2021-07-09 op if (file->ungetpos >= file->ungetsize) {
666 c39be742 2021-07-09 op void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
667 c39be742 2021-07-09 op if (p == NULL)
668 c39be742 2021-07-09 op err(1, "lungetc");
669 c39be742 2021-07-09 op file->ungetbuf = p;
670 c39be742 2021-07-09 op file->ungetsize *= 2;
671 c39be742 2021-07-09 op }
672 c39be742 2021-07-09 op file->ungetbuf[file->ungetpos++] = c;
673 c39be742 2021-07-09 op }
674 c39be742 2021-07-09 op
675 c39be742 2021-07-09 op int
676 c39be742 2021-07-09 op findeol(void)
677 c39be742 2021-07-09 op {
678 c39be742 2021-07-09 op int c;
679 c39be742 2021-07-09 op
680 c39be742 2021-07-09 op /* Skip to either EOF or the first real EOL. */
681 c39be742 2021-07-09 op while (1) {
682 c39be742 2021-07-09 op c = lgetc(0);
683 c39be742 2021-07-09 op if (c == '\n') {
684 c39be742 2021-07-09 op file->lineno++;
685 3b21cca3 2021-06-29 op break;
686 c39be742 2021-07-09 op }
687 c39be742 2021-07-09 op if (c == EOF)
688 74f0778b 2021-06-16 op break;
689 c39be742 2021-07-09 op }
690 c39be742 2021-07-09 op return ERROR;
691 c39be742 2021-07-09 op }
692 c39be742 2021-07-09 op
693 c39be742 2021-07-09 op int
694 c39be742 2021-07-09 op yylex(void)
695 c39be742 2021-07-09 op {
696 1bd706dc 2021-07-09 op char buf[8096];
697 1bd706dc 2021-07-09 op char *p, *val;
698 1bd706dc 2021-07-09 op int quotec, next, c;
699 1bd706dc 2021-07-09 op int token;
700 c39be742 2021-07-09 op
701 c39be742 2021-07-09 op top:
702 c39be742 2021-07-09 op p = buf;
703 c39be742 2021-07-09 op while ((c = lgetc(0)) == ' ' || c == '\t')
704 c39be742 2021-07-09 op ; /* nothing */
705 c39be742 2021-07-09 op
706 c39be742 2021-07-09 op yylval.lineno = file->lineno;
707 c39be742 2021-07-09 op if (c == '#')
708 c39be742 2021-07-09 op while ((c = lgetc(0)) != '\n' && c != EOF)
709 c39be742 2021-07-09 op ; /* nothing */
710 c39be742 2021-07-09 op if (c == '$' && !expanding) {
711 c39be742 2021-07-09 op while (1) {
712 c39be742 2021-07-09 op if ((c = lgetc(0)) == EOF)
713 c39be742 2021-07-09 op return 0;
714 67f49405 2021-07-09 op if (p + 1 >= buf + sizeof(buf) -1) {
715 67f49405 2021-07-09 op yyerror("string too long");
716 67f49405 2021-07-09 op return findeol();
717 67f49405 2021-07-09 op }
718 67f49405 2021-07-09 op if (isalnum(c) || c == '_') {
719 67f49405 2021-07-09 op *p++ = c;
720 67f49405 2021-07-09 op continue;
721 67f49405 2021-07-09 op }
722 67f49405 2021-07-09 op *p = '\0';
723 67f49405 2021-07-09 op lungetc(c);
724 67f49405 2021-07-09 op break;
725 67f49405 2021-07-09 op }
726 67f49405 2021-07-09 op val = symget(buf);
727 67f49405 2021-07-09 op if (val == NULL) {
728 67f49405 2021-07-09 op yyerror("macro `%s' not defined", buf);
729 67f49405 2021-07-09 op return findeol();
730 67f49405 2021-07-09 op }
731 67f49405 2021-07-09 op yylval.v.string = xstrdup(val);
732 67f49405 2021-07-09 op return STRING;
733 67f49405 2021-07-09 op }
734 67f49405 2021-07-09 op if (c == '@' && !expanding) {
735 67f49405 2021-07-09 op while (1) {
736 67f49405 2021-07-09 op if ((c = lgetc(0)) == EOF)
737 67f49405 2021-07-09 op return 0;
738 c39be742 2021-07-09 op
739 c39be742 2021-07-09 op if (p + 1 >= buf + sizeof(buf) - 1) {
740 c39be742 2021-07-09 op yyerror("string too long");
741 c39be742 2021-07-09 op return findeol();
742 c39be742 2021-07-09 op }
743 c39be742 2021-07-09 op if (isalnum(c) || c == '_') {
744 c39be742 2021-07-09 op *p++ = c;
745 74f0778b 2021-06-16 op continue;
746 74f0778b 2021-06-16 op }
747 c39be742 2021-07-09 op *p = '\0';
748 c39be742 2021-07-09 op lungetc(c);
749 c39be742 2021-07-09 op break;
750 74f0778b 2021-06-16 op }
751 c39be742 2021-07-09 op val = symget(buf);
752 c39be742 2021-07-09 op if (val == NULL) {
753 c39be742 2021-07-09 op yyerror("macro '%s' not defined", buf);
754 c39be742 2021-07-09 op return findeol();
755 74f0778b 2021-06-16 op }
756 c39be742 2021-07-09 op p = val + strlen(val) - 1;
757 c39be742 2021-07-09 op lungetc(DONE_EXPAND);
758 c39be742 2021-07-09 op while (p >= val) {
759 c39be742 2021-07-09 op lungetc(*p);
760 c39be742 2021-07-09 op p--;
761 c39be742 2021-07-09 op }
762 c39be742 2021-07-09 op lungetc(START_EXPAND);
763 c39be742 2021-07-09 op goto top;
764 74f0778b 2021-06-16 op }
765 74f0778b 2021-06-16 op
766 c39be742 2021-07-09 op switch (c) {
767 c39be742 2021-07-09 op case '\'':
768 c39be742 2021-07-09 op case '"':
769 c39be742 2021-07-09 op quotec = c;
770 c39be742 2021-07-09 op while (1) {
771 c39be742 2021-07-09 op if ((c = lgetc(quotec)) == EOF)
772 c39be742 2021-07-09 op return 0;
773 c39be742 2021-07-09 op if (c == '\n') {
774 c39be742 2021-07-09 op file->lineno++;
775 c39be742 2021-07-09 op continue;
776 c39be742 2021-07-09 op } else if (c == '\\') {
777 c39be742 2021-07-09 op if ((next = lgetc(quotec)) == EOF)
778 c39be742 2021-07-09 op return (0);
779 c39be742 2021-07-09 op if (next == quotec || next == ' ' ||
780 c39be742 2021-07-09 op next == '\t')
781 c39be742 2021-07-09 op c = next;
782 c39be742 2021-07-09 op else if (next == '\n') {
783 c39be742 2021-07-09 op file->lineno++;
784 c39be742 2021-07-09 op continue;
785 c39be742 2021-07-09 op } else
786 c39be742 2021-07-09 op lungetc(next);
787 c39be742 2021-07-09 op } else if (c == quotec) {
788 c39be742 2021-07-09 op *p = '\0';
789 c39be742 2021-07-09 op break;
790 c39be742 2021-07-09 op } else if (c == '\0') {
791 f3966209 2021-07-13 op yyerror("invalid syntax");
792 c39be742 2021-07-09 op return findeol();
793 c39be742 2021-07-09 op }
794 c39be742 2021-07-09 op if (p + 1 >= buf + sizeof(buf) - 1) {
795 c39be742 2021-07-09 op yyerror("string too long");
796 c39be742 2021-07-09 op return findeol();
797 c39be742 2021-07-09 op }
798 c39be742 2021-07-09 op *p++ = c;
799 c39be742 2021-07-09 op }
800 c39be742 2021-07-09 op yylval.v.string = strdup(buf);
801 c39be742 2021-07-09 op if (yylval.v.string == NULL)
802 c39be742 2021-07-09 op err(1, "yylex: strdup");
803 c39be742 2021-07-09 op return STRING;
804 74f0778b 2021-06-16 op }
805 c39be742 2021-07-09 op
806 c39be742 2021-07-09 op #define allowed_to_end_number(x) \
807 c39be742 2021-07-09 op (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
808 c39be742 2021-07-09 op
809 c39be742 2021-07-09 op if (c == '-' || isdigit(c)) {
810 c39be742 2021-07-09 op do {
811 c39be742 2021-07-09 op *p++ = c;
812 c39be742 2021-07-09 op if ((size_t)(p-buf) >= sizeof(buf)) {
813 c39be742 2021-07-09 op yyerror("string too long");
814 c39be742 2021-07-09 op return findeol();
815 c39be742 2021-07-09 op }
816 c39be742 2021-07-09 op } while ((c = lgetc(0)) != EOF && isdigit(c));
817 c39be742 2021-07-09 op lungetc(c);
818 c39be742 2021-07-09 op if (p == buf + 1 && buf[0] == '-')
819 c39be742 2021-07-09 op goto nodigits;
820 c39be742 2021-07-09 op if (c == EOF || allowed_to_end_number(c)) {
821 c39be742 2021-07-09 op const char *errstr = NULL;
822 c39be742 2021-07-09 op
823 c39be742 2021-07-09 op *p = '\0';
824 c39be742 2021-07-09 op yylval.v.number = strtonum(buf, LLONG_MIN,
825 c39be742 2021-07-09 op LLONG_MAX, &errstr);
826 c39be742 2021-07-09 op if (errstr) {
827 c39be742 2021-07-09 op yyerror("\"%s\" invalid number: %s",
828 c39be742 2021-07-09 op buf, errstr);
829 c39be742 2021-07-09 op return findeol();
830 c39be742 2021-07-09 op }
831 c39be742 2021-07-09 op return NUM;
832 c39be742 2021-07-09 op } else {
833 c39be742 2021-07-09 op nodigits:
834 c39be742 2021-07-09 op while (p > buf + 1)
835 c39be742 2021-07-09 op lungetc(*--p);
836 c39be742 2021-07-09 op c = *--p;
837 c39be742 2021-07-09 op if (c == '-')
838 c39be742 2021-07-09 op return c;
839 c39be742 2021-07-09 op }
840 74f0778b 2021-06-16 op }
841 c39be742 2021-07-09 op
842 c39be742 2021-07-09 op #define allowed_in_string(x) \
843 c39be742 2021-07-09 op (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
844 c39be742 2021-07-09 op x != '{' && x != '}' && \
845 c39be742 2021-07-09 op x != '!' && x != '=' && x != '#' && \
846 67f49405 2021-07-09 op x != ',' && x != ';'))
847 c39be742 2021-07-09 op
848 67f49405 2021-07-09 op if (isalnum(c) || c == ':' || c == '_') {
849 c39be742 2021-07-09 op do {
850 c39be742 2021-07-09 op *p++ = c;
851 c39be742 2021-07-09 op if ((size_t)(p-buf) >= sizeof(buf)) {
852 c39be742 2021-07-09 op yyerror("string too long");
853 c39be742 2021-07-09 op return findeol();
854 c39be742 2021-07-09 op }
855 c39be742 2021-07-09 op } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
856 c39be742 2021-07-09 op lungetc(c);
857 c39be742 2021-07-09 op *p = '\0';
858 c39be742 2021-07-09 op if ((token = lookup(buf)) == STRING)
859 c39be742 2021-07-09 op yylval.v.string = xstrdup(buf);
860 c39be742 2021-07-09 op return token;
861 74f0778b 2021-06-16 op }
862 c39be742 2021-07-09 op if (c == '\n') {
863 c39be742 2021-07-09 op yylval.lineno = file->lineno;
864 c39be742 2021-07-09 op file->lineno++;
865 74f0778b 2021-06-16 op }
866 c39be742 2021-07-09 op if (c == EOF)
867 c39be742 2021-07-09 op return 0;
868 c39be742 2021-07-09 op return c;
869 c39be742 2021-07-09 op }
870 c39be742 2021-07-09 op
871 c39be742 2021-07-09 op struct file *
872 c39be742 2021-07-09 op pushfile(const char *name, int secret)
873 c39be742 2021-07-09 op {
874 c39be742 2021-07-09 op struct file *nfile;
875 c39be742 2021-07-09 op
876 c39be742 2021-07-09 op nfile = xcalloc(1, sizeof(*nfile));
877 c39be742 2021-07-09 op nfile->name = xstrdup(name);
878 c39be742 2021-07-09 op if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
879 83272dfe 2021-08-23 op log_warn(NULL, "can't open %s: %s", nfile->name,
880 c39be742 2021-07-09 op strerror(errno));
881 c39be742 2021-07-09 op free(nfile->name);
882 c39be742 2021-07-09 op free(nfile);
883 c39be742 2021-07-09 op return NULL;
884 74f0778b 2021-06-16 op }
885 c39be742 2021-07-09 op nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
886 c39be742 2021-07-09 op nfile->ungetsize = 16;
887 c39be742 2021-07-09 op nfile->ungetbuf = xcalloc(1, nfile->ungetsize);
888 c39be742 2021-07-09 op TAILQ_INSERT_TAIL(&files, nfile, entry);
889 c39be742 2021-07-09 op return nfile;
890 c39be742 2021-07-09 op }
891 74f0778b 2021-06-16 op
892 c39be742 2021-07-09 op int
893 c39be742 2021-07-09 op popfile(void)
894 c39be742 2021-07-09 op {
895 c39be742 2021-07-09 op struct file *prev;
896 13ed2fb6 2021-01-27 op
897 c39be742 2021-07-09 op if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
898 c39be742 2021-07-09 op prev->errors += file->errors;
899 13ed2fb6 2021-01-27 op
900 c39be742 2021-07-09 op TAILQ_REMOVE(&files, file, entry);
901 c39be742 2021-07-09 op fclose(file->stream);
902 c39be742 2021-07-09 op free(file->name);
903 c39be742 2021-07-09 op free(file->ungetbuf);
904 c39be742 2021-07-09 op free(file);
905 c39be742 2021-07-09 op file = prev;
906 c39be742 2021-07-09 op return file ? 0 : EOF;
907 13ed2fb6 2021-01-27 op }
908 13ed2fb6 2021-01-27 op
909 13ed2fb6 2021-01-27 op void
910 c39be742 2021-07-09 op parse_conf(const char *filename)
911 13ed2fb6 2021-01-27 op {
912 c39be742 2021-07-09 op struct sym *sym, *next;
913 3b21cca3 2021-06-29 op
914 c39be742 2021-07-09 op file = pushfile(filename, 0);
915 c39be742 2021-07-09 op if (file == NULL)
916 83272dfe 2021-08-23 op exit(1);
917 c39be742 2021-07-09 op topfile = file;
918 c39be742 2021-07-09 op
919 13ed2fb6 2021-01-27 op yyparse();
920 c39be742 2021-07-09 op errors = file->errors;
921 c39be742 2021-07-09 op popfile();
922 13ed2fb6 2021-01-27 op
923 c39be742 2021-07-09 op /* Free macros and check which have not been used. */
924 3b21cca3 2021-06-29 op TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
925 3b21cca3 2021-06-29 op /* TODO: warn if !sym->used */
926 3b21cca3 2021-06-29 op if (!sym->persist) {
927 3b21cca3 2021-06-29 op free(sym->name);
928 3b21cca3 2021-06-29 op free(sym->val);
929 3b21cca3 2021-06-29 op TAILQ_REMOVE(&symhead, sym, entry);
930 3b21cca3 2021-06-29 op free(sym);
931 3b21cca3 2021-06-29 op }
932 3b21cca3 2021-06-29 op }
933 c39be742 2021-07-09 op
934 c39be742 2021-07-09 op if (errors)
935 c39be742 2021-07-09 op exit(1);
936 13ed2fb6 2021-01-27 op }
937 e17642a7 2021-02-01 op
938 f0a01fc7 2021-10-09 op void
939 f0a01fc7 2021-10-09 op print_conf(void)
940 f0a01fc7 2021-10-09 op {
941 f0a01fc7 2021-10-09 op struct vhost *h;
942 f0a01fc7 2021-10-09 op /* struct location *l; */
943 f0a01fc7 2021-10-09 op /* struct envlist *e; */
944 f0a01fc7 2021-10-09 op /* struct alist *a; */
945 f0a01fc7 2021-10-09 op
946 7277bb7d 2022-09-10 op if (*conf.chroot != '\0')
947 f0a01fc7 2021-10-09 op printf("chroot \"%s\"\n", conf.chroot);
948 f0a01fc7 2021-10-09 op printf("ipv6 %s\n", conf.ipv6 ? "on" : "off");
949 f0a01fc7 2021-10-09 op /* XXX: defined mimes? */
950 f0a01fc7 2021-10-09 op printf("port %d\n", conf.port);
951 f0a01fc7 2021-10-09 op printf("prefork %d\n", conf.prefork);
952 f0a01fc7 2021-10-09 op /* XXX: protocols? */
953 7277bb7d 2022-09-10 op if (*conf.user != '\0')
954 f0a01fc7 2021-10-09 op printf("user \"%s\"\n", conf.user);
955 f0a01fc7 2021-10-09 op
956 f0a01fc7 2021-10-09 op TAILQ_FOREACH(h, &hosts, vhosts) {
957 f0a01fc7 2021-10-09 op printf("\nserver \"%s\" {\n", h->domain);
958 f0a01fc7 2021-10-09 op printf(" cert \"%s\"\n", h->cert);
959 f0a01fc7 2021-10-09 op printf(" key \"%s\"\n", h->key);
960 f0a01fc7 2021-10-09 op /* TODO: print locations... */
961 f0a01fc7 2021-10-09 op printf("}\n");
962 f0a01fc7 2021-10-09 op }
963 f0a01fc7 2021-10-09 op }
964 f0a01fc7 2021-10-09 op
965 c39be742 2021-07-09 op int
966 c39be742 2021-07-09 op symset(const char *name, const char *val, int persist)
967 c39be742 2021-07-09 op {
968 c39be742 2021-07-09 op struct sym *sym;
969 c39be742 2021-07-09 op
970 c39be742 2021-07-09 op TAILQ_FOREACH(sym, &symhead, entry) {
971 c39be742 2021-07-09 op if (!strcmp(name, sym->name))
972 c39be742 2021-07-09 op break;
973 c39be742 2021-07-09 op }
974 c39be742 2021-07-09 op
975 c39be742 2021-07-09 op if (sym != NULL) {
976 c39be742 2021-07-09 op if (sym->persist)
977 c39be742 2021-07-09 op return 0;
978 c39be742 2021-07-09 op else {
979 c39be742 2021-07-09 op free(sym->name);
980 c39be742 2021-07-09 op free(sym->val);
981 c39be742 2021-07-09 op TAILQ_REMOVE(&symhead, sym, entry);
982 c39be742 2021-07-09 op free(sym);
983 c39be742 2021-07-09 op }
984 c39be742 2021-07-09 op }
985 c39be742 2021-07-09 op
986 c39be742 2021-07-09 op sym = xcalloc(1, sizeof(*sym));
987 c39be742 2021-07-09 op sym->name = xstrdup(name);
988 c39be742 2021-07-09 op sym->val = xstrdup(val);
989 c39be742 2021-07-09 op sym->used = 0;
990 c39be742 2021-07-09 op sym->persist = persist;
991 c39be742 2021-07-09 op
992 c39be742 2021-07-09 op TAILQ_INSERT_TAIL(&symhead, sym, entry);
993 c39be742 2021-07-09 op return 0;
994 c39be742 2021-07-09 op }
995 c39be742 2021-07-09 op
996 c39be742 2021-07-09 op int
997 c39be742 2021-07-09 op cmdline_symset(char *s)
998 c39be742 2021-07-09 op {
999 c39be742 2021-07-09 op char *sym, *val;
1000 c39be742 2021-07-09 op int ret;
1001 c39be742 2021-07-09 op
1002 c39be742 2021-07-09 op if ((val = strrchr(s, '=')) == NULL)
1003 c39be742 2021-07-09 op return -1;
1004 c39be742 2021-07-09 op sym = xcalloc(1, val - s + 1);
1005 c39be742 2021-07-09 op memcpy(sym, s, val - s);
1006 c39be742 2021-07-09 op ret = symset(sym, val + 1, 1);
1007 c39be742 2021-07-09 op free(sym);
1008 c39be742 2021-07-09 op return ret;
1009 c39be742 2021-07-09 op }
1010 c39be742 2021-07-09 op
1011 e17642a7 2021-02-01 op char *
1012 c39be742 2021-07-09 op symget(const char *nam)
1013 c39be742 2021-07-09 op {
1014 c39be742 2021-07-09 op struct sym *sym;
1015 c39be742 2021-07-09 op
1016 c39be742 2021-07-09 op TAILQ_FOREACH(sym, &symhead, entry) {
1017 c39be742 2021-07-09 op if (strcmp(nam, sym->name) == 0) {
1018 c39be742 2021-07-09 op sym->used = 1;
1019 c39be742 2021-07-09 op return sym->val;
1020 c39be742 2021-07-09 op }
1021 c39be742 2021-07-09 op }
1022 c39be742 2021-07-09 op return NULL;
1023 c39be742 2021-07-09 op }
1024 c39be742 2021-07-09 op
1025 c39be742 2021-07-09 op struct vhost *
1026 c39be742 2021-07-09 op new_vhost(void)
1027 c39be742 2021-07-09 op {
1028 b7967bc1 2021-01-02 op return xcalloc(1, sizeof(struct vhost));
1029 c39be742 2021-07-09 op }
1030 c39be742 2021-07-09 op
1031 c39be742 2021-07-09 op struct location *
1032 c39be742 2021-07-09 op new_location(void)
1033 c39be742 2021-07-09 op {
1034 c39be742 2021-07-09 op struct location *l;
1035 c39be742 2021-07-09 op
1036 c39be742 2021-07-09 op l = xcalloc(1, sizeof(*l));
1037 c39be742 2021-07-09 op l->dirfd = -1;
1038 c39be742 2021-07-09 op l->fcgi = -1;
1039 c39be742 2021-07-09 op return l;
1040 c39be742 2021-07-09 op }
1041 c39be742 2021-07-09 op
1042 b7967bc1 2021-01-02 op struct proxy *
1043 b7967bc1 2021-01-02 op new_proxy(void)
1044 b7967bc1 2021-01-02 op {
1045 b7967bc1 2021-01-02 op struct proxy *p;
1046 76000995 2022-09-06 op
1047 76000995 2022-09-06 op conf.can_open_sockets = 1;
1048 b7967bc1 2021-01-02 op
1049 b7967bc1 2021-01-02 op p = xcalloc(1, sizeof(*p));
1050 b7967bc1 2021-01-02 op p->protocols = TLS_PROTOCOLS_DEFAULT;
1051 b7967bc1 2021-01-02 op return p;
1052 b7967bc1 2021-01-02 op }
1053 b7967bc1 2021-01-02 op
1054 c39be742 2021-07-09 op char *
1055 e17642a7 2021-02-01 op ensure_absolute_path(char *path)
1056 e17642a7 2021-02-01 op {
1057 e17642a7 2021-02-01 op if (path == NULL || *path != '/')
1058 adbe6a64 2021-04-30 op yyerror("not an absolute path: %s", path);
1059 e17642a7 2021-02-01 op return path;
1060 e17642a7 2021-02-01 op }
1061 6abda252 2021-02-06 op
1062 6abda252 2021-02-06 op int
1063 6abda252 2021-02-06 op check_block_code(int n)
1064 6abda252 2021-02-06 op {
1065 6abda252 2021-02-06 op if (n < 10 || n >= 70 || (n >= 20 && n <= 29))
1066 6abda252 2021-02-06 op yyerror("invalid block code %d", n);
1067 6abda252 2021-02-06 op return n;
1068 6abda252 2021-02-06 op }
1069 6abda252 2021-02-06 op
1070 6abda252 2021-02-06 op char *
1071 6abda252 2021-02-06 op check_block_fmt(char *fmt)
1072 6abda252 2021-02-06 op {
1073 6abda252 2021-02-06 op char *s;
1074 6abda252 2021-02-06 op
1075 6abda252 2021-02-06 op for (s = fmt; *s; ++s) {
1076 6abda252 2021-02-06 op if (*s != '%')
1077 6abda252 2021-02-06 op continue;
1078 6abda252 2021-02-06 op switch (*++s) {
1079 6abda252 2021-02-06 op case '%':
1080 6abda252 2021-02-06 op case 'p':
1081 6abda252 2021-02-06 op case 'q':
1082 6abda252 2021-02-06 op case 'P':
1083 6abda252 2021-02-06 op case 'N':
1084 6abda252 2021-02-06 op break;
1085 6abda252 2021-02-06 op default:
1086 6abda252 2021-02-06 op yyerror("invalid format specifier %%%c", *s);
1087 6abda252 2021-02-06 op }
1088 6abda252 2021-02-06 op }
1089 6abda252 2021-02-06 op
1090 6abda252 2021-02-06 op return fmt;
1091 6abda252 2021-02-06 op }
1092 6abda252 2021-02-06 op
1093 6abda252 2021-02-06 op int
1094 6abda252 2021-02-06 op check_strip_no(int n)
1095 6abda252 2021-02-06 op {
1096 6abda252 2021-02-06 op if (n <= 0)
1097 6abda252 2021-02-06 op yyerror("invalid strip number %d", n);
1098 a709ddf5 2021-02-07 op return n;
1099 a709ddf5 2021-02-07 op }
1100 a709ddf5 2021-02-07 op
1101 a709ddf5 2021-02-07 op int
1102 391825e3 2021-07-09 op check_port_num(int n)
1103 391825e3 2021-07-09 op {
1104 391825e3 2021-07-09 op if (n <= 0 || n >= UINT16_MAX)
1105 391825e3 2021-07-09 op yyerror("port number is %s: %d",
1106 391825e3 2021-07-09 op n <= 0 ? "too small" : "too large",
1107 391825e3 2021-07-09 op n);
1108 391825e3 2021-07-09 op return n;
1109 391825e3 2021-07-09 op }
1110 391825e3 2021-07-09 op
1111 391825e3 2021-07-09 op int
1112 a709ddf5 2021-02-07 op check_prefork_num(int n)
1113 a709ddf5 2021-02-07 op {
1114 2c3e53da 2021-03-03 op if (n <= 0 || n >= PROC_MAX)
1115 a709ddf5 2021-02-07 op yyerror("invalid prefork number %d", n);
1116 6abda252 2021-02-06 op return n;
1117 6abda252 2021-02-06 op }
1118 49b73ba1 2021-02-10 op
1119 49b73ba1 2021-02-10 op void
1120 49b73ba1 2021-02-10 op advance_loc(void)
1121 49b73ba1 2021-02-10 op {
1122 b8e64ccd 2021-03-31 op loc = new_location();
1123 b8e64ccd 2021-03-31 op TAILQ_INSERT_TAIL(&host->locations, loc, locations);
1124 49b73ba1 2021-02-10 op }
1125 c705ecb1 2021-05-03 op
1126 c705ecb1 2021-05-03 op void
1127 b7967bc1 2021-01-02 op advance_proxy(void)
1128 b7967bc1 2021-01-02 op {
1129 b7967bc1 2021-01-02 op proxy = new_proxy();
1130 b7967bc1 2021-01-02 op TAILQ_INSERT_TAIL(&host->proxies, proxy, proxies);
1131 b7967bc1 2021-01-02 op }
1132 b7967bc1 2021-01-02 op
1133 b7967bc1 2021-01-02 op void
1134 b7967bc1 2021-01-02 op parsehp(char *str, char **host, const char **port, const char *def)
1135 b7967bc1 2021-01-02 op {
1136 b7967bc1 2021-01-02 op char *at;
1137 b7967bc1 2021-01-02 op const char *errstr;
1138 b7967bc1 2021-01-02 op
1139 b7967bc1 2021-01-02 op *host = str;
1140 b7967bc1 2021-01-02 op
1141 b7967bc1 2021-01-02 op if ((at = strchr(str, ':')) != NULL) {
1142 b7967bc1 2021-01-02 op *at++ = '\0';
1143 b7967bc1 2021-01-02 op *port = at;
1144 b7967bc1 2021-01-02 op } else
1145 b7967bc1 2021-01-02 op *port = def;
1146 b7967bc1 2021-01-02 op
1147 b7967bc1 2021-01-02 op strtonum(*port, 1, UINT16_MAX, &errstr);
1148 b7967bc1 2021-01-02 op if (errstr != NULL)
1149 b7967bc1 2021-01-02 op yyerror("port is %s: %s", errstr, *port);
1150 b7967bc1 2021-01-02 op }
1151 b7967bc1 2021-01-02 op
1152 b7967bc1 2021-01-02 op void
1153 c705ecb1 2021-05-03 op only_once(const void *ptr, const char *name)
1154 c705ecb1 2021-05-03 op {
1155 c705ecb1 2021-05-03 op if (ptr != NULL)
1156 c705ecb1 2021-05-03 op yyerror("`%s' specified more than once", name);
1157 c705ecb1 2021-05-03 op }
1158 8ad1c570 2021-05-09 op
1159 8ad1c570 2021-05-09 op void
1160 8ad1c570 2021-05-09 op only_oncei(int i, const char *name)
1161 8ad1c570 2021-05-09 op {
1162 8ad1c570 2021-05-09 op if (i != -1)
1163 8ad1c570 2021-05-09 op yyerror("`%s' specified more than once", name);
1164 8ad1c570 2021-05-09 op }
1165 8ad1c570 2021-05-09 op
1166 8ad1c570 2021-05-09 op int
1167 8ad1c570 2021-05-09 op fastcgi_conf(char *path, char *port, char *prog)
1168 8ad1c570 2021-05-09 op {
1169 8ad1c570 2021-05-09 op struct fcgi *f;
1170 8ad1c570 2021-05-09 op int i;
1171 8ad1c570 2021-05-09 op
1172 76000995 2022-09-06 op conf.can_open_sockets = 1;
1173 76000995 2022-09-06 op
1174 8ad1c570 2021-05-09 op for (i = 0; i < FCGI_MAX; ++i) {
1175 8ad1c570 2021-05-09 op f = &fcgi[i];
1176 fafc6849 2021-06-29 op
1177 8ad1c570 2021-05-09 op if (f->path == NULL) {
1178 8ad1c570 2021-05-09 op f->id = i;
1179 8ad1c570 2021-05-09 op f->path = path;
1180 8ad1c570 2021-05-09 op f->port = port;
1181 8ad1c570 2021-05-09 op f->prog = prog;
1182 8ad1c570 2021-05-09 op return i;
1183 8ad1c570 2021-05-09 op }
1184 8ad1c570 2021-05-09 op
1185 8ad1c570 2021-05-09 op /* XXX: what to do with prog? */
1186 8ad1c570 2021-05-09 op if (!strcmp(f->path, path) &&
1187 8ad1c570 2021-05-09 op ((port == NULL && f->port == NULL) ||
1188 8ad1c570 2021-05-09 op !strcmp(f->port, port))) {
1189 8ad1c570 2021-05-09 op free(path);
1190 8ad1c570 2021-05-09 op free(port);
1191 8ad1c570 2021-05-09 op return i;
1192 8ad1c570 2021-05-09 op }
1193 8ad1c570 2021-05-09 op }
1194 8ad1c570 2021-05-09 op
1195 8ad1c570 2021-05-09 op yyerror("too much `fastcgi' rules defined.");
1196 8ad1c570 2021-05-09 op return -1;
1197 c92b802b 2021-06-11 op }
1198 c92b802b 2021-06-11 op
1199 c92b802b 2021-06-11 op void
1200 2025e96d 2022-09-10 op add_param(char *name, char *val)
1201 c92b802b 2021-06-11 op {
1202 c92b802b 2021-06-11 op struct envlist *e;
1203 2025e96d 2022-09-10 op struct envhead *h = &host->params;
1204 c92b802b 2021-06-11 op
1205 c92b802b 2021-06-11 op e = xcalloc(1, sizeof(*e));
1206 c92b802b 2021-06-11 op e->name = name;
1207 c92b802b 2021-06-11 op e->value = val;
1208 c92b802b 2021-06-11 op if (TAILQ_EMPTY(h))
1209 c92b802b 2021-06-11 op TAILQ_INSERT_HEAD(h, e, envs);
1210 c92b802b 2021-06-11 op else
1211 c92b802b 2021-06-11 op TAILQ_INSERT_TAIL(h, e, envs);
1212 3b21cca3 2021-06-29 op }