GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/httpd/parse.c Lines: 184 633 29.1 %
Date: 2017-11-07 Branches: 109 424 25.7 %

Line Branch Exec Source
1
#include <stdlib.h>
2
#include <string.h>
3
#define YYBYACC 1
4
#define YYMAJOR 1
5
#define YYMINOR 9
6
#define YYLEX yylex()
7
#define YYEMPTY -1
8
#define yyclearin (yychar=(YYEMPTY))
9
#define yyerrok (yyerrflag=0)
10
#define YYRECOVERING() (yyerrflag!=0)
11
#define YYPREFIX "yy"
12
#line 28 "parse.y"
13
#include <sys/types.h>
14
#include <sys/socket.h>
15
#include <sys/stat.h>
16
#include <sys/queue.h>
17
#include <sys/tree.h>
18
#include <sys/ioctl.h>
19
#include <sys/sockio.h>
20
#include <sys/time.h>
21
22
#include <net/if.h>
23
#include <netinet/in.h>
24
#include <arpa/inet.h>
25
26
#include <ctype.h>
27
#include <unistd.h>
28
#include <err.h>
29
#include <errno.h>
30
#include <limits.h>
31
#include <stdint.h>
32
#include <stdarg.h>
33
#include <stdio.h>
34
#include <netdb.h>
35
#include <string.h>
36
#include <ifaddrs.h>
37
#include <syslog.h>
38
39
#include "httpd.h"
40
#include "http.h"
41
42
TAILQ_HEAD(files, file)		 files = TAILQ_HEAD_INITIALIZER(files);
43
static struct file {
44
	TAILQ_ENTRY(file)	 entry;
45
	FILE			*stream;
46
	char			*name;
47
	int			 lineno;
48
	int			 errors;
49
} *file, *topfile;
50
struct file	*pushfile(const char *, int);
51
int		 popfile(void);
52
int		 check_file_secrecy(int, const char *);
53
int		 yyparse(void);
54
int		 yylex(void);
55
int		 yyerror(const char *, ...)
56
    __attribute__((__format__ (printf, 1, 2)))
57
    __attribute__((__nonnull__ (1)));
58
int		 kw_cmp(const void *, const void *);
59
int		 lookup(char *);
60
int		 lgetc(int);
61
int		 lungetc(int);
62
int		 findeol(void);
63
64
TAILQ_HEAD(symhead, sym)	 symhead = TAILQ_HEAD_INITIALIZER(symhead);
65
struct sym {
66
	TAILQ_ENTRY(sym)	 entry;
67
	int			 used;
68
	int			 persist;
69
	char			*nam;
70
	char			*val;
71
};
72
int		 symset(const char *, const char *, int);
73
char		*symget(const char *);
74
75
struct httpd		*conf = NULL;
76
static int		 errors = 0;
77
static int		 loadcfg = 0;
78
uint32_t		 last_server_id = 0;
79
uint32_t		 last_auth_id = 0;
80
81
static struct server	*srv = NULL, *parentsrv = NULL;
82
static struct server_config *srv_conf = NULL;
83
struct serverlist	 servers;
84
struct media_type	 media;
85
86
struct address	*host_v4(const char *);
87
struct address	*host_v6(const char *);
88
int		 host_dns(const char *, struct addresslist *,
89
		    int, struct portrange *, const char *, int);
90
int		 host_if(const char *, struct addresslist *,
91
		    int, struct portrange *, const char *, int);
92
int		 host(const char *, struct addresslist *,
93
		    int, struct portrange *, const char *, int);
94
void		 host_free(struct addresslist *);
95
struct server	*server_inherit(struct server *, struct server_config *,
96
		    struct server_config *);
97
int		 getservice(char *);
98
int		 is_if_in_group(const char *, const char *);
99
100
typedef struct {
101
	union {
102
		int64_t			 number;
103
		char			*string;
104
		struct timeval		 tv;
105
		struct portrange	 port;
106
		struct auth		 auth;
107
		struct {
108
			struct sockaddr_storage	 ss;
109
			char			 name[HOST_NAME_MAX+1];
110
		}			 addr;
111
	} v;
112
	int lineno;
113
} YYSTYPE;
114
115
#line 116 "parse.c"
116
#define ACCESS 257
117
#define ALIAS 258
118
#define AUTO 259
119
#define BACKLOG 260
120
#define BODY 261
121
#define BUFFER 262
122
#define CERTIFICATE 263
123
#define CHROOT 264
124
#define CIPHERS 265
125
#define COMMON 266
126
#define COMBINED 267
127
#define CONNECTION 268
128
#define DHE 269
129
#define DIRECTORY 270
130
#define ECDHE 271
131
#define ERR 272
132
#define FCGI 273
133
#define INDEX 274
134
#define IP 275
135
#define KEY 276
136
#define LIFETIME 277
137
#define LISTEN 278
138
#define LOCATION 279
139
#define LOG 280
140
#define LOGDIR 281
141
#define MATCH 282
142
#define MAXIMUM 283
143
#define NO 284
144
#define NODELAY 285
145
#define OCSP 286
146
#define ON 287
147
#define PORT 288
148
#define PREFORK 289
149
#define PROTOCOLS 290
150
#define REQUESTS 291
151
#define ROOT 292
152
#define SACK 293
153
#define SERVER 294
154
#define SOCKET 295
155
#define STRIP 296
156
#define STYLE 297
157
#define SYSLOG 298
158
#define TCP 299
159
#define TICKET 300
160
#define TIMEOUT 301
161
#define TLS 302
162
#define TYPE 303
163
#define TYPES 304
164
#define HSTS 305
165
#define MAXAGE 306
166
#define SUBDOMAINS 307
167
#define DEFAULT 308
168
#define PRELOAD 309
169
#define REQUEST 310
170
#define ERROR 311
171
#define INCLUDE 312
172
#define AUTHENTICATE 313
173
#define WITH 314
174
#define BLOCK 315
175
#define DROP 316
176
#define RETURN 317
177
#define PASS 318
178
#define STRING 319
179
#define NUMBER 320
180
#define YYERRCODE 256
181
const short yylhs[] =
182
	{                                        -1,
183
    0,    0,    0,    0,    0,    0,    0,    0,    8,    9,
184
    2,    2,   10,   10,   10,   10,   14,   11,   16,   16,
185
   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
186
   17,   28,   17,   17,   17,   17,   29,   29,   29,   30,
187
   30,   31,   31,   31,   25,   25,   33,   25,   36,   25,
188
   34,   34,   35,   20,   20,   37,   37,   38,   38,   38,
189
48
   38,   21,   21,   39,   39,   40,   40,   40,   40,   40,
190
72
   40,   40,   40,   40,   40,   22,   22,   42,   42,   41,
191
24
   41,   26,   26,    7,    7,   23,   23,   44,   44,   43,
192
   43,   43,   43,   24,   24,   24,   46,   46,   45,   45,
193
   45,   45,   45,   47,   47,   47,   27,   27,   27,   27,
194
144
   48,    3,    3,    6,    6,   19,   19,   49,   49,   50,
195
   50,   50,   50,   50,   50,   50,   12,   51,   51,   52,
196

144
   52,   13,   53,   53,   55,    1,    1,    4,    5,    5,
197
   54,   54,   15,   15,   32,   32,   18,
198
};
199
const short yylen[] =
200
	{                                         2,
201
72
    0,    3,    2,    3,    3,    3,    3,    3,    2,    3,
202
    0,    1,    2,    2,    2,    3,    0,    8,    3,    2,
203
72
    5,    3,    1,    1,    1,    1,    1,    1,    1,    1,
204
144
    1,    0,    8,    3,    1,    1,    5,    2,    1,    3,
205
    2,    2,    1,    1,    2,    1,    0,    6,    0,    3,
206
144
    3,    2,    2,    5,    2,    3,    2,    2,    3,    3,
207
144
    4,    5,    2,    3,    2,    2,    2,    2,    2,    2,
208
    2,    2,    3,    3,    2,    2,    5,    3,    2,    1,
209
144
    2,    2,    2,    3,    2,    2,    5,    3,    2,    2,
210
    2,    2,    3,    2,    5,    2,    3,    2,    2,    1,
211
    2,    2,    2,    1,    1,    1,    4,    2,    1,    1,
212
    1,    0,    1,    0,    1,    5,    2,    3,    2,    1,
213
    2,    1,    2,    2,    3,    3,    5,    3,    2,    3,
214
    1,    3,    2,    1,    1,    2,    2,    1,    1,    1,
215
    1,    0,    2,    0,    2,    1,    2,
216
};
217
const short yydefred[] =
218
144
	{                                      1,
219
72
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
220
72
    3,    0,    0,    0,    0,    0,    8,   14,   15,   13,
221
  113,    0,    0,    0,    9,    0,    2,    4,    5,    6,
222
    7,   17,    0,    0,    0,   16,   10,    0,  143,  131,
223
72
    0,    0,    0,    0,    0,  140,  139,  135,    0,  134,
224
  127,    0,    0,  129,  132,    0,  141,  130,  133,  128,
225
  147,    0,    0,    0,    0,    0,    0,    0,    0,    0,
226
144
    0,    0,    0,    0,    0,  111,  110,   35,    0,    0,
227
72
   23,   24,   25,   26,   27,   28,   29,   30,   31,   36,
228
    0,    0,    0,    0,    0,    0,   55,    0,    0,    0,
229
    0,   86,    0,    0,    0,    0,    0,    0,    0,    0,
230
  100,    0,   94,   45,   96,   82,    0,   80,    0,   76,
231
    0,    0,    0,  122,  120,    0,    0,  117,    0,    0,
232
    0,    0,    0,    0,    0,    0,    0,    0,   63,    0,
233
   43,   44,    0,   38,    0,    0,    0,   83,   18,    0,
234
72
   20,  108,    0,   22,    0,    0,  138,   58,    0,    0,
235
   92,   90,    0,   91,    0,    0,    0,   50,    0,   32,
236
72
  102,  103,  101,  104,  105,  106,   99,    0,   81,    0,
237
  124,    0,  123,  121,    0,    0,   66,   69,   70,   71,
238
72
   67,   75,   68,   72,    0,    0,   42,    0,   34,   85,
239
    0,   19,    0,   60,    0,   59,    0,    0,   93,    0,
240
72
    0,    0,   53,   12,    0,    0,    0,    0,    0,    0,
241
  126,  125,    0,    0,   73,   74,    0,    0,    0,    0,
242
72
   84,  115,  107,   61,   54,    0,    0,   57,  146,    0,
243
   89,    0,   87,    0,    0,    0,   21,    0,   98,    0,
244
72
   95,   79,    0,   77,  116,  119,    0,   62,   65,    0,
245
72
   37,   41,    0,    0,  145,   56,   88,   48,   52,    0,
246
72
  137,  136,    0,   97,   78,  118,   64,   40,   51,    0,
247
72
   33,
248
72
};
249
const short yydgoto[] =
250
72
	{                                       1,
251
72
  247,  215,   22,  158,   48,  233,  148,   78,   13,   14,
252
72
   15,   16,   41,   38,   34,   79,   80,  239,   81,   82,
253
72
   83,   84,   85,   86,   87,   88,   89,  216,   90,  229,
254
  230,  240,  103,  244,  245,  104,  207,  208,  227,  228,
255
72
  219,  220,  210,  211,  217,  218,  177,   91,  223,  224,
256
72
   42,   43,   49,   58,   50,
257
144
};
258
144
const short yysindex[] =
259
	{                                      0,
260
144
  -10,   14, -281, -224, -216, -170,    6, -177, -187,   73,
261
144
    0,  127,  137,  146,  147,  151,    0,    0,    0,    0,
262
    0, -153,  161, -145,    0, -143,    0,    0,    0,    0,
263
72
    0,    0,  161, -219,  128,    0,    0,   61,    0,    0,
264
 -293, -120,  167, -131,  161,    0,    0,    0,  -58,    0,
265
    0,  167,  161,    0,    0,  479,    0,    0,    0,    0,
266
72
    0, -170, -119, -116,    0,  -97, -170, -112, -188, -115,
267
  -65, -117,  -98, -110, -220,    0,    0,    0,  399,  161,
268
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
269
72
 -198, -122, -200, -118, -100,  161,    0,  -69, -107, -242,
270
  161,    0,   90,  -81, -103, -102,  -96,  -95,  -76, -127,
271
    0,  161,    0,    0,    0,    0,  -99,    0,  161,    0,
272
  -94,  -92, -265,    0,    0,  -37,  161,    0,  -90,  -88,
273
72
  -86,  -84,  -83,  -63,  -80,  -78,  -34,  161,    0,  -73,
274
    0,    0,  161,    0, -145,  -71,  -70,    0,    0,  167,
275
72
    0,    0,  -68,    0,  -64,  -12,    0,    0, -118, -271,
276
    0,    0,  -24,    0, -215,  161,  -62,    0,  -51,    0,
277
    0,    0,    0,    0,    0,    0,    0, -243,    0, -274,
278
    0,  -60,    0,    0,  -57,   -2,    0,    0,    0,    0,
279
    0,    0,    0,    0, -287, -162,    0, -186,    0,    0,
280
72
  -55,    0,  -54,    0,  -53,    0,  143,    3,    0,    3,
281
72
  145,  -81,    0,    0,  -16,  152,    3,  149,    3,  155,
282
    0,    0,  160,    3,    0,    0,  164,    3,  165,    3,
283
72
    0,    0,    0,    0,    0,  161,  161,    0,    0, -271,
284
72
    0, -215,    0,  170,    3, -169,    0,  161,    0, -243,
285
    0,    0, -274,    0,    0,    0,   -2,    0,    0, -162,
286
72
    0,    0, -186,    0,    0,    0,    0,    0,    0,  -81,
287

72
    0,    0,  479,    0,    0,    0,    0,    0,    0,  416,
288
    0,};
289
const short yyrindex[] =
290
	{                                      0,
291
72
    0,    0,    0,    0,    0,  -42,    0,    0,    0,    0,
292
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
293
    0,    0, -214,    0,    0,    0,    0,    0,    0,    0,
294
72
    0,    0,  179,    0,    0,    0,    0,    0,    0,    0,
295
    0,    0,    0,    0,  525,    0,    0,    0,  286,    0,
296
    0,    0,  343,    0,    0,    0,    0,    0,    0,    0,
297
    0,  -42,    0,    0,    8,    0,  -42,    0,    0,    0,
298
    0,    0,   54,    0,    0,    0,    0,    0,    0,  462,
299
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
300
   71,    0,    0,    0,    0, -195,    0,    0,    0,    0,
301
 -194,    0,    0,    0,    0,    0,    0,    0,    0,    0,
302
72
    0, -241,    0,    0,    0,    0,    0,    0, -217,    0,
303
    0,    0,    0,    0,    0,    0,  118,    0,    0,    0,
304
    0,    0,    0,    0,    0,    0,    0,  -31,    0,    0,
305
    0,    0, -144,    0,    0,    0,    0,    0,    0,    0,
306
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
307
    0,    0,    0,    0,    0,    2,    0,    0,   11,    0,
308
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
309
72
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
310
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
311
    0,    0,  117,    0,    0,    0,    0,  176,    0,  176,
312
    0,    0,    0,    0,    0,    0,  176,    0,  176,    0,
313
    0,    0,    0,  176,    0,    0,    0,  176,    0,  176,
314
    0,    0,    0,    0,    0,  236, -223,    0,    0,    0,
315
    0,    0,    0,    0,  176,    0,    0,  525,    0,    0,
316
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
317
    0,    0,    0,  293,    0,    0,    0,    0,    0,    0,
318
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
319
    0,};
