Bug Summary

File:src/usr.sbin/httpd/obj/parse.c
Warning:line 2044, column 12
Use of zero-allocated memory

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name parse.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/httpd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/httpd -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/httpd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c parse.c
1#include <stdlib.h>
2#include <string.h>
3#define YYBYACC1 1
4#define YYMAJOR1 1
5#define YYMINOR9 9
6#define YYLEXyylex() yylex()
7#define YYEMPTY-1 -1
8#define yyclearin(yychar=(-1)) (yychar=(YYEMPTY-1))
9#define yyerrok(yyerrflag=0) (yyerrflag=0)
10#define YYRECOVERING()(yyerrflag!=0) (yyerrflag!=0)
11#define YYPREFIX"yy" "yy"
12#line 29 "/usr/src/usr.sbin/httpd/parse.y"
13#include <sys/types.h>
14#include <sys/socket.h>
15#include <sys/un.h>
16#include <sys/stat.h>
17#include <sys/queue.h>
18#include <sys/tree.h>
19#include <sys/ioctl.h>
20#include <sys/sockio.h>
21#include <sys/time.h>
22
23#include <net/if.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
26
27#include <ctype.h>
28#include <unistd.h>
29#include <err.h>
30#include <errno(*__errno()).h>
31#include <limits.h>
32#include <stdint.h>
33#include <stdarg.h>
34#include <stdio.h>
35#include <netdb.h>
36#include <string.h>
37#include <ifaddrs.h>
38#include <syslog.h>
39
40#include "httpd.h"
41#include "http.h"
42
43TAILQ_HEAD(files, file)struct files { struct file *tqh_first; struct file **tqh_last
; }
files = TAILQ_HEAD_INITIALIZER(files){ ((void*)0), &(files).tqh_first };
44static struct file {
45 TAILQ_ENTRY(file)struct { struct file *tqe_next; struct file **tqe_prev; } entry;
46 FILE *stream;
47 char *name;
48 size_t ungetpos;
49 size_t ungetsize;
50 u_char *ungetbuf;
51 int eof_reached;
52 int lineno;
53 int errors;
54} *file, *topfile;
55struct file *pushfile(const char *, int);
56int popfile(void);
57int check_file_secrecy(int, const char *);
58int yyparse(void);
59int yylex(void);
60int yyerror(const char *, ...)
61 __attribute__((__format__ (printf, 1, 2)))
62 __attribute__((__nonnull__ (1)));
63int kw_cmp(const void *, const void *);
64int lookup(char *);
65int igetc(void);
66int lgetc(int);
67void lungetc(int);
68int findeol(void);
69
70TAILQ_HEAD(symhead, sym)struct symhead { struct sym *tqh_first; struct sym **tqh_last
; }
symhead = TAILQ_HEAD_INITIALIZER(symhead){ ((void*)0), &(symhead).tqh_first };
71struct sym {
72 TAILQ_ENTRY(sym)struct { struct sym *tqe_next; struct sym **tqe_prev; } entry;
73 int used;
74 int persist;
75 char *nam;
76 char *val;
77};
78int symset(const char *, const char *, int);
79char *symget(const char *);
80
81struct httpd *conf = NULL((void*)0);
82static int errors = 0;
83static int loadcfg = 0;
84uint32_t last_server_id = 0;
85uint32_t last_auth_id = 0;
86
87static struct server *srv = NULL((void*)0), *parentsrv = NULL((void*)0);
88static struct server_config *srv_conf = NULL((void*)0);
89struct serverlist servers;
90struct media_type media;
91
92struct address *host_v4(const char *);
93struct address *host_v6(const char *);
94int host_dns(const char *, struct addresslist *,
95 int, struct portrange *, const char *, int);
96int host_if(const char *, struct addresslist *,
97 int, struct portrange *, const char *, int);
98int host(const char *, struct addresslist *,
99 int, struct portrange *, const char *, int);
100struct server *server_inherit(struct server *, struct server_config *,
101 struct server_config *);
102int listen_on(const char *, int, struct portrange *);
103int getservice(char *);
104int is_if_in_group(const char *, const char *);
105int get_fastcgi_dest(struct server_config *, const char *, char *);
106void remove_locations(struct server_config *);
107
108typedef struct {
109 union {
110 int64_t number;
111 char *string;
112 struct timeval tv;
113 struct portrange port;
114 struct auth auth;
115 } v;
116 int lineno;
117} YYSTYPE;
118
119#line 120 "parse.c"
120#define ACCESS257 257
121#define ALIAS258 258
122#define AUTO259 259
123#define BACKLOG260 260
124#define BODY261 261
125#define BUFFER262 262
126#define CERTIFICATE263 263
127#define CHROOT264 264
128#define CIPHERS265 265
129#define COMMON266 266
130#define COMBINED267 267
131#define CONNECTION268 268
132#define DHE269 269
133#define DIRECTORY270 270
134#define ECDHE271 271
135#define ERR272 272
136#define FCGI273 273
137#define INDEX274 274
138#define IP275 275
139#define KEY276 276
140#define LIFETIME277 277
141#define LISTEN278 278
142#define LOCATION279 279
143#define LOG280 280
144#define LOGDIR281 281
145#define MATCH282 282
146#define MAXIMUM283 283
147#define NO284 284
148#define NODELAY285 285
149#define OCSP286 286
150#define ON287 287
151#define PORT288 288
152#define PREFORK289 289
153#define PROTOCOLS290 290
154#define REQUESTS291 291
155#define ROOT292 292
156#define SACK293 293
157#define SERVER294 294
158#define SOCKET295 295
159#define STRIP296 296
160#define STYLE297 297
161#define SYSLOG298 298
162#define TCP299 299
163#define TICKET300 300
164#define TIMEOUT301 301
165#define TLS302 302
166#define TYPE303 303
167#define TYPES304 304
168#define HSTS305 305
169#define MAXAGE306 306
170#define SUBDOMAINS307 307
171#define DEFAULT308 308
172#define PRELOAD309 309
173#define REQUEST310 310
174#define ERROR311 311
175#define INCLUDE312 312
176#define AUTHENTICATE313 313
177#define WITH314 314
178#define BLOCK315 315
179#define DROP316 316
180#define RETURN317 317
181#define PASS318 318
182#define REWRITE319 319
183#define CA320 320
184#define CLIENT321 321
185#define CRL322 322
186#define OPTIONAL323 323
187#define PARAM324 324
188#define FORWARDED325 325
189#define FOUND326 326
190#define NOT327 327
191#define ERRDOCS328 328
192#define STRING329 329
193#define NUMBER330 330
194#define YYERRCODE256 256
195const short yylhs[] =
196 { -1,
197 0, 0, 0, 0, 0, 0, 0, 0, 10, 11,
198 3, 3, 12, 12, 12, 12, 12, 16, 13, 18,
199 18, 19, 19, 19, 19, 19, 19, 19, 19, 19,
200 19, 19, 19, 19, 19, 31, 19, 19, 19, 19,
201 5, 5, 5, 32, 32, 32, 33, 33, 34, 34,
202 34, 28, 28, 36, 28, 39, 28, 37, 37, 38,
203 38, 38, 38, 38, 22, 22, 40, 40, 41, 41,
204 41, 41, 23, 23, 42, 42, 43, 43, 43, 43,
205 43, 43, 43, 43, 43, 43, 43, 44, 44, 44,
206 25, 25, 46, 46, 45, 24, 24, 48, 48, 47,
207 47, 47, 29, 29, 9, 9, 26, 26, 50, 50,
208 49, 49, 49, 49, 27, 27, 27, 52, 52, 51,
209 51, 51, 51, 51, 53, 53, 53, 53, 30, 30,
210 30, 30, 54, 4, 4, 8, 8, 2, 2, 21,
211 21, 55, 55, 56, 56, 56, 56, 56, 56, 56,
212 14, 57, 57, 58, 58, 15, 59, 59, 61, 1,
213 1, 6, 7, 7, 60, 60, 17, 17, 35, 35,
214 20,
215};
216const short yylen[] =
217 { 2,
218 0, 3, 2, 3, 3, 3, 3, 3, 2, 3,
219 0, 1, 2, 2, 2, 2, 3, 0, 8, 3,
220 2, 5, 3, 2, 2, 1, 1, 1, 1, 1,
221 1, 1, 1, 1, 1, 0, 9, 3, 1, 1,
222 0, 1, 2, 5, 2, 1, 3, 2, 2, 1,
223 1, 2, 1, 0, 6, 0, 3, 3, 2, 2,
224 3, 4, 3, 2, 5, 2, 3, 2, 2, 3,
225 3, 4, 5, 2, 3, 2, 2, 2, 2, 2,
226 4, 2, 2, 2, 3, 3, 2, 0, 3, 2,
227 2, 5, 3, 2, 1, 2, 5, 3, 2, 2,
228 2, 2, 2, 2, 3, 2, 2, 5, 3, 2,
229 2, 2, 2, 3, 2, 5, 2, 3, 2, 2,
230 1, 2, 2, 2, 1, 1, 1, 1, 4, 2,
231 1, 1, 1, 0, 1, 0, 1, 1, 1, 5,
232 2, 3, 2, 1, 2, 1, 2, 2, 3, 3,
233 5, 3, 2, 3, 1, 3, 2, 1, 1, 2,
234 2, 1, 1, 1, 1, 0, 2, 0, 2, 1,
235 2,
236};
237const short yydefred[] =
238 { 1,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 3, 0, 0, 0, 0, 0, 8, 14, 16,
241 13, 135, 0, 0, 0, 9, 15, 0, 2, 4,
242 5, 6, 7, 18, 0, 0, 0, 17, 10, 0,
243 167, 155, 0, 0, 0, 0, 0, 164, 163, 159,
244 0, 158, 151, 0, 0, 153, 156, 0, 165, 154,
245 157, 152, 171, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 133, 132,
247 0, 39, 0, 0, 26, 27, 28, 29, 30, 31,
248 32, 33, 34, 35, 40, 0, 0, 0, 0, 0,
249 0, 66, 0, 0, 0, 0, 107, 0, 0, 0,
250 42, 0, 0, 0, 0, 0, 0, 121, 0, 115,
251 52, 117, 103, 25, 95, 0, 91, 0, 0, 0,
252 146, 144, 0, 0, 141, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 74, 0, 50, 51,
254 0, 45, 0, 0, 0, 0, 0, 96, 0, 0,
255 104, 24, 19, 0, 21, 130, 0, 23, 0, 0,
256 162, 69, 0, 0, 113, 111, 0, 112, 0, 0,
257 0, 0, 0, 57, 0, 43, 0, 123, 124, 122,
258 125, 126, 127, 128, 120, 0, 0, 148, 0, 147,
259 145, 0, 0, 77, 80, 82, 83, 78, 87, 79,
260 84, 0, 0, 0, 49, 0, 38, 101, 102, 100,
261 0, 106, 0, 20, 0, 71, 0, 70, 0, 0,
262 114, 0, 0, 0, 0, 60, 64, 0, 12, 0,
263 36, 0, 0, 0, 0, 150, 149, 0, 0, 85,
264 86, 88, 0, 0, 0, 0, 0, 0, 105, 137,
265 129, 72, 65, 0, 0, 68, 170, 0, 110, 0,
266 108, 0, 0, 0, 63, 0, 22, 0, 119, 0,
267 116, 94, 0, 92, 140, 143, 0, 0, 73, 76,
268 0, 44, 48, 0, 99, 0, 97, 0, 169, 67,
269 109, 55, 59, 0, 139, 138, 62, 161, 160, 0,
270 118, 93, 142, 0, 90, 75, 47, 98, 58, 0,
271 89, 0, 37,
272};
273const short yydgoto[] =
274 { 1,
275 277, 307, 240, 23, 113, 172, 50, 261, 161, 82,
276 14, 15, 16, 17, 43, 40, 36, 83, 84, 267,
277 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
278 278, 95, 255, 256, 268, 108, 272, 273, 109, 229,
279 230, 253, 254, 288, 244, 245, 257, 258, 232, 233,
280 242, 243, 195, 96, 248, 249, 44, 45, 51, 60,
281 52,
282};
283const short yysindex[] =
284 { 0,
285 -10, 13, -288, -275, -249, -217, -40, -226, -238, -230,
286 43, 0, 119, 126, 129, 148, 153, 0, 0, 0,
287 0, 0, -136, 203, -110, 0, 0, -108, 0, 0,
288 0, 0, 0, 0, 203, -239, 181, 0, 0, 106,
289 0, 0, -205, -113, 230, -88, 203, 0, 0, 0,
290 -57, 0, 0, 230, 203, 0, 0, -244, 0, 0,
291 0, 0, 0, -217, -76, -112, 0, -44, -174, -60,
292 -235, -118, -28, 596, -104, -54, -119, -201, 0, 0,
293 -79, 0, 448, 203, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, 0, 0, -229, -78, -266, -75, -49,
295 203, 0, -12, -65, -141, 203, 0, 145, -194, -55,
296 0, -48, -217, -52, -43, -29, -236, 0, 203, 0,
297 0, 0, 0, 0, 0, 203, 0, -47, -42, -265,
298 0, 0, 19, 203, 0, -41, -36, -32, -26, -24,
299 -11, -23, -20, 18, -8, 203, 0, -30, 0, 0,
300 203, 0, -110, -18, -17, -14, 203, 0, -3, -4,
301 0, 0, 0, 230, 0, 0, -9, 0, -2, 68,
302 0, 0, -75, -66, 0, 0, 57, 0, -152, 203,
303 -253, 2, 8, 0, 32, 0, 10, 0, 0, 0,
304 0, 0, 0, 0, 0, -178, 17, 0, 11, 0,
305 0, 20, -242, 0, 0, 0, 0, 0, 0, 0,
306 0, -271, 22, 667, 0, -133, 0, 0, 0, 0,
307 -257, 0, 23, 0, 24, 0, 25, 0, 217, 5,
308 0, 5, 222, -194, 27, 0, 0, 29, 0, 60,
309 0, 5, 229, 5, 234, 0, 0, 235, 5, 0,
310 0, 0, 236, 5, 237, 5, 5, 238, 0, 0,
311 0, 0, 0, 203, 203, 0, 0, -66, 0, -152,
312 0, 240, 5, -163, 0, -142, 0, 243, 0, -178,
313 0, 0, 17, 0, 0, 0, -242, -96, 0, 0,
314 667, 0, 0, -133, 0, -257, 0, 0, 0, 0,
315 0, 0, 0, -194, 0, 0, 0, 0, 0, 203,
316 0, 0, 0, 39, 0, 0, 0, 0, 0, -244,
317 0, 494, 0,};
318const short yyrindex[] =
319 { 0,
320 0, 0, 0, 0, 0, 42, 0, 0, 0, 0,
321 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
322 0, 0, 0, -232, 0, 0, 0, 0, 0, 0,
323 0, 0, 0, 0, 257, 0, 0, 0, 0, 0,
324 0, 0, 0, 0, 0, 0, 431, 0, 0, 0,
325 362, 0, 0, 0, 385, 0, 0, 0, 0, 0,
326 0, 0, 0, 42, 0, 0, 12, 0, -273, 0,
327 0, 0, 0, 0, 128, 0, 0, 0, 0, 0,
328 0, 0, 0, 545, 0, 0, 0, 0, 0, 0,
329 0, 0, 0, 0, 0, 174, 0, 0, 0, 0,
330 -35, 0, 0, 0, 0, -95, 0, 0, 0, 0,
331 0, 0, 42, 0, 0, 0, 0, 0, -39, 0,
332 0, 0, 0, 0, 0, -78, 0, 0, 0, 0,
333 0, 0, 0, -144, 0, 0, 0, 0, 0, 0,
334 0, 0, 0, 0, 0, 685, 0, 0, 0, 0,
335 -46, 0, 0, 0, 0, 0, -214, 0, 0, 0,
336 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
337 0, 0, 0, 0, 0, 0, 0, 0, 0, -181,
338 0, 0, 0, 0, 86, 0, 0, 0, 0, 0,
339 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
340 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
341 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
342 0, 0, 0, 0, 191, 0, 0, 0, 0, 251,
343 0, 251, 0, 0, 0, 0, 0, 0, 0, 0,
344 0, 251, 0, 251, 0, 0, 0, 0, 251, 0,
345 0, 0, 0, 251, 0, 251, 251, 0, 0, 0,
346 0, 0, 0, -115, 618, 0, 0, 0, 0, 0,
347 0, 0, 251, 65, 0, 0, 0, 0, 0, 0,
348 0, 0, 0, 0, 0, 0, 0, 111, 0, 0,
349 0, 0, 0, 0, 0, 0, 0, 330, 0, 0,
350 0, 0, 0, 0, 0, 0, 0, 0, 0, 431,
351 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
352 0, 0, 0,};
353const short yygindex[] =
354 { 0,
355 0, 0, 0, -56, 0, 212, 0, 0, 0, 16,
356 0, 0, 0, 0, -19, 0, -34, 67, -80, -38,
357 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
358 0, 0, 94, 317, -146, 0, 90, 288, 0, 131,
359 335, 113, 328, 0, 333, 132, 332, 115, 348, 147,
360 352, 138, 0, 0, 141, 358, 0, 381, 0, 0,
361 383,
362};
363#define YYTABLESIZE1006 1006
364const short yytable[] =
365 { 12,
366 41, 59, 164, 157, 126, 38, 56, 97, 41, 168,
367 106, 53, 58, 64, 264, 62, 13, 128, 151, 200,
368 63, 53, 18, 65, 169, 66, 154, 201, 67, 191,
369 192, 193, 129, 68, 69, 70, 250, 121, 155, 71,
370 19, 130, 131, 170, 122, 235, 101, 72, 265, 165,
371 132, 42, 133, 20, 73, 41, 187, 74, 251, 42,
372 75, 156, 119, 76, 22, 77, 174, 9, 78, 168,
373 79, 179, 9, 80, 61, 236, 25, 123, 114, 168,
374 21, 168, 24, 81, 196, 270, 166, 167, 194, 37,
375 26, 197, 124, 115, 134, 280, 168, 283, 27, 203,
376 181, 182, 287, 28, 168, 116, 103, 291, 61, 294,
377 296, 214, 159, 168, 168, 168, 216, 177, 117, 118,
378 81, 104, 221, 48, 49, 224, 304, 160, 29, 183,
379 168, 105, 178, 217, 54, 30, 53, 46, 31, 168,
380 168, 168, 168, 168, 168, 234, 103, 168, 168, 168,
381 168, 111, 112, 168, 81, 168, 168, 32, 168, 168,
382 168, 104, 33, 168, 154, 305, 306, 168, 168, 168,
383 168, 105, 148, 149, 168, 150, 155, 168, 168, 168,
384 168, 168, 168, 131, 168, 168, 308, 309, 168, 61,
385 168, 168, 34, 168, 168, 266, 114, 269, 9, 156,
386 136, 148, 149, 168, 150, 168, 98, 279, 168, 282,
387 125, 115, 35, 168, 286, 37, 98, 168, 37, 290,
388 39, 293, 295, 116, 99, 314, 315, 46, 47, 298,
389 299, 128, 168, 100, 99, 81, 117, 118, 303, 55,
390 57, 164, 110, 100, 168, 2, 129, 168, 153, 162,
391 168, 173, 46, 3, 171, 130, 131, 168, 168, 168,
392 168, 175, 168, 176, 132, 168, 133, 180, 190, 53,
393 4, 48, 49, 185, 168, 320, 188, 186, 5, 53,
394 202, 53, 198, 6, 53, 189, 199, 204, 209, 53,
395 53, 53, 205, 7, 212, 53, 206, 8, 131, 215,
396 218, 9, 207, 53, 208, 210, 56, 56, 211, 223,
397 53, 213, 219, 53, 220, 136, 53, 10, 11, 53,
398 225, 53, 61, 53, 53, 222, 53, 226, 227, 53,
399 231, 237, 61, 239, 61, 56, 238, 61, 241, 53,
400 246, 263, 61, 61, 61, 125, 271, 276, 61, 247,
401 252, 259, 260, 281, 262, 274, 61, 275, 284, 285,
402 289, 292, 297, 61, 302, 310, 61, 321, 81, 61,
403 134, 166, 61, 11, 61, 168, 61, 61, 81, 61,
404 81, 168, 61, 81, 228, 46, 322, 317, 81, 81,
405 81, 152, 61, 319, 81, 46, 184, 46, 300, 102,
406 46, 147, 81, 316, 127, 46, 46, 46, 158, 81,
407 318, 46, 81, 107, 312, 81, 301, 311, 81, 46,
408 81, 120, 81, 81, 54, 81, 46, 313, 81, 46,
409 135, 131, 46, 61, 0, 46, 0, 46, 81, 46,
410 46, 131, 46, 131, 0, 46, 131, 0, 136, 0,
411 0, 131, 131, 131, 167, 46, 0, 131, 136, 0,
412 136, 0, 0, 136, 0, 131, 0, 0, 136, 136,
413 136, 0, 131, 0, 136, 131, 0, 0, 131, 0,
414 0, 131, 136, 131, 0, 131, 131, 0, 131, 136,
415 0, 131, 136, 0, 0, 136, 0, 0, 136, 0,
416 136, 131, 136, 136, 0, 136, 0, 0, 136, 168,
417 0, 0, 0, 168, 168, 168, 168, 0, 136, 168,
418 0, 168, 0, 0, 168, 168, 168, 168, 168, 168,
419 168, 168, 168, 0, 168, 168, 168, 0, 0, 168,
420 168, 168, 168, 0, 0, 0, 168, 0, 168, 168,
421 0, 168, 168, 168, 168, 168, 168, 168, 168, 0,
422 0, 168, 168, 168, 168, 168, 168, 0, 168, 168,
423 0, 168, 163, 0, 168, 168, 0, 168, 0, 0,
424 168, 0, 0, 0, 168, 168, 171, 0, 171, 171,
425 0, 0, 171, 0, 171, 0, 0, 0, 171, 0,
426 171, 171, 0, 171, 171, 171, 0, 0, 0, 0,
427 0, 0, 171, 171, 171, 171, 0, 0, 323, 171,
428 0, 0, 171, 0, 171, 171, 171, 171, 0, 171,
429 171, 0, 0, 0, 0, 171, 171, 0, 171, 171,
430 0, 0, 168, 0, 0, 0, 0, 0, 171, 0,
431 171, 0, 168, 171, 168, 0, 0, 168, 171, 0,
432 0, 0, 168, 168, 168, 0, 0, 0, 168, 168,
433 0, 0, 0, 0, 0, 0, 168, 0, 0, 0,
434 0, 0, 0, 168, 0, 0, 168, 0, 168, 168,
435 0, 0, 168, 0, 168, 0, 168, 168, 168, 168,
436 168, 0, 168, 168, 0, 64, 0, 0, 168, 168,
437 168, 0, 168, 168, 168, 65, 0, 66, 146, 0,
438 67, 0, 168, 0, 0, 68, 69, 70, 0, 168,
439 0, 71, 168, 0, 0, 168, 0, 0, 168, 72,
440 168, 0, 168, 168, 0, 168, 73, 0, 168, 74,
441 0, 64, 75, 0, 0, 76, 0, 77, 168, 9,
442 78, 65, 79, 66, 0, 80, 67, 0, 0, 0,
443 0, 68, 69, 70, 0, 81, 0, 71, 0, 0,
444 0, 0, 0, 0, 0, 72, 0, 0, 0, 0,
445 0, 0, 73, 0, 0, 74, 0, 0, 75, 0,
446 0, 76, 168, 77, 0, 9, 78, 0, 79, 0,
447 0, 80, 168, 0, 168, 0, 0, 168, 0, 0,
448 0, 81, 168, 168, 168, 0, 0, 0, 168, 0,
449 0, 0, 0, 0, 0, 0, 168, 0, 0, 0,
450 0, 0, 0, 168, 0, 0, 168, 0, 0, 168,
451 0, 0, 168, 0, 168, 0, 168, 168, 136, 168,
452 137, 0, 168, 0, 138, 0, 139, 0, 0, 0,
453 0, 140, 168, 0, 168, 0, 168, 168, 0, 141,
454 168, 142, 168, 0, 0, 143, 168, 0, 168, 168,
455 0, 168, 168, 168, 0, 144, 0, 0, 0, 0,
456 168, 168, 168, 168, 0, 0, 0, 168, 0, 0,
457 168, 0, 168, 168, 168, 168, 145, 168, 168, 0,
458 0, 0, 0, 168, 168, 0, 168, 168, 0, 136,
459 0, 137, 0, 0, 0, 138, 168, 139, 168, 0,
460 0, 168, 140, 0, 0, 0, 168, 168, 0, 168,
461 141, 0, 142, 168, 0, 168, 143, 0, 0, 0,
462 168, 0, 0, 0, 0, 0, 144, 0, 168, 0,
463 168, 0, 0, 0, 168, 0, 0, 0, 0, 0,
464 0, 0, 0, 0, 168, 0, 0, 145, 0, 0,
465 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
466 0, 0, 0, 0, 0, 168,
467};
468const short yycheck[] =
469 { 10,
470 35, 59, 83, 123, 123, 25, 45, 64, 282, 125,
471 123, 125, 47, 258, 10, 54, 1, 260, 123, 285,
472 55, 10, 10, 268, 291, 270, 284, 293, 273, 266,
473 267, 268, 275, 278, 279, 280, 308, 273, 296, 284,
474 329, 284, 285, 310, 280, 299, 123, 292, 44, 84,
475 293, 36, 295, 329, 299, 329, 113, 302, 330, 44,
476 305, 319, 123, 308, 282, 310, 101, 312, 313, 284,
477 315, 106, 312, 318, 10, 329, 303, 313, 257, 312,
478 330, 296, 123, 328, 119, 232, 316, 317, 325, 329,
479 329, 126, 328, 272, 123, 242, 329, 244, 329, 134,
480 295, 296, 249, 61, 319, 284, 259, 254, 44, 256,
481 257, 146, 314, 295, 296, 260, 151, 259, 297, 298,
482 10, 274, 157, 329, 330, 164, 273, 329, 10, 324,
483 275, 284, 274, 153, 123, 10, 125, 10, 10, 284,
484 285, 257, 324, 259, 260, 180, 259, 263, 293, 265,
485 295, 326, 327, 269, 44, 271, 272, 10, 274, 275,
486 276, 274, 10, 259, 284, 329, 330, 283, 284, 285,
487 286, 284, 306, 307, 290, 309, 296, 293, 274, 295,
488 296, 297, 298, 10, 300, 301, 329, 330, 284, 125,
489 306, 307, 329, 309, 310, 230, 257, 232, 312, 319,
490 10, 306, 307, 319, 309, 321, 283, 242, 324, 244,
491 329, 272, 10, 329, 249, 329, 283, 257, 329, 254,
492 329, 256, 257, 284, 301, 322, 323, 47, 123, 264,
493 265, 260, 272, 310, 301, 125, 297, 298, 273, 10,
494 329, 322, 287, 310, 284, 256, 275, 283, 303, 329,
495 329, 301, 125, 264, 330, 284, 285, 297, 298, 306,
496 307, 274, 309, 329, 293, 301, 295, 123, 298, 258,
497 281, 329, 330, 329, 310, 310, 329, 326, 289, 268,
498 262, 270, 330, 294, 273, 329, 329, 329, 300, 278,
499 279, 280, 329, 304, 277, 284, 329, 308, 125, 330,
500 319, 312, 329, 292, 329, 329, 295, 296, 329, 314,
501 299, 320, 330, 302, 329, 125, 305, 328, 329, 308,
502 330, 310, 258, 312, 313, 329, 315, 330, 261, 318,
503 274, 330, 268, 302, 270, 324, 329, 273, 329, 328,
504 330, 125, 278, 279, 280, 329, 125, 288, 284, 330,
505 329, 329, 329, 125, 330, 329, 292, 329, 125, 125,
506 125, 125, 125, 299, 125, 123, 302, 329, 258, 305,
507 329, 10, 308, 288, 310, 125, 312, 313, 268, 315,
508 270, 125, 318, 273, 173, 258, 320, 294, 278, 279,
509 280, 75, 328, 304, 284, 268, 109, 270, 268, 65,
510 273, 74, 292, 291, 72, 278, 279, 280, 77, 299,
511 296, 284, 302, 66, 283, 305, 270, 280, 308, 292,
512 310, 70, 312, 313, 44, 315, 299, 287, 318, 302,
513 73, 258, 305, 51, -1, 308, -1, 310, 328, 312,
514 313, 268, 315, 270, -1, 318, 273, -1, 258, -1,
515 -1, 278, 279, 280, 125, 328, -1, 284, 268, -1,
516 270, -1, -1, 273, -1, 292, -1, -1, 278, 279,
517 280, -1, 299, -1, 284, 302, -1, -1, 305, -1,
518 -1, 308, 292, 310, -1, 312, 313, -1, 315, 299,
519 -1, 318, 302, -1, -1, 305, -1, -1, 308, -1,
520 310, 328, 312, 313, -1, 315, -1, -1, 318, 125,
521 -1, -1, -1, 257, 258, 259, 260, -1, 328, 263,
522 -1, 265, -1, -1, 268, 269, 270, 271, 272, 273,
523 274, 275, 276, -1, 278, 279, 280, -1, -1, 283,
524 284, 285, 286, -1, -1, -1, 290, -1, 292, 293,
525 -1, 295, 296, 297, 298, 299, 300, 301, 302, -1,
526 -1, 305, 306, 307, 308, 309, 310, -1, 312, 313,
527 -1, 315, 125, -1, 318, 319, -1, 321, -1, -1,
528 324, -1, -1, -1, 328, 329, 257, -1, 259, 260,
529 -1, -1, 263, -1, 265, -1, -1, -1, 269, -1,
530 271, 272, -1, 274, 275, 276, -1, -1, -1, -1,
531 -1, -1, 283, 284, 285, 286, -1, -1, 125, 290,
532 -1, -1, 293, -1, 295, 296, 297, 298, -1, 300,
533 301, -1, -1, -1, -1, 306, 307, -1, 309, 310,
534 -1, -1, 258, -1, -1, -1, -1, -1, 319, -1,
535 321, -1, 268, 324, 270, -1, -1, 273, 329, -1,
536 -1, -1, 278, 279, 280, -1, -1, -1, 284, 125,
537 -1, -1, -1, -1, -1, -1, 292, -1, -1, -1,
538 -1, -1, -1, 299, -1, -1, 302, -1, 258, 305,
539 -1, -1, 308, -1, 310, -1, 312, 313, 268, 315,
540 270, -1, 318, 273, -1, 258, -1, -1, 278, 279,
541 280, -1, 328, 329, 284, 268, -1, 270, 123, -1,
542 273, -1, 292, -1, -1, 278, 279, 280, -1, 299,
543 -1, 284, 302, -1, -1, 305, -1, -1, 308, 292,
544 310, -1, 312, 313, -1, 315, 299, -1, 318, 302,
545 -1, 258, 305, -1, -1, 308, -1, 310, 328, 312,
546 313, 268, 315, 270, -1, 318, 273, -1, -1, -1,
547 -1, 278, 279, 280, -1, 328, -1, 284, -1, -1,
548 -1, -1, -1, -1, -1, 292, -1, -1, -1, -1,
549 -1, -1, 299, -1, -1, 302, -1, -1, 305, -1,
550 -1, 308, 258, 310, -1, 312, 313, -1, 315, -1,
551 -1, 318, 268, -1, 270, -1, -1, 273, -1, -1,
552 -1, 328, 278, 279, 280, -1, -1, -1, 284, -1,
553 -1, -1, -1, -1, -1, -1, 292, -1, -1, -1,
554 -1, -1, -1, 299, -1, -1, 302, -1, -1, 305,
555 -1, -1, 308, -1, 310, -1, 312, 313, 263, 315,
556 265, -1, 318, -1, 269, -1, 271, -1, -1, -1,
557 -1, 276, 328, -1, 257, -1, 259, 260, -1, 284,
558 263, 286, 265, -1, -1, 290, 269, -1, 271, 272,
559 -1, 274, 275, 276, -1, 300, -1, -1, -1, -1,
560 283, 284, 285, 286, -1, -1, -1, 290, -1, -1,
561 293, -1, 295, 296, 297, 298, 321, 300, 301, -1,
562 -1, -1, -1, 306, 307, -1, 309, 310, -1, 263,
563 -1, 265, -1, -1, -1, 269, 319, 271, 321, -1,
564 -1, 324, 276, -1, -1, -1, 329, 263, -1, 265,
565 284, -1, 286, 269, -1, 271, 290, -1, -1, -1,
566 276, -1, -1, -1, -1, -1, 300, -1, 284, -1,
567 286, -1, -1, -1, 290, -1, -1, -1, -1, -1,
568 -1, -1, -1, -1, 300, -1, -1, 321, -1, -1,
569 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
570 -1, -1, -1, -1, -1, 321,
571};
572#define YYFINAL1 1
573#ifndef YYDEBUG0
574#define YYDEBUG0 0
575#endif
576#define YYMAXTOKEN330 330
577#if YYDEBUG0
578const char * const yyname[] =
579 {
580"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5810,0,0,0,0,0,0,0,0,0,0,0,0,"','",0,0,"'/'",0,0,0,0,0,0,0,0,0,0,0,"';'",0,"'='",0,
5820,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5830,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'{'",0,"'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,
5840,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5850,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5860,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
587"ACCESS","ALIAS","AUTO","BACKLOG","BODY","BUFFER","CERTIFICATE","CHROOT",
588"CIPHERS","COMMON","COMBINED","CONNECTION","DHE","DIRECTORY","ECDHE","ERR",
589"FCGI","INDEX","IP","KEY","LIFETIME","LISTEN","LOCATION","LOG","LOGDIR","MATCH",
590"MAXIMUM","NO","NODELAY","OCSP","ON","PORT","PREFORK","PROTOCOLS","REQUESTS",
591"ROOT","SACK","SERVER","SOCKET","STRIP","STYLE","SYSLOG","TCP","TICKET",
592"TIMEOUT","TLS","TYPE","TYPES","HSTS","MAXAGE","SUBDOMAINS","DEFAULT","PRELOAD",
593"REQUEST","ERROR","INCLUDE","AUTHENTICATE","WITH","BLOCK","DROP","RETURN",
594"PASS","REWRITE","CA","CLIENT","CRL","OPTIONAL","PARAM","FORWARDED","FOUND",
595"NOT","ERRDOCS","STRING","NUMBER",
596};
597const char * const yyrule[] =
598 {"$accept : grammar",
599"grammar :",
600"grammar : grammar include '\\n'",
601"grammar : grammar '\\n'",
602"grammar : grammar varset '\\n'",
603"grammar : grammar main '\\n'",
604"grammar : grammar server '\\n'",
605"grammar : grammar types '\\n'",
606"grammar : grammar error '\\n'",
607"include : INCLUDE STRING",
608"varset : STRING '=' STRING",
609"opttls :",
610"opttls : TLS",
611"main : PREFORK NUMBER",
612"main : CHROOT STRING",
613"main : ERRDOCS STRING",
614"main : LOGDIR STRING",
615"main : DEFAULT TYPE mediastring",
616"$$1 :",
617"server : SERVER optmatch STRING $$1 '{' optnl serveropts_l '}'",
618"serveropts_l : serveropts_l serveroptsl nl",
619"serveropts_l : serveroptsl optnl",
620"serveroptsl : LISTEN ON STRING opttls port",
621"serveroptsl : ALIAS optmatch STRING",
622"serveroptsl : ERRDOCS STRING",
623"serveroptsl : NO ERRDOCS",
624"serveroptsl : tcpip",
625"serveroptsl : connection",
626"serveroptsl : tls",
627"serveroptsl : request",
628"serveroptsl : root",
629"serveroptsl : directory",
630"serveroptsl : logformat",
631"serveroptsl : fastcgi",
632"serveroptsl : authenticate",
633"serveroptsl : filter",
634"$$2 :",
635"serveroptsl : LOCATION optfound optmatch STRING $$2 '{' optnl serveropts_l '}'",
636"serveroptsl : DEFAULT TYPE mediastring",
637"serveroptsl : include",
638"serveroptsl : hsts",
639"optfound :",
640"optfound : FOUND",
641"optfound : NOT FOUND",
642"hsts : HSTS '{' optnl hstsflags_l '}'",
643"hsts : HSTS hstsflags",
644"hsts : HSTS",
645"hstsflags_l : hstsflags optcommanl hstsflags_l",
646"hstsflags_l : hstsflags optnl",
647"hstsflags : MAXAGE NUMBER",
648"hstsflags : SUBDOMAINS",
649"hstsflags : PRELOAD",
650"fastcgi : NO FCGI",
651"fastcgi : FCGI",
652"$$3 :",
653"fastcgi : FCGI $$3 '{' optnl fcgiflags_l '}'",
654"$$4 :",
655"fastcgi : FCGI $$4 fcgiflags",
656"fcgiflags_l : fcgiflags optcommanl fcgiflags_l",
657"fcgiflags_l : fcgiflags optnl",
658"fcgiflags : SOCKET STRING",
659"fcgiflags : SOCKET TCP STRING",
660"fcgiflags : SOCKET TCP STRING fcgiport",
661"fcgiflags : PARAM STRING STRING",
662"fcgiflags : STRIP NUMBER",
663"connection : CONNECTION '{' optnl conflags_l '}'",
664"connection : CONNECTION conflags",
665"conflags_l : conflags optcommanl conflags_l",
666"conflags_l : conflags optnl",
667"conflags : TIMEOUT timeout",
668"conflags : REQUEST TIMEOUT timeout",
669"conflags : MAXIMUM REQUESTS NUMBER",
670"conflags : MAXIMUM REQUEST BODY NUMBER",
671"tls : TLS '{' optnl tlsopts_l '}'",
672"tls : TLS tlsopts",
673"tlsopts_l : tlsopts optcommanl tlsopts_l",
674"tlsopts_l : tlsopts optnl",
675"tlsopts : CERTIFICATE STRING",
676"tlsopts : KEY STRING",
677"tlsopts : OCSP STRING",
678"tlsopts : CIPHERS STRING",
679"tlsopts : CLIENT CA STRING tlsclientopt",
680"tlsopts : DHE STRING",
681"tlsopts : ECDHE STRING",
682"tlsopts : PROTOCOLS STRING",
683"tlsopts : TICKET LIFETIME DEFAULT",
684"tlsopts : TICKET LIFETIME NUMBER",
685"tlsopts : NO TICKET",
686"tlsclientopt :",
687"tlsclientopt : tlsclientopt CRL STRING",
688"tlsclientopt : tlsclientopt OPTIONAL",
689"root : ROOT rootflags",
690"root : ROOT '{' optnl rootflags_l '}'",
691"rootflags_l : rootflags optcommanl rootflags_l",
692"rootflags_l : rootflags optnl",
693"rootflags : STRING",
694"request : REQUEST requestflags",
695"request : REQUEST '{' optnl requestflags_l '}'",
696"requestflags_l : requestflags optcommanl requestflags_l",
697"requestflags_l : requestflags optnl",
698"requestflags : REWRITE STRING",
699"requestflags : NO REWRITE",
700"requestflags : STRIP NUMBER",
701"authenticate : NO AUTHENTICATE",
702"authenticate : AUTHENTICATE authopts",
703"authopts : STRING WITH STRING",
704"authopts : WITH STRING",
705"directory : DIRECTORY dirflags",
706"directory : DIRECTORY '{' optnl dirflags_l '}'",
707"dirflags_l : dirflags optcommanl dirflags_l",
708"dirflags_l : dirflags optnl",
709"dirflags : INDEX STRING",
710"dirflags : NO INDEX",
711"dirflags : AUTO INDEX",
712"dirflags : NO AUTO INDEX",
713"logformat : LOG logflags",
714"logformat : LOG '{' optnl logflags_l '}'",
715"logformat : NO LOG",
716"logflags_l : logflags optcommanl logflags_l",
717"logflags_l : logflags optnl",
718"logflags : STYLE logstyle",
719"logflags : SYSLOG",
720"logflags : NO SYSLOG",
721"logflags : ACCESS STRING",
722"logflags : ERR STRING",
723"logstyle : COMMON",
724"logstyle : COMBINED",
725"logstyle : CONNECTION",
726"logstyle : FORWARDED",
727"filter : block RETURN NUMBER optstring",
728"filter : block DROP",
729"filter : block",
730"filter : PASS",
731"block : BLOCK",
732"optmatch :",
733"optmatch : MATCH",
734"optstring :",
735"optstring : STRING",
736"fcgiport : NUMBER",
737"fcgiport : STRING",
738"tcpip : TCP '{' optnl tcpflags_l '}'",
739"tcpip : TCP tcpflags",
740"tcpflags_l : tcpflags optcommanl tcpflags_l",
741"tcpflags_l : tcpflags optnl",
742"tcpflags : SACK",
743"tcpflags : NO SACK",
744"tcpflags : NODELAY",
745"tcpflags : NO NODELAY",
746"tcpflags : BACKLOG NUMBER",
747"tcpflags : SOCKET BUFFER NUMBER",
748"tcpflags : IP STRING NUMBER",
749"types : TYPES '{' optnl mediaopts_l '}'",
750"mediaopts_l : mediaopts_l mediaoptsl nl",
751"mediaopts_l : mediaoptsl nl",
752"mediaoptsl : mediastring medianames_l optsemicolon",
753"mediaoptsl : include",
754"mediastring : STRING '/' STRING",
755"medianames_l : medianames_l medianamesl",
756"medianames_l : medianamesl",
757"medianamesl : numberstring",
758"port : PORT NUMBER",
759"port : PORT STRING",
760"timeout : NUMBER",
761"numberstring : NUMBER",
762"numberstring : STRING",
763"optsemicolon : ';'",
764"optsemicolon :",
765"optnl : '\\n' optnl",
766"optnl :",
767"optcommanl : ',' optnl",
768"optcommanl : nl",
769"nl : '\\n' optnl",
770};
771#endif
772#ifdef YYSTACKSIZE10000
773#undef YYMAXDEPTH10000
774#define YYMAXDEPTH10000 YYSTACKSIZE10000
775#else
776#ifdef YYMAXDEPTH10000
777#define YYSTACKSIZE10000 YYMAXDEPTH10000
778#else
779#define YYSTACKSIZE10000 10000
780#define YYMAXDEPTH10000 10000
781#endif
782#endif
783#define YYINITSTACKSIZE200 200
784/* LINTUSED */
785int yydebug;
786int yynerrs;
787int yyerrflag;
788int yychar;
789short *yyssp;
790YYSTYPE *yyvsp;
791YYSTYPE yyval;
792YYSTYPE yylval;
793short *yyss;
794short *yysslim;
795YYSTYPE *yyvs;
796unsigned int yystacksize;
797int yyparse(void);
798#line 1384 "/usr/src/usr.sbin/httpd/parse.y"
799
800struct keywords {
801 const char *k_name;
802 int k_val;
803};
804
805int
806yyerror(const char *fmt, ...)
807{
808 va_list ap;
809 char *msg;
810
811 file->errors++;
812 va_start(ap, fmt)__builtin_va_start(ap, fmt);
813 if (vasprintf(&msg, fmt, ap) == -1)
814 fatalx("yyerror vasprintf");
815 va_end(ap)__builtin_va_end(ap);
816 logit(LOG_CRIT2, "%s:%d: %s", file->name, yylval.lineno, msg);
817 free(msg);
818 return (0);
819}
820
821int
822kw_cmp(const void *k, const void *e)
823{
824 return (strcmp(k, ((const struct keywords *)e)->k_name));
825}
826
827int
828lookup(char *s)
829{
830 /* this has to be sorted always */
831 static const struct keywords keywords[] = {
832 { "access", ACCESS257 },
833 { "alias", ALIAS258 },
834 { "authenticate", AUTHENTICATE313},
835 { "auto", AUTO259 },
836 { "backlog", BACKLOG260 },
837 { "block", BLOCK315 },
838 { "body", BODY261 },
839 { "buffer", BUFFER262 },
840 { "ca", CA320 },
841 { "certificate", CERTIFICATE263 },
842 { "chroot", CHROOT264 },
843 { "ciphers", CIPHERS265 },
844 { "client", CLIENT321 },
845 { "combined", COMBINED267 },
846 { "common", COMMON266 },
847 { "connection", CONNECTION268 },
848 { "crl", CRL322 },
849 { "default", DEFAULT308 },
850 { "dhe", DHE269 },
851 { "directory", DIRECTORY270 },
852 { "drop", DROP316 },
853 { "ecdhe", ECDHE271 },
854 { "errdocs", ERRDOCS328 },
855 { "error", ERR272 },
856 { "fastcgi", FCGI273 },
857 { "forwarded", FORWARDED325 },
858 { "found", FOUND326 },
859 { "hsts", HSTS305 },
860 { "include", INCLUDE312 },
861 { "index", INDEX274 },
862 { "ip", IP275 },
863 { "key", KEY276 },
864 { "lifetime", LIFETIME277 },
865 { "listen", LISTEN278 },
866 { "location", LOCATION279 },
867 { "log", LOG280 },
868 { "logdir", LOGDIR281 },
869 { "match", MATCH282 },
870 { "max", MAXIMUM283 },
871 { "max-age", MAXAGE306 },
872 { "no", NO284 },
873 { "nodelay", NODELAY285 },
874 { "not", NOT327 },
875 { "ocsp", OCSP286 },
876 { "on", ON287 },
877 { "optional", OPTIONAL323 },
878 { "param", PARAM324 },
879 { "pass", PASS318 },
880 { "port", PORT288 },
881 { "prefork", PREFORK289 },
882 { "preload", PRELOAD309 },
883 { "protocols", PROTOCOLS290 },
884 { "request", REQUEST310 },
885 { "requests", REQUESTS291 },
886 { "return", RETURN317 },
887 { "rewrite", REWRITE319 },
888 { "root", ROOT292 },
889 { "sack", SACK293 },
890 { "server", SERVER294 },
891 { "socket", SOCKET295 },
892 { "strip", STRIP296 },
893 { "style", STYLE297 },
894 { "subdomains", SUBDOMAINS307 },
895 { "syslog", SYSLOG298 },
896 { "tcp", TCP299 },
897 { "ticket", TICKET300 },
898 { "timeout", TIMEOUT301 },
899 { "tls", TLS302 },
900 { "type", TYPE303 },
901 { "types", TYPES304 },
902 { "with", WITH314 }
903 };
904 const struct keywords *p;
905
906 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
907 sizeof(keywords[0]), kw_cmp);
908
909 if (p)
910 return (p->k_val);
911 else
912 return (STRING329);
913}
914
915#define START_EXPAND1 1
916#define DONE_EXPAND2 2
917
918static int expanding;
919
920int
921igetc(void)
922{
923 int c;
924
925 while (1) {
926 if (file->ungetpos > 0)
927 c = file->ungetbuf[--file->ungetpos];
928 else
929 c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget
(file->stream) : (int)(*(file->stream)->_p++)) : (getc
)(file->stream))
;
930
931 if (c == START_EXPAND1)
932 expanding = 1;
933 else if (c == DONE_EXPAND2)
934 expanding = 0;
935 else
936 break;
937 }
938 return (c);
939}
940
941int
942lgetc(int quotec)
943{
944 int c, next;
945
946 if (quotec) {
947 if ((c = igetc()) == EOF(-1)) {
948 yyerror("reached end of file while parsing "
949 "quoted string");
950 if (file == topfile || popfile() == EOF(-1))
951 return (EOF(-1));
952 return (quotec);
953 }
954 return (c);
955 }
956
957 while ((c = igetc()) == '\\') {
958 next = igetc();
959 if (next != '\n') {
960 c = next;
961 break;
962 }
963 yylval.lineno = file->lineno;
964 file->lineno++;
965 }
966
967 if (c == EOF(-1)) {
968 /*
969 * Fake EOL when hit EOF for the first time. This gets line
970 * count right if last line in included file is syntactically
971 * invalid and has no newline.
972 */
973 if (file->eof_reached == 0) {
974 file->eof_reached = 1;
975 return ('\n');
976 }
977 while (c == EOF(-1)) {
978 if (file == topfile || popfile() == EOF(-1))
979 return (EOF(-1));
980 c = igetc();
981 }
982 }
983 return (c);
984}
985
986void
987lungetc(int c)
988{
989 if (c == EOF(-1))
990 return;
991
992 if (file->ungetpos >= file->ungetsize) {
993 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
994 if (p == NULL((void*)0))
995 err(1, "%s", __func__);
996 file->ungetbuf = p;
997 file->ungetsize *= 2;
998 }
999 file->ungetbuf[file->ungetpos++] = c;
1000}
1001
1002int
1003findeol(void)
1004{
1005 int c;
1006
1007 /* skip to either EOF or the first real EOL */
1008 while (1) {
1009 c = lgetc(0);
1010 if (c == '\n') {
1011 file->lineno++;
1012 break;
1013 }
1014 if (c == EOF(-1))
1015 break;
1016 }
1017 return (ERROR311);
1018}
1019
1020int
1021yylex(void)
1022{
1023 char buf[8096];
1024 char *p, *val;
1025 int quotec, next, c;
1026 int token;
1027
1028top:
1029 p = buf;
1030 while ((c = lgetc(0)) == ' ' || c == '\t')
1031 ; /* nothing */
1032
1033 yylval.lineno = file->lineno;
1034 if (c == '#')
1035 while ((c = lgetc(0)) != '\n' && c != EOF(-1))
1036 ; /* nothing */
1037 if (c == '$' && !expanding) {
1038 while (1) {
1039 if ((c = lgetc(0)) == EOF(-1))
1040 return (0);
1041
1042 if (p + 1 >= buf + sizeof(buf) - 1) {
1043 yyerror("string too long");
1044 return (findeol());
1045 }
1046 if (isalnum(c) || c == '_') {
1047 *p++ = c;
1048 continue;
1049 }
1050 *p = '\0';
1051 lungetc(c);
1052 break;
1053 }
1054 val = symget(buf);
1055 if (val == NULL((void*)0)) {
1056 yyerror("macro '%s' not defined", buf);
1057 return (findeol());
1058 }
1059 p = val + strlen(val) - 1;
1060 lungetc(DONE_EXPAND2);
1061 while (p >= val) {
1062 lungetc((unsigned char)*p);
1063 p--;
1064 }
1065 lungetc(START_EXPAND1);
1066 goto top;
1067 }
1068
1069 switch (c) {
1070 case '\'':
1071 case '"':
1072 quotec = c;
1073 while (1) {
1074 if ((c = lgetc(quotec)) == EOF(-1))
1075 return (0);
1076 if (c == '\n') {
1077 file->lineno++;
1078 continue;
1079 } else if (c == '\\') {
1080 if ((next = lgetc(quotec)) == EOF(-1))
1081 return (0);
1082 if (next == quotec || next == ' ' ||
1083 next == '\t')
1084 c = next;
1085 else if (next == '\n') {
1086 file->lineno++;
1087 continue;
1088 } else
1089 lungetc(next);
1090 } else if (c == quotec) {
1091 *p = '\0';
1092 break;
1093 } else if (c == '\0') {
1094 yyerror("syntax error");
1095 return (findeol());
1096 }
1097 if (p + 1 >= buf + sizeof(buf) - 1) {
1098 yyerror("string too long");
1099 return (findeol());
1100 }
1101 *p++ = c;
1102 }
1103 yylval.v.string = strdup(buf);
1104 if (yylval.v.string == NULL((void*)0))
1105 err(1, "%s", __func__);
1106 return (STRING329);
1107 }
1108
1109#define allowed_to_end_number(x)(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' ||
x == '=')
\
1110 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
1111
1112 if (c == '-' || isdigit(c)) {
1113 do {
1114 *p++ = c;
1115 if ((size_t)(p-buf) >= sizeof(buf)) {
1116 yyerror("string too long");
1117 return (findeol());
1118 }
1119 } while ((c = lgetc(0)) != EOF(-1) && isdigit(c));
1120 lungetc(c);
1121 if (p == buf + 1 && buf[0] == '-')
1122 goto nodigits;
1123 if (c == EOF(-1) || allowed_to_end_number(c)(isspace(c) || c == ')' || c ==',' || c == '/' || c == '}' ||
c == '=')
) {
1124 const char *errstr = NULL((void*)0);
1125
1126 *p = '\0';
1127 yylval.v.number = strtonum(buf, LLONG_MIN(-9223372036854775807LL -1LL),
1128 LLONG_MAX9223372036854775807LL, &errstr);
1129 if (errstr) {
1130 yyerror("\"%s\" invalid number: %s",
1131 buf, errstr);
1132 return (findeol());
1133 }
1134 return (NUMBER330);
1135 } else {
1136nodigits:
1137 while (p > buf + 1)
1138 lungetc((unsigned char)*--p);
1139 c = (unsigned char)*--p;
1140 if (c == '-')
1141 return (c);
1142 }
1143 }
1144
1145#define allowed_in_string(x)(isalnum(x) || (ispunct(x) && x != '(' && x !=
')' && x != '{' && x != '}' && x != '<'
&& x != '>' && x != '!' && x != '='
&& x != '#' && x != ',' && x != ';' &&
x != '/'))
\
1146 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
1147 x != '{' && x != '}' && x != '<' && x != '>' && \
1148 x != '!' && x != '=' && x != '#' && \
1149 x != ',' && x != ';' && x != '/'))
1150
1151 if (isalnum(c) || c == ':' || c == '_' || c == '*') {
1152 do {
1153 *p++ = c;
1154 if ((size_t)(p-buf) >= sizeof(buf)) {
1155 yyerror("string too long");
1156 return (findeol());
1157 }
1158 } while ((c = lgetc(0)) != EOF(-1) && (allowed_in_string(c)(isalnum(c) || (ispunct(c) && c != '(' && c !=
')' && c != '{' && c != '}' && c != '<'
&& c != '>' && c != '!' && c != '='
&& c != '#' && c != ',' && c != ';' &&
c != '/'))
));
1159 lungetc(c);
1160 *p = '\0';
1161 if ((token = lookup(buf)) == STRING329)
1162 if ((yylval.v.string = strdup(buf)) == NULL((void*)0))
1163 err(1, "%s", __func__);
1164 return (token);
1165 }
1166 if (c == '\n') {
1167 yylval.lineno = file->lineno;
1168 file->lineno++;
1169 }
1170 if (c == EOF(-1))
1171 return (0);
1172 return (c);
1173}
1174
1175int
1176check_file_secrecy(int fd, const char *fname)
1177{
1178 struct stat st;
1179
1180 if (fstat(fd, &st)) {
1181 log_warn("cannot stat %s", fname);
1182 return (-1);
1183 }
1184 if (st.st_uid != 0 && st.st_uid != getuid()) {
1185 log_warnx("%s: owner not root or current user", fname);
1186 return (-1);
1187 }
1188 if (st.st_mode & (S_IWGRP0000020 | S_IXGRP0000010 | S_IRWXO0000007)) {
1189 log_warnx("%s: group writable or world read/writable", fname);
1190 return (-1);
1191 }
1192 return (0);
1193}
1194
1195struct file *
1196pushfile(const char *name, int secret)
1197{
1198 struct file *nfile;
1199
1200 if ((nfile = calloc(1, sizeof(struct file))) == NULL((void*)0)) {
1201 log_warn("%s", __func__);
1202 return (NULL((void*)0));
1203 }
1204 if ((nfile->name = strdup(name)) == NULL((void*)0)) {
1205 log_warn("%s", __func__);
1206 free(nfile);
1207 return (NULL((void*)0));
1208 }
1209 if ((nfile->stream = fopen(nfile->name, "r")) == NULL((void*)0)) {
1210 log_warn("%s: %s", __func__, nfile->name);
1211 free(nfile->name);
1212 free(nfile);
1213 return (NULL((void*)0));
1214 } else if (secret &&
1215 check_file_secrecy(fileno(nfile->stream)(!__isthreaded ? ((nfile->stream)->_file) : (fileno)(nfile
->stream))
, nfile->name)) {
1216 fclose(nfile->stream);
1217 free(nfile->name);
1218 free(nfile);
1219 return (NULL((void*)0));
1220 }
1221 nfile->lineno = TAILQ_EMPTY(&files)(((&files)->tqh_first) == ((void*)0)) ? 1 : 0;
1222 nfile->ungetsize = 16;
1223 nfile->ungetbuf = malloc(nfile->ungetsize);
1224 if (nfile->ungetbuf == NULL((void*)0)) {
1225 log_warn("%s", __func__);
1226 fclose(nfile->stream);
1227 free(nfile->name);
1228 free(nfile);
1229 return (NULL((void*)0));
1230 }
1231 TAILQ_INSERT_TAIL(&files, nfile, entry)do { (nfile)->entry.tqe_next = ((void*)0); (nfile)->entry
.tqe_prev = (&files)->tqh_last; *(&files)->tqh_last
= (nfile); (&files)->tqh_last = &(nfile)->entry
.tqe_next; } while (0)
;
1232 return (nfile);
1233}
1234
1235int
1236popfile(void)
1237{
1238 struct file *prev;
1239
1240 if ((prev = TAILQ_PREV(file, files, entry)(*(((struct files *)((file)->entry.tqe_prev))->tqh_last
))
) != NULL((void*)0))
1241 prev->errors += file->errors;
1242
1243 TAILQ_REMOVE(&files, file, entry)do { if (((file)->entry.tqe_next) != ((void*)0)) (file)->
entry.tqe_next->entry.tqe_prev = (file)->entry.tqe_prev
; else (&files)->tqh_last = (file)->entry.tqe_prev;
*(file)->entry.tqe_prev = (file)->entry.tqe_next; ; ; }
while (0)
;
1244 fclose(file->stream);
1245 free(file->name);
1246 free(file->ungetbuf);
1247 free(file);
1248 file = prev;
1249 return (file ? 0 : EOF(-1));
1250}
1251
1252int
1253parse_config(const char *filename, struct httpd *x_conf)
1254{
1255 struct sym *sym, *next;
1256 struct media_type dflt = HTTPD_DEFAULT_TYPE{ "bin", "application", "octet-stream", ((void*)0) };
1257
1258 conf = x_conf;
1259 if (config_init(conf) == -1) {
1260 log_warn("%s: cannot initialize configuration", __func__);
1261 return (-1);
1262 }
1263
1264 /* Set default media type */
1265 memcpy(&conf->sc_default_type, &dflt, sizeof(struct media_type));
1266
1267 errors = 0;
1268
1269 if ((file = pushfile(filename, 0)) == NULL((void*)0))
1270 return (-1);
1271
1272 topfile = file;
1273 setservent(1);
1274
1275 yyparse();
1276 errors = file->errors;
1277 while (popfile() != EOF(-1))
1278 ;
1279
1280 endservent();
1281 endprotoent();
1282
1283 /* Free macros */
1284 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next)for ((sym) = ((&symhead)->tqh_first); (sym) != ((void*
)0) && ((next) = ((sym)->entry.tqe_next), 1); (sym
) = (next))
{
1285 if (!sym->persist) {
1286 free(sym->nam);
1287 free(sym->val);
1288 TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void*)0)) (sym)->
entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev;
else (&symhead)->tqh_last = (sym)->entry.tqe_prev;
*(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while
(0)
;
1289 free(sym);
1290 }
1291 }
1292
1293 return (errors ? -1 : 0);
1294}
1295
1296int
1297load_config(const char *filename, struct httpd *x_conf)
1298{
1299 struct sym *sym, *next;
1300 struct http_mediatype mediatypes[] = MEDIA_TYPES{ { "css", "text", "css" }, { "html", "text", "html" }, { "txt"
, "text", "plain" }, { "gif", "image", "gif" }, { "jpeg", "image"
, "jpeg" }, { "jpg", "image", "jpeg" }, { "png", "image", "png"
}, { "svg", "image", "svg+xml" }, { "js", "application", "javascript"
}, { ((void*)0) } }
;
1301 struct media_type m;
1302 int i;
1303
1304 conf = x_conf;
1305 conf->sc_flags = 0;
1306
1307 loadcfg = 1;
1308 errors = 0;
1309 last_server_id = 0;
1310 last_auth_id = 0;
1311
1312 srv = NULL((void*)0);
1313
1314 if ((file = pushfile(filename, 0)) == NULL((void*)0))
1315 return (-1);
1316
1317 topfile = file;
1318 setservent(1);
1319
1320 yyparse();
1321 errors = file->errors;
1322 popfile();
1323
1324 endservent();
1325 endprotoent();
1326
1327 /* Free macros and check which have not been used. */
1328 for (sym = TAILQ_FIRST(&symhead)((&symhead)->tqh_first); sym != NULL((void*)0); sym = next) {
1329 next = TAILQ_NEXT(sym, entry)((sym)->entry.tqe_next);
1330 if ((conf->sc_opts & HTTPD_OPT_VERBOSE0x01) && !sym->used)
1331 fprintf(stderr(&__sF[2]), "warning: macro '%s' not "
1332 "used\n", sym->nam);
1333 if (!sym->persist) {
1334 free(sym->nam);
1335 free(sym->val);
1336 TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void*)0)) (sym)->
entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev;
else (&symhead)->tqh_last = (sym)->entry.tqe_prev;
*(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while
(0)
;
1337 free(sym);
1338 }
1339 }
1340
1341 if (TAILQ_EMPTY(conf->sc_servers)(((conf->sc_servers)->tqh_first) == ((void*)0))) {
1342 log_warnx("no actions, nothing to do");
1343 errors++;
1344 }
1345
1346 if (RB_EMPTY(conf->sc_mediatypes)((conf->sc_mediatypes)->rbh_root == ((void*)0))) {
1347 /* Add default media types */
1348 for (i = 0; mediatypes[i].media_name != NULL((void*)0); i++) {
1349 (void)strlcpy(m.media_name, mediatypes[i].media_name,
1350 sizeof(m.media_name));
1351 (void)strlcpy(m.media_type, mediatypes[i].media_type,
1352 sizeof(m.media_type));
1353 (void)strlcpy(m.media_subtype,
1354 mediatypes[i].media_subtype,
1355 sizeof(m.media_subtype));
1356 m.media_encoding = NULL((void*)0);
1357
1358 if (media_add(conf->sc_mediatypes, &m) == NULL((void*)0)) {
1359 log_warnx("failed to add default media \"%s\"",
1360 m.media_name);
1361 errors++;
1362 }
1363 }
1364 }
1365
1366 return (errors ? -1 : 0);
1367}
1368
1369int
1370symset(const char *nam, const char *val, int persist)
1371{
1372 struct sym *sym;
1373
1374 TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void*)
0); (sym) = ((sym)->entry.tqe_next))
{
1375 if (strcmp(nam, sym->nam) == 0)
1376 break;
1377 }
1378
1379 if (sym != NULL((void*)0)) {
1380 if (sym->persist == 1)
1381 return (0);
1382 else {
1383 free(sym->nam);
1384 free(sym->val);
1385 TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void*)0)) (sym)->
entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev;
else (&symhead)->tqh_last = (sym)->entry.tqe_prev;
*(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while
(0)
;
1386 free(sym);
1387 }
1388 }
1389 if ((sym = calloc(1, sizeof(*sym))) == NULL((void*)0))
1390 return (-1);
1391
1392 sym->nam = strdup(nam);
1393 if (sym->nam == NULL((void*)0)) {
1394 free(sym);
1395 return (-1);
1396 }
1397 sym->val = strdup(val);
1398 if (sym->val == NULL((void*)0)) {
1399 free(sym->nam);
1400 free(sym);
1401 return (-1);
1402 }
1403 sym->used = 0;
1404 sym->persist = persist;
1405 TAILQ_INSERT_TAIL(&symhead, sym, entry)do { (sym)->entry.tqe_next = ((void*)0); (sym)->entry.tqe_prev
= (&symhead)->tqh_last; *(&symhead)->tqh_last =
(sym); (&symhead)->tqh_last = &(sym)->entry.tqe_next
; } while (0)
;
1406 return (0);
1407}
1408
1409int
1410cmdline_symset(char *s)
1411{
1412 char *sym, *val;
1413 int ret;
1414
1415 if ((val = strrchr(s, '=')) == NULL((void*)0))
1416 return (-1);
1417 sym = strndup(s, val - s);
1418 if (sym == NULL((void*)0))
1419 errx(1, "%s: strndup", __func__);
1420 ret = symset(sym, val + 1, 1);
1421 free(sym);
1422
1423 return (ret);
1424}
1425
1426char *
1427symget(const char *nam)
1428{
1429 struct sym *sym;
1430
1431 TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void*)
0); (sym) = ((sym)->entry.tqe_next))
{
1432 if (strcmp(nam, sym->nam) == 0) {
1433 sym->used = 1;
1434 return (sym->val);
1435 }
1436 }
1437 return (NULL((void*)0));
1438}
1439
1440struct address *
1441host_v4(const char *s)
1442{
1443 struct in_addr ina;
1444 struct sockaddr_in *sain;
1445 struct address *h;
1446
1447 memset(&ina, 0, sizeof(ina));
1448 if (inet_pton(AF_INET2, s, &ina) != 1)
1449 return (NULL((void*)0));
1450
1451 if ((h = calloc(1, sizeof(*h))) == NULL((void*)0))
1452 fatal(__func__);
1453 sain = (struct sockaddr_in *)&h->ss;
1454 sain->sin_len = sizeof(struct sockaddr_in);
1455 sain->sin_family = AF_INET2;
1456 sain->sin_addr.s_addr = ina.s_addr;
1457 if (sain->sin_addr.s_addr == INADDR_ANY((u_int32_t)(0x00000000)))
1458 h->prefixlen = 0; /* 0.0.0.0 address */
1459 else
1460 h->prefixlen = -1; /* host address */
1461 return (h);
1462}
1463
1464struct address *
1465host_v6(const char *s)
1466{
1467 struct addrinfo hints, *res;
1468 struct sockaddr_in6 *sa_in6;
1469 struct address *h = NULL((void*)0);
1470
1471 memset(&hints, 0, sizeof(hints));
1472 hints.ai_family = AF_INET624;
1473 hints.ai_socktype = SOCK_DGRAM2; /* dummy */
1474 hints.ai_flags = AI_NUMERICHOST4;
1475 if (getaddrinfo(s, "0", &hints, &res) == 0) {
1476 if ((h = calloc(1, sizeof(*h))) == NULL((void*)0))
1477 fatal(__func__);
1478 sa_in6 = (struct sockaddr_in6 *)&h->ss;
1479 sa_in6->sin6_len = sizeof(struct sockaddr_in6);
1480 sa_in6->sin6_family = AF_INET624;
1481 memcpy(&sa_in6->sin6_addr,
1482 &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
1483 sizeof(sa_in6->sin6_addr));
1484 sa_in6->sin6_scope_id =
1485 ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
1486 if (memcmp(&sa_in6->sin6_addr, &in6addr_any,
1487 sizeof(sa_in6->sin6_addr)) == 0)
1488 h->prefixlen = 0; /* any address */
1489 else
1490 h->prefixlen = -1; /* host address */
1491 freeaddrinfo(res);
1492 }
1493
1494 return (h);
1495}
1496
1497int
1498host_dns(const char *s, struct addresslist *al, int max,
1499 struct portrange *port, const char *ifname, int ipproto)
1500{
1501 struct addrinfo hints, *res0, *res;
1502 int error, cnt = 0;
1503 struct sockaddr_in *sain;
1504 struct sockaddr_in6 *sin6;
1505 struct address *h;
1506
1507 if ((cnt = host_if(s, al, max, port, ifname, ipproto)) != 0)
1508 return (cnt);
1509
1510 memset(&hints, 0, sizeof(hints));
1511 hints.ai_family = PF_UNSPEC0;
1512 hints.ai_socktype = SOCK_DGRAM2; /* DUMMY */
1513 hints.ai_flags = AI_ADDRCONFIG64;
1514 error = getaddrinfo(s, NULL((void*)0), &hints, &res0);
1515 if (error == EAI_AGAIN-3 || error == EAI_NODATA-5 || error == EAI_NONAME-2)
1516 return (0);
1517 if (error) {
1518 log_warnx("%s: could not parse \"%s\": %s", __func__, s,
1519 gai_strerror(error));
1520 return (-1);
1521 }
1522
1523 for (res = res0; res && cnt < max; res = res->ai_next) {
1524 if (res->ai_family != AF_INET2 &&
1525 res->ai_family != AF_INET624)
1526 continue;
1527 if ((h = calloc(1, sizeof(*h))) == NULL((void*)0))
1528 fatal(__func__);
1529
1530 if (port != NULL((void*)0))
1531 memcpy(&h->port, port, sizeof(h->port));
1532 if (ifname != NULL((void*)0)) {
1533 if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
1534 sizeof(h->ifname))
1535 log_warnx("%s: interface name truncated",
1536 __func__);
1537 freeaddrinfo(res0);
1538 free(h);
1539 return (-1);
1540 }
1541 if (ipproto != -1)
1542 h->ipproto = ipproto;
1543 h->ss.ss_family = res->ai_family;
1544 h->prefixlen = -1; /* host address */
1545
1546 if (res->ai_family == AF_INET2) {
1547 sain = (struct sockaddr_in *)&h->ss;
1548 sain->sin_len = sizeof(struct sockaddr_in);
1549 sain->sin_addr.s_addr = ((struct sockaddr_in *)
1550 res->ai_addr)->sin_addr.s_addr;
1551 } else {
1552 sin6 = (struct sockaddr_in6 *)&h->ss;
1553 sin6->sin6_len = sizeof(struct sockaddr_in6);
1554 memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
1555 res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
1556 }
1557
1558 TAILQ_INSERT_HEAD(al, h, entry)do { if (((h)->entry.tqe_next = (al)->tqh_first) != ((void
*)0)) (al)->tqh_first->entry.tqe_prev = &(h)->entry
.tqe_next; else (al)->tqh_last = &(h)->entry.tqe_next
; (al)->tqh_first = (h); (h)->entry.tqe_prev = &(al
)->tqh_first; } while (0)
;
1559 cnt++;
1560 }
1561 if (cnt == max && res) {
1562 log_warnx("%s: %s resolves to more than %d hosts", __func__,
1563 s, max);
1564 }
1565 freeaddrinfo(res0);
1566 return (cnt);
1567}
1568
1569int
1570host_if(const char *s, struct addresslist *al, int max,
1571 struct portrange *port, const char *ifname, int ipproto)
1572{
1573 struct ifaddrs *ifap, *p;
1574 struct sockaddr_in *sain;
1575 struct sockaddr_in6 *sin6;
1576 struct address *h;
1577 int cnt = 0, af;
1578
1579 if (getifaddrs(&ifap) == -1)
1580 fatal("getifaddrs");
1581
1582 /* First search for IPv4 addresses */
1583 af = AF_INET2;
1584
1585 nextaf:
1586 for (p = ifap; p != NULL((void*)0) && cnt < max; p = p->ifa_next) {
1587 if (p->ifa_addr == NULL((void*)0) ||
1588 p->ifa_addr->sa_family != af ||
1589 (strcmp(s, p->ifa_name) != 0 &&
1590 !is_if_in_group(p->ifa_name, s)))
1591 continue;
1592 if ((h = calloc(1, sizeof(*h))) == NULL((void*)0))
1593 fatal("calloc");
1594
1595 if (port != NULL((void*)0))
1596 memcpy(&h->port, port, sizeof(h->port));
1597 if (ifname != NULL((void*)0)) {
1598 if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
1599 sizeof(h->ifname))
1600 log_warnx("%s: interface name truncated",
1601 __func__);
1602 freeifaddrs(ifap);
1603 free(h);
1604 return (-1);
1605 }
1606 if (ipproto != -1)
1607 h->ipproto = ipproto;
1608 h->ss.ss_family = af;
1609 h->prefixlen = -1; /* host address */
1610
1611 if (af == AF_INET2) {
1612 sain = (struct sockaddr_in *)&h->ss;
1613 sain->sin_len = sizeof(struct sockaddr_in);
1614 sain->sin_addr.s_addr = ((struct sockaddr_in *)
1615 p->ifa_addr)->sin_addr.s_addr;
1616 } else {
1617 sin6 = (struct sockaddr_in6 *)&h->ss;
1618 sin6->sin6_len = sizeof(struct sockaddr_in6);
1619 memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
1620 p->ifa_addr)->sin6_addr, sizeof(struct in6_addr));
1621 sin6->sin6_scope_id = ((struct sockaddr_in6 *)
1622 p->ifa_addr)->sin6_scope_id;
1623 }
1624
1625 TAILQ_INSERT_HEAD(al, h, entry)do { if (((h)->entry.tqe_next = (al)->tqh_first) != ((void
*)0)) (al)->tqh_first->entry.tqe_prev = &(h)->entry
.tqe_next; else (al)->tqh_last = &(h)->entry.tqe_next
; (al)->tqh_first = (h); (h)->entry.tqe_prev = &(al
)->tqh_first; } while (0)
;
1626 cnt++;
1627 }
1628 if (af == AF_INET2) {
1629 /* Next search for IPv6 addresses */
1630 af = AF_INET624;
1631 goto nextaf;
1632 }
1633
1634 if (cnt > max) {
1635 log_warnx("%s: %s resolves to more than %d hosts", __func__,
1636 s, max);
1637 }
1638 freeifaddrs(ifap);
1639 return (cnt);
1640}
1641
1642int
1643host(const char *s, struct addresslist *al, int max,
1644 struct portrange *port, const char *ifname, int ipproto)
1645{
1646 struct address *h;
1647
1648 h = host_v4(s);
1649
1650 /* IPv6 address? */
1651 if (h == NULL((void*)0))
1652 h = host_v6(s);
1653
1654 if (h != NULL((void*)0)) {
1655 if (port != NULL((void*)0))
1656 memcpy(&h->port, port, sizeof(h->port));
1657 if (ifname != NULL((void*)0)) {
1658 if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
1659 sizeof(h->ifname)) {
1660 log_warnx("%s: interface name truncated",
1661 __func__);
1662 free(h);
1663 return (-1);
1664 }
1665 }
1666 if (ipproto != -1)
1667 h->ipproto = ipproto;
1668
1669 TAILQ_INSERT_HEAD(al, h, entry)do { if (((h)->entry.tqe_next = (al)->tqh_first) != ((void
*)0)) (al)->tqh_first->entry.tqe_prev = &(h)->entry
.tqe_next; else (al)->tqh_last = &(h)->entry.tqe_next
; (al)->tqh_first = (h); (h)->entry.tqe_prev = &(al
)->tqh_first; } while (0)
;
1670 return (1);
1671 }
1672
1673 return (host_dns(s, al, max, port, ifname, ipproto));
1674}
1675
1676struct server *
1677server_inherit(struct server *src, struct server_config *alias,
1678 struct server_config *addr)
1679{
1680 struct server *dst, *s, *dstl;
1681
1682 if ((dst = calloc(1, sizeof(*dst))) == NULL((void*)0))
1683 fatal("out of memory");
1684
1685 /* Copy the source server and assign a new Id */
1686 memcpy(&dst->srv_conf, &src->srv_conf, sizeof(dst->srv_conf));
1687 if ((dst->srv_conf.tls_cert_file =
1688 strdup(src->srv_conf.tls_cert_file)) == NULL((void*)0))
1689 fatal("out of memory");
1690 if ((dst->srv_conf.tls_key_file =
1691 strdup(src->srv_conf.tls_key_file)) == NULL((void*)0))
1692 fatal("out of memory");
1693 if (src->srv_conf.tls_ocsp_staple_file != NULL((void*)0)) {
1694 if ((dst->srv_conf.tls_ocsp_staple_file =
1695 strdup(src->srv_conf.tls_ocsp_staple_file)) == NULL((void*)0))
1696 fatal("out of memory");
1697 }
1698
1699 if (src->srv_conf.return_uri != NULL((void*)0) &&
1700 (dst->srv_conf.return_uri =
1701 strdup(src->srv_conf.return_uri)) == NULL((void*)0))
1702 fatal("out of memory");
1703
1704 dst->srv_conf.id = ++last_server_id;
1705 dst->srv_conf.parent_id = dst->srv_conf.id;
1706 dst->srv_s = -1;
1707
1708 if (last_server_id == INT_MAX2147483647) {
1709 yyerror("too many servers defined");
1710 serverconfig_free(&dst->srv_conf);
1711 free(dst);
1712 return (NULL((void*)0));
1713 }
1714
1715 /* Now set alias and listen address */
1716 strlcpy(dst->srv_conf.name, alias->name, sizeof(dst->srv_conf.name));
1717 memcpy(&dst->srv_conf.ss, &addr->ss, sizeof(dst->srv_conf.ss));
1718 dst->srv_conf.port = addr->port;
1719 dst->srv_conf.prefixlen = addr->prefixlen;
1720 if (addr->flags & SRVFLAG_TLS0x00002000)
1721 dst->srv_conf.flags |= SRVFLAG_TLS0x00002000;
1722 else
1723 dst->srv_conf.flags &= ~SRVFLAG_TLS0x00002000;
1724
1725 /* Don't inherit the "match" option, use it from the alias */
1726 dst->srv_conf.flags &= ~SRVFLAG_SERVER_MATCH0x00200000;
1727 dst->srv_conf.flags |= (alias->flags & SRVFLAG_SERVER_MATCH0x00200000);
1728
1729 if (server_tls_load_keypair(dst) == -1)
1730 log_warnx("%s:%d: server \"%s\": failed to "
1731 "load public/private keys", file->name,
1732 yylval.lineno, dst->srv_conf.name);
1733
1734 if (server_tls_load_ca(dst) == -1) {
1735 yyerror("failed to load ca cert(s) for server %s",
1736 dst->srv_conf.name);
1737 serverconfig_free(&dst->srv_conf);
1738 return NULL((void*)0);
1739 }
1740
1741 if (server_tls_load_crl(dst) == -1) {
1742 yyerror("failed to load crl(s) for server %s",
1743 dst->srv_conf.name);
1744 serverconfig_free(&dst->srv_conf);
1745 free(dst);
1746 return NULL((void*)0);
1747 }
1748
1749 if (server_tls_load_ocsp(dst) == -1) {
1750 yyerror("failed to load ocsp staple "
1751 "for server %s", dst->srv_conf.name);
1752 serverconfig_free(&dst->srv_conf);
1753 free(dst);
1754 return (NULL((void*)0));
1755 }
1756
1757 /* Check if the new server already exists */
1758 if (server_match(dst, 1) != NULL((void*)0)) {
1759 yyerror("server \"%s\" defined twice",
1760 dst->srv_conf.name);
1761 serverconfig_free(&dst->srv_conf);
1762 free(dst);
1763 return (NULL((void*)0));
1764 }
1765
1766 /* Copy all the locations of the source server */
1767 TAILQ_FOREACH(s, conf->sc_servers, srv_entry)for((s) = ((conf->sc_servers)->tqh_first); (s) != ((void
*)0); (s) = ((s)->srv_entry.tqe_next))
{
1768 if (!(s->srv_conf.flags & SRVFLAG_LOCATION0x00000020 &&
1769 s->srv_conf.parent_id == src->srv_conf.parent_id))
1770 continue;
1771
1772 if ((dstl = calloc(1, sizeof(*dstl))) == NULL((void*)0))
1773 fatal("out of memory");
1774
1775 memcpy(&dstl->srv_conf, &s->srv_conf, sizeof(dstl->srv_conf));
1776 strlcpy(dstl->srv_conf.name, alias->name,
1777 sizeof(dstl->srv_conf.name));
1778
1779 /* Copy the new Id and listen address */
1780 dstl->srv_conf.id = ++last_server_id;
1781 dstl->srv_conf.parent_id = dst->srv_conf.id;
1782 memcpy(&dstl->srv_conf.ss, &addr->ss,
1783 sizeof(dstl->srv_conf.ss));
1784 dstl->srv_conf.port = addr->port;
1785 dstl->srv_conf.prefixlen = addr->prefixlen;
1786 dstl->srv_s = -1;
1787
1788 DPRINTF("adding location \"%s\" for \"%s[%u]\"",do {} while(0)
1789 dstl->srv_conf.location,do {} while(0)
1790 dstl->srv_conf.name, dstl->srv_conf.id)do {} while(0);
1791
1792 TAILQ_INSERT_TAIL(conf->sc_servers, dstl, srv_entry)do { (dstl)->srv_entry.tqe_next = ((void*)0); (dstl)->srv_entry
.tqe_prev = (conf->sc_servers)->tqh_last; *(conf->sc_servers
)->tqh_last = (dstl); (conf->sc_servers)->tqh_last =
&(dstl)->srv_entry.tqe_next; } while (0)
;
1793 }
1794
1795 return (dst);
1796}
1797
1798int
1799listen_on(const char *addr, int tls, struct portrange *port)
1800{
1801 struct addresslist al;
1802 struct address *h;
1803 struct server_config *s_conf, *alias = NULL((void*)0);
1804
1805 if (parentsrv != NULL((void*)0)) {
1806 yyerror("listen %s inside location", addr);
1807 return (-1);
1808 }
1809
1810 TAILQ_INIT(&al)do { (&al)->tqh_first = ((void*)0); (&al)->tqh_last
= &(&al)->tqh_first; } while (0)
;
1811 if (strcmp("*", addr) == 0) {
1812 if (host("0.0.0.0", &al, 1, port, NULL((void*)0), -1) <= 0) {
1813 yyerror("invalid listen ip: %s",
1814 "0.0.0.0");
1815 return (-1);
1816 }
1817 if (host("::", &al, 1, port, NULL((void*)0), -1) <= 0) {
1818 yyerror("invalid listen ip: %s", "::");
1819 return (-1);
1820 }
1821 } else {
1822 if (host(addr, &al, HTTPD_MAX_ALIAS_IP16, port, NULL((void*)0),
1823 -1) <= 0) {
1824 yyerror("invalid listen ip: %s", addr);
1825 return (-1);
1826 }
1827 }
1828
1829 while ((h = TAILQ_FIRST(&al)((&al)->tqh_first)) != NULL((void*)0)) {
1830 if (srv->srv_conf.ss.ss_family != AF_UNSPEC0) {
1831 if ((alias = calloc(1,
1832 sizeof(*alias))) == NULL((void*)0))
1833 fatal("out of memory");
1834 /* Add as an IP-based alias. */
1835 s_conf = alias;
1836 } else
1837 s_conf = &srv->srv_conf;
1838 memcpy(&s_conf->ss, &h->ss, sizeof(s_conf->ss));
1839 s_conf->prefixlen = h->prefixlen;
1840 /* Set the default port to 80 or 443 */
1841 if (!h->port.op)
1842 s_conf->port = htons(tls ?(__uint16_t)(__builtin_constant_p(tls ? 443 : 80) ? (__uint16_t
)(((__uint16_t)(tls ? 443 : 80) & 0xffU) << 8 | ((__uint16_t
)(tls ? 443 : 80) & 0xff00U) >> 8) : __swap16md(tls
? 443 : 80))
1843 HTTPS_PORT : HTTP_PORT)(__uint16_t)(__builtin_constant_p(tls ? 443 : 80) ? (__uint16_t
)(((__uint16_t)(tls ? 443 : 80) & 0xffU) << 8 | ((__uint16_t
)(tls ? 443 : 80) & 0xff00U) >> 8) : __swap16md(tls
? 443 : 80))
;
1844 else
1845 s_conf->port = h->port.val[0];
1846
1847 if (tls)
1848 s_conf->flags |= SRVFLAG_TLS0x00002000;
1849
1850 if (alias != NULL((void*)0)) {
1851 /*
1852 * IP-based; use name match flags from
1853 * parent
1854 */
1855 alias->flags &= ~SRVFLAG_SERVER_MATCH0x00200000;
1856 alias->flags |= srv->srv_conf.flags &
1857 SRVFLAG_SERVER_MATCH0x00200000;
1858 TAILQ_INSERT_TAIL(&srv->srv_hosts,do { (alias)->entry.tqe_next = ((void*)0); (alias)->entry
.tqe_prev = (&srv->srv_hosts)->tqh_last; *(&srv
->srv_hosts)->tqh_last = (alias); (&srv->srv_hosts
)->tqh_last = &(alias)->entry.tqe_next; } while (0)
1859 alias, entry)do { (alias)->entry.tqe_next = ((void*)0); (alias)->entry
.tqe_prev = (&srv->srv_hosts)->tqh_last; *(&srv
->srv_hosts)->tqh_last = (alias); (&srv->srv_hosts
)->tqh_last = &(alias)->entry.tqe_next; } while (0)
;
1860 }
1861 TAILQ_REMOVE(&al, h, entry)do { if (((h)->entry.tqe_next) != ((void*)0)) (h)->entry
.tqe_next->entry.tqe_prev = (h)->entry.tqe_prev; else (
&al)->tqh_last = (h)->entry.tqe_prev; *(h)->entry
.tqe_prev = (h)->entry.tqe_next; ; ; } while (0)
;
1862 free(h);
1863 }
1864
1865 return (0);
1866}
1867
1868int
1869getservice(char *n)
1870{
1871 struct servent *s;
1872 const char *errstr;
1873 long long llval;
1874
1875 llval = strtonum(n, 0, UINT16_MAX0xffff, &errstr);
1876 if (errstr) {
1877 s = getservbyname(n, "tcp");
1878 if (s == NULL((void*)0))
1879 s = getservbyname(n, "udp");
1880 if (s == NULL((void*)0))
1881 return (-1);
1882 return (s->s_port);
1883 }
1884
1885 return (htons((unsigned short)llval)(__uint16_t)(__builtin_constant_p((unsigned short)llval) ? (__uint16_t
)(((__uint16_t)((unsigned short)llval) & 0xffU) << 8
| ((__uint16_t)((unsigned short)llval) & 0xff00U) >>
8) : __swap16md((unsigned short)llval))
);
1886}
1887
1888int
1889is_if_in_group(const char *ifname, const char *groupname)
1890{
1891 unsigned int len;
1892 struct ifgroupreq ifgr;
1893 struct ifg_req *ifg;
1894 int s;
1895 int ret = 0;
1896
1897 if ((s = socket(AF_INET2, SOCK_DGRAM2, 0)) == -1)
1898 err(1, "socket");
1899
1900 memset(&ifgr, 0, sizeof(ifgr));
1901 if (strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ16) >= IFNAMSIZ16)
1902 err(1, "IFNAMSIZ");
1903 if (ioctl(s, SIOCGIFGROUP(((unsigned long)0x80000000|(unsigned long)0x40000000) | ((sizeof
(struct ifgroupreq) & 0x1fff) << 16) | ((('i')) <<
8) | ((136)))
, (caddr_t)&ifgr) == -1) {
1904 if (errno(*__errno()) == EINVAL22 || errno(*__errno()) == ENOTTY25)
1905 goto end;
1906 err(1, "SIOCGIFGROUP");
1907 }
1908
1909 len = ifgr.ifgr_len;
1910 ifgr.ifgr_groupsifgr_ifgru.ifgru_groups = calloc(len / sizeof(struct ifg_req),
1911 sizeof(struct ifg_req));
1912 if (ifgr.ifgr_groupsifgr_ifgru.ifgru_groups == NULL((void*)0))
1913 err(1, "getifgroups");
1914 if (ioctl(s, SIOCGIFGROUP(((unsigned long)0x80000000|(unsigned long)0x40000000) | ((sizeof
(struct ifgroupreq) & 0x1fff) << 16) | ((('i')) <<
8) | ((136)))
, (caddr_t)&ifgr) == -1)
1915 err(1, "SIOCGIFGROUP");
1916
1917 ifg = ifgr.ifgr_groupsifgr_ifgru.ifgru_groups;
1918 for (; ifg && len >= sizeof(struct ifg_req); ifg++) {
1919 len -= sizeof(struct ifg_req);
1920 if (strcmp(ifg->ifgrq_groupifgrq_ifgrqu.ifgrqu_group, groupname) == 0) {
1921 ret = 1;
1922 break;
1923 }
1924 }
1925 free(ifgr.ifgr_groupsifgr_ifgru.ifgru_groups);
1926
1927end:
1928 close(s);
1929 return (ret);
1930}
1931
1932int
1933get_fastcgi_dest(struct server_config *xsrv_conf, const char *node, char *port)
1934{
1935 struct addrinfo hints, *res;
1936 int s;
1937
1938 memset(&hints, 0, sizeof(hints));
1939 hints.ai_family = AF_UNSPEC0;
1940 hints.ai_socktype = SOCK_STREAM1;
1941
1942 if ((s = getaddrinfo(node, port, &hints, &res)) != 0) {
1943 yyerror("getaddrinfo: %s\n", gai_strerror(s));
1944 return -1;
1945 }
1946
1947 memset(&(xsrv_conf)->fastcgi_ss, 0, sizeof(xsrv_conf->fastcgi_ss));
1948 memcpy(&(xsrv_conf)->fastcgi_ss, res->ai_addr, res->ai_addrlen);
1949
1950 freeaddrinfo(res);
1951
1952 return (0);
1953}
1954
1955void
1956remove_locations(struct server_config *xsrv_conf)
1957{
1958 struct server *s, *next;
1959
1960 TAILQ_FOREACH_SAFE(s, conf->sc_servers, srv_entry, next)for ((s) = ((conf->sc_servers)->tqh_first); (s) != ((void
*)0) && ((next) = ((s)->srv_entry.tqe_next), 1); (
s) = (next))
{
1961 if (!(s->srv_conf.flags & SRVFLAG_LOCATION0x00000020 &&
1962 s->srv_conf.parent_id == xsrv_conf->parent_id))
1963 continue;
1964 TAILQ_REMOVE(conf->sc_servers, s, srv_entry)do { if (((s)->srv_entry.tqe_next) != ((void*)0)) (s)->
srv_entry.tqe_next->srv_entry.tqe_prev = (s)->srv_entry
.tqe_prev; else (conf->sc_servers)->tqh_last = (s)->
srv_entry.tqe_prev; *(s)->srv_entry.tqe_prev = (s)->srv_entry
.tqe_next; ; ; } while (0)
;
1965 serverconfig_free(&s->srv_conf);
1966 free(s);
1967 }
1968}
1969#line 1962 "parse.c"
1970/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1971static int yygrowstack(void)
1972{
1973 unsigned int newsize;
1974 long sslen;
1975 short *newss;
1976 YYSTYPE *newvs;
1977
1978 if ((newsize = yystacksize) == 0)
3
Assuming the condition is false
4
Taking false branch
1979 newsize = YYINITSTACKSIZE200;
1980 else if (newsize >= YYMAXDEPTH10000)
5
Assuming 'newsize' is < YYMAXDEPTH
6
Taking false branch
1981 return -1;
1982 else if ((newsize *= 2) > YYMAXDEPTH10000)
7
Assuming the condition is false
8
Taking false branch
1983 newsize = YYMAXDEPTH10000;
1984 sslen = yyssp - yyss;
1985#ifdef SIZE_MAX0xffffffffffffffffUL
1986#define YY_SIZE_MAX0xffffffffffffffffUL SIZE_MAX0xffffffffffffffffUL
1987#else
1988#define YY_SIZE_MAX0xffffffffffffffffUL 0xffffffffU
1989#endif
1990 if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newss)
9
Assuming 'newsize' is 0
1991 goto bail;
1992 newss = (short *)realloc(yyss, newsize * sizeof *newss);
1993 if (newss == NULL((void*)0))
10
Assuming 'newss' is not equal to NULL
11
Taking false branch
1994 goto bail;
1995 yyss = newss;
1996 yyssp = newss + sslen;
1997 if (newsize
11.1
'newsize' is 0
&& YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newvs)
1998 goto bail;
1999 newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs);
2000 if (newvs == NULL((void*)0))
12
Assuming 'newvs' is not equal to NULL
13
Taking false branch
2001 goto bail;
2002 yyvs = newvs;
2003 yyvsp = newvs + sslen;
2004 yystacksize = newsize;
2005 yysslim = yyss + newsize - 1;
2006 return 0;
2007bail:
2008 if (yyss)
2009 free(yyss);
2010 if (yyvs)
2011 free(yyvs);
2012 yyss = yyssp = NULL((void*)0);
2013 yyvs = yyvsp = NULL((void*)0);
2014 yystacksize = 0;
2015 return -1;
2016}
2017
2018#define YYABORTgoto yyabort goto yyabort
2019#define YYREJECTgoto yyabort goto yyabort
2020#define YYACCEPTgoto yyaccept goto yyaccept
2021#define YYERRORgoto yyerrlab goto yyerrlab
2022int
2023yyparse(void)
2024{
2025 int yym, yyn, yystate;
2026#if YYDEBUG0
2027 const char *yys;
2028
2029 if ((yys = getenv("YYDEBUG")))
2030 {
2031 yyn = *yys;
2032 if (yyn >= '0' && yyn <= '9')
2033 yydebug = yyn - '0';
2034 }
2035#endif /* YYDEBUG */
2036
2037 yynerrs = 0;
2038 yyerrflag = 0;
2039 yychar = (-1);
2040
2041 if (yyss == NULL((void*)0) && yygrowstack()) goto yyoverflow;
1
Assuming 'yyss' is equal to NULL
2
Calling 'yygrowstack'
14
Returning from 'yygrowstack'
15
Taking false branch
2042 yyssp = yyss;
2043 yyvsp = yyvs;
2044 *yyssp = yystate = 0;
16
Use of zero-allocated memory
2045
2046yyloop:
2047 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
2048 if (yychar < 0)
2049 {
2050 if ((yychar = yylex()) < 0) yychar = 0;
2051#if YYDEBUG0
2052 if (yydebug)
2053 {
2054 yys = 0;
2055 if (yychar <= YYMAXTOKEN330) yys = yyname[yychar];
2056 if (!yys) yys = "illegal-symbol";
2057 printf("%sdebug: state %d, reading %d (%s)\n",
2058 YYPREFIX"yy", yystate, yychar, yys);
2059 }
2060#endif
2061 }
2062 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
2063 yyn <= YYTABLESIZE1006 && yycheck[yyn] == yychar)
2064 {
2065#if YYDEBUG0
2066 if (yydebug)
2067 printf("%sdebug: state %d, shifting to state %d\n",
2068 YYPREFIX"yy", yystate, yytable[yyn]);
2069#endif
2070 if (yyssp >= yysslim && yygrowstack())
2071 {
2072 goto yyoverflow;
2073 }
2074 *++yyssp = yystate = yytable[yyn];
2075 *++yyvsp = yylval;
2076 yychar = (-1);
2077 if (yyerrflag > 0) --yyerrflag;
2078 goto yyloop;
2079 }
2080 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
2081 yyn <= YYTABLESIZE1006 && yycheck[yyn] == yychar)
2082 {
2083 yyn = yytable[yyn];
2084 goto yyreduce;
2085 }
2086 if (yyerrflag) goto yyinrecovery;
2087#if defined(__GNUC__4)
2088 goto yynewerror;
2089#endif
2090yynewerror:
2091 yyerror("syntax error");
2092#if defined(__GNUC__4)
2093 goto yyerrlab;
2094#endif
2095yyerrlab:
2096 ++yynerrs;
2097yyinrecovery:
2098 if (yyerrflag < 3)
2099 {
2100 yyerrflag = 3;
2101 for (;;)
2102 {
2103 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 &&
2104 yyn <= YYTABLESIZE1006 && yycheck[yyn] == YYERRCODE256)
2105 {
2106#if YYDEBUG0
2107 if (yydebug)
2108 printf("%sdebug: state %d, error recovery shifting\
2109 to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]);
2110#endif
2111 if (yyssp >= yysslim && yygrowstack())
2112 {
2113 goto yyoverflow;
2114 }
2115 *++yyssp = yystate = yytable[yyn];
2116 *++yyvsp = yylval;
2117 goto yyloop;
2118 }
2119 else
2120 {
2121#if YYDEBUG0
2122 if (yydebug)
2123 printf("%sdebug: error recovery discarding state %d\n",
2124 YYPREFIX"yy", *yyssp);
2125#endif
2126 if (yyssp <= yyss) goto yyabort;
2127 --yyssp;
2128 --yyvsp;
2129 }
2130 }
2131 }
2132 else
2133 {
2134 if (yychar == 0) goto yyabort;
2135#if YYDEBUG0
2136 if (yydebug)
2137 {
2138 yys = 0;
2139 if (yychar <= YYMAXTOKEN330) yys = yyname[yychar];
2140 if (!yys) yys = "illegal-symbol";
2141 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
2142 YYPREFIX"yy", yystate, yychar, yys);
2143 }
2144#endif
2145 yychar = (-1);
2146 goto yyloop;
2147 }
2148yyreduce:
2149#if YYDEBUG0
2150 if (yydebug)
2151 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
2152 YYPREFIX"yy", yystate, yyn, yyrule[yyn]);
2153#endif
2154 yym = yylen[yyn];
2155 if (yym)
2156 yyval = yyvsp[1-yym];
2157 else
2158 memset(&yyval, 0, sizeof yyval);
2159 switch (yyn)
2160 {
2161case 8:
2162#line 163 "/usr/src/usr.sbin/httpd/parse.y"
2163{ file->errors++; }
2164break;
2165case 9:
2166#line 166 "/usr/src/usr.sbin/httpd/parse.y"
2167{
2168 struct file *nfile;
2169
2170 if ((nfile = pushfile(yyvsp[0].v.string, 0)) == NULL((void*)0)) {
2171 yyerror("failed to include file %s", yyvsp[0].v.string);
2172 free(yyvsp[0].v.string);
2173 YYERRORgoto yyerrlab;
2174 }
2175 free(yyvsp[0].v.string);
2176
2177 file = nfile;
2178 lungetc('\n');
2179 }
2180break;
2181case 10:
2182#line 181 "/usr/src/usr.sbin/httpd/parse.y"
2183{
2184 char *s = yyvsp[-2].v.string;
2185 while (*s++) {
2186 if (isspace((unsigned char)*s)) {
2187 yyerror("macro name cannot contain "
2188 "whitespace");
2189 free(yyvsp[-2].v.string);
2190 free(yyvsp[0].v.string);
2191 YYERRORgoto yyerrlab;
2192 }
2193 }
2194 if (symset(yyvsp[-2].v.string, yyvsp[0].v.string, 0) == -1)
2195 fatal("cannot store variable");
2196 free(yyvsp[-2].v.string);
2197 free(yyvsp[0].v.string);
2198 }
2199break;
2200case 11:
2201#line 199 "/usr/src/usr.sbin/httpd/parse.y"
2202{ yyval.v.number = 0; }
2203break;
2204case 12:
2205#line 200 "/usr/src/usr.sbin/httpd/parse.y"
2206{ yyval.v.number = 1; }
2207break;
2208case 13:
2209#line 203 "/usr/src/usr.sbin/httpd/parse.y"
2210{
2211 if (loadcfg)
2212 break;
2213 if (yyvsp[0].v.number <= 0 || yyvsp[0].v.number > PROC_MAX_INSTANCES32) {
2214 yyerror("invalid number of preforked "
2215 "servers: %lld", yyvsp[0].v.number);
2216 YYERRORgoto yyerrlab;
2217 }
2218 conf->sc_prefork_server = yyvsp[0].v.number;
2219 }
2220break;
2221case 14:
2222#line 213 "/usr/src/usr.sbin/httpd/parse.y"
2223{
2224 conf->sc_chroot = yyvsp[0].v.string;
2225 }
2226break;
2227case 15:
2228#line 216 "/usr/src/usr.sbin/httpd/parse.y"
2229{
2230 if (yyvsp[0].v.string != NULL((void*)0) && strlcpy(conf->sc_errdocroot, yyvsp[0].v.string,
2231 sizeof(conf->sc_errdocroot)) >=
2232 sizeof(conf->sc_errdocroot)) {
2233 yyerror("errdoc root path too long");
2234 free(yyvsp[0].v.string);
2235 YYERRORgoto yyerrlab;
2236 }
2237 free(yyvsp[0].v.string);
2238 conf->sc_custom_errdocs = 1;
2239 }
2240break;
2241case 16:
2242#line 227 "/usr/src/usr.sbin/httpd/parse.y"
2243{
2244 conf->sc_logdir = yyvsp[0].v.string;
2245 }
2246break;
2247case 17:
2248#line 230 "/usr/src/usr.sbin/httpd/parse.y"
2249{
2250 memcpy(&conf->sc_default_type, &media,
2251 sizeof(struct media_type));
2252 }
2253break;
2254case 18:
2255#line 236 "/usr/src/usr.sbin/httpd/parse.y"
2256{
2257 struct server *s;
2258 struct sockaddr_un *sun;
2259
2260 if (!loadcfg) {
2261 free(yyvsp[0].v.string);
2262 YYACCEPTgoto yyaccept;
2263 }
2264
2265 if ((s = calloc(1, sizeof (*s))) == NULL((void*)0))
2266 fatal("out of memory");
2267
2268 if (strlcpy(s->srv_conf.name, yyvsp[0].v.string,
2269 sizeof(s->srv_conf.name)) >=
2270 sizeof(s->srv_conf.name)) {
2271 yyerror("server name truncated");
2272 free(yyvsp[0].v.string);
2273 free(s);
2274 YYERRORgoto yyerrlab;
2275 }
2276 free(yyvsp[0].v.string);
2277
2278 strlcpy(s->srv_conf.root, HTTPD_DOCROOT"/htdocs",
2279 sizeof(s->srv_conf.root));
2280 strlcpy(s->srv_conf.index, HTTPD_INDEX"index.html",
2281 sizeof(s->srv_conf.index));
2282 strlcpy(s->srv_conf.accesslog, HTTPD_ACCESS_LOG"access.log",
2283 sizeof(s->srv_conf.accesslog));
2284 strlcpy(s->srv_conf.errorlog, HTTPD_ERROR_LOG"error.log",
2285 sizeof(s->srv_conf.errorlog));
2286 s->srv_conf.id = ++last_server_id;
2287 s->srv_conf.parent_id = s->srv_conf.id;
2288 s->srv_s = -1;
2289 s->srv_conf.timeout.tv_sec = SERVER_TIMEOUT600;
2290 s->srv_conf.requesttimeout.tv_sec =
2291 SERVER_REQUESTTIMEOUT60;
2292 s->srv_conf.maxrequests = SERVER_MAXREQUESTS100;
2293 s->srv_conf.maxrequestbody = SERVER_MAXREQUESTBODY1048576;
2294 s->srv_conf.flags = SRVFLAG_LOG0x00000100;
2295 if (yyvsp[-1].v.number)
2296 s->srv_conf.flags |= SRVFLAG_SERVER_MATCH0x00200000;
2297 s->srv_conf.logformat = LOG_FORMAT_COMMON;
2298 s->srv_conf.tls_protocols = TLS_PROTOCOLS_DEFAULT((1 << 3)|(1 << 4));
2299 if ((s->srv_conf.tls_cert_file =
2300 strdup(HTTPD_TLS_CERT"/etc/ssl/server.crt")) == NULL((void*)0))
2301 fatal("out of memory");
2302 if ((s->srv_conf.tls_key_file =
2303 strdup(HTTPD_TLS_KEY"/etc/ssl/private/server.key")) == NULL((void*)0))
2304 fatal("out of memory");
2305 strlcpy(s->srv_conf.tls_ciphers,
2306 HTTPD_TLS_CIPHERS"compat",
2307 sizeof(s->srv_conf.tls_ciphers));
2308 strlcpy(s->srv_conf.tls_dhe_params,
2309 HTTPD_TLS_DHE_PARAMS"none",
2310 sizeof(s->srv_conf.tls_dhe_params));
2311 strlcpy(s->srv_conf.tls_ecdhe_curves,
2312 HTTPD_TLS_ECDHE_CURVES"default",
2313 sizeof(s->srv_conf.tls_ecdhe_curves));
2314
2315 sun = (struct sockaddr_un *)&s->srv_conf.fastcgi_ss;
2316 sun->sun_family = AF_UNIX1;
2317 (void)strlcpy(sun->sun_path, HTTPD_FCGI_SOCKET"/run/slowcgi.sock",
2318 sizeof(sun->sun_path));
2319 sun->sun_len = sizeof(struct sockaddr_un);
2320
2321 s->srv_conf.hsts_max_age = SERVER_HSTS_DEFAULT_AGE31536000;
2322
2323 (void)strlcpy(s->srv_conf.errdocroot,
2324 conf->sc_errdocroot,
2325 sizeof(s->srv_conf.errdocroot));
2326 if (conf->sc_custom_errdocs)
2327 s->srv_conf.flags |= SRVFLAG_ERRDOCS0x00000400;
2328
2329 if (last_server_id == INT_MAX2147483647) {
2330 yyerror("too many servers defined");
2331 free(s);
2332 YYERRORgoto yyerrlab;
2333 }
2334 srv = s;
2335 srv_conf = &srv->srv_conf;
2336
2337 SPLAY_INIT(&srv->srv_clients)do { (&srv->srv_clients)->sph_root = ((void*)0); } while
(0)
;
2338 TAILQ_INIT(&srv->srv_hosts)do { (&srv->srv_hosts)->tqh_first = ((void*)0); (&
srv->srv_hosts)->tqh_last = &(&srv->srv_hosts
)->tqh_first; } while (0)
;
2339 TAILQ_INIT(&srv_conf->fcgiparams)do { (&srv_conf->fcgiparams)->tqh_first = ((void*)0
); (&srv_conf->fcgiparams)->tqh_last = &(&srv_conf
->fcgiparams)->tqh_first; } while (0)
;
2340
2341 TAILQ_INSERT_TAIL(&srv->srv_hosts, srv_conf, entry)do { (srv_conf)->entry.tqe_next = ((void*)0); (srv_conf)->
entry.tqe_prev = (&srv->srv_hosts)->tqh_last; *(&
srv->srv_hosts)->tqh_last = (srv_conf); (&srv->srv_hosts
)->tqh_last = &(srv_conf)->entry.tqe_next; } while (
0)
;
2342 }
2343break;
2344case 19:
2345#line 322 "/usr/src/usr.sbin/httpd/parse.y"
2346{
2347 struct server *s, *sn;
2348 struct server_config *a, *b;
2349
2350 srv_conf = &srv->srv_conf;
2351
2352 /* Check if the new server already exists. */
2353 if (server_match(srv, 1) != NULL((void*)0)) {
2354 yyerror("server \"%s\" defined twice",
2355 srv->srv_conf.name);
2356 serverconfig_free(srv_conf);
2357 free(srv);
2358 YYABORTgoto yyabort;
2359 }
2360
2361 if (srv->srv_conf.ss.ss_family == AF_UNSPEC0) {
2362 yyerror("listen address not specified");
2363 serverconfig_free(srv_conf);
2364 free(srv);
2365 YYERRORgoto yyerrlab;
2366 }
2367
2368 if ((s = server_match(srv, 0)) != NULL((void*)0)) {
2369 if ((s->srv_conf.flags & SRVFLAG_TLS0x00002000) !=
2370 (srv->srv_conf.flags & SRVFLAG_TLS0x00002000)) {
2371 yyerror("server \"%s\": tls and "
2372 "non-tls on same address/port",
2373 srv->srv_conf.name);
2374 serverconfig_free(srv_conf);
2375 free(srv);
2376 YYERRORgoto yyerrlab;
2377 }
2378 if (srv->srv_conf.flags & SRVFLAG_TLS0x00002000 &&
2379 server_tls_cmp(s, srv) != 0) {
2380 yyerror("server \"%s\": tls "
2381 "configuration mismatch on same "
2382 "address/port",
2383 srv->srv_conf.name);
2384 serverconfig_free(srv_conf);
2385 free(srv);
2386 YYERRORgoto yyerrlab;
2387 }
2388 }
2389
2390 if ((srv->srv_conf.flags & SRVFLAG_TLS0x00002000) &&
2391 srv->srv_conf.tls_protocols == 0) {
2392 yyerror("server \"%s\": no tls protocols",
2393 srv->srv_conf.name);
2394 serverconfig_free(srv_conf);
2395 free(srv);
2396 YYERRORgoto yyerrlab;
2397 }
2398
2399 if (server_tls_load_keypair(srv) == -1) {
2400 /* Soft fail as there may be no certificate. */
2401 log_warnx("%s:%d: server \"%s\": failed to "
2402 "load public/private keys", file->name,
2403 yylval.lineno, srv->srv_conf.name);
2404
2405 remove_locations(srv_conf);
2406 serverconfig_free(srv_conf);
2407 srv_conf = NULL((void*)0);
2408 free(srv);
2409 srv = NULL((void*)0);
2410 break;
2411 }
2412
2413 if (server_tls_load_ca(srv) == -1) {
2414 yyerror("server \"%s\": failed to load "
2415 "ca cert(s)", srv->srv_conf.name);
2416 serverconfig_free(srv_conf);
2417 free(srv);
2418 YYERRORgoto yyerrlab;
2419 }
2420
2421 if (server_tls_load_crl(srv) == -1) {
2422 yyerror("server \"%s\": failed to load crl(s)",
2423 srv->srv_conf.name);
2424 serverconfig_free(srv_conf);
2425 free(srv);
2426 YYERRORgoto yyerrlab;
2427 }
2428
2429 if (server_tls_load_ocsp(srv) == -1) {
2430 yyerror("server \"%s\": failed to load "
2431 "ocsp staple", srv->srv_conf.name);
2432 serverconfig_free(srv_conf);
2433 free(srv);
2434 YYERRORgoto yyerrlab;
2435 }
2436
2437 DPRINTF("adding server \"%s[%u]\"",do {} while(0)
2438 srv->srv_conf.name, srv->srv_conf.id)do {} while(0);
2439
2440 TAILQ_INSERT_TAIL(conf->sc_servers, srv, srv_entry)do { (srv)->srv_entry.tqe_next = ((void*)0); (srv)->srv_entry
.tqe_prev = (conf->sc_servers)->tqh_last; *(conf->sc_servers
)->tqh_last = (srv); (conf->sc_servers)->tqh_last = &
(srv)->srv_entry.tqe_next; } while (0)
;
2441
2442 /*
2443 * Add aliases and additional listen addresses as
2444 * individual servers.
2445 */
2446 TAILQ_FOREACH(a, &srv->srv_hosts, entry)for((a) = ((&srv->srv_hosts)->tqh_first); (a) != ((
void*)0); (a) = ((a)->entry.tqe_next))
{
2447 /* listen address */
2448 if (a->ss.ss_family == AF_UNSPEC0)
2449 continue;
2450 TAILQ_FOREACH(b, &srv->srv_hosts, entry)for((b) = ((&srv->srv_hosts)->tqh_first); (b) != ((
void*)0); (b) = ((b)->entry.tqe_next))
{
2451 /* alias name */
2452 if (*b->name == '\0' ||
2453 (b == &srv->srv_conf && b == a))
2454 continue;
2455
2456 if ((sn = server_inherit(srv,
2457 b, a)) == NULL((void*)0)) {
2458 serverconfig_free(srv_conf);
2459 free(srv);
2460 YYABORTgoto yyabort;
2461 }
2462
2463 DPRINTF("adding server \"%s[%u]\"",do {} while(0)
2464 sn->srv_conf.name, sn->srv_conf.id)do {} while(0);
2465
2466 TAILQ_INSERT_TAIL(conf->sc_servers,do { (sn)->srv_entry.tqe_next = ((void*)0); (sn)->srv_entry
.tqe_prev = (conf->sc_servers)->tqh_last; *(conf->sc_servers
)->tqh_last = (sn); (conf->sc_servers)->tqh_last = &
(sn)->srv_entry.tqe_next; } while (0)
2467 sn, srv_entry)do { (sn)->srv_entry.tqe_next = ((void*)0); (sn)->srv_entry
.tqe_prev = (conf->sc_servers)->tqh_last; *(conf->sc_servers
)->tqh_last = (sn); (conf->sc_servers)->tqh_last = &
(sn)->srv_entry.tqe_next; } while (0)
;
2468 }
2469 }
2470
2471 /* Remove temporary aliases */
2472 TAILQ_FOREACH_SAFE(a, &srv->srv_hosts, entry, b)for ((a) = ((&srv->srv_hosts)->tqh_first); (a) != (
(void*)0) && ((b) = ((a)->entry.tqe_next), 1); (a)
= (b))
{
2473 TAILQ_REMOVE(&srv->srv_hosts, a, entry)do { if (((a)->entry.tqe_next) != ((void*)0)) (a)->entry
.tqe_next->entry.tqe_prev = (a)->entry.tqe_prev; else (
&srv->srv_hosts)->tqh_last = (a)->entry.tqe_prev
; *(a)->entry.tqe_prev = (a)->entry.tqe_next; ; ; } while
(0)
;
2474 if (a == &srv->srv_conf)
2475 continue;
2476 serverconfig_free(a);
2477 free(a);
2478 }
2479
2480 srv = NULL((void*)0);
2481 srv_conf = NULL((void*)0);
2482 }
2483break;
2484case 22:
2485#line 465 "/usr/src/usr.sbin/httpd/parse.y"
2486{
2487 if (listen_on(yyvsp[-2].v.string, yyvsp[-1].v.number, &yyvsp[0].v.port) == -1) {
2488 free(yyvsp[-2].v.string);
2489 YYERRORgoto yyerrlab;
2490 }
2491 free(yyvsp[-2].v.string);
2492 }
2493break;
2494case 23:
2495#line 472 "/usr/src/usr.sbin/httpd/parse.y"
2496{
2497 struct server_config *alias;
2498
2499 if (parentsrv != NULL((void*)0)) {
2500 yyerror("alias inside location");
2501 free(yyvsp[0].v.string);
2502 YYERRORgoto yyerrlab;
2503 }
2504
2505 if ((alias = calloc(1, sizeof(*alias))) == NULL((void*)0))
2506 fatal("out of memory");
2507
2508 if (strlcpy(alias->name, yyvsp[0].v.string, sizeof(alias->name)) >=
2509 sizeof(alias->name)) {
2510 yyerror("server alias truncated");
2511 free(yyvsp[0].v.string);
2512 free(alias);
2513 YYERRORgoto yyerrlab;
2514 }
2515 free(yyvsp[0].v.string);
2516
2517 if (yyvsp[-1].v.number)
2518 alias->flags |= SRVFLAG_SERVER_MATCH0x00200000;
2519
2520 TAILQ_INSERT_TAIL(&srv->srv_hosts, alias, entry)do { (alias)->entry.tqe_next = ((void*)0); (alias)->entry
.tqe_prev = (&srv->srv_hosts)->tqh_last; *(&srv
->srv_hosts)->tqh_last = (alias); (&srv->srv_hosts
)->tqh_last = &(alias)->entry.tqe_next; } while (0)
;
2521 }
2522break;
2523case 24:
2524#line 498 "/usr/src/usr.sbin/httpd/parse.y"
2525{
2526 if (parentsrv != NULL((void*)0)) {
2527 yyerror("errdocs inside location");
2528 YYERRORgoto yyerrlab;
2529 }
2530 if (yyvsp[0].v.string != NULL((void*)0) && strlcpy(srv->srv_conf.errdocroot, yyvsp[0].v.string,
2531 sizeof(srv->srv_conf.errdocroot)) >=
2532 sizeof(srv->srv_conf.errdocroot)) {
2533 yyerror("errdoc root path too long");
2534 free(yyvsp[0].v.string);
2535 YYERRORgoto yyerrlab;
2536 }
2537 free(yyvsp[0].v.string);
2538 srv->srv_conf.flags |= SRVFLAG_ERRDOCS0x00000400;
2539 }
2540break;
2541case 25:
2542#line 513 "/usr/src/usr.sbin/httpd/parse.y"
2543{
2544 if (parentsrv != NULL((void*)0)) {
2545 yyerror("errdocs inside location");
2546 YYERRORgoto yyerrlab;
2547 }
2548 srv->srv_conf.flags &= ~SRVFLAG_ERRDOCS0x00000400;
2549 }
2550break;
2551case 26:
2552#line 520 "/usr/src/usr.sbin/httpd/parse.y"
2553{
2554 if (parentsrv != NULL((void*)0)) {
2555 yyerror("tcp flags inside location");
2556 YYERRORgoto yyerrlab;
2557 }
2558 }
2559break;
2560case 27:
2561#line 526 "/usr/src/usr.sbin/httpd/parse.y"
2562{
2563 if (parentsrv != NULL((void*)0)) {
2564 yyerror("connection options inside location");
2565 YYERRORgoto yyerrlab;
2566 }
2567 }
2568break;
2569case 28:
2570#line 532 "/usr/src/usr.sbin/httpd/parse.y"
2571{
2572 struct server_config *sc;
2573 int tls_flag = 0;
2574
2575 if (parentsrv != NULL((void*)0)) {
2576 yyerror("tls configuration inside location");
2577 YYERRORgoto yyerrlab;
2578 }
2579
2580 /* Ensure that at least one server has TLS enabled. */
2581 TAILQ_FOREACH(sc, &srv->srv_hosts, entry)for((sc) = ((&srv->srv_hosts)->tqh_first); (sc) != (
(void*)0); (sc) = ((sc)->entry.tqe_next))
{
2582 tls_flag |= (sc->flags & SRVFLAG_TLS0x00002000);
2583 }
2584 if (tls_flag == 0) {
2585 yyerror("tls options without tls listener");
2586 YYERRORgoto yyerrlab;
2587 }
2588 }
2589break;
2590case 36:
2591#line 557 "/usr/src/usr.sbin/httpd/parse.y"
2592{
2593 struct server *s;
2594 struct sockaddr_un *sun;
2595
2596 if (srv->srv_conf.ss.ss_family == AF_UNSPEC0) {
2597 yyerror("listen address not specified");
2598 free(yyvsp[0].v.string);
2599 YYERRORgoto yyerrlab;
2600 }
2601
2602 if (parentsrv != NULL((void*)0)) {
2603 yyerror("location %s inside location", yyvsp[0].v.string);
2604 free(yyvsp[0].v.string);
2605 YYERRORgoto yyerrlab;
2606 }
2607
2608 if (!loadcfg) {
2609 free(yyvsp[0].v.string);
2610 YYACCEPTgoto yyaccept;
2611 }
2612
2613 if ((s = calloc(1, sizeof (*s))) == NULL((void*)0))
2614 fatal("out of memory");
2615
2616 if (strlcpy(s->srv_conf.location, yyvsp[0].v.string,
2617 sizeof(s->srv_conf.location)) >=
2618 sizeof(s->srv_conf.location)) {
2619 yyerror("server location truncated");
2620 free(yyvsp[0].v.string);
2621 free(s);
2622 YYERRORgoto yyerrlab;
2623 }
2624 free(yyvsp[0].v.string);
2625
2626 if (strlcpy(s->srv_conf.name, srv->srv_conf.name,
2627 sizeof(s->srv_conf.name)) >=
2628 sizeof(s->srv_conf.name)) {
2629 yyerror("server name truncated");
2630 free(s);
2631 YYERRORgoto yyerrlab;
2632 }
2633
2634 sun = (struct sockaddr_un *)&s->srv_conf.fastcgi_ss;
2635 sun->sun_family = AF_UNIX1;
2636 (void)strlcpy(sun->sun_path, HTTPD_FCGI_SOCKET"/run/slowcgi.sock",
2637 sizeof(sun->sun_path));
2638 sun->sun_len = sizeof(struct sockaddr_un);
2639
2640 s->srv_conf.id = ++last_server_id;
2641 /* A location entry uses the parent id */
2642 s->srv_conf.parent_id = srv->srv_conf.id;
2643 s->srv_conf.flags = SRVFLAG_LOCATION0x00000020;
2644 if (yyvsp[-2].v.number == 1) {
2645 s->srv_conf.flags &=
2646 ~SRVFLAG_LOCATION_NOT_FOUND0x80000000;
2647 s->srv_conf.flags |=
2648 SRVFLAG_LOCATION_FOUND0x40000000;
2649 } else if (yyvsp[-2].v.number == -1) {
2650 s->srv_conf.flags &=
2651 ~SRVFLAG_LOCATION_FOUND0x40000000;
2652 s->srv_conf.flags |=
2653 SRVFLAG_LOCATION_NOT_FOUND0x80000000;
2654 }
2655 if (yyvsp[-1].v.number)
2656 s->srv_conf.flags |= SRVFLAG_LOCATION_MATCH0x00100000;
2657 s->srv_s = -1;
2658 memcpy(&s->srv_conf.ss, &srv->srv_conf.ss,
2659 sizeof(s->srv_conf.ss));
2660 s->srv_conf.port = srv->srv_conf.port;
2661 s->srv_conf.prefixlen = srv->srv_conf.prefixlen;
2662 s->srv_conf.tls_flags = srv->srv_conf.tls_flags;
2663
2664 if (last_server_id == INT_MAX2147483647) {
2665 yyerror("too many servers/locations defined");
2666 free(s);
2667 YYERRORgoto yyerrlab;
2668 }
2669 parentsrv = srv;
2670 srv = s;
2671 srv_conf = &srv->srv_conf;
2672 SPLAY_INIT(&srv->srv_clients)do { (&srv->srv_clients)->sph_root = ((void*)0); } while
(0)
;
2673 }
2674break;
2675case 37:
2676#line 638 "/usr/src/usr.sbin/httpd/parse.y"
2677{
2678 struct server *s = NULL((void*)0);
2679 uint32_t f;
2680
2681 f = SRVFLAG_LOCATION_FOUND0x40000000 |
2682 SRVFLAG_LOCATION_NOT_FOUND0x80000000;
2683
2684 TAILQ_FOREACH(s, conf->sc_servers, srv_entry)for((s) = ((conf->sc_servers)->tqh_first); (s) != ((void
*)0); (s) = ((s)->srv_entry.tqe_next))
{
2685 /* Compare locations of same parent server */
2686 if ((s->srv_conf.flags & SRVFLAG_LOCATION0x00000020) &&
2687 s->srv_conf.parent_id ==
2688 srv_conf->parent_id &&
2689 (s->srv_conf.flags & f) ==
2690 (srv_conf->flags & f) &&
2691 strcmp(s->srv_conf.location,
2692 srv_conf->location) == 0)
2693 break;
2694 }
2695 if (s != NULL((void*)0)) {
2696 yyerror("location \"%s\" defined twice",
2697 srv->srv_conf.location);
2698 serverconfig_free(srv_conf);
2699 free(srv);
2700 YYABORTgoto yyabort;
2701 }
2702
2703 DPRINTF("adding location \"%s\" for \"%s[%u]\"",do {} while(0)
2704 srv->srv_conf.location,do {} while(0)
2705 srv->srv_conf.name, srv->srv_conf.id)do {} while(0);
2706
2707 TAILQ_INSERT_TAIL(conf->sc_servers, srv, srv_entry)do { (srv)->srv_entry.tqe_next = ((void*)0); (srv)->srv_entry
.tqe_prev = (conf->sc_servers)->tqh_last; *(conf->sc_servers
)->tqh_last = (srv); (conf->sc_servers)->tqh_last = &
(srv)->srv_entry.tqe_next; } while (0)
;
2708
2709 srv = parentsrv;
2710 srv_conf = &parentsrv->srv_conf;
2711 parentsrv = NULL((void*)0);
2712 }
2713break;
2714case 38:
2715#line 674 "/usr/src/usr.sbin/httpd/parse.y"
2716{
2717 srv_conf->flags |= SRVFLAG_DEFAULT_TYPE0x00800000;
2718 memcpy(&srv_conf->default_type, &media,
2719 sizeof(struct media_type));
2720 }
2721break;
2722case 40:
2723#line 680 "/usr/src/usr.sbin/httpd/parse.y"
2724{
2725 if (parentsrv != NULL((void*)0)) {
2726 yyerror("hsts inside location");
2727 YYERRORgoto yyerrlab;
2728 }
2729 srv->srv_conf.flags |= SRVFLAG_SERVER_HSTS0x00400000;
2730 }
2731break;
2732case 41:
2733#line 689 "/usr/src/usr.sbin/httpd/parse.y"
2734{ yyval.v.number = 0; }
2735break;
2736case 42:
2737#line 690 "/usr/src/usr.sbin/httpd/parse.y"
2738{ yyval.v.number = 1; }
2739break;
2740case 43:
2741#line 691 "/usr/src/usr.sbin/httpd/parse.y"
2742{ yyval.v.number = -1; }
2743break;
2744case 49:
2745#line 703 "/usr/src/usr.sbin/httpd/parse.y"
2746{
2747 if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > INT_MAX2147483647) {
2748 yyerror("invalid number of seconds: %lld", yyvsp[0].v.number);
2749 YYERRORgoto yyerrlab;
2750 }
2751 srv_conf->hsts_max_age = yyvsp[0].v.number;
2752 }
2753break;
2754case 50:
2755#line 710 "/usr/src/usr.sbin/httpd/parse.y"
2756{
2757 srv->srv_conf.hsts_flags |= HSTSFLAG_SUBDOMAINS0x01;
2758 }
2759break;
2760case 51:
2761#line 713 "/usr/src/usr.sbin/httpd/parse.y"
2762{
2763 srv->srv_conf.hsts_flags |= HSTSFLAG_PRELOAD0x02;
2764 }
2765break;
2766case 52:
2767#line 718 "/usr/src/usr.sbin/httpd/parse.y"
2768{
2769 srv_conf->flags &= ~SRVFLAG_FCGI0x00000040;
2770 srv_conf->flags |= SRVFLAG_NO_FCGI0x00000080;
2771 }
2772break;
2773case 53:
2774#line 722 "/usr/src/usr.sbin/httpd/parse.y"
2775{
2776 srv_conf->flags &= ~SRVFLAG_NO_FCGI0x00000080;
2777 srv_conf->flags |= SRVFLAG_FCGI0x00000040;
2778 }
2779break;
2780case 54:
2781#line 726 "/usr/src/usr.sbin/httpd/parse.y"
2782{
2783 srv_conf->flags &= ~SRVFLAG_NO_FCGI0x00000080;
2784 srv_conf->flags |= SRVFLAG_FCGI0x00000040;
2785 }
2786break;
2787case 56:
2788#line 730 "/usr/src/usr.sbin/httpd/parse.y"
2789{
2790 srv_conf->flags &= ~SRVFLAG_NO_FCGI0x00000080;
2791 srv_conf->flags |= SRVFLAG_FCGI0x00000040;
2792 }
2793break;
2794case 60:
2795#line 740 "/usr/src/usr.sbin/httpd/parse.y"
2796{
2797 struct sockaddr_un *sun;
2798 sun = (struct sockaddr_un *)&srv_conf->fastcgi_ss;
2799 memset(sun, 0, sizeof(*sun));
2800 sun->sun_family = AF_UNIX1;
2801 if (strlcpy(sun->sun_path, yyvsp[0].v.string, sizeof(sun->sun_path))
2802 >= sizeof(sun->sun_path)) {
2803 yyerror("socket path too long");
2804 free(yyvsp[0].v.string);
2805 YYERRORgoto yyerrlab;
2806 }
2807 srv_conf->fastcgi_ss.ss_len =
2808 sizeof(struct sockaddr_un);
2809 free(yyvsp[0].v.string);
2810 }
2811break;
2812case 61:
2813#line 755 "/usr/src/usr.sbin/httpd/parse.y"
2814{
2815 if (get_fastcgi_dest(srv_conf, yyvsp[0].v.string, FCGI_DEFAULT_PORT"9000")
2816 == -1) {
2817 free(yyvsp[0].v.string);
2818 YYERRORgoto yyerrlab;
2819 }
2820 free(yyvsp[0].v.string);
2821 }
2822break;
2823case 62:
2824#line 763 "/usr/src/usr.sbin/httpd/parse.y"
2825{
2826 if (get_fastcgi_dest(srv_conf, yyvsp[-1].v.string, yyvsp[0].v.string) == -1) {
2827 free(yyvsp[-1].v.string);
2828 free(yyvsp[0].v.string);
2829 YYERRORgoto yyerrlab;
2830 }
2831 free(yyvsp[-1].v.string);
2832 free(yyvsp[0].v.string);
2833 }
2834break;
2835case 63:
2836#line 772 "/usr/src/usr.sbin/httpd/parse.y"
2837{
2838 struct fastcgi_param *param;
2839
2840 if ((param = calloc(1, sizeof(*param))) == NULL((void*)0))
2841 fatal("out of memory");
2842
2843 if (strlcpy(param->name, yyvsp[-1].v.string, sizeof(param->name)) >=
2844 sizeof(param->name)) {
2845 yyerror("fastcgi_param name truncated");
2846 free(yyvsp[-1].v.string);
2847 free(yyvsp[0].v.string);
2848 free(param);
2849 YYERRORgoto yyerrlab;
2850 }
2851 if (strlcpy(param->value, yyvsp[0].v.string, sizeof(param->value)) >=
2852 sizeof(param->value)) {
2853 yyerror("fastcgi_param value truncated");
2854 free(yyvsp[-1].v.string);
2855 free(yyvsp[0].v.string);
2856 free(param);
2857 YYERRORgoto yyerrlab;
2858 }
2859 free(yyvsp[-1].v.string);
2860 free(yyvsp[0].v.string);
2861
2862 DPRINTF("[%s,%s,%d]: adding param \"%s\" value \"%s\"",do {} while(0)
2863 srv_conf->location, srv_conf->name, srv_conf->id,do {} while(0)
2864 param->name, param->value)do {} while(0);
2865 TAILQ_INSERT_HEAD(&srv_conf->fcgiparams, param, entry)do { if (((param)->entry.tqe_next = (&srv_conf->fcgiparams
)->tqh_first) != ((void*)0)) (&srv_conf->fcgiparams
)->tqh_first->entry.tqe_prev = &(param)->entry.tqe_next
; else (&srv_conf->fcgiparams)->tqh_last = &(param
)->entry.tqe_next; (&srv_conf->fcgiparams)->tqh_first
= (param); (param)->entry.tqe_prev = &(&srv_conf->
fcgiparams)->tqh_first; } while (0)
;
2866 }
2867break;
2868case 64:
2869#line 802 "/usr/src/usr.sbin/httpd/parse.y"
2870{
2871 if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > INT_MAX2147483647) {
2872 yyerror("invalid fastcgi strip number");
2873 YYERRORgoto yyerrlab;
2874 }
2875 srv_conf->fcgistrip = yyvsp[0].v.number;
2876 }
2877break;
2878case 69:
2879#line 819 "/usr/src/usr.sbin/httpd/parse.y"
2880{
2881 memcpy(&srv_conf->timeout, &yyvsp[0].v.tv,
2882 sizeof(struct timeval));
2883 }
2884break;
2885case 70:
2886#line 823 "/usr/src/usr.sbin/httpd/parse.y"
2887{
2888 memcpy(&srv_conf->requesttimeout, &yyvsp[0].v.tv,
2889 sizeof(struct timeval));
2890 }
2891break;
2892case 71:
2893#line 827 "/usr/src/usr.sbin/httpd/parse.y"
2894{
2895 srv_conf->maxrequests = yyvsp[0].v.number;
2896 }
2897break;
2898case 72:
2899#line 830 "/usr/src/usr.sbin/httpd/parse.y"
2900{
2901 srv_conf->maxrequestbody = yyvsp[0].v.number;
2902 }
2903break;
2904case 77:
2905#line 843 "/usr/src/usr.sbin/httpd/parse.y"
2906{
2907 free(srv_conf->tls_cert_file);
2908 if ((srv_conf->tls_cert_file = strdup(yyvsp[0].v.string)) == NULL((void*)0))
2909 fatal("out of memory");
2910 free(yyvsp[0].v.string);
2911 }
2912break;
2913case 78:
2914#line 849 "/usr/src/usr.sbin/httpd/parse.y"
2915{
2916 free(srv_conf->tls_key_file);
2917 if ((srv_conf->tls_key_file = strdup(yyvsp[0].v.string)) == NULL((void*)0))
2918 fatal("out of memory");
2919 free(yyvsp[0].v.string);
2920 }
2921break;
2922case 79:
2923#line 855 "/usr/src/usr.sbin/httpd/parse.y"
2924{
2925 free(srv_conf->tls_ocsp_staple_file);
2926 if ((srv_conf->tls_ocsp_staple_file = strdup(yyvsp[0].v.string))
2927 == NULL((void*)0))
2928 fatal("out of memory");
2929 free(yyvsp[0].v.string);
2930 }
2931break;
2932case 80:
2933#line 862 "/usr/src/usr.sbin/httpd/parse.y"
2934{
2935 if (strlcpy(srv_conf->tls_ciphers, yyvsp[0].v.string,
2936 sizeof(srv_conf->tls_ciphers)) >=
2937 sizeof(srv_conf->tls_ciphers)) {
2938 yyerror("ciphers too long");
2939 free(yyvsp[0].v.string);
2940 YYERRORgoto yyerrlab;
2941 }
2942 free(yyvsp[0].v.string);
2943 }
2944break;
2945case 81:
2946#line 872 "/usr/src/usr.sbin/httpd/parse.y"
2947{
2948 srv_conf->tls_flags |= TLSFLAG_CA0x01;
2949 free(srv_conf->tls_ca_file);
2950 if ((srv_conf->tls_ca_file = strdup(yyvsp[-1].v.string)) == NULL((void*)0))
2951 fatal("out of memory");
2952 free(yyvsp[-1].v.string);
2953 }
2954break;
2955case 82:
2956#line 879 "/usr/src/usr.sbin/httpd/parse.y"
2957{
2958 if (strlcpy(srv_conf->tls_dhe_params, yyvsp[0].v.string,
2959 sizeof(srv_conf->tls_dhe_params)) >=
2960 sizeof(srv_conf->tls_dhe_params)) {
2961 yyerror("dhe too long");
2962 free(yyvsp[0].v.string);
2963 YYERRORgoto yyerrlab;
2964 }
2965 free(yyvsp[0].v.string);
2966 }
2967break;
2968case 83:
2969#line 889 "/usr/src/usr.sbin/httpd/parse.y"
2970{
2971 if (strlcpy(srv_conf->tls_ecdhe_curves, yyvsp[0].v.string,
2972 sizeof(srv_conf->tls_ecdhe_curves)) >=
2973 sizeof(srv_conf->tls_ecdhe_curves)) {
2974 yyerror("ecdhe too long");
2975 free(yyvsp[0].v.string);
2976 YYERRORgoto yyerrlab;
2977 }
2978 free(yyvsp[0].v.string);
2979 }
2980break;
2981case 84:
2982#line 899 "/usr/src/usr.sbin/httpd/parse.y"
2983{
2984 if (tls_config_parse_protocols(
2985 &srv_conf->tls_protocols, yyvsp[0].v.string) != 0) {
2986 yyerror("invalid tls protocols");
2987 free(yyvsp[0].v.string);
2988 YYERRORgoto yyerrlab;
2989 }
2990 free(yyvsp[0].v.string);
2991 }
2992break;
2993case 85:
2994#line 908 "/usr/src/usr.sbin/httpd/parse.y"
2995{
2996 srv_conf->tls_ticket_lifetime = SERVER_DEF_TLS_LIFETIME(2 * 3600);
2997 }
2998break;
2999case 86:
3000#line 911 "/usr/src/usr.sbin/httpd/parse.y"
3001{
3002 if (yyvsp[0].v.number != 0 && yyvsp[0].v.number < SERVER_MIN_TLS_LIFETIME(60)) {
3003 yyerror("ticket lifetime too small");
3004 YYERRORgoto yyerrlab;
3005 }
3006 if (yyvsp[0].v.number > SERVER_MAX_TLS_LIFETIME(24 * 3600)) {
3007 yyerror("ticket lifetime too large");
3008 YYERRORgoto yyerrlab;
3009 }
3010 srv_conf->tls_ticket_lifetime = yyvsp[0].v.number;
3011 }
3012break;
3013case 87:
3014#line 922 "/usr/src/usr.sbin/httpd/parse.y"
3015{
3016 srv_conf->tls_ticket_lifetime = 0;
3017 }
3018break;
3019case 89:
3020#line 928 "/usr/src/usr.sbin/httpd/parse.y"
3021{
3022 srv_conf->tls_flags = TLSFLAG_CRL0x02;
3023 free(srv_conf->tls_crl_file);
3024 if ((srv_conf->tls_crl_file = strdup(yyvsp[0].v.string)) == NULL((void*)0))
3025 fatal("out of memory");
3026 free(yyvsp[0].v.string);
3027 }
3028break;
3029case 90:
3030#line 935 "/usr/src/usr.sbin/httpd/parse.y"
3031{
3032 srv_conf->tls_flags |= TLSFLAG_OPTIONAL0x04;
3033 }
3034break;
3035case 95:
3036#line 947 "/usr/src/usr.sbin/httpd/parse.y"
3037{
3038 if (strlcpy(srv->srv_conf.root, yyvsp[0].v.string,
3039 sizeof(srv->srv_conf.root)) >=
3040 sizeof(srv->srv_conf.root)) {
3041 yyerror("document root too long");
3042 free(yyvsp[0].v.string);
3043 YYERRORgoto yyerrlab;
3044 }
3045 free(yyvsp[0].v.string);
3046 srv->srv_conf.flags |= SRVFLAG_ROOT0x00000010;
3047 }
3048break;
3049case 100:
3050#line 968 "/usr/src/usr.sbin/httpd/parse.y"
3051{
3052 if (strlcpy(srv->srv_conf.path, yyvsp[0].v.string,
3053 sizeof(srv->srv_conf.path)) >=
3054 sizeof(srv->srv_conf.path)) {
3055 yyerror("request path too long");
3056 free(yyvsp[0].v.string);
3057 YYERRORgoto yyerrlab;
3058 }
3059 free(yyvsp[0].v.string);
3060 srv->srv_conf.flags |= SRVFLAG_PATH_REWRITE0x01000000;
3061 srv->srv_conf.flags &= ~SRVFLAG_NO_PATH_REWRITE0x02000000;
3062 }
3063break;
3064case 101:
3065#line 980 "/usr/src/usr.sbin/httpd/parse.y"
3066{
3067 srv->srv_conf.flags |= SRVFLAG_NO_PATH_REWRITE0x02000000;
3068 srv->srv_conf.flags &= ~SRVFLAG_PATH_REWRITE0x01000000;
3069 }
3070break;
3071case 102:
3072#line 984 "/usr/src/usr.sbin/httpd/parse.y"
3073{
3074 if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > INT_MAX2147483647) {
3075 yyerror("invalid strip number");
3076 YYERRORgoto yyerrlab;
3077 }
3078 srv->srv_conf.strip = yyvsp[0].v.number;
3079 }
3080break;
3081case 103:
3082#line 993 "/usr/src/usr.sbin/httpd/parse.y"
3083{
3084 srv->srv_conf.flags |= SRVFLAG_NO_AUTH0x00020000;
3085 }
3086break;
3087case 104:
3088#line 996 "/usr/src/usr.sbin/httpd/parse.y"
3089{
3090 struct auth *auth;
3091
3092 if ((auth = auth_add(conf->sc_auth, &yyvsp[0].v.auth)) == NULL((void*)0)) {
3093 yyerror("failed to add auth");
3094 YYERRORgoto yyerrlab;
3095 }
3096
3097 if (auth->auth_id == 0) {
3098 /* New htpasswd, get new Id */
3099 auth->auth_id = ++last_auth_id;
3100 if (last_auth_id == INT_MAX2147483647) {
3101 yyerror("too many auth ids defined");
3102 auth_free(conf->sc_auth, auth);
3103 YYERRORgoto yyerrlab;
3104 }
3105 }
3106
3107 srv->srv_conf.auth_id = auth->auth_id;
3108 srv->srv_conf.flags |= SRVFLAG_AUTH0x00010000;
3109 }
3110break;
3111case 105:
3112#line 1019 "/usr/src/usr.sbin/httpd/parse.y"
3113{
3114 if (strlcpy(srv->srv_conf.auth_realm, yyvsp[-2].v.string,
3115 sizeof(srv->srv_conf.auth_realm)) >=
3116 sizeof(srv->srv_conf.auth_realm)) {
3117 yyerror("basic auth realm name too long");
3118 free(yyvsp[-2].v.string);
3119 YYERRORgoto yyerrlab;
3120 }
3121 free(yyvsp[-2].v.string);
3122 if (strlcpy(yyval.v.auth.auth_htpasswd, yyvsp[0].v.string,
3123 sizeof(yyval.v.auth.auth_htpasswd)) >=
3124 sizeof(yyval.v.auth.auth_htpasswd)) {
3125 yyerror("password file name too long");
3126 free(yyvsp[0].v.string);
3127 YYERRORgoto yyerrlab;
3128 }
3129 free(yyvsp[0].v.string);
3130
3131 }
3132break;
3133case 106:
3134#line 1038 "/usr/src/usr.sbin/httpd/parse.y"
3135{
3136 if (strlcpy(yyval.v.auth.auth_htpasswd, yyvsp[0].v.string,
3137 sizeof(yyval.v.auth.auth_htpasswd)) >=
3138 sizeof(yyval.v.auth.auth_htpasswd)) {
3139 yyerror("password file name too long");
3140 free(yyvsp[0].v.string);
3141 YYERRORgoto yyerrlab;
3142 }
3143 free(yyvsp[0].v.string);
3144 }
3145break;
3146case 111:
3147#line 1057 "/usr/src/usr.sbin/httpd/parse.y"
3148{
3149 if (strlcpy(srv_conf->index, yyvsp[0].v.string,
3150 sizeof(srv_conf->index)) >=
3151 sizeof(srv_conf->index)) {
3152 yyerror("index file too long");
3153 free(yyvsp[0].v.string);
3154 YYERRORgoto yyerrlab;
3155 }
3156 srv_conf->flags &= ~SRVFLAG_NO_INDEX0x00000002;
3157 srv_conf->flags |= SRVFLAG_INDEX0x00000001;
3158 free(yyvsp[0].v.string);
3159 }
3160break;
3161case 112:
3162#line 1069 "/usr/src/usr.sbin/httpd/parse.y"
3163{
3164 srv_conf->flags &= ~SRVFLAG_INDEX0x00000001;
3165 srv_conf->flags |= SRVFLAG_NO_INDEX0x00000002;
3166 }
3167break;
3168case 113:
3169#line 1073 "/usr/src/usr.sbin/httpd/parse.y"
3170{
3171 srv_conf->flags &= ~SRVFLAG_NO_AUTO_INDEX0x00000008;
3172 srv_conf->flags |= SRVFLAG_AUTO_INDEX0x00000004;
3173 }
3174break;
3175case 114:
3176#line 1077 "/usr/src/usr.sbin/httpd/parse.y"
3177{
3178 srv_conf->flags &= ~SRVFLAG_AUTO_INDEX0x00000004;
3179 srv_conf->flags |= SRVFLAG_NO_AUTO_INDEX0x00000008;
3180 }
3181break;
3182case 117:
3183#line 1086 "/usr/src/usr.sbin/httpd/parse.y"
3184{
3185 srv_conf->flags &= ~SRVFLAG_LOG0x00000100;
3186 srv_conf->flags |= SRVFLAG_NO_LOG0x00000200;
3187 }
3188break;
3189case 121:
3190#line 1097 "/usr/src/usr.sbin/httpd/parse.y"
3191{
3192 srv_conf->flags &= ~SRVFLAG_NO_SYSLOG0x00001000;
3193 srv_conf->flags |= SRVFLAG_SYSLOG0x00000800;
3194 }
3195break;
3196case 122:
3197#line 1101 "/usr/src/usr.sbin/httpd/parse.y"
3198{
3199 srv_conf->flags &= ~SRVFLAG_SYSLOG0x00000800;
3200 srv_conf->flags |= SRVFLAG_NO_SYSLOG0x00001000;
3201 }
3202break;
3203case 123:
3204#line 1105 "/usr/src/usr.sbin/httpd/parse.y"
3205{
3206 if (strlcpy(srv_conf->accesslog, yyvsp[0].v.string,
3207 sizeof(srv_conf->accesslog)) >=
3208 sizeof(srv_conf->accesslog)) {
3209 yyerror("access log name too long");
3210 free(yyvsp[0].v.string);
3211 YYERRORgoto yyerrlab;
3212 }
3213 free(yyvsp[0].v.string);
3214 srv_conf->flags |= SRVFLAG_ACCESS_LOG0x00004000;
3215 }
3216break;
3217case 124:
3218#line 1116 "/usr/src/usr.sbin/httpd/parse.y"
3219{
3220 if (strlcpy(srv_conf->errorlog, yyvsp[0].v.string,
3221 sizeof(srv_conf->errorlog)) >=
3222 sizeof(srv_conf->errorlog)) {
3223 yyerror("error log name too long");
3224 free(yyvsp[0].v.string);
3225 YYERRORgoto yyerrlab;
3226 }
3227 free(yyvsp[0].v.string);
3228 srv_conf->flags |= SRVFLAG_ERROR_LOG0x00008000;
3229 }
3230break;
3231case 125:
3232#line 1129 "/usr/src/usr.sbin/httpd/parse.y"
3233{
3234 srv_conf->flags &= ~SRVFLAG_NO_LOG0x00000200;
3235 srv_conf->flags |= SRVFLAG_LOG0x00000100;
3236 srv_conf->logformat = LOG_FORMAT_COMMON;
3237 }
3238break;
3239case 126:
3240#line 1134 "/usr/src/usr.sbin/httpd/parse.y"
3241{
3242 srv_conf->flags &= ~SRVFLAG_NO_LOG0x00000200;
3243 srv_conf->flags |= SRVFLAG_LOG0x00000100;
3244 srv_conf->logformat = LOG_FORMAT_COMBINED;
3245 }
3246break;
3247case 127:
3248#line 1139 "/usr/src/usr.sbin/httpd/parse.y"
3249{
3250 srv_conf->flags &= ~SRVFLAG_NO_LOG0x00000200;
3251 srv_conf->flags |= SRVFLAG_LOG0x00000100;
3252 srv_conf->logformat = LOG_FORMAT_CONNECTION;
3253 }
3254break;
3255case 128:
3256#line 1144 "/usr/src/usr.sbin/httpd/parse.y"
3257{
3258 srv_conf->flags &= ~SRVFLAG_NO_LOG0x00000200;
3259 srv_conf->flags |= SRVFLAG_LOG0x00000100;
3260 srv_conf->logformat = LOG_FORMAT_FORWARDED;
3261 }
3262break;
3263case 129:
3264#line 1151 "/usr/src/usr.sbin/httpd/parse.y"
3265{
3266 if (yyvsp[-1].v.number <= 0 || server_httperror_byid(yyvsp[-1].v.number) == NULL((void*)0)) {
3267 yyerror("invalid return code: %lld", yyvsp[-1].v.number);
3268 free(yyvsp[0].v.string);
3269 YYERRORgoto yyerrlab;
3270 }
3271 srv_conf->return_code = yyvsp[-1].v.number;
3272
3273 if (yyvsp[0].v.string != NULL((void*)0)) {
3274 /* Only for 3xx redirection headers */
3275 if (yyvsp[-1].v.number < 300 || yyvsp[-1].v.number > 399) {
3276 yyerror("invalid return code for "
3277 "location URI");
3278 free(yyvsp[0].v.string);
3279 YYERRORgoto yyerrlab;
3280 }
3281 srv_conf->return_uri = yyvsp[0].v.string;
3282 srv_conf->return_uri_len = strlen(yyvsp[0].v.string) + 1;
3283 }
3284 }
3285break;
3286case 130:
3287#line 1171 "/usr/src/usr.sbin/httpd/parse.y"
3288{
3289 /* No return code, silently drop the connection */
3290 srv_conf->return_code = 0;
3291 }
3292break;
3293case 131:
3294#line 1175 "/usr/src/usr.sbin/httpd/parse.y"
3295{
3296 /* Forbidden */
3297 srv_conf->return_code = 403;
3298 }
3299break;
3300case 132:
3301#line 1179 "/usr/src/usr.sbin/httpd/parse.y"
3302{
3303 srv_conf->flags &= ~SRVFLAG_BLOCK0x00040000;
3304 srv_conf->flags |= SRVFLAG_NO_BLOCK0x00080000;
3305 }
3306break;
3307case 133:
3308#line 1185 "/usr/src/usr.sbin/httpd/parse.y"
3309{
3310 srv_conf->flags &= ~SRVFLAG_NO_BLOCK0x00080000;
3311 srv_conf->flags |= SRVFLAG_BLOCK0x00040000;
3312 }
3313break;
3314case 134:
3315#line 1191 "/usr/src/usr.sbin/httpd/parse.y"
3316{ yyval.v.number = 0; }
3317break;
3318case 135:
3319#line 1192 "/usr/src/usr.sbin/httpd/parse.y"
3320{ yyval.v.number = 1; }
3321break;
3322case 136:
3323#line 1195 "/usr/src/usr.sbin/httpd/parse.y"
3324{ yyval.v.string = NULL((void*)0); }
3325break;
3326case 137:
3327#line 1196 "/usr/src/usr.sbin/httpd/parse.y"
3328{ yyval.v.string = yyvsp[0].v.string; }
3329break;
3330case 138:
3331#line 1199 "/usr/src/usr.sbin/httpd/parse.y"
3332{
3333 if (yyvsp[0].v.number <= 0 || yyvsp[0].v.number > (int)USHRT_MAX(32767 *2 +1)) {
3334 yyerror("invalid port: %lld", yyvsp[0].v.number);
3335 YYERRORgoto yyerrlab;
3336 }
3337 if (asprintf(&yyval.v.string, "%lld", yyvsp[0].v.number) == -1) {
3338 yyerror("out of memory");
3339 YYERRORgoto yyerrlab;
3340 }
3341 }
3342break;
3343case 139:
3344#line 1209 "/usr/src/usr.sbin/httpd/parse.y"
3345{
3346 if (getservice(yyvsp[0].v.string) <= 0) {
3347 yyerror("invalid port: %s", yyvsp[0].v.string);
3348 free(yyvsp[0].v.string);
3349 YYERRORgoto yyerrlab;
3350 }
3351
3352 yyval.v.string = yyvsp[0].v.string;
3353 }
3354break;
3355case 144:
3356#line 1228 "/usr/src/usr.sbin/httpd/parse.y"
3357{ srv_conf->tcpflags |= TCPFLAG_SACK0x04; }
3358break;
3359case 145:
3360#line 1229 "/usr/src/usr.sbin/httpd/parse.y"
3361{ srv_conf->tcpflags |= TCPFLAG_NSACK0x08; }
3362break;
3363case 146:
3364#line 1230 "/usr/src/usr.sbin/httpd/parse.y"
3365{
3366 srv_conf->tcpflags |= TCPFLAG_NODELAY0x01;
3367 }
3368break;
3369case 147:
3370#line 1233 "/usr/src/usr.sbin/httpd/parse.y"
3371{
3372 srv_conf->tcpflags |= TCPFLAG_NNODELAY0x02;
3373 }
3374break;
3375case 148:
3376#line 1236 "/usr/src/usr.sbin/httpd/parse.y"
3377{
3378 if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > SERVER_MAX_CLIENTS1024) {
3379 yyerror("invalid backlog: %lld", yyvsp[0].v.number);
3380 YYERRORgoto yyerrlab;
3381 }
3382 srv_conf->tcpbacklog = yyvsp[0].v.number;
3383 }
3384break;
3385case 149:
3386#line 1243 "/usr/src/usr.sbin/httpd/parse.y"
3387{
3388 srv_conf->tcpflags |= TCPFLAG_BUFSIZ0x10;
3389 if ((srv_conf->tcpbufsiz = yyvsp[0].v.number) < 0) {
3390 yyerror("invalid socket buffer size: %lld", yyvsp[0].v.number);
3391 YYERRORgoto yyerrlab;
3392 }
3393 }
3394break;
3395case 150:
3396#line 1250 "/usr/src/usr.sbin/httpd/parse.y"
3397{
3398 if (yyvsp[0].v.number < 0) {
3399 yyerror("invalid ttl: %lld", yyvsp[0].v.number);
3400 free(yyvsp[-1].v.string);
3401 YYERRORgoto yyerrlab;
3402 }
3403 if (strcasecmp("ttl", yyvsp[-1].v.string) == 0) {
3404 srv_conf->tcpflags |= TCPFLAG_IPTTL0x20;
3405 srv_conf->tcpipttl = yyvsp[0].v.number;
3406 } else if (strcasecmp("minttl", yyvsp[-1].v.string) == 0) {
3407 srv_conf->tcpflags |= TCPFLAG_IPMINTTL0x40;
3408 srv_conf->tcpipminttl = yyvsp[0].v.number;
3409 } else {
3410 yyerror("invalid TCP/IP flag: %s", yyvsp[-1].v.string);
3411 free(yyvsp[-1].v.string);
3412 YYERRORgoto yyerrlab;
3413 }
3414 free(yyvsp[-1].v.string);
3415 }
3416break;
3417case 156:
3418#line 1282 "/usr/src/usr.sbin/httpd/parse.y"
3419{
3420 if (strlcpy(media.media_type, yyvsp[-2].v.string,
3421 sizeof(media.media_type)) >=
3422 sizeof(media.media_type) ||
3423 strlcpy(media.media_subtype, yyvsp[0].v.string,
3424 sizeof(media.media_subtype)) >=
3425 sizeof(media.media_subtype)) {
3426 yyerror("media type too long");
3427 free(yyvsp[-2].v.string);
3428 free(yyvsp[0].v.string);
3429 YYERRORgoto yyerrlab;
3430 }
3431 free(yyvsp[-2].v.string);
3432 free(yyvsp[0].v.string);
3433 }
3434break;
3435case 159:
3436#line 1303 "/usr/src/usr.sbin/httpd/parse.y"
3437{
3438 if (strlcpy(media.media_name, yyvsp[0].v.string,
3439 sizeof(media.media_name)) >=
3440 sizeof(media.media_name)) {
3441 yyerror("media name too long");
3442 free(yyvsp[0].v.string);
3443 YYERRORgoto yyerrlab;
3444 }
3445 free(yyvsp[0].v.string);
3446
3447 if (!loadcfg)
3448 break;
3449
3450 if (media_add(conf->sc_mediatypes, &media) == NULL((void*)0)) {
3451 yyerror("failed to add media type");
3452 YYERRORgoto yyerrlab;
3453 }
3454 }
3455break;
3456case 160:
3457#line 1323 "/usr/src/usr.sbin/httpd/parse.y"
3458{
3459 if (yyvsp[0].v.number <= 0 || yyvsp[0].v.number > (int)USHRT_MAX(32767 *2 +1)) {
3460 yyerror("invalid port: %lld", yyvsp[0].v.number);
3461 YYERRORgoto yyerrlab;
3462 }
3463 yyval.v.port.val[0] = htons(yyvsp[0].v.number)(__uint16_t)(__builtin_constant_p(yyvsp[0].v.number) ? (__uint16_t
)(((__uint16_t)(yyvsp[0].v.number) & 0xffU) << 8 | (
(__uint16_t)(yyvsp[0].v.number) & 0xff00U) >> 8) : __swap16md
(yyvsp[0].v.number))
;
3464 yyval.v.port.op = 1;
3465 }
3466break;
3467case 161:
3468#line 1331 "/usr/src/usr.sbin/httpd/parse.y"
3469{
3470 int val;
3471
3472 if ((val = getservice(yyvsp[0].v.string)) == -1) {
3473 yyerror("invalid port: %s", yyvsp[0].v.string);
3474 free(yyvsp[0].v.string);
3475 YYERRORgoto yyerrlab;
3476 }
3477 free(yyvsp[0].v.string);
3478
3479 yyval.v.port.val[0] = val;
3480 yyval.v.port.op = 1;
3481 }
3482break;
3483case 162:
3484#line 1347 "/usr/src/usr.sbin/httpd/parse.y"
3485{
3486 if (yyvsp[0].v.number < 0) {
3487 yyerror("invalid timeout: %lld", yyvsp[0].v.number);
3488 YYERRORgoto yyerrlab;
3489 }
3490 yyval.v.tv.tv_sec = yyvsp[0].v.number;
3491 yyval.v.tv.tv_usec = 0;
3492 }
3493break;
3494case 163:
3495#line 1357 "/usr/src/usr.sbin/httpd/parse.y"
3496{
3497 char *s;
3498 if (asprintf(&s, "%lld", yyvsp[0].v.number) == -1) {
3499 yyerror("asprintf: number");
3500 YYERRORgoto yyerrlab;
3501 }
3502 yyval.v.string = s;
3503 }
3504break;
3505#line 3498 "parse.c"
3506 }
3507 yyssp -= yym;
3508 yystate = *yyssp;
3509 yyvsp -= yym;
3510 yym = yylhs[yyn];
3511 if (yystate == 0 && yym == 0)
3512 {
3513#if YYDEBUG0
3514 if (yydebug)
3515 printf("%sdebug: after reduction, shifting from state 0 to\
3516 state %d\n", YYPREFIX"yy", YYFINAL1);
3517#endif
3518 yystate = YYFINAL1;
3519 *++yyssp = YYFINAL1;
3520 *++yyvsp = yyval;
3521 if (yychar < 0)
3522 {
3523 if ((yychar = yylex()) < 0) yychar = 0;
3524#if YYDEBUG0
3525 if (yydebug)
3526 {
3527 yys = 0;
3528 if (yychar <= YYMAXTOKEN330) yys = yyname[yychar];
3529 if (!yys) yys = "illegal-symbol";
3530 printf("%sdebug: state %d, reading %d (%s)\n",
3531 YYPREFIX"yy", YYFINAL1, yychar, yys);
3532 }
3533#endif
3534 }
3535 if (yychar == 0) goto yyaccept;
3536 goto yyloop;
3537 }
3538 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
3539 yyn <= YYTABLESIZE1006 && yycheck[yyn] == yystate)
3540 yystate = yytable[yyn];
3541 else
3542 yystate = yydgoto[yym];
3543#if YYDEBUG0
3544 if (yydebug)
3545 printf("%sdebug: after reduction, shifting from state %d \
3546to state %d\n", YYPREFIX"yy", *yyssp, yystate);
3547#endif
3548 if (yyssp >= yysslim && yygrowstack())
3549 {
3550 goto yyoverflow;
3551 }
3552 *++yyssp = yystate;
3553 *++yyvsp = yyval;
3554 goto yyloop;
3555yyoverflow:
3556 yyerror("yacc stack overflow");
3557yyabort:
3558 if (yyss)
3559 free(yyss);
3560 if (yyvs)
3561 free(yyvs);
3562 yyss = yyssp = NULL((void*)0);
3563 yyvs = yyvsp = NULL((void*)0);
3564 yystacksize = 0;
3565 return (1);
3566yyaccept:
3567 if (yyss)
3568 free(yyss);
3569 if (yyvs)
3570 free(yyvs);
3571 yyss = yyssp = NULL((void*)0);
3572 yyvs = yyvsp = NULL((void*)0);
3573 yystacksize = 0;
3574 return (0);
3575}