320
const short yygindex[] =
321
	{                                      0,
322
    0,    0,   49,  156,    0,    0,    0,   34,    0,    0,
323
    0,    0,  -15,    0,  -30,   32,  -77,  -33,    0,    0,
324
    0,    0,    0,    0,    0,    0,    0,    0,    0,   43,
325
  235,  -75,    0,   41,  210,    0,   77,  255,   59,  253,
326
  258,   78,  266,   93,  268,   87,    0,    0,   83,  271,
327
    0,  301,    0,    0,  296,
328
};
329
#define YYTABLESIZE 843
330

96
const short yytable[] =
331
24
	{                                      11,
332
   57,  150,   39,   96,   51,  138,  101,  119,   36,   54,
333
  112,   93,  236,  107,   56,  144,  163,   46,   60,  183,
334
  225,  117,   61,   17,  143,   46,   47,  184,  108,   94,
335
  144,  164,  226,  144,   12,  144,  144,   18,   95,  144,
336
  109,  144,  144,   98,  118,  144,  237,  144,  144,  151,
337
  144,  144,  144,  110,  111,  144,  144,  127,   99,  144,
338
  144,  144,  144,   39,  144,  160,  144,   40,  100,  144,
339
72
  165,  144,  144,  144,  144,   40,  144,  144,  144,  144,
340
  109,  178,  144,  144,  114,  144,  144,  144,  180,  144,
341
  155,  115,    9,  146,   19,  144,  186,  144,  147,   35,
342
  129,  144,  130,   20,  144,  144,  131,  196,  132,  156,
343
   92,   21,  198,  133,  144,  106,  202,  152,  153,  140,
344
  141,  134,  142,  135,  116,   24,  114,  136,   23,  199,
345
   47,   25,   46,   26,  242,  212,   27,  137,  174,  175,
346
  176,  250,   98,  253,  107,  129,   28,  130,  257,  271,
347
72
  272,  131,  260,  132,  263,   29,   30,   99,  133,  108,
348
   31,  144,  144,   93,  144,   32,  134,  100,  135,  270,
349
   33,  109,  136,   35,   44,   37,   53,  238,   39,  241,
350
  117,   94,  137,   45,  110,  111,  249,   55,  252,  105,
351
   95,    9,  145,  256,  121,  109,  154,  259,   35,  262,
352
  159,  157,  150,  118,  161,  264,  265,  140,  141,  122,
353
  142,  162,  166,  167,  269,  169,  170,  273,  123,  124,
354
  179,  173,  171,  172,  185,  181,  182,  125,  187,  126,
355
  188,  144,  189,  144,  190,  191,  192,  144,  193,  144,
356
  194,  114,  195,  201,  144,    2,  197,  200,  205,  209,
357
  214,  203,  144,    3,  144,  204,  213,  121,  144,  221,
358
72
   46,   47,  222,  231,  232,   46,  234,  235,  144,  243,
359
    4,  246,  122,  251,  248,   46,  112,   46,    5,  254,
360
   46,  123,  124,    6,  255,   46,   46,   46,  258,  261,
361
  125,   46,  126,    7,  268,  142,  144,    8,   11,   46,
362
  144,    9,   49,  144,  280,  278,   46,  144,   10,   46,
363
  279,   39,   46,  168,  206,   46,  266,   97,  277,   46,
364
288
   46,   39,   46,   39,  139,   46,   39,  120,  109,  102,
365
  275,   39,   39,   39,  267,  113,  274,   39,  109,  276,
366
72
  109,  128,   52,  109,   59,   39,    0,    0,  109,  109,
367
  109,    0,   39,    0,  109,   39,    0,    0,   39,    0,
368
288
  144,   39,  109,    0,    0,   39,   39,    0,   39,  109,
369
    0,   39,  109,    0,  114,  109,    0,  144,  109,    0,
370

144
    0,    0,  109,  109,  114,  109,  114,    0,  109,  114,
371
144
    0,    0,  144,    0,  114,  114,  114,    0,    0,    0,
372
  114,  144,  144,    0,    0,    0,    0,    0,  114,    0,
373
  144,    0,  144,    0,    0,  114,    0,  143,  114,    0,
374
    0,  114,    0,    0,  114,    0,    0,    0,  114,  114,
375
    0,  114,    0,    0,  114,  144,  144,  144,  144,    0,
376
    0,  144,    0,  144,    0,    0,  144,  144,  144,  144,
377
  144,  144,  144,  144,  144,    0,  144,  144,  144,    0,
378
    0,  144,  144,  144,  144,    0,    0,  144,  144,    0,
379
  144,  144,    0,  144,  144,  144,  144,  144,  144,  144,
380
  144,    0,    0,  144,  144,  144,  144,  144,  144,    0,
381
  144,  144,  144,  144,  144,  144,  144,  144,  144,    0,
382
  144,    0,    0,    0,  144,    0,  144,  144,    0,  144,
383
  144,  144,    0,    0,    0,    0,    0,    0,  144,  144,
384
  144,  144,    0,  149,    0,  144,    0,    0,  144,    0,
385
  144,  144,  144,  144,    0,  144,  144,    0,    0,    0,
386
  281,  144,  144,    0,  144,  144,    0,    0,    0,  147,
387
    0,  147,  147,    0,  144,  147,    0,  147,    0,    0,
388
    0,  147,    0,  147,  147,    0,  147,  147,  147,    0,
389
    0,    0,    0,    0,    0,  147,  147,  147,  147,    0,
390
360
    0,    0,  147,    0,    0,  147,  144,  147,  147,  147,
391
216
  147,    0,  147,  147,    0,    0,    0,    0,  147,  147,
392
72
  144,  147,  147,    0,    0,    0,    0,    0,    0,    0,
393
  144,  147,  144,    0,    0,  144,    0,    0,    0,    0,
394
  144,  144,  144,    0,    0,    0,  144,    0,    0,    0,
395
    0,    0,    0,    0,  144,    0,    0,    0,    0,    0,
396
    0,  144,    0,    0,  144,    0,    0,  144,    0,    0,
397
  144,    0,    0,    0,  144,  144,   62,  144,    0,    0,
398
72
  144,  144,    0,    0,    0,    0,   63,    0,   64,    0,
399
72
    0,   65,    0,   62,    0,    0,   66,   67,   68,    0,
400

72
    0,    0,   69,   63,    0,   64,    0,    0,   65,    0,
401
   70,    0,    0,   66,   67,   68,    0,   71,    0,   69,
402
   72,    0,    0,   73,    0,    0,   74,   70,    0,    0,
403
    9,   75,    0,   76,   71,    0,   77,   72,    0,  144,
404
   73,    0,    0,   74,    0,    0,    0,    9,   75,  144,
405
   76,  144,    0,   77,  144,    0,   62,    0,    0,  144,
406
  144,  144,    0,    0,    0,  144,   63,    0,   64,    0,
407
    0,   65,    0,  144,    0,    0,   66,   67,   68,    0,
408
72
  144,    0,   69,  144,    0,    0,  144,    0,    0,  144,
409
   70,    0,    0,  144,  144,    0,  144,   71,    0,  144,
410
   72,    0,  144,   73,    0,    0,   74,    0,    0,    0,
411
    9,   75,  144,   76,  144,    0,   77,  144,    0,    0,
412
72
    0,    0,  144,  144,  144,    0,    0,    0,  144,    0,
413
    0,    0,    0,    0,    0,    0,  144,    0,    0,    0,
414
    0,    0,    0,  144,    0,    0,  144,    0,    0,  144,
415
    0,    0,  144,    0,    0,    0,  144,  144,    0,  144,
416
    0,    0,  144,
417
};
418
72
const short yycheck[] =
419
	{                                      10,
420
   59,   79,   33,  123,  125,  123,  123,  123,   24,   43,
421
  123,  283,   10,  257,   45,  257,  259,   10,   52,  285,
422
  308,  296,   53,   10,  123,  319,  320,  293,  272,  301,
423
  272,  274,  320,  257,    1,  259,  260,  319,  310,  263,
424
  284,  265,  284,  259,  319,  269,   44,  271,  272,   80,
425
  274,  275,  276,  297,  298,  297,  298,  123,  274,  283,
426
  284,  285,  286,   10,  259,   96,  290,   34,  284,  293,
427
  101,  295,  296,  297,  298,   42,  300,  301,  296,  274,
428
72
   10,  112,  306,  307,  273,  309,  310,  283,  119,  284,
429
72
  291,  280,  312,  314,  319,  319,  127,  312,  319,  319,
430
  263,  319,  265,  320,  319,  301,  269,  138,  271,  310,
431
   62,  282,  143,  276,  310,   67,  150,  316,  317,  306,
432
  307,  284,  309,  286,  313,  303,   10,  290,  123,  145,
433
  123,  319,  125,   61,  210,  166,   10,  300,  266,  267,
434
72
  268,  217,  259,  219,  257,  263,   10,  265,  224,  319,
435
72
  320,  269,  228,  271,  230,   10,   10,  274,  276,  272,
436
72
   10,  306,  307,  283,  309,  319,  284,  284,  286,  245,
437
72
   10,  284,  290,  319,   47,  319,   10,  208,  125,  210,
438
72
  296,  301,  300,  123,  297,  298,  217,  319,  219,  287,
439
72
  310,  312,  303,  224,  260,  125,  319,  228,  319,  230,
440
  301,  320,  280,  319,  274,  236,  237,  306,  307,  275,
441
72
  309,  319,  123,  295,  245,  319,  319,  248,  284,  285,
442
24
  320,  298,  319,  319,  262,  320,  319,  293,  319,  295,
443
  319,  263,  319,  265,  319,  319,  300,  269,  319,  271,
444
72
  319,  125,  277,  314,  276,  256,  320,  319,  261,  274,
445
  302,  320,  284,  264,  286,  320,  319,  260,  290,  320,
446
  319,  320,  320,  319,  319,  258,  320,  125,  300,  125,
447
  281,  288,  275,  125,  123,  268,  319,  270,  289,  125,
448
  273,  284,  285,  294,  125,  278,  279,  280,  125,  125,
449
  293,  284,  295,  304,  125,   10,  295,  308,  288,  292,
450
  125,  312,  295,  125,  273,  263,  299,   73,  319,  302,
451
  270,  258,  305,  104,  159,  308,  240,   63,  260,  312,
452
144
  313,  268,  315,  270,   72,  318,  273,   70,  258,   64,
453
  253,  278,  279,  280,  242,   68,  250,  284,  268,  257,
454
  270,   71,   42,  273,   49,  292,   -1,   -1,  278,  279,
455
  280,   -1,  299,   -1,  284,  302,   -1,   -1,  305,   -1,
456
  125,  308,  292,   -1,   -1,  312,  313,   -1,  315,  299,
457
   -1,  318,  302,   -1,  258,  305,   -1,  260,  308,   -1,
458
   -1,   -1,  312,  313,  268,  315,  270,   -1,  318,  273,
459
   -1,   -1,  275,   -1,  278,  279,  280,   -1,   -1,   -1,
460
  284,  284,  285,   -1,   -1,   -1,   -1,   -1,  292,   -1,
461
  293,   -1,  295,   -1,   -1,  299,   -1,  125,  302,   -1,
462
   -1,  305,   -1,   -1,  308,   -1,   -1,   -1,  312,  313,
463
   -1,  315,   -1,   -1,  318,  257,  258,  259,  260,   -1,
464
   -1,  263,   -1,  265,   -1,   -1,  268,  269,  270,  271,
465
  272,  273,  274,  275,  276,   -1,  278,  279,  280,   -1,
466
   -1,  283,  284,  285,  286,   -1,   -1,  125,  290,   -1,
467
  292,  293,   -1,  295,  296,  297,  298,  299,  300,  301,
468
  302,   -1,   -1,  305,  306,  307,  308,  309,  310,   -1,
469
  312,  313,  257,  315,  259,  260,  318,  319,  263,   -1,
470
  265,   -1,   -1,   -1,  269,   -1,  271,  272,   -1,  274,
471
  275,  276,   -1,   -1,   -1,   -1,   -1,   -1,  283,  284,
472
  285,  286,   -1,  125,   -1,  290,   -1,   -1,  293,   -1,
473
  295,  296,  297,  298,   -1,  300,  301,   -1,   -1,   -1,
474
  125,  306,  307,   -1,  309,  310,   -1,   -1,   -1,  257,
475
   -1,  259,  260,   -1,  319,  263,   -1,  265,   -1,   -1,
476
   -1,  269,   -1,  271,  272,   -1,  274,  275,  276,   -1,
477
   -1,   -1,   -1,   -1,   -1,  283,  284,  285,  286,   -1,
478
   -1,   -1,  290,   -1,   -1,  293,  125,  295,  296,  297,
479
  298,   -1,  300,  301,   -1,   -1,   -1,   -1,  306,  307,
480
  258,  309,  310,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
481
  268,  319,  270,   -1,   -1,  273,   -1,   -1,   -1,   -1,
482
  278,  279,  280,   -1,   -1,   -1,  284,   -1,   -1,   -1,
483
   -1,   -1,   -1,   -1,  292,   -1,   -1,   -1,   -1,   -1,
484
   -1,  299,   -1,   -1,  302,   -1,   -1,  305,   -1,   -1,
485
  308,   -1,   -1,   -1,  312,  313,  258,  315,   -1,   -1,
486
  318,  319,   -1,   -1,   -1,   -1,  268,   -1,  270,   -1,
487
   -1,  273,   -1,  258,   -1,   -1,  278,  279,  280,   -1,
488
   -1,   -1,  284,  268,   -1,  270,   -1,   -1,  273,   -1,
489
  292,   -1,   -1,  278,  279,  280,   -1,  299,   -1,  284,
490
  302,   -1,   -1,  305,   -1,   -1,  308,  292,   -1,   -1,
491
  312,  313,   -1,  315,  299,   -1,  318,  302,   -1,  258,
492
  305,   -1,   -1,  308,   -1,   -1,   -1,  312,  313,  268,
493
  315,  270,   -1,  318,  273,   -1,  258,   -1,   -1,  278,
494
  279,  280,   -1,   -1,   -1,  284,  268,   -1,  270,   -1,
495
48
   -1,  273,   -1,  292,   -1,   -1,  278,  279,  280,   -1,
496
  299,   -1,  284,  302,   -1,   -1,  305,   -1,   -1,  308,
497
  292,   -1,   -1,  312,  313,   -1,  315,  299,   -1,  318,
498
  302,   -1,  258,  305,   -1,   -1,  308,   -1,   -1,   -1,
499
  312,  313,  268,  315,  270,   -1,  318,  273,   -1,   -1,
500
   -1,   -1,  278,  279,  280,   -1,   -1,   -1,  284,   -1,
501
192
   -1,   -1,   -1,   -1,   -1,   -1,  292,   -1,   -1,   -1,
502
48
   -1,   -1,   -1,  299,   -1,   -1,  302,   -1,   -1,  305,
503
   -1,   -1,  308,   -1,   -1,   -1,  312,  313,   -1,  315,
504
48
   -1,   -1,  318,
505
};
506
#define YYFINAL 1
507
#ifndef YYDEBUG
508
48
#define YYDEBUG 0
509
#endif
510
#define YYMAXTOKEN 320
511
#if YYDEBUG
512
const char * const yyname[] =
513
	{
514
"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,
515
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,
516
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,0,
517
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,
518
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,0,
519
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,0,
520
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,
521
"ACCESS","ALIAS","AUTO","BACKLOG","BODY","BUFFER","CERTIFICATE","CHROOT",
522
"CIPHERS","COMMON","COMBINED","CONNECTION","DHE","DIRECTORY","ECDHE","ERR",
523
"FCGI","INDEX","IP","KEY","LIFETIME","LISTEN","LOCATION","LOG","LOGDIR","MATCH",
524
"MAXIMUM","NO","NODELAY","OCSP","ON","PORT","PREFORK","PROTOCOLS","REQUESTS",
525
"ROOT","SACK","SERVER","SOCKET","STRIP","STYLE","SYSLOG","TCP","TICKET",
526
"TIMEOUT","TLS","TYPE","TYPES","HSTS","MAXAGE","SUBDOMAINS","DEFAULT","PRELOAD",
527
"REQUEST","ERROR","INCLUDE","AUTHENTICATE","WITH","BLOCK","DROP","RETURN",
528
"PASS","STRING","NUMBER",
529
};
530
const char * const yyrule[] =
531
	{"$accept : grammar",
532
"grammar :",
533
"grammar : grammar include '\\n'",
534
"grammar : grammar '\\n'",
535
"grammar : grammar varset '\\n'",
536
"grammar : grammar main '\\n'",
537
"grammar : grammar server '\\n'",
538
"grammar : grammar types '\\n'",
539
"grammar : grammar error '\\n'",
540
"include : INCLUDE STRING",
541
"varset : STRING '=' STRING",
542
"opttls :",
543
"opttls : TLS",
544
"main : PREFORK NUMBER",
545
"main : CHROOT STRING",
546
"main : LOGDIR STRING",
547
"main : DEFAULT TYPE mediastring",
548
"$$1 :",
549
"server : SERVER optmatch STRING $$1 '{' optnl serveropts_l '}'",
550
"serveropts_l : serveropts_l serveroptsl nl",
551
"serveropts_l : serveroptsl optnl",
552
"serveroptsl : LISTEN ON STRING opttls port",
553
"serveroptsl : ALIAS optmatch STRING",
554
"serveroptsl : tcpip",
555
"serveroptsl : connection",
556
"serveroptsl : tls",
557
"serveroptsl : root",
558
"serveroptsl : directory",
559
"serveroptsl : logformat",
560
"serveroptsl : fastcgi",
561
"serveroptsl : authenticate",
562
"serveroptsl : filter",
563
"$$2 :",
564
"serveroptsl : LOCATION optmatch STRING $$2 '{' optnl serveropts_l '}'",
565
"serveroptsl : DEFAULT TYPE mediastring",
566
"serveroptsl : include",
567
"serveroptsl : hsts",
568
"hsts : HSTS '{' optnl hstsflags_l '}'",
569
"hsts : HSTS hstsflags",
570
"hsts : HSTS",
571
"hstsflags_l : hstsflags optcommanl hstsflags_l",
572
"hstsflags_l : hstsflags optnl",
573
"hstsflags : MAXAGE NUMBER",
574
"hstsflags : SUBDOMAINS",
575
"hstsflags : PRELOAD",
576
"fastcgi : NO FCGI",
577
"fastcgi : FCGI",
578
"$$3 :",
579
"fastcgi : FCGI $$3 '{' optnl fcgiflags_l '}'",
580
"$$4 :",
581
"fastcgi : FCGI $$4 fcgiflags",
582
"fcgiflags_l : fcgiflags optcommanl fcgiflags_l",
583
"fcgiflags_l : fcgiflags optnl",
584
"fcgiflags : SOCKET STRING",
585
"connection : CONNECTION '{' optnl conflags_l '}'",
586
"connection : CONNECTION conflags",
587
"conflags_l : conflags optcommanl conflags_l",
588
"conflags_l : conflags optnl",
589
"conflags : TIMEOUT timeout",
590
"conflags : REQUEST TIMEOUT timeout",
591
"conflags : MAXIMUM REQUESTS NUMBER",
592
"conflags : MAXIMUM REQUEST BODY NUMBER",
593
"tls : TLS '{' optnl tlsopts_l '}'",
594
"tls : TLS tlsopts",
595
"tlsopts_l : tlsopts optcommanl tlsopts_l",
596
"tlsopts_l : tlsopts optnl",
597
"tlsopts : CERTIFICATE STRING",
598
"tlsopts : KEY STRING",
599
"tlsopts : OCSP STRING",
600
"tlsopts : CIPHERS STRING",
601
"tlsopts : DHE STRING",
602
"tlsopts : ECDHE STRING",
603
"tlsopts : PROTOCOLS STRING",
604
"tlsopts : TICKET LIFETIME DEFAULT",
605
"tlsopts : TICKET LIFETIME NUMBER",
606
"tlsopts : NO TICKET",
607
"root : ROOT rootflags",
608
"root : ROOT '{' optnl rootflags_l '}'",
609
"rootflags_l : rootflags optcommanl rootflags_l",
610
"rootflags_l : rootflags optnl",
611
"rootflags : STRING",
612
"rootflags : STRIP NUMBER",
613
"authenticate : NO AUTHENTICATE",
614
"authenticate : AUTHENTICATE authopts",
615
"authopts : STRING WITH STRING",
616
"authopts : WITH STRING",
617
"directory : DIRECTORY dirflags",
618
"directory : DIRECTORY '{' optnl dirflags_l '}'",
619
"dirflags_l : dirflags optcommanl dirflags_l",
620
"dirflags_l : dirflags optnl",
621
"dirflags : INDEX STRING",
622
"dirflags : NO INDEX",
623
"dirflags : AUTO INDEX",
624
"dirflags : NO AUTO INDEX",
625
"logformat : LOG logflags",
626
"logformat : LOG '{' optnl logflags_l '}'",
627
"logformat : NO LOG",
628
"logflags_l : logflags optcommanl logflags_l",
629
"logflags_l : logflags optnl",
630
"logflags : STYLE logstyle",
631
"logflags : SYSLOG",
632
"logflags : NO SYSLOG",
633
"logflags : ACCESS STRING",
634
"logflags : ERR STRING",
635
"logstyle : COMMON",
636
"logstyle : COMBINED",
637
"logstyle : CONNECTION",
638
"filter : block RETURN NUMBER optstring",
639
"filter : block DROP",
640
"filter : block",
641
"filter : PASS",
642
"block : BLOCK",
643
"optmatch :",
644
"optmatch : MATCH",
645
"optstring :",
646
"optstring : STRING",
647
"tcpip : TCP '{' optnl tcpflags_l '}'",
648
"tcpip : TCP tcpflags",
649
"tcpflags_l : tcpflags optcommanl tcpflags_l",
650
"tcpflags_l : tcpflags optnl",
651
"tcpflags : SACK",
652
"tcpflags : NO SACK",
653
"tcpflags : NODELAY",
654
"tcpflags : NO NODELAY",
655
"tcpflags : BACKLOG NUMBER",
656
"tcpflags : SOCKET BUFFER NUMBER",
657
"tcpflags : IP STRING NUMBER",
658
"types : TYPES '{' optnl mediaopts_l '}'",
659
"mediaopts_l : mediaopts_l mediaoptsl nl",
660
"mediaopts_l : mediaoptsl nl",
661
"mediaoptsl : mediastring medianames_l optsemicolon",
662
"mediaoptsl : include",
663
"mediastring : STRING '/' STRING",
664
"medianames_l : medianames_l medianamesl",
665
"medianames_l : medianamesl",
666
"medianamesl : numberstring",
667
"port : PORT NUMBER",
668
"port : PORT STRING",
669
"timeout : NUMBER",
670
"numberstring : NUMBER",
671
"numberstring : STRING",
672
"optsemicolon : ';'",
673
"optsemicolon :",
674
"optnl : '\\n' optnl",
675
"optnl :",
676
"optcommanl : ',' optnl",
677
"optcommanl : nl",
678
"nl : '\\n' optnl",
679
};
680
#endif
681
#ifdef YYSTACKSIZE
682
#undef YYMAXDEPTH
683
#define YYMAXDEPTH YYSTACKSIZE
684
#else
685
#ifdef YYMAXDEPTH
686
#define YYSTACKSIZE YYMAXDEPTH
687
#else
688
#define YYSTACKSIZE 10000
689
#define YYMAXDEPTH 10000
690
#endif
691
#endif
692
#define YYINITSTACKSIZE 200
693
/* LINTUSED */
694
int yydebug;
695
int yynerrs;
696
int yyerrflag;
697
int yychar;
698
short *yyssp;
699
YYSTYPE *yyvsp;
700
YYSTYPE yyval;
701
YYSTYPE yylval;
702
short *yyss;
703
short *yysslim;
704
YYSTYPE *yyvs;
705
unsigned int yystacksize;
706
int yyparse(void);
707
#line 1179 "parse.y"
708
709
struct keywords {
710
	const char	*k_name;
711
	int		 k_val;
712
24
};
713
24
714
int
715
24
yyerror(const char *fmt, ...)
716
{
717
24
	va_list		 ap;
718
24
	char		*msg;
719
24
720
	file->errors++;
721
24
	va_start(ap, fmt);
722
	if (vasprintf(&msg, fmt, ap) == -1)
723
24
		fatalx("yyerror vasprintf");
724
	va_end(ap);
725
	logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg);
726
	free(msg);
727
	return (0);
728
}
729
730
int
731
kw_cmp(const void *k, const void *e)
732
{
733
	return (strcmp(k, ((const struct keywords *)e)->k_name));
734
}
735
736
int
737
lookup(char *s)
738
{
739
	/* this has to be sorted always */
740
	static const struct keywords keywords[] = {
741
		{ "access",		ACCESS },
742
		{ "alias",		ALIAS },
743
		{ "authenticate",	AUTHENTICATE},
744
		{ "auto",		AUTO },
745
		{ "backlog",		BACKLOG },
746
		{ "block",		BLOCK },
747
		{ "body",		BODY },
748
		{ "buffer",		BUFFER },
749
		{ "certificate",	CERTIFICATE },
750
		{ "chroot",		CHROOT },
751
		{ "ciphers",		CIPHERS },
752
		{ "combined",		COMBINED },
753
		{ "common",		COMMON },
754
		{ "connection",		CONNECTION },
755
		{ "default",		DEFAULT },
756
		{ "dhe",		DHE },
757
		{ "directory",		DIRECTORY },
758
		{ "drop",		DROP },
759
		{ "ecdhe",		ECDHE },
760
		{ "error",		ERR },
761
		{ "fastcgi",		FCGI },
762
		{ "hsts",		HSTS },
763
		{ "include",		INCLUDE },
764
		{ "index",		INDEX },
765
		{ "ip",			IP },
766
		{ "key",		KEY },
767
		{ "lifetime",		LIFETIME },
768
		{ "listen",		LISTEN },
769
		{ "location",		LOCATION },
770
		{ "log",		LOG },
771
		{ "logdir",		LOGDIR },
772
		{ "match",		MATCH },
773
		{ "max",		MAXIMUM },
774
		{ "max-age",		MAXAGE },
775
		{ "no",			NO },
776
		{ "nodelay",		NODELAY },
777
		{ "ocsp",		OCSP },
778
		{ "on",			ON },
779
		{ "pass",		PASS },
780
		{ "port",		PORT },
781
		{ "prefork",		PREFORK },
782
		{ "preload",		PRELOAD },
783
		{ "protocols",		PROTOCOLS },
784
		{ "request",		REQUEST },
785
		{ "requests",		REQUESTS },
786
		{ "return",		RETURN },
787
		{ "root",		ROOT },
788
		{ "sack",		SACK },
789
		{ "server",		SERVER },
790
		{ "socket",		SOCKET },
791
		{ "strip",		STRIP },
792
		{ "style",		STYLE },
793
		{ "subdomains",		SUBDOMAINS },
794
		{ "syslog",		SYSLOG },
795
		{ "tcp",		TCP },
796
		{ "ticket",		TICKET },
797
144
		{ "timeout",		TIMEOUT },
798
72
		{ "tls",		TLS },
799
		{ "type",		TYPE },
800
		{ "types",		TYPES },
801
		{ "with",		WITH }
802
	};
803
	const struct keywords	*p;
804
72
805
72
	p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
806
	    sizeof(keywords[0]), kw_cmp);
807
72
808
	if (p)
809
		return (p->k_val);
810
	else
811
		return (STRING);
812
}
813
814
#define MAXPUSHBACK	128
815
816
unsigned char	*parsebuf;
817
int		 parseindex;
818
unsigned char	 pushback_buffer[MAXPUSHBACK];
819
int		 pushback_index = 0;
820
821
int
822
lgetc(int quotec)
823
{
824
	int		c, next;
825
826
	if (parsebuf) {
827
		/* Read character from the parsebuffer instead of input. */
828
		if (parseindex >= 0) {
829
			c = parsebuf[parseindex++];
830
			if (c != '\0')
831
				return (c);
832
			parsebuf = NULL;
833
		} else
834
			parseindex++;
835
	}
836
837
	if (pushback_index)
838
		return (pushback_buffer[--pushback_index]);
839
840
	if (quotec) {
841
		if ((c = getc(file->stream)) == EOF) {
842
			yyerror("reached end of file while parsing "
843
			    "quoted string");
844
			if (file == topfile || popfile() == EOF)
845
				return (EOF);
846
			return (quotec);
847
		}
848
		return (c);
849
	}
850
851
	while ((c = getc(file->stream)) == '\\') {
852
		next = getc(file->stream);
853
		if (next != '\n') {
854
			c = next;
855
			break;
856
		}
857
		yylval.lineno = file->lineno;
858
		file->lineno++;
859
	}
860
861
	while (c == EOF) {
862
		if (file == topfile || popfile() == EOF)
863
			return (EOF);
864
		c = getc(file->stream);
865
	}
866
	return (c);
867
}
868
869
int
870
lungetc(int c)
871
{
872
	if (c == EOF)
873
		return (EOF);
874
	if (parsebuf) {
875
		parseindex--;
876
		if (parseindex >= 0)
877
			return (c);
878
	}
879
	if (pushback_index < MAXPUSHBACK-1)
880
		return (pushback_buffer[pushback_index++] = c);
881
	else
882
		return (EOF);
883
}
884
885
int
886
findeol(void)
887
{
888
	int	c;
889
890
	parsebuf = NULL;
891
892
	/* skip to either EOF or the first real EOL */
893
	while (1) {
894
		if (pushback_index)
895
			c = pushback_buffer[--pushback_index];
896
		else
897
			c = lgetc(0);
898
		if (c == '\n') {
899
			file->lineno++;
900
			break;
901
		}
902
		if (c == EOF)
903
			break;
904
	}
905
	return (ERROR);
906
}
907
908
int
909
yylex(void)
910
{
911
	unsigned char	 buf[8096];
912
	unsigned char	*p, *val;
913
	int		 quotec, next, c;
914
	int		 token;
915
916
top:
917
	p = buf;
918
	while ((c = lgetc(0)) == ' ' || c == '\t')
919
		; /* nothing */
920
921
	yylval.lineno = file->lineno;
922
	if (c == '#')
923
		while ((c = lgetc(0)) != '\n' && c != EOF)
924
			; /* nothing */
925
	if (c == '$' && parsebuf == NULL) {
926
		while (1) {
927
			if ((c = lgetc(0)) == EOF)
928
				return (0);
929
930
			if (p + 1 >= buf + sizeof(buf) - 1) {
931
				yyerror("string too long");
932
				return (findeol());
933
			}
934
			if (isalnum(c) || c == '_') {
935
				*p++ = c;
936
				continue;
937
			}
938
			*p = '\0';
939
			lungetc(c);
940
			break;
941
		}
942
		val = symget(buf);
943
		if (val == NULL) {
944
			yyerror("macro '%s' not defined", buf);
945
			return (findeol());
946
		}
947
		parsebuf = val;
948
		parseindex = 0;
949
		goto top;
950
	}
951
952
	switch (c) {
953
	case '\'':
954
	case '"':
955
		quotec = c;
956
		while (1) {
957
			if ((c = lgetc(quotec)) == EOF)
958
72
				return (0);
959
72
			if (c == '\n') {
960
72
				file->lineno++;
961
				continue;
962
72
			} else if (c == '\\') {
963
				if ((next = lgetc(quotec)) == EOF)
964
					return (0);
965
				if (next == quotec || c == ' ' || c == '\t')
966
					c = next;
967
				else if (next == '\n') {
968
					file->lineno++;
969
					continue;
970
				} else
971
					lungetc(next);
972
			} else if (c == quotec) {
973
				*p = '\0';
974
				break;
975
			} else if (c == '\0') {
976
				yyerror("syntax error");
977
				return (findeol());
978
			}
979
			if (p + 1 >= buf + sizeof(buf) - 1) {
980
				yyerror("string too long");
981
				return (findeol());
982
			}
983
			*p++ = c;
984
		}
985
		yylval.v.string = strdup(buf);
986
		if (yylval.v.string == NULL)
987
			err(1, "yylex: strdup");
988
		return (STRING);
989
	}
990
991
#define allowed_to_end_number(x) \
992
	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
993
994
	if (c == '-' || isdigit(c)) {
995
		do {
996
			*p++ = c;
997
			if ((unsigned)(p-buf) >= sizeof(buf)) {
998
				yyerror("string too long");
999
				return (findeol());
1000
			}
1001
		} while ((c = lgetc(0)) != EOF && isdigit(c));
1002
		lungetc(c);
1003
		if (p == buf + 1 && buf[0] == '-')
1004
			goto nodigits;
1005
		if (c == EOF || allowed_to_end_number(c)) {
1006
			const char *errstr = NULL;
1007
1008
			*p = '\0';
1009
144
			yylval.v.number = strtonum(buf, LLONG_MIN,
1010
144
			    LLONG_MAX, &errstr);
1011
			if (errstr) {
1012
				yyerror("\"%s\" invalid number: %s",
1013
				    buf, errstr);
1014
				return (findeol());
1015
			}
1016
			return (NUMBER);
1017
		} else {
1018
nodigits:
1019
			while (p > buf + 1)
1020
				lungetc(*--p);
1021
			c = *--p;
1022
			if (c == '-')
1023
				return (c);
1024
		}
1025
	}
1026
1027
#define allowed_in_string(x) \
1028
	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
1029
	x != '{' && x != '}' && x != '<' && x != '>' && \
1030
	x != '!' && x != '=' && x != '#' && \
1031
	x != ',' && x != ';' && x != '/'))
1032
1033
	if (isalnum(c) || c == ':' || c == '_' || c == '*') {
1034
		do {
1035
			*p++ = c;
1036
			if ((unsigned)(p-buf) >= sizeof(buf)) {
1037
				yyerror("string too long");
1038
				return (findeol());
1039
			}
1040
		} while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
1041
		lungetc(c);
1042
		*p = '\0';
1043
		if ((token = lookup(buf)) == STRING)
1044
			if ((yylval.v.string = strdup(buf)) == NULL)
1045
				err(1, "yylex: strdup");
1046
		return (token);
1047
	}
1048
	if (c == '\n') {
1049
		yylval.lineno = file->lineno;
1050
		file->lineno++;
1051
	}
1052
	if (c == EOF)
1053
		return (0);
1054
	return (c);
1055
}
1056
1057
int
1058
check_file_secrecy(int fd, const char *fname)
1059
{
1060
	struct stat	st;
1061
1062
	if (fstat(fd, &st)) {
1063
		log_warn("cannot stat %s", fname);
1064
		return (-1);
1065
	}
1066
	if (st.st_uid != 0 && st.st_uid != getuid()) {
1067
		log_warnx("%s: owner not root or current user", fname);
1068
		return (-1);
1069
	}
1070
	if (st.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)) {
1071
		log_warnx("%s: group writable or world read/writable", fname);
1072
		return (-1);
1073
	}
1074
	return (0);
1075
}
1076
1077
struct file *
1078
pushfile(const char *name, int secret)
1079
{
1080
	struct file	*nfile;
1081
1082
	if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
1083
		log_warn("%s: malloc", __func__);
1084
		return (NULL);
1085
	}
1086
	if ((nfile->name = strdup(name)) == NULL) {
1087
		log_warn("%s: malloc", __func__);
1088
		free(nfile);
1089
		return (NULL);
1090
	}
1091
	if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
1092
		log_warn("%s: %s", __func__, nfile->name);
1093
		free(nfile->name);
1094
		free(nfile);
1095
		return (NULL);
1096
	} else if (secret &&
1097
	    check_file_secrecy(fileno(nfile->stream), nfile->name)) {
1098
		fclose(nfile->stream);
1099
		free(nfile->name);
1100
		free(nfile);
1101
		return (NULL);
1102
	}
1103
	nfile->lineno = 1;
1104
	TAILQ_INSERT_TAIL(&files, nfile, entry);
1105
	return (nfile);
1106
}
1107
1108
int
1109
popfile(void)
1110
{
1111
	struct file	*prev;
1112
1113
	if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
1114
		prev->errors += file->errors;
1115
1116
	TAILQ_REMOVE(&files, file, entry);
1117
	fclose(file->stream);
1118
	free(file->name);
1119
	free(file);
1120
	file = prev;
1121

144
	return (file ? 0 : EOF);
1122
}
1123
1124
int
1125
72
parse_config(const char *filename, struct httpd *x_conf)
1126
{
1127
72
	struct sym		*sym, *next;
1128
	struct media_type	 dflt = HTTPD_DEFAULT_TYPE;
1129
1130
	conf = x_conf;
1131
	if (config_init(conf) == -1) {
1132
		log_warn("%s: cannot initialize configuration", __func__);
1133
		return (-1);
1134
	}
1135
1136
	/* Set default media type */
1137
	memcpy(&conf->sc_default_type, &dflt, sizeof(struct media_type));
1138
1139
	errors = 0;
1140
1141
	if ((file = pushfile(filename, 0)) == NULL)
1142
		return (-1);
1143
1144
	topfile = file;
1145
	setservent(1);
1146
1147
	yyparse();
1148
	errors = file->errors;
1149
	popfile();
1150
1151
	endservent();
1152
	endprotoent();
1153
1154
	/* Free macros */
1155
	TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
1156
		if (!sym->persist) {
1157
			free(sym->nam);
1158
			free(sym->val);
1159
			TAILQ_REMOVE(&symhead, sym, entry);
1160
			free(sym);
1161
		}
1162
	}
1163
1164
	return (errors ? -1 : 0);
1165
}
1166
1167
int
1168
load_config(const char *filename, struct httpd *x_conf)
1169
{
1170
	struct sym		*sym, *next;
1171
	struct http_mediatype	 mediatypes[] = MEDIA_TYPES;
1172
	struct media_type	 m;
1173
	int			 i;
1174
1175
	conf = x_conf;
1176
	conf->sc_flags = 0;
1177
1178
	loadcfg = 1;
1179
	errors = 0;
1180
	last_server_id = 0;
1181
	last_auth_id = 0;
1182
1183
	srv = NULL;
1184
1185
	if ((file = pushfile(filename, 0)) == NULL)
1186
		return (-1);
1187
1188
	topfile = file;
1189
	setservent(1);
1190
1191
	yyparse();
1192
	errors = file->errors;
1193
	popfile();
1194
1195
	endservent();
1196
	endprotoent();
1197
1198
	/* Free macros and check which have not been used. */
1199
	for (sym = TAILQ_FIRST(&symhead); sym != NULL; sym = next) {
1200
		next = TAILQ_NEXT(sym, entry);
1201
		if ((conf->sc_opts & HTTPD_OPT_VERBOSE) && !sym->used)
1202
			fprintf(stderr, "warning: macro '%s' not "
1203
			    "used\n", sym->nam);
1204
		if (!sym->persist) {
1205
			free(sym->nam);
1206
			free(sym->val);
1207
			TAILQ_REMOVE(&symhead, sym, entry);
1208
			free(sym);
1209
		}
1210
	}
1211
1212
	if (TAILQ_EMPTY(conf->sc_servers)) {
1213
		log_warnx("no actions, nothing to do");
1214
		errors++;
1215
	}
1216
1217
	if (RB_EMPTY(conf->sc_mediatypes)) {
1218
		/* Add default media types */
1219
		for (i = 0; mediatypes[i].media_name != NULL; i++) {
1220
			(void)strlcpy(m.media_name, mediatypes[i].media_name,
1221
			    sizeof(m.media_name));
1222
			(void)strlcpy(m.media_type, mediatypes[i].media_type,
1223
			    sizeof(m.media_type));
1224
			(void)strlcpy(m.media_subtype,
1225
			    mediatypes[i].media_subtype,
1226
			    sizeof(m.media_subtype));
1227
			m.media_encoding = NULL;
1228
1229
			if (media_add(conf->sc_mediatypes, &m) == NULL) {
1230
				log_warnx("failed to add default media \"%s\"",
1231
				    m.media_name);
1232
				errors++;
1233
			}
1234
		}
1235
	}
1236
1237
	return (errors ? -1 : 0);
1238
}
1239
1240
int
1241
symset(const char *nam, const char *val, int persist)
1242
{
1243
	struct sym	*sym;
1244
1245
	TAILQ_FOREACH(sym, &symhead, entry) {
1246
		if (strcmp(nam, sym->nam) == 0)
1247
			break;
1248
	}
1249
1250
	if (sym != NULL) {
1251
		if (sym->persist == 1)
1252
			return (0);
1253
		else {
1254
			free(sym->nam);
1255
			free(sym->val);
1256
			TAILQ_REMOVE(&symhead, sym, entry);
1257
			free(sym);
1258
		}
1259
	}
1260
	if ((sym = calloc(1, sizeof(*sym))) == NULL)
1261
		return (-1);
1262
1263
	sym->nam = strdup(nam);
1264
	if (sym->nam == NULL) {
1265
		free(sym);
1266
		return (-1);
1267
	}
1268
	sym->val = strdup(val);
1269
	if (sym->val == NULL) {
1270
		free(sym->nam);
1271
		free(sym);
1272
		return (-1);
1273
	}
1274
	sym->used = 0;
1275
	sym->persist = persist;
1276
	TAILQ_INSERT_TAIL(&symhead, sym, entry);
1277
	return (0);
1278
}
1279
1280
int
1281
cmdline_symset(char *s)
1282
{
1283
	char	*sym, *val;
1284
	int	ret;
1285
	size_t	len;
1286
1287
	if ((val = strrchr(s, '=')) == NULL)
1288
		return (-1);
1289
1290
	len = strlen(s) - strlen(val) + 1;
1291
	if ((sym = malloc(len)) == NULL)
1292
		errx(1, "cmdline_symset: malloc");
1293
1294
	(void)strlcpy(sym, s, len);
1295
1296
	ret = symset(sym, val + 1, 1);
1297
	free(sym);
1298
1299
	return (ret);
1300
}
1301
1302
char *
1303
symget(const char *nam)
1304
{
1305
	struct sym	*sym;
1306
1307
	TAILQ_FOREACH(sym, &symhead, entry) {
1308
		if (strcmp(nam, sym->nam) == 0) {
1309
			sym->used = 1;
1310
			return (sym->val);
1311
		}
1312
	}
1313
	return (NULL);
1314
}
1315
1316
struct address *
1317
host_v4(const char *s)
1318
{
1319
	struct in_addr		 ina;
1320
	struct sockaddr_in	*sain;
1321
	struct address		*h;
1322
1323
	memset(&ina, 0, sizeof(ina));
1324
	if (inet_pton(AF_INET, s, &ina) != 1)
1325
		return (NULL);
1326
1327
	if ((h = calloc(1, sizeof(*h))) == NULL)
1328
		fatal(__func__);
1329
	sain = (struct sockaddr_in *)&h->ss;
1330
	sain->sin_len = sizeof(struct sockaddr_in);
1331
	sain->sin_family = AF_INET;
1332
	sain->sin_addr.s_addr = ina.s_addr;
1333
	if (sain->sin_addr.s_addr == INADDR_ANY)
1334
		h->prefixlen = 0; /* 0.0.0.0 address */
1335
	else
1336
		h->prefixlen = -1; /* host address */
1337
	return (h);
1338
}
1339
1340
struct address *
1341
host_v6(const char *s)
1342
{
1343
	struct addrinfo		 hints, *res;
1344
	struct sockaddr_in6	*sa_in6;
1345
	struct address		*h = NULL;
1346
1347
	memset(&hints, 0, sizeof(hints));
1348
	hints.ai_family = AF_INET6;
1349
	hints.ai_socktype = SOCK_DGRAM; /* dummy */
1350
	hints.ai_flags = AI_NUMERICHOST;
1351
	if (getaddrinfo(s, "0", &hints, &res) == 0) {
1352
		if ((h = calloc(1, sizeof(*h))) == NULL)
1353
			fatal(__func__);
1354
		sa_in6 = (struct sockaddr_in6 *)&h->ss;
1355
		sa_in6->sin6_len = sizeof(struct sockaddr_in6);
1356
		sa_in6->sin6_family = AF_INET6;
1357
		memcpy(&sa_in6->sin6_addr,
1358
		    &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
1359
		    sizeof(sa_in6->sin6_addr));
1360
		sa_in6->sin6_scope_id =
1361
		    ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
1362
		if (memcmp(&sa_in6->sin6_addr, &in6addr_any,
1363
		    sizeof(sa_in6->sin6_addr)) == 0)
1364
			h->prefixlen = 0; /* any address */
1365
		else
1366
			h->prefixlen = -1; /* host address */
1367
		freeaddrinfo(res);
1368
	}
1369
1370
	return (h);
1371
}
1372
1373
int
1374
host_dns(const char *s, struct addresslist *al, int max,
1375
    struct portrange *port, const char *ifname, int ipproto)
1376
{
1377
	struct addrinfo		 hints, *res0, *res;
1378
	int			 error, cnt = 0;
1379
	struct sockaddr_in	*sain;
1380
	struct sockaddr_in6	*sin6;
1381
	struct address		*h;
1382
1383
	if ((cnt = host_if(s, al, max, port, ifname, ipproto)) != 0)
1384
		return (cnt);
1385
1386
	memset(&hints, 0, sizeof(hints));
1387
	hints.ai_family = PF_UNSPEC;
1388
	hints.ai_socktype = SOCK_DGRAM; /* DUMMY */
1389
	hints.ai_flags = AI_ADDRCONFIG;
1390
	error = getaddrinfo(s, NULL, &hints, &res0);
1391
	if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME)
1392
		return (0);
1393
	if (error) {
1394
		log_warnx("%s: could not parse \"%s\": %s", __func__, s,
1395
		    gai_strerror(error));
1396
		return (-1);
1397
	}
1398
1399
	for (res = res0; res && cnt < max; res = res->ai_next) {
1400
		if (res->ai_family != AF_INET &&
1401
		    res->ai_family != AF_INET6)
1402
			continue;
1403
		if ((h = calloc(1, sizeof(*h))) == NULL)
1404
			fatal(__func__);
1405
1406
		if (port != NULL)
1407
			memcpy(&h->port, port, sizeof(h->port));
1408
		if (ifname != NULL) {
1409
			if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
1410
			    sizeof(h->ifname))
1411
				log_warnx("%s: interface name truncated",
1412
				    __func__);
1413
			freeaddrinfo(res0);
1414
			free(h);
1415
			return (-1);
1416
		}
1417
		if (ipproto != -1)
1418
			h->ipproto = ipproto;
1419
		h->ss.ss_family = res->ai_family;
1420
		h->prefixlen = -1; /* host address */
1421
1422
		if (res->ai_family == AF_INET) {
1423
			sain = (struct sockaddr_in *)&h->ss;
1424
			sain->sin_len = sizeof(struct sockaddr_in);
1425
			sain->sin_addr.s_addr = ((struct sockaddr_in *)
1426
			    res->ai_addr)->sin_addr.s_addr;
1427
		} else {
1428
			sin6 = (struct sockaddr_in6 *)&h->ss;
1429
			sin6->sin6_len = sizeof(struct sockaddr_in6);
1430
			memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
1431
			    res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
1432
		}
1433
1434
		TAILQ_INSERT_HEAD(al, h, entry);
1435
		cnt++;
1436
	}
1437
	if (cnt == max && res) {
1438
		log_warnx("%s: %s resolves to more than %d hosts", __func__,
1439
		    s, max);
1440
	}
1441
	freeaddrinfo(res0);
1442
	return (cnt);
1443
}
1444
1445
int
1446
host_if(const char *s, struct addresslist *al, int max,
1447
    struct portrange *port, const char *ifname, int ipproto)
1448
{
1449
	struct ifaddrs		*ifap, *p;
1450
	struct sockaddr_in	*sain;
1451
	struct sockaddr_in6	*sin6;
1452
	struct address		*h;
1453
	int			 cnt = 0, af;
1454
1455
	if (getifaddrs(&ifap) == -1)
1456
		fatal("getifaddrs");
1457
1458
	/* First search for IPv4 addresses */
1459
	af = AF_INET;
1460
1461
 nextaf:
1462
	for (p = ifap; p != NULL && cnt < max; p = p->ifa_next) {
1463
		if (p->ifa_addr->sa_family != af ||
1464
		    (strcmp(s, p->ifa_name) != 0 &&
1465
		    !is_if_in_group(p->ifa_name, s)))
1466
			continue;
1467
		if ((h = calloc(1, sizeof(*h))) == NULL)
1468
			fatal("calloc");
1469
1470
		if (port != NULL)
1471
			memcpy(&h->port, port, sizeof(h->port));
1472
		if (ifname != NULL) {
1473
			if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
1474
			    sizeof(h->ifname))
1475
				log_warnx("%s: interface name truncated",
1476
				    __func__);
1477
			freeifaddrs(ifap);
1478
			return (-1);
1479
		}
1480
		if (ipproto != -1)
1481
			h->ipproto = ipproto;
1482
		h->ss.ss_family = af;
1483
		h->prefixlen = -1; /* host address */
1484
1485
		if (af == AF_INET) {
1486
			sain = (struct sockaddr_in *)&h->ss;
1487
			sain->sin_len = sizeof(struct sockaddr_in);
1488
			sain->sin_addr.s_addr = ((struct sockaddr_in *)
1489
			    p->ifa_addr)->sin_addr.s_addr;
1490
		} else {
1491
			sin6 = (struct sockaddr_in6 *)&h->ss;
1492
			sin6->sin6_len = sizeof(struct sockaddr_in6);
1493
			memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
1494
			    p->ifa_addr)->sin6_addr, sizeof(struct in6_addr));
1495
			sin6->sin6_scope_id = ((struct sockaddr_in6 *)
1496
			    p->ifa_addr)->sin6_scope_id;
1497
		}
1498
1499
		TAILQ_INSERT_HEAD(al, h, entry);
1500
		cnt++;
1501
	}
1502
	if (af == AF_INET) {
1503
		/* Next search for IPv6 addresses */
1504
		af = AF_INET6;
1505
		goto nextaf;
1506
	}
1507
1508
	if (cnt > max) {
1509
		log_warnx("%s: %s resolves to more than %d hosts", __func__,
1510
		    s, max);
1511
	}
1512
	freeifaddrs(ifap);
1513
	return (cnt);
1514
}
1515
1516
int
1517
host(const char *s, struct addresslist *al, int max,
1518
    struct portrange *port, const char *ifname, int ipproto)
1519
{
1520
	struct address *h;
1521
1522
	if (strcmp("*", s) == 0)
1523
		s = "0.0.0.0";
1524
1525
	h = host_v4(s);
1526
1527
	/* IPv6 address? */
1528
	if (h == NULL)
1529
		h = host_v6(s);
1530
1531
	if (h != NULL) {
1532
		if (port != NULL)
1533
			memcpy(&h->port, port, sizeof(h->port));
1534
		if (ifname != NULL) {
1535
			if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
1536
			    sizeof(h->ifname)) {
1537
				log_warnx("%s: interface name truncated",
1538
				    __func__);
1539
				free(h);
1540
				return (-1);
1541
			}
1542
		}
1543
		if (ipproto != -1)
1544
			h->ipproto = ipproto;
1545
1546
		TAILQ_INSERT_HEAD(al, h, entry);
1547
		return (1);
1548
	}
1549
1550
	return (host_dns(s, al, max, port, ifname, ipproto));
1551
}
1552
1553
void
1554
host_free(struct addresslist *al)
1555
{
1556
	struct address	 *h;
1557
1558
	while ((h = TAILQ_FIRST(al)) != NULL) {
1559
		TAILQ_REMOVE(al, h, entry);
1560
		free(h);
1561
	}
1562
}
1563
1564
struct server *
1565
server_inherit(struct server *src, struct server_config *alias,
1566
    struct server_config *addr)
1567
{
1568
	struct server	*dst, *s, *dstl;
1569
1570
	if ((dst = calloc(1, sizeof(*dst))) == NULL)
1571
		fatal("out of memory");
1572
1573
	/* Copy the source server and assign a new Id */
1574
	memcpy(&dst->srv_conf, &src->srv_conf, sizeof(dst->srv_conf));
1575
	if ((dst->srv_conf.tls_cert_file =
1576
	    strdup(src->srv_conf.tls_cert_file)) == NULL)
1577
		fatal("out of memory");
1578
	if ((dst->srv_conf.tls_key_file =
1579
	    strdup(src->srv_conf.tls_key_file)) == NULL)
1580
		fatal("out of memory");
1581
	if (src->srv_conf.tls_ocsp_staple_file != NULL) {
1582
		if ((dst->srv_conf.tls_ocsp_staple_file =
1583
		    strdup(src->srv_conf.tls_ocsp_staple_file)) == NULL)
1584
			fatal("out of memory");
1585
	}
1586
1587
	if (src->srv_conf.return_uri != NULL &&
1588
	    (dst->srv_conf.return_uri =
1589
	    strdup(src->srv_conf.return_uri)) == NULL)
1590
		fatal("out of memory");
1591
1592
	dst->srv_conf.id = ++last_server_id;
1593
	dst->srv_conf.parent_id = dst->srv_conf.id;
1594
	dst->srv_s = -1;
1595
1596
	if (last_server_id == INT_MAX) {
1597
		yyerror("too many servers defined");
1598
		serverconfig_free(&dst->srv_conf);
1599
		free(dst);
1600
		return (NULL);
1601
	}
1602
1603
	/* Now set alias and listen address */
1604
	strlcpy(dst->srv_conf.name, alias->name, sizeof(dst->srv_conf.name));
1605
	memcpy(&dst->srv_conf.ss, &addr->ss, sizeof(dst->srv_conf.ss));
1606
	dst->srv_conf.port = addr->port;
1607
	dst->srv_conf.prefixlen = addr->prefixlen;
1608
	if (addr->flags & SRVFLAG_TLS)
1609
		dst->srv_conf.flags |= SRVFLAG_TLS;
1610
	else
1611
		dst->srv_conf.flags &= ~SRVFLAG_TLS;
1612
1613
	/* Don't inherit the "match" option, use it from the alias */
1614
	dst->srv_conf.flags &= ~SRVFLAG_SERVER_MATCH;
1615
	dst->srv_conf.flags |= (alias->flags & SRVFLAG_SERVER_MATCH);
1616
1617
	if (server_tls_load_keypair(dst) == -1) {
1618
		yyerror("failed to load public/private keys "
1619
		    "for server %s", dst->srv_conf.name);
1620
		serverconfig_free(&dst->srv_conf);
1621
		free(dst);
1622
		return (NULL);
1623
	}
1624
1625
	if (server_tls_load_ocsp(dst) == -1) {
1626
		yyerror("failed to load ocsp staple "
1627
		    "for server %s", dst->srv_conf.name);
1628
		serverconfig_free(&dst->srv_conf);
1629
		free(dst);
1630
		return (NULL);
1631
	}
1632
1633
	/* Check if the new server already exists */
1634
	if (server_match(dst, 1) != NULL) {
1635
		yyerror("server \"%s\" defined twice",
1636
		    dst->srv_conf.name);
1637
		serverconfig_free(&dst->srv_conf);
1638
		free(dst);
1639
		return (NULL);
1640
	}
1641
1642
	/* Copy all the locations of the source server */
1643
	TAILQ_FOREACH(s, conf->sc_servers, srv_entry) {
1644
		if (!(s->srv_conf.flags & SRVFLAG_LOCATION &&
1645
		    s->srv_conf.parent_id == src->srv_conf.parent_id))
1646
			continue;
1647
1648
		if ((dstl = calloc(1, sizeof(*dstl))) == NULL)
1649
			fatal("out of memory");
1650
1651
		memcpy(&dstl->srv_conf, &s->srv_conf, sizeof(dstl->srv_conf));
1652
		strlcpy(dstl->srv_conf.name, alias->name,
1653
		    sizeof(dstl->srv_conf.name));
1654
1655
		/* Copy the new Id and listen address */
1656
		dstl->srv_conf.id = ++last_server_id;
1657
		dstl->srv_conf.parent_id = dst->srv_conf.id;
1658
		memcpy(&dstl->srv_conf.ss, &addr->ss,
1659
		    sizeof(dstl->srv_conf.ss));
1660
		dstl->srv_conf.port = addr->port;
1661
		dstl->srv_conf.prefixlen = addr->prefixlen;
1662
		dstl->srv_s = -1;
1663
1664
		DPRINTF("adding location \"%s\" for \"%s[%u]\"",
1665
		    dstl->srv_conf.location,
1666
		    dstl->srv_conf.name, dstl->srv_conf.id);
1667
1668
		TAILQ_INSERT_TAIL(conf->sc_servers, dstl, srv_entry);
1669
	}
1670
1671
	return (dst);
1672
}
1673
1674
int
1675
getservice(char *n)
1676
{
1677
	struct servent	*s;
1678
	const char	*errstr;
1679
	long long	 llval;
1680
1681
	llval = strtonum(n, 0, UINT16_MAX, &errstr);
1682
	if (errstr) {
1683
		s = getservbyname(n, "tcp");
1684
		if (s == NULL)
1685
			s = getservbyname(n, "udp");
1686
		if (s == NULL) {
1687
			yyerror("unknown port %s", n);
1688
			return (-1);
1689
		}
1690
		return (s->s_port);
1691
	}
1692
1693
	return (htons((unsigned short)llval));
1694
}
1695
1696
int
1697
is_if_in_group(const char *ifname, const char *groupname)
1698
{
1699
	unsigned int		 len;
1700
	struct ifgroupreq	 ifgr;
1701
	struct ifg_req		*ifg;
1702
	int			 s;
1703
	int			 ret = 0;
1704
1705
	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
1706
		err(1, "socket");
1707
1708
	memset(&ifgr, 0, sizeof(ifgr));
1709
	if (strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ) >= IFNAMSIZ)
1710
		err(1, "IFNAMSIZ");
1711
	if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) {
1712
		if (errno == EINVAL || errno == ENOTTY)
1713
			goto end;
1714
		err(1, "SIOCGIFGROUP");
1715
	}
1716
1717
	len = ifgr.ifgr_len;
1718
	ifgr.ifgr_groups = calloc(len / sizeof(struct ifg_req),
1719
	    sizeof(struct ifg_req));
1720
	if (ifgr.ifgr_groups == NULL)
1721
		err(1, "getifgroups");
1722
	if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifgr) == -1)
1723
		err(1, "SIOCGIFGROUP");
1724
1725
	ifg = ifgr.ifgr_groups;
1726
	for (; ifg && len >= sizeof(struct ifg_req); ifg++) {
1727
		len -= sizeof(struct ifg_req);
1728
		if (strcmp(ifg->ifgrq_group, groupname) == 0) {
1729
			ret = 1;
1730
			break;
1731
		}
1732
	}
1733
	free(ifgr.ifgr_groups);
1734
1735
end:
1736
	close(s);
1737
	return (ret);
1738
}
1739
#line 1732 "parse.c"
1740
288
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1741
144
static int yygrowstack(void)
1742
{
1743
    unsigned int newsize;
1744
    long sslen;
1745
    short *newss;
1746
144
    YYSTYPE *newvs;
1747
1748
    if ((newsize = yystacksize) == 0)
1749
        newsize = YYINITSTACKSIZE;
1750
    else if (newsize >= YYMAXDEPTH)
1751
        return -1;
1752

288
    else if ((newsize *= 2) > YYMAXDEPTH)
1753
        newsize = YYMAXDEPTH;
1754
288
    sslen = yyssp - yyss;
1755
144
#ifdef SIZE_MAX
1756
144
#define YY_SIZE_MAX SIZE_MAX
1757
#else
1758
144
#define YY_SIZE_MAX 0xffffffffU
1759
144
#endif
1760

288
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
1761
        goto bail;
1762
288
    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
1763
144
      (short *)malloc(newsize * sizeof *newss); /* overflow check above */
1764
144
    if (newss == NULL)
1765
        goto bail;
1766
144
    yyss = newss;
1767
144
    yyssp = newss + sslen;
1768
144
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
1769
144
        goto bail;
1770
144
    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
1771
      (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
1772
    if (newvs == NULL)
1773
        goto bail;
1774
    yyvs = newvs;
1775
    yyvsp = newvs + sslen;
1776
    yystacksize = newsize;
1777
    yysslim = yyss + newsize - 1;
1778
    return 0;
1779
bail:
1780
144
    if (yyss)
1781
            free(yyss);
1782
    if (yyvs)
1783
            free(yyvs);
1784
    yyss = yyssp = NULL;
1785
    yyvs = yyvsp = NULL;
1786
    yystacksize = 0;
1787
    return -1;
1788
}
1789
1790
#define YYABORT goto yyabort
1791
#define YYREJECT goto yyabort
1792
#define YYACCEPT goto yyaccept
1793
#define YYERROR goto yyerrlab
1794
int
1795
yyparse(void)
1796
{
1797
    int yym, yyn, yystate;
1798
#if YYDEBUG
1799
    const char *yys;
1800
1801
288
    if ((yys = getenv("YYDEBUG")))
1802
144
    {
1803
144
        yyn = *yys;
1804
        if (yyn >= '0' && yyn <= '9')
1805

288
            yydebug = yyn - '0';
1806
144
    }
1807
144
#endif /* YYDEBUG */
1808
144
1809
    yynerrs = 0;
1810
    yyerrflag = 0;
1811
6264
    yychar = (-1);
1812
3552
1813
    if (yyss == NULL && yygrowstack()) goto yyoverflow;
1814
2448
    yyssp = yyss;
1815
    yyvsp = yyvs;
1816
    *yyssp = yystate = 0;
1817
1818
yyloop:
1819
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1820
    if (yychar < 0)
1821
    {
1822
        if ((yychar = yylex()) < 0) yychar = 0;
1823
#if YYDEBUG
1824
        if (yydebug)
1825
2448
        {
1826

14208
            yys = 0;
1827
7104
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1828
            if (!yys) yys = "illegal-symbol";
1829
            printf("%sdebug: state %d, reading %d (%s)\n",
1830
                    YYPREFIX, yystate, yychar, yys);
1831
        }
1832
#endif
1833
    }
1834

3024
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1835
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1836
    {
1837
#if YYDEBUG
1838
3024
        if (yydebug)
1839
3024
            printf("%sdebug: state %d, shifting to state %d\n",
1840
3024
                    YYPREFIX, yystate, yytable[yyn]);
1841
3024
#endif
1842
        if (yyssp >= yysslim && yygrowstack())
1843
        {
1844

2112
            goto yyoverflow;
1845
1056
        }
1846
        *++yyssp = yystate = yytable[yyn];
1847
528
        *++yyvsp = yylval;
1848
528
        yychar = (-1);
1849
        if (yyerrflag > 0)  --yyerrflag;
1850
        goto yyloop;
1851
    }
1852
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1853
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1854
    {
1855
        yyn = yytable[yyn];
1856
        goto yyreduce;
1857
    }
1858
    if (yyerrflag) goto yyinrecovery;
1859
#if defined(__GNUC__)
1860
    goto yynewerror;
1861
#endif
1862
yynewerror:
1863
    yyerror("syntax error");
1864
#if defined(__GNUC__)
1865
    goto yyerrlab;
1866
#endif
1867
yyerrlab:
1868
    ++yynerrs;
1869
yyinrecovery:
1870
    if (yyerrflag < 3)
1871
    {
1872
        yyerrflag = 3;
1873
        for (;;)
1874
        {
1875
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1876
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1877
            {
1878
#if YYDEBUG
1879
                if (yydebug)
1880
                    printf("%sdebug: state %d, error recovery shifting\
1881
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1882
#endif
1883
                if (yyssp >= yysslim && yygrowstack())
1884
                {
1885
                    goto yyoverflow;
1886
                }
1887
                *++yyssp = yystate = yytable[yyn];
1888
                *++yyvsp = yylval;
1889
                goto yyloop;
1890
            }
1891
            else
1892
            {
1893
#if YYDEBUG
1894
                if (yydebug)
1895
                    printf("%sdebug: error recovery discarding state %d\n",
1896
                            YYPREFIX, *yyssp);
1897
#endif
1898
                if (yyssp <= yyss) goto yyabort;
1899
                --yyssp;
1900
                --yyvsp;
1901
            }
1902
        }
1903
    }
1904
    else
1905
    {
1906
        if (yychar == 0) goto yyabort;
1907
#if YYDEBUG
1908
        if (yydebug)
1909
        {
1910
            yys = 0;
1911
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1912
            if (!yys) yys = "illegal-symbol";
1913
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1914
                    YYPREFIX, yystate, yychar, yys);
1915
        }
1916
#endif
1917
        yychar = (-1);
1918
3240
        goto yyloop;
1919
3240
    }
1920
2424
yyreduce:
1921
#if YYDEBUG
1922
816
    if (yydebug)
1923




















4272
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1924
                YYPREFIX, yystate, yyn, yyrule[yyn]);
1925
#endif
1926
    yym = yylen[yyn];
1927
    if (yym)
1928
        yyval = yyvsp[1-yym];
1929
    else
1930
        memset(&yyval, 0, sizeof yyval);
1931
    switch (yyn)
1932
    {
1933
case 8:
1934
#line 155 "parse.y"
1935
{ file->errors++; }
1936
break;
1937
case 9:
1938
#line 158 "parse.y"
1939
{
1940
			struct file	*nfile;
1941
1942
			if ((nfile = pushfile(yyvsp[0].v.string, 0)) == NULL) {
1943
				yyerror("failed to include file %s", yyvsp[0].v.string);
1944
				free(yyvsp[0].v.string);
1945
				YYERROR;
1946
			}
1947
			free(yyvsp[0].v.string);
1948
1949
			file = nfile;
1950
			lungetc('\n');
1951
		}
1952
break;
1953
case 10:
1954
#line 173 "parse.y"
1955
{
1956
			char *s = yyvsp[-2].v.string;
1957
			while (*s++) {
1958
				if (isspace((unsigned char)*s)) {
1959
					yyerror("macro name cannot contain "
1960
					    "whitespace");
1961
					YYERROR;
1962
				}
1963
			}
1964
			if (symset(yyvsp[-2].v.string, yyvsp[0].v.string, 0) == -1)
1965
				fatal("cannot store variable");
1966
			free(yyvsp[-2].v.string);
1967
			free(yyvsp[0].v.string);
1968
		}
1969
break;
1970
case 11:
1971
#line 189 "parse.y"
1972
{ yyval.v.number = 0; }
1973
break;
1974
case 12:
1975
#line 190 "parse.y"
1976
{ yyval.v.number = 1; }
1977
break;
1978
case 13:
1979
#line 193 "parse.y"
1980
{
1981
			if (loadcfg)
1982
				break;
1983
			if (yyvsp[0].v.number <= 0 || yyvsp[0].v.number > PROC_MAX_INSTANCES) {
1984
				yyerror("invalid number of preforked "
1985
				    "servers: %lld", yyvsp[0].v.number);
1986
				YYERROR;
1987
			}
1988
			conf->sc_prefork_server = yyvsp[0].v.number;
1989
		}
1990
break;
1991
case 14:
1992
#line 203 "parse.y"
1993
{
1994
			conf->sc_chroot = yyvsp[0].v.string;
1995
		}
1996
break;
1997
case 15:
1998
#line 206 "parse.y"
1999
{
2000
			conf->sc_logdir = yyvsp[0].v.string;
2001
		}
2002
break;
2003
case 16:
2004
#line 209 "parse.y"
2005
{
2006
			memcpy(&conf->sc_default_type, &media,
2007
			    sizeof(struct media_type));
2008
		}
2009
break;
2010
case 17:
2011
#line 215 "parse.y"
2012
{
2013
			struct server	*s;
2014
2015
			if (!loadcfg) {
2016
				free(yyvsp[0].v.string);
2017
				YYACCEPT;
2018
			}
2019
2020
			if ((s = calloc(1, sizeof (*s))) == NULL)
2021
				fatal("out of memory");
2022
2023
			if (strlcpy(s->srv_conf.name, yyvsp[0].v.string,
2024
			    sizeof(s->srv_conf.name)) >=
2025
			    sizeof(s->srv_conf.name)) {
2026
				yyerror("server name truncated");
2027
				free(yyvsp[0].v.string);
2028
				free(s);
2029
				YYERROR;
2030
			}
2031
			free(yyvsp[0].v.string);
2032
2033
			strlcpy(s->srv_conf.root, HTTPD_DOCROOT,
2034
			    sizeof(s->srv_conf.root));
2035
			strlcpy(s->srv_conf.index, HTTPD_INDEX,
2036
			    sizeof(s->srv_conf.index));
2037
			strlcpy(s->srv_conf.accesslog, HTTPD_ACCESS_LOG,
2038
			    sizeof(s->srv_conf.accesslog));
2039
			strlcpy(s->srv_conf.errorlog, HTTPD_ERROR_LOG,
2040
			    sizeof(s->srv_conf.errorlog));
2041
			s->srv_conf.id = ++last_server_id;
2042
			s->srv_conf.parent_id = s->srv_conf.id;
2043
			s->srv_s = -1;
2044
			s->srv_conf.timeout.tv_sec = SERVER_TIMEOUT;
2045
			s->srv_conf.requesttimeout.tv_sec =
2046
			    SERVER_REQUESTTIMEOUT;
2047
			s->srv_conf.maxrequests = SERVER_MAXREQUESTS;
2048
			s->srv_conf.maxrequestbody = SERVER_MAXREQUESTBODY;
2049
			s->srv_conf.flags = SRVFLAG_LOG;
2050
			if (yyvsp[-1].v.number)
2051
				s->srv_conf.flags |= SRVFLAG_SERVER_MATCH;
2052
			s->srv_conf.logformat = LOG_FORMAT_COMMON;
2053
			s->srv_conf.tls_protocols = TLS_PROTOCOLS_DEFAULT;
2054
			if ((s->srv_conf.tls_cert_file =
2055
			    strdup(HTTPD_TLS_CERT)) == NULL)
2056
				fatal("out of memory");
2057
			if ((s->srv_conf.tls_key_file =
2058
			    strdup(HTTPD_TLS_KEY)) == NULL)
2059
				fatal("out of memory");
2060
			strlcpy(s->srv_conf.tls_ciphers,
2061
			    HTTPD_TLS_CIPHERS,
2062
			    sizeof(s->srv_conf.tls_ciphers));
2063
			strlcpy(s->srv_conf.tls_dhe_params,
2064
			    HTTPD_TLS_DHE_PARAMS,
2065
			    sizeof(s->srv_conf.tls_dhe_params));
2066
			strlcpy(s->srv_conf.tls_ecdhe_curves,
2067
			    HTTPD_TLS_ECDHE_CURVES,
2068
			    sizeof(s->srv_conf.tls_ecdhe_curves));
2069
2070
			s->srv_conf.hsts_max_age = SERVER_HSTS_DEFAULT_AGE;
2071
2072
			if (last_server_id == INT_MAX) {
2073
				yyerror("too many servers defined");
2074
				free(s);
2075
				YYERROR;
2076
			}
2077
			srv = s;
2078
			srv_conf = &srv->srv_conf;
2079
2080
			SPLAY_INIT(&srv->srv_clients);
2081
			TAILQ_INIT(&srv->srv_hosts);
2082
2083
			TAILQ_INSERT_TAIL(&srv->srv_hosts, srv_conf, entry);
2084
		}
2085
break;
2086
case 18:
2087
#line 287 "parse.y"
2088
{
2089
			struct server		*s, *sn;
2090
			struct server_config	*a, *b;
2091
2092
			srv_conf = &srv->srv_conf;
2093
2094
			/* Check if the new server already exists. */
2095
			if (server_match(srv, 1) != NULL) {
2096
				yyerror("server \"%s\" defined twice",
2097
				    srv->srv_conf.name);
2098
				serverconfig_free(srv_conf);
2099
				free(srv);
2100
				YYABORT;
2101
			}
2102
2103
			if (srv->srv_conf.ss.ss_family == AF_UNSPEC) {
2104
				yyerror("listen address not specified");
2105
				serverconfig_free(srv_conf);
2106
				free(srv);
2107
				YYERROR;
2108
			}
2109
2110
			if ((s = server_match(srv, 0)) != NULL) {
2111
				if ((s->srv_conf.flags & SRVFLAG_TLS) !=
2112
				    (srv->srv_conf.flags & SRVFLAG_TLS)) {
2113
					yyerror("server \"%s\": tls and "
2114
					    "non-tls on same address/port",
2115
					    srv->srv_conf.name);
2116
					serverconfig_free(srv_conf);
2117
					free(srv);
2118
					YYERROR;
2119
				}
2120
				if (server_tls_cmp(s, srv, 0) != 0) {
2121
					yyerror("server \"%s\": tls "
2122
					    "configuration mismatch on same "
2123
					    "address/port",
2124
					    srv->srv_conf.name);
2125
					serverconfig_free(srv_conf);
2126
					free(srv);
2127
					YYERROR;
2128
				}
2129
			}
2130
2131
			if ((srv->srv_conf.flags & SRVFLAG_TLS) &&
2132
			    srv->srv_conf.tls_protocols == 0) {
2133
				yyerror("server \"%s\": no tls protocols",
2134
				    srv->srv_conf.name);
2135
				serverconfig_free(srv_conf);
2136
				free(srv);
2137
				YYERROR;
2138
			}
2139
2140
			if (server_tls_load_keypair(srv) == -1) {
2141
				yyerror("server \"%s\": failed to load "
2142
				    "public/private keys", srv->srv_conf.name);
2143
				serverconfig_free(srv_conf);
2144
				free(srv);
2145
				YYERROR;
2146
			}
2147
2148
			if (server_tls_load_ocsp(srv) == -1) {
2149
				yyerror("server \"%s\": failed to load "
2150
				    "ocsp staple", srv->srv_conf.name);
2151
				serverconfig_free(srv_conf);
2152
				free(srv);
2153
				YYERROR;
2154
			}
2155
2156
			DPRINTF("adding server \"%s[%u]\"",
2157
			    srv->srv_conf.name, srv->srv_conf.id);
2158
2159
			TAILQ_INSERT_TAIL(conf->sc_servers, srv, srv_entry);
2160
2161
			/*
2162
			 * Add aliases and additional listen addresses as
2163
			 * individual servers.
2164
			 */
2165
			TAILQ_FOREACH(a, &srv->srv_hosts, entry) {
2166
				/* listen address */
2167
				if (a->ss.ss_family == AF_UNSPEC)
2168
					continue;
2169
				TAILQ_FOREACH(b, &srv->srv_hosts, entry) {
2170
					/* alias name */
2171
					if (*b->name == '\0' ||
2172
					    (b == &srv->srv_conf && b == a))
2173
						continue;
2174
2175
					if ((sn = server_inherit(srv,
2176
					    b, a)) == NULL) {
2177
						serverconfig_free(srv_conf);
2178
						free(srv);
2179
						YYABORT;
2180
					}
2181
2182
					DPRINTF("adding server \"%s[%u]\"",
2183
					    sn->srv_conf.name, sn->srv_conf.id);
2184
2185
					TAILQ_INSERT_TAIL(conf->sc_servers,
2186
					    sn, srv_entry);
2187
				}
2188
			}
2189
2190
			/* Remove temporary aliases */
2191
			TAILQ_FOREACH_SAFE(a, &srv->srv_hosts, entry, b) {
2192
				TAILQ_REMOVE(&srv->srv_hosts, a, entry);
2193
				if (a == &srv->srv_conf)
2194
					continue;
2195
				serverconfig_free(a);
2196
				free(a);
2197
			}
2198
2199
			srv = NULL;
2200
			srv_conf = NULL;
2201
		}
2202
break;
2203
case 21:
2204
#line 407 "parse.y"
2205
{
2206
			struct addresslist	 al;
2207
			struct address		*h;
2208
			struct server_config	*s_conf, *alias = NULL;
2209
2210
			if (parentsrv != NULL) {
2211
				yyerror("listen %s inside location", yyvsp[-2].v.string);
2212
				free(yyvsp[-2].v.string);
2213
				YYERROR;
2214
			}
2215
2216
			if (srv->srv_conf.ss.ss_family != AF_UNSPEC) {
2217
				if ((alias = calloc(1,
2218
				    sizeof(*alias))) == NULL)
2219
					fatal("out of memory");
2220
2221
				/* Add as an IP-based alias. */
2222
				s_conf = alias;
2223
			} else
2224
				s_conf = &srv->srv_conf;
2225
2226
			TAILQ_INIT(&al);
2227
			if (host(yyvsp[-2].v.string, &al, 1, &yyvsp[0].v.port, NULL, -1) <= 0) {
2228
				yyerror("invalid listen ip: %s", yyvsp[-2].v.string);
2229
				free(yyvsp[-2].v.string);
2230
				YYERROR;
2231
			}
2232
			free(yyvsp[-2].v.string);
2233
			h = TAILQ_FIRST(&al);
2234
			memcpy(&s_conf->ss, &h->ss, sizeof(s_conf->ss));
2235
			s_conf->port = h->port.val[0];
2236
			s_conf->prefixlen = h->prefixlen;
2237
			host_free(&al);
2238
2239
			if (yyvsp[-1].v.number)
2240
				s_conf->flags |= SRVFLAG_TLS;
2241
2242
			if (alias != NULL) {
2243
				/* IP-based; use name match flags from parent */
2244
				alias->flags &= ~SRVFLAG_SERVER_MATCH;
2245
				alias->flags |= srv->srv_conf.flags &
2246
				    SRVFLAG_SERVER_MATCH;
2247
				TAILQ_INSERT_TAIL(&srv->srv_hosts,
2248
				    alias, entry);
2249
			}
2250
		}
2251
break;
2252
case 22:
2253
#line 453 "parse.y"
2254
{
2255
			struct server_config	*alias;
2256
2257
			if (parentsrv != NULL) {
2258
				yyerror("alias inside location");
2259
				free(yyvsp[0].v.string);
2260
				YYERROR;
2261
			}
2262
2263
			if ((alias = calloc(1, sizeof(*alias))) == NULL)
2264
				fatal("out of memory");
2265
2266
			if (strlcpy(alias->name, yyvsp[0].v.string, sizeof(alias->name)) >=
2267
			    sizeof(alias->name)) {
2268
				yyerror("server alias truncated");
2269
				free(yyvsp[0].v.string);
2270
				free(alias);
2271
				YYERROR;
2272
			}
2273
			free(yyvsp[0].v.string);
2274
2275
			if (yyvsp[-1].v.number)
2276
				alias->flags |= SRVFLAG_SERVER_MATCH;
2277
2278
			TAILQ_INSERT_TAIL(&srv->srv_hosts, alias, entry);
2279
		}
2280
break;
2281
case 23:
2282
#line 479 "parse.y"
2283
{
2284
			if (parentsrv != NULL) {
2285
				yyerror("tcp flags inside location");
2286
				YYERROR;
2287
			}
2288
		}
2289
break;
2290
case 24:
2291
#line 485 "parse.y"
2292
{
2293
			if (parentsrv != NULL) {
2294
				yyerror("connection options inside location");
2295
				YYERROR;
2296
			}
2297
		}
2298
break;
2299
case 25:
2300
#line 491 "parse.y"
2301
{
2302
			struct server_config	*sc;
2303
			int			 tls_flag = 0;
2304
2305
			if (parentsrv != NULL) {
2306
				yyerror("tls configuration inside location");
2307
				YYERROR;
2308
			}
2309
2310
			/* Ensure that at least one server has TLS enabled. */
2311
			TAILQ_FOREACH(sc, &srv->srv_hosts, entry) {
2312
				tls_flag |= (sc->flags & SRVFLAG_TLS);
2313
			}
2314
			if (tls_flag == 0) {
2315
				yyerror("tls options without tls listener");
2316
				YYERROR;
2317
			}
2318
		}
2319
break;
2320
case 32:
2321
#line 515 "parse.y"
2322
{
2323
			struct server	*s;
2324
2325
			if (srv->srv_conf.ss.ss_family == AF_UNSPEC) {
2326
				yyerror("listen address not specified");
2327
				free(yyvsp[0].v.string);
2328
				YYERROR;
2329
			}
2330
2331
			if (parentsrv != NULL) {
2332
				yyerror("location %s inside location", yyvsp[0].v.string);
2333
				free(yyvsp[0].v.string);
2334
				YYERROR;
2335
			}
2336
2337
			if (!loadcfg) {
2338
				free(yyvsp[0].v.string);
2339
				YYACCEPT;
2340
			}
2341
2342
			if ((s = calloc(1, sizeof (*s))) == NULL)
2343
				fatal("out of memory");
2344
2345
			if (strlcpy(s->srv_conf.location, yyvsp[0].v.string,
2346
			    sizeof(s->srv_conf.location)) >=
2347
			    sizeof(s->srv_conf.location)) {
2348
				yyerror("server location truncated");
2349
				free(yyvsp[0].v.string);
2350
				free(s);
2351
				YYERROR;
2352
			}
2353
			free(yyvsp[0].v.string);
2354
2355
			if (strlcpy(s->srv_conf.name, srv->srv_conf.name,
2356
			    sizeof(s->srv_conf.name)) >=
2357
			    sizeof(s->srv_conf.name)) {
2358
				yyerror("server name truncated");
2359
				free(s);
2360
				YYERROR;
2361
			}
2362
2363
			s->srv_conf.id = ++last_server_id;
2364
			/* A location entry uses the parent id */
2365
			s->srv_conf.parent_id = srv->srv_conf.id;
2366
			s->srv_conf.flags = SRVFLAG_LOCATION;
2367
			if (yyvsp[-1].v.number)
2368
				s->srv_conf.flags |= SRVFLAG_LOCATION_MATCH;
2369
			s->srv_s = -1;
2370
			memcpy(&s->srv_conf.ss, &srv->srv_conf.ss,
2371
			    sizeof(s->srv_conf.ss));
2372
			s->srv_conf.port = srv->srv_conf.port;
2373
			s->srv_conf.prefixlen = srv->srv_conf.prefixlen;
2374
2375
			if (last_server_id == INT_MAX) {
2376
				yyerror("too many servers/locations defined");
2377
				free(s);
2378
				YYERROR;
2379
			}
2380
			parentsrv = srv;
2381
			srv = s;
2382
			srv_conf = &srv->srv_conf;
2383
			SPLAY_INIT(&srv->srv_clients);
2384
		}
2385
break;
2386
case 33:
2387
#line 577 "parse.y"
2388
{
2389
			struct server	*s = NULL;
2390
2391
			TAILQ_FOREACH(s, conf->sc_servers, srv_entry) {
2392
				if ((s->srv_conf.flags & SRVFLAG_LOCATION) &&
2393
				    s->srv_conf.id == srv_conf->id &&
2394
				    strcmp(s->srv_conf.location,
2395
				    srv_conf->location) == 0)
2396
					break;
2397
			}
2398
			if (s != NULL) {
2399
				yyerror("location \"%s\" defined twice",
2400
				    srv->srv_conf.location);
2401
				serverconfig_free(srv_conf);
2402
				free(srv);
2403
				YYABORT;
2404
			}
2405
2406
			DPRINTF("adding location \"%s\" for \"%s[%u]\"",
2407
			    srv->srv_conf.location,
2408
			    srv->srv_conf.name, srv->srv_conf.id);
2409
2410
			TAILQ_INSERT_TAIL(conf->sc_servers, srv, srv_entry);
2411
2412
			srv = parentsrv;
2413
			srv_conf = &parentsrv->srv_conf;
2414
			parentsrv = NULL;
2415
		}
2416
break;
2417
case 34:
2418
#line 605 "parse.y"
2419
{
2420
			srv_conf->flags |= SRVFLAG_DEFAULT_TYPE;
2421
			memcpy(&srv_conf->default_type, &media,
2422
			    sizeof(struct media_type));
2423
		}
2424
break;
2425
case 36:
2426
#line 611 "parse.y"
2427
{
2428
			if (parentsrv != NULL) {
2429
				yyerror("hsts inside location");
2430
				YYERROR;
2431
			}
2432
			srv->srv_conf.flags |= SRVFLAG_SERVER_HSTS;
2433
		}
2434
break;
2435
case 42:
2436
#line 629 "parse.y"
2437
{
2438
			if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > INT_MAX) {
2439
				yyerror("invalid number of seconds: %lld", yyvsp[0].v.number);
2440
				YYERROR;
2441
			}
2442
			srv_conf->hsts_max_age = yyvsp[0].v.number;
2443
		}
2444
break;
2445
case 43:
2446
#line 636 "parse.y"
2447
{
2448
			srv->srv_conf.hsts_flags |= HSTSFLAG_SUBDOMAINS;
2449
		}
2450
break;
2451
case 44:
2452
#line 639 "parse.y"
2453
{
2454
			srv->srv_conf.hsts_flags |= HSTSFLAG_PRELOAD;
2455
		}
2456
break;
2457
case 45:
2458
#line 644 "parse.y"
2459
{
2460
			srv_conf->flags &= ~SRVFLAG_FCGI;
2461
			srv_conf->flags |= SRVFLAG_NO_FCGI;
2462
		}
2463
break;
2464
case 46:
2465
#line 648 "parse.y"
2466
{
2467
			srv_conf->flags &= ~SRVFLAG_NO_FCGI;
2468
			srv_conf->flags |= SRVFLAG_FCGI;
2469
		}
2470
break;
2471
case 47:
2472
#line 652 "parse.y"
2473
{
2474
			srv_conf->flags &= ~SRVFLAG_NO_FCGI;
2475
			srv_conf->flags |= SRVFLAG_FCGI;
2476
		}
2477
break;
2478
case 49:
2479
#line 656 "parse.y"
2480
{
2481
			srv_conf->flags &= ~SRVFLAG_NO_FCGI;
2482
			srv_conf->flags |= SRVFLAG_FCGI;
2483
		}
2484
break;
2485
case 53:
2486
#line 666 "parse.y"
2487
{
2488
			if (strlcpy(srv_conf->socket, yyvsp[0].v.string,
2489
			    sizeof(srv_conf->socket)) >=
2490
			    sizeof(srv_conf->socket)) {
2491
				yyerror("fastcgi socket too long");
2492
				free(yyvsp[0].v.string);
2493
				YYERROR;
2494
			}
2495
			free(yyvsp[0].v.string);
2496
			srv_conf->flags |= SRVFLAG_SOCKET;
2497
		}
2498
break;
2499
case 58:
2500
#line 687 "parse.y"
2501
{
2502
			memcpy(&srv_conf->timeout, &yyvsp[0].v.tv,
2503
			    sizeof(struct timeval));
2504
		}
2505
break;
2506
case 59:
2507
#line 691 "parse.y"
2508
{
2509
			memcpy(&srv_conf->requesttimeout, &yyvsp[0].v.tv,
2510
			    sizeof(struct timeval));
2511
		}
2512
break;
2513
case 60:
2514
#line 695 "parse.y"
2515
{
2516
			srv_conf->maxrequests = yyvsp[0].v.number;
2517
		}
2518
break;
2519
case 61:
2520
#line 698 "parse.y"
2521
{
2522
			srv_conf->maxrequestbody = yyvsp[0].v.number;
2523
		}
2524
break;
2525
case 66:
2526
#line 711 "parse.y"
2527
{
2528
			free(srv_conf->tls_cert_file);
2529
			if ((srv_conf->tls_cert_file = strdup(yyvsp[0].v.string)) == NULL)
2530
				fatal("out of memory");
2531
			free(yyvsp[0].v.string);
2532
		}
2533
break;
2534
case 67:
2535
#line 717 "parse.y"
2536
{
2537
			free(srv_conf->tls_key_file);
2538
			if ((srv_conf->tls_key_file = strdup(yyvsp[0].v.string)) == NULL)
2539
				fatal("out of memory");
2540
			free(yyvsp[0].v.string);
2541
		}
2542
break;
2543
case 68:
2544
#line 723 "parse.y"
2545
{
2546
			free(srv_conf->tls_ocsp_staple_file);
2547
			if ((srv_conf->tls_ocsp_staple_file = strdup(yyvsp[0].v.string))
2548
			    == NULL)
2549
				fatal("out of memory");
2550
			free(yyvsp[0].v.string);
2551
		}
2552
break;
2553
case 69:
2554
#line 730 "parse.y"
2555
{
2556
			if (strlcpy(srv_conf->tls_ciphers, yyvsp[0].v.string,
2557
			    sizeof(srv_conf->tls_ciphers)) >=
2558
			    sizeof(srv_conf->tls_ciphers)) {
2559
				yyerror("ciphers too long");
2560
				free(yyvsp[0].v.string);
2561
				YYERROR;
2562
			}
2563
			free(yyvsp[0].v.string);
2564
		}
2565
break;
2566
case 70:
2567
#line 740 "parse.y"
2568
{
2569
			if (strlcpy(srv_conf->tls_dhe_params, yyvsp[0].v.string,
2570
			    sizeof(srv_conf->tls_dhe_params)) >=
2571
			    sizeof(srv_conf->tls_dhe_params)) {
2572
				yyerror("dhe too long");
2573
				free(yyvsp[0].v.string);
2574
				YYERROR;
2575
			}
2576
			free(yyvsp[0].v.string);
2577
		}
2578
break;
2579
case 71:
2580
#line 750 "parse.y"
2581
{
2582
			if (strlcpy(srv_conf->tls_ecdhe_curves, yyvsp[0].v.string,
2583
			    sizeof(srv_conf->tls_ecdhe_curves)) >=
2584
			    sizeof(srv_conf->tls_ecdhe_curves)) {
2585
				yyerror("ecdhe too long");
2586
				free(yyvsp[0].v.string);
2587
				YYERROR;
2588
			}
2589
			free(yyvsp[0].v.string);
2590
		}
2591
break;
2592
case 72:
2593
#line 760 "parse.y"
2594
{
2595
			if (tls_config_parse_protocols(
2596
			    &srv_conf->tls_protocols, yyvsp[0].v.string) != 0) {
2597
				yyerror("invalid tls protocols");
2598
				free(yyvsp[0].v.string);
2599
				YYERROR;
2600
			}
2601
			free(yyvsp[0].v.string);
2602
		}
2603
break;
2604
case 73:
2605
#line 769 "parse.y"
2606
{
2607
			srv_conf->tls_ticket_lifetime = SERVER_DEF_TLS_LIFETIME;
2608
		}
2609
break;
2610
case 74:
2611
#line 772 "parse.y"
2612
{
2613
			if (yyvsp[0].v.number != 0 && yyvsp[0].v.number < SERVER_MIN_TLS_LIFETIME) {
2614
				yyerror("ticket lifetime too small");
2615
				YYERROR;
2616
			}
2617
			if (yyvsp[0].v.number > SERVER_MAX_TLS_LIFETIME) {
2618
				yyerror("ticket lifetime too large");
2619
				YYERROR;
2620
			}
2621
			srv_conf->tls_ticket_lifetime = yyvsp[0].v.number;
2622
		}
2623
break;
2624
case 75:
2625
#line 783 "parse.y"
2626
{
2627
			srv_conf->tls_ticket_lifetime = 0;
2628
		}
2629
break;
2630
case 80:
2631
#line 796 "parse.y"
2632
{
2633
			if (strlcpy(srv->srv_conf.root, yyvsp[0].v.string,
2634
			    sizeof(srv->srv_conf.root)) >=
2635
			    sizeof(srv->srv_conf.root)) {
2636
				yyerror("document root too long");
2637
				free(yyvsp[0].v.string);
2638
				YYERROR;
2639
			}
2640
			free(yyvsp[0].v.string);
2641
			srv->srv_conf.flags |= SRVFLAG_ROOT;
2642
		}
2643
break;
2644
case 81:
2645
#line 807 "parse.y"
2646
{
2647
			if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > INT_MAX) {
2648
				yyerror("invalid strip number");
2649
				YYERROR;
2650
			}
2651
			srv->srv_conf.strip = yyvsp[0].v.number;
2652
		}
2653
break;
2654
case 82:
2655
#line 816 "parse.y"
2656
{
2657
			srv->srv_conf.flags |= SRVFLAG_NO_AUTH;
2658
		}
2659
break;
2660
case 83:
2661
#line 819 "parse.y"
2662
{
2663
			struct auth	*auth;
2664
2665
			if ((auth = auth_add(conf->sc_auth, &yyvsp[0].v.auth)) == NULL) {
2666
				yyerror("failed to add auth");
2667
				YYERROR;
2668
			}
2669
2670
			if (auth->auth_id == 0) {
2671
				/* New htpasswd, get new Id */
2672
				auth->auth_id = ++last_auth_id;
2673
				if (last_auth_id == INT_MAX) {
2674
					yyerror("too many auth ids defined");
2675
					auth_free(conf->sc_auth, auth);
2676
					YYERROR;
2677
				}
2678
			}
2679
2680
			srv->srv_conf.auth_id = auth->auth_id;
2681
			srv->srv_conf.flags |= SRVFLAG_AUTH;
2682
		}
2683
break;
2684
case 84:
2685
#line 842 "parse.y"
2686
{
2687
			if (strlcpy(srv->srv_conf.auth_realm, yyvsp[-2].v.string,
2688
			    sizeof(srv->srv_conf.auth_realm)) >=
2689
			    sizeof(srv->srv_conf.auth_realm)) {
2690
				yyerror("basic auth realm name too long");
2691
				free(yyvsp[-2].v.string);
2692
				YYERROR;
2693
			}
2694
			free(yyvsp[-2].v.string);
2695
			if (strlcpy(yyval.v.auth.auth_htpasswd, yyvsp[0].v.string,
2696
			    sizeof(yyval.v.auth.auth_htpasswd)) >=
2697
			    sizeof(yyval.v.auth.auth_htpasswd)) {
2698
				yyerror("password file name too long");
2699
				free(yyvsp[0].v.string);
2700
				YYERROR;
2701
			}
2702
			free(yyvsp[0].v.string);
2703
2704
		}
2705
break;
2706
case 85:
2707
#line 861 "parse.y"
2708
{
2709
			if (strlcpy(yyval.v.auth.auth_htpasswd, yyvsp[0].v.string,
2710
			    sizeof(yyval.v.auth.auth_htpasswd)) >=
2711
			    sizeof(yyval.v.auth.auth_htpasswd)) {
2712
				yyerror("password file name too long");
2713
				free(yyvsp[0].v.string);
2714
				YYERROR;
2715
			}
2716
			free(yyvsp[0].v.string);
2717
		}
2718
break;
2719
case 90:
2720
#line 880 "parse.y"
2721
{
2722
			if (strlcpy(srv_conf->index, yyvsp[0].v.string,
2723
			    sizeof(srv_conf->index)) >=
2724
			    sizeof(srv_conf->index)) {
2725
				yyerror("index file too long");
2726
				free(yyvsp[0].v.string);
2727
				YYERROR;
2728
			}
2729
			srv_conf->flags &= ~SRVFLAG_NO_INDEX;
2730
			srv_conf->flags |= SRVFLAG_INDEX;
2731
			free(yyvsp[0].v.string);
2732
		}
2733
break;
2734
case 91:
2735
#line 892 "parse.y"
2736
{
2737
			srv_conf->flags &= ~SRVFLAG_INDEX;
2738
			srv_conf->flags |= SRVFLAG_NO_INDEX;
2739
		}
2740
break;
2741
case 92:
2742
#line 896 "parse.y"
2743
{
2744
			srv_conf->flags &= ~SRVFLAG_NO_AUTO_INDEX;
2745
			srv_conf->flags |= SRVFLAG_AUTO_INDEX;
2746
		}
2747
break;
2748
case 93:
2749
#line 900 "parse.y"
2750
{
2751
			srv_conf->flags &= ~SRVFLAG_AUTO_INDEX;
2752
			srv_conf->flags |= SRVFLAG_NO_AUTO_INDEX;
2753
		}
2754
break;
2755
case 96:
2756
#line 909 "parse.y"
2757
{
2758
			srv_conf->flags &= ~SRVFLAG_LOG;
2759
			srv_conf->flags |= SRVFLAG_NO_LOG;
2760
		}
2761
break;
2762
case 100:
2763
#line 920 "parse.y"
2764
{
2765
			srv_conf->flags &= ~SRVFLAG_NO_SYSLOG;
2766
			srv_conf->flags |= SRVFLAG_SYSLOG;
2767
		}
2768
break;
2769
case 101:
2770
#line 924 "parse.y"
2771
{
2772
			srv_conf->flags &= ~SRVFLAG_SYSLOG;
2773
			srv_conf->flags |= SRVFLAG_NO_SYSLOG;
2774
		}
2775
break;
2776
case 102:
2777
#line 928 "parse.y"
2778
{
2779
			if (strlcpy(srv_conf->accesslog, yyvsp[0].v.string,
2780
			    sizeof(srv_conf->accesslog)) >=
2781
			    sizeof(srv_conf->accesslog)) {
2782
				yyerror("access log name too long");
2783
				free(yyvsp[0].v.string);
2784
				YYERROR;
2785
			}
2786
			free(yyvsp[0].v.string);
2787
			srv_conf->flags |= SRVFLAG_ACCESS_LOG;
2788
		}
2789
break;
2790
case 103:
2791
#line 939 "parse.y"
2792
{
2793
			if (strlcpy(srv_conf->errorlog, yyvsp[0].v.string,
2794
			    sizeof(srv_conf->errorlog)) >=
2795
			    sizeof(srv_conf->errorlog)) {
2796
				yyerror("error log name too long");
2797
				free(yyvsp[0].v.string);
2798
				YYERROR;
2799
			}
2800
			free(yyvsp[0].v.string);
2801
			srv_conf->flags |= SRVFLAG_ERROR_LOG;
2802
		}
2803
break;
2804
case 104:
2805
#line 952 "parse.y"
2806
{
2807
			srv_conf->flags &= ~SRVFLAG_NO_LOG;
2808
			srv_conf->flags |= SRVFLAG_LOG;
2809
			srv_conf->logformat = LOG_FORMAT_COMMON;
2810
		}
2811
break;
2812
case 105:
2813
#line 957 "parse.y"
2814
{
2815
			srv_conf->flags &= ~SRVFLAG_NO_LOG;
2816
			srv_conf->flags |= SRVFLAG_LOG;
2817
			srv_conf->logformat = LOG_FORMAT_COMBINED;
2818
		}
2819
break;
2820
case 106:
2821
#line 962 "parse.y"
2822
{
2823
			srv_conf->flags &= ~SRVFLAG_NO_LOG;
2824
			srv_conf->flags |= SRVFLAG_LOG;
2825
			srv_conf->logformat = LOG_FORMAT_CONNECTION;
2826
		}
2827
break;
2828
case 107:
2829
#line 969 "parse.y"
2830
{
2831
			if (yyvsp[-1].v.number <= 0 || server_httperror_byid(yyvsp[-1].v.number) == NULL) {
2832
				yyerror("invalid return code: %lld", yyvsp[-1].v.number);
2833
				free(yyvsp[0].v.string);
2834
				YYERROR;
2835
			}
2836
			srv_conf->return_code = yyvsp[-1].v.number;
2837
2838
			if (yyvsp[0].v.string != NULL) {
2839
				/* Only for 3xx redirection headers */
2840
				if (yyvsp[-1].v.number < 300 || yyvsp[-1].v.number > 399) {
2841
					yyerror("invalid return code for "
2842
					    "location URI");
2843
					free(yyvsp[0].v.string);
2844
					YYERROR;
2845
				}
2846
				srv_conf->return_uri = yyvsp[0].v.string;
2847
				srv_conf->return_uri_len = strlen(yyvsp[0].v.string) + 1;
2848
			}
2849
		}
2850
break;
2851
case 108:
2852
#line 989 "parse.y"
2853
{
2854
			/* No return code, silently drop the connection */
2855
			srv_conf->return_code = 0;
2856
		}
2857
break;
2858
case 109:
2859
#line 993 "parse.y"
2860
{
2861
			/* Forbidden */
2862
			srv_conf->return_code = 403;
2863
		}
2864
break;
2865
case 110:
2866
#line 997 "parse.y"
2867
{
2868
			srv_conf->flags &= ~SRVFLAG_BLOCK;
2869
			srv_conf->flags |= SRVFLAG_NO_BLOCK;
2870
		}
2871
break;
2872
case 111:
2873
#line 1003 "parse.y"
2874
{
2875
			srv_conf->flags &= ~SRVFLAG_NO_BLOCK;
2876
			srv_conf->flags |= SRVFLAG_BLOCK;
2877
		}
2878
break;
2879
case 112:
2880
#line 1009 "parse.y"
2881
{ yyval.v.number = 0; }
2882
break;
2883
case 113:
2884
#line 1010 "parse.y"
2885
{ yyval.v.number = 1; }
2886
break;
2887
case 114:
2888
#line 1013 "parse.y"
2889
{ yyval.v.string = NULL; }
2890
break;
2891
case 115:
2892
#line 1014 "parse.y"
2893
{ yyval.v.string = yyvsp[0].v.string; }
2894
break;
2895
case 120:
2896
#line 1025 "parse.y"
2897
{ srv_conf->tcpflags |= TCPFLAG_SACK; }
2898
break;
2899
case 121:
2900
#line 1026 "parse.y"
2901
{ srv_conf->tcpflags |= TCPFLAG_NSACK; }
2902
break;
2903
case 122:
2904
#line 1027 "parse.y"
2905
{
2906
			srv_conf->tcpflags |= TCPFLAG_NODELAY;
2907
		}
2908
break;
2909
case 123:
2910
#line 1030 "parse.y"
2911
{
2912
			srv_conf->tcpflags |= TCPFLAG_NNODELAY;
2913
		}
2914
break;
2915
case 124:
2916
#line 1033 "parse.y"
2917
{
2918
			if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > SERVER_MAX_CLIENTS) {
2919
				yyerror("invalid backlog: %lld", yyvsp[0].v.number);
2920
				YYERROR;
2921
			}
2922
			srv_conf->tcpbacklog = yyvsp[0].v.number;
2923
		}
2924
break;
2925
case 125:
2926
#line 1040 "parse.y"
2927
{
2928
			srv_conf->tcpflags |= TCPFLAG_BUFSIZ;
2929
			if ((srv_conf->tcpbufsiz = yyvsp[0].v.number) < 0) {
2930
				yyerror("invalid socket buffer size: %lld", yyvsp[0].v.number);
2931
				YYERROR;
2932
			}
2933
		}
2934
break;
2935
case 126:
2936
#line 1047 "parse.y"
2937
{
2938
			if (yyvsp[0].v.number < 0) {
2939
				yyerror("invalid ttl: %lld", yyvsp[0].v.number);
2940
				free(yyvsp[-1].v.string);
2941
				YYERROR;
2942
			}
2943
			if (strcasecmp("ttl", yyvsp[-1].v.string) == 0) {
2944
				srv_conf->tcpflags |= TCPFLAG_IPTTL;
2945
				srv_conf->tcpipttl = yyvsp[0].v.number;
2946
			} else if (strcasecmp("minttl", yyvsp[-1].v.string) == 0) {
2947
				srv_conf->tcpflags |= TCPFLAG_IPMINTTL;
2948
				srv_conf->tcpipminttl = yyvsp[0].v.number;
2949
			} else {
2950
				yyerror("invalid TCP/IP flag: %s", yyvsp[-1].v.string);
2951
				free(yyvsp[-1].v.string);
2952
				YYERROR;
2953
			}
2954
			free(yyvsp[-1].v.string);
2955
		}
2956
break;
2957
case 132:
2958
#line 1079 "parse.y"
2959
{
2960
			if (strlcpy(media.media_type, yyvsp[-2].v.string,
2961
			    sizeof(media.media_type)) >=
2962
			    sizeof(media.media_type) ||
2963
			    strlcpy(media.media_subtype, yyvsp[0].v.string,
2964
			    sizeof(media.media_subtype)) >=
2965
			    sizeof(media.media_subtype)) {
2966
				yyerror("media type too long");
2967
				free(yyvsp[-2].v.string);
2968
				free(yyvsp[0].v.string);
2969
				YYERROR;
2970
			}
2971
			free(yyvsp[-2].v.string);
2972
			free(yyvsp[0].v.string);
2973
		}
2974
break;
2975
case 135:
2976
#line 1100 "parse.y"
2977
{
2978
			if (strlcpy(media.media_name, yyvsp[0].v.string,
2979
			    sizeof(media.media_name)) >=
2980
			    sizeof(media.media_name)) {
2981
				yyerror("media name too long");
2982
				free(yyvsp[0].v.string);
2983
				YYERROR;
2984
			}
2985
			free(yyvsp[0].v.string);
2986
2987
			if (!loadcfg)
2988
				break;
2989
2990
			if (media_add(conf->sc_mediatypes, &media) == NULL) {
2991
				yyerror("failed to add media type");
2992
				YYERROR;
2993
			}
2994
		}
2995
break;
2996
case 136:
2997
#line 1120 "parse.y"
2998
{
2999
			if (yyvsp[0].v.number <= 0 || yyvsp[0].v.number > (int)USHRT_MAX) {
3000
				yyerror("invalid port: %lld", yyvsp[0].v.number);
3001
				YYERROR;
3002
			}
3003
			yyval.v.port.val[0] = htons(yyvsp[0].v.number);
3004
		}
3005
break;
3006
case 137:
3007
#line 1127 "parse.y"
3008
{
3009
			int	 val;
3010
3011
			if ((val = getservice(yyvsp[0].v.string)) == -1) {
3012
				yyerror("invalid port: %s", yyvsp[0].v.string);
3013
				free(yyvsp[0].v.string);
3014
				YYERROR;
3015
			}
3016
			free(yyvsp[0].v.string);
3017
3018
			yyval.v.port.val[0] = val;
3019
		}
3020
break;
3021
case 138:
3022
#line 1142 "parse.y"
3023
{
3024
			if (yyvsp[0].v.number < 0) {
3025
				yyerror("invalid timeout: %lld", yyvsp[0].v.number);
3026
				YYERROR;
3027
			}
3028
			yyval.v.tv.tv_sec = yyvsp[0].v.number;
3029
			yyval.v.tv.tv_usec = 0;
3030
		}
3031
break;
3032
case 139:
3033
#line 1152 "parse.y"
3034
{
3035
			char *s;
3036
			if (asprintf(&s, "%lld", yyvsp[0].v.number) == -1) {
3037
3168
				yyerror("asprintf: number");
3038
3168
				YYERROR;
3039
3168
			}
3040
3168
			yyval.v.string = s;
3041
3168
		}
3042
break;
3043
#line 3036 "parse.c"
3044
    }
3045
    yyssp -= yym;
3046
    yystate = *yyssp;
3047
    yyvsp -= yym;
3048
    yym = yylhs[yyn];
3049
648
    if (yystate == 0 && yym == 0)
3050
648
    {
3051
648
#if YYDEBUG
3052
        if (yydebug)
3053
648
            printf("%sdebug: after reduction, shifting from state 0 to\
3054
 state %d\n", YYPREFIX, YYFINAL);
3055
#endif
3056
        yystate = YYFINAL;
3057
        *++yyssp = YYFINAL;
3058
        *++yyvsp = yyval;
3059
        if (yychar < 0)
3060
        {
3061
            if ((yychar = yylex()) < 0) yychar = 0;
3062
#if YYDEBUG
3063
            if (yydebug)
3064
648
            {
3065
648
                yys = 0;
3066
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
3067
                if (!yys) yys = "illegal-symbol";
3068

7056
                printf("%sdebug: state %d, reading %d (%s)\n",
3069
3000
                        YYPREFIX, YYFINAL, yychar, yys);
3070
1056
            }
3071
#endif
3072
1464
        }
3073
        if (yychar == 0) goto yyaccept;
3074
        goto yyloop;
3075
    }
3076
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
3077
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
3078

2520
        yystate = yytable[yyn];
3079
    else
3080
        yystate = yydgoto[yym];
3081
#if YYDEBUG
3082
2520
    if (yydebug)
3083
2520
        printf("%sdebug: after reduction, shifting from state %d \
3084
2520
to state %d\n", YYPREFIX, *yyssp, yystate);
3085
#endif
3086
    if (yyssp >= yysslim && yygrowstack())
3087
    {
3088
        goto yyoverflow;
3089
    }
3090
    *++yyssp = yystate;
3091
    *++yyvsp = yyval;
3092
    goto yyloop;
3093
yyoverflow:
3094
    yyerror("yacc stack overflow");
3095
yyabort:
3096
    if (yyss)
3097
144
            free(yyss);
3098
144
    if (yyvs)
3099
144
            free(yyvs);
3100
144
    yyss = yyssp = NULL;
3101
144
    yyvs = yyvsp = NULL;
3102
144
    yystacksize = 0;
3103
144
    return (1);
3104
144
yyaccept:
3105
144
    if (yyss)
3106
            free(yyss);
3107
    if (yyvs)
3108
            free(yyvs);
3109
    yyss = yyssp = NULL;
3110
    yyvs = yyvsp = NULL;
3111
    yystacksize = 0;
3112
    return (0);
3113
